Skip to content

Commit 1987528

Browse files
committed
refactor: mp模块统一accountId未初始化值为-1,删除QueryParams定义
1 parent 036c9b3 commit 1987528

File tree

11 files changed

+42
-83
lines changed

11 files changed

+42
-83
lines changed

src/api/mp/account/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import request from '@/config/axios'
22

33
export interface AccountVO {
4-
id?: number
4+
id: number
55
name: string
66
}
77

src/views/mp/autoReply/index.vue

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,22 +103,18 @@ import ReplyTable from './components/ReplyTable.vue'
103103
import { MsgType } from './components/types'
104104
const message = useMessage() // 消息
105105
106+
const accountId = ref(-1) // 公众号ID
106107
const msgType = ref<MsgType>(MsgType.Keyword) // 消息类型
107108
const RequestMessageTypes = ['text', 'image', 'voice', 'video', 'shortvideo', 'location', 'link'] // 允许选择的请求消息类型
108109
const loading = ref(true) // 遮罩层
109110
const total = ref(0) // 总条数
110111
const list = ref<any[]>([]) // 自动回复列表
111112
const formRef = ref<FormInstance | null>(null) // 表单 ref
112113
// 查询参数
113-
interface QueryParams {
114-
pageNo: number
115-
pageSize: number
116-
accountId: number
117-
}
118-
const queryParams: QueryParams = reactive({
114+
const queryParams = reactive({
119115
pageNo: 1,
120116
pageSize: 10,
121-
accountId: 0
117+
accountId: accountId
122118
})
123119
124120
const dialogTitle = ref('') // 弹出层标题
@@ -127,7 +123,7 @@ const replyForm = ref<any>({}) // 表单参数
127123
// 回复消息
128124
const reply = ref<Reply>({
129125
type: ReplyType.Text,
130-
accountId: 0
126+
accountId: -1
131127
})
132128
// 表单校验
133129
const rules = {
@@ -137,8 +133,9 @@ const rules = {
137133
138134
/** 侦听账号变化 */
139135
const onAccountChanged = (id: number) => {
140-
queryParams.accountId = id
136+
accountId.value = id
141137
reply.value.accountId = id
138+
queryParams.pageNo = 1
142139
getList()
143140
}
144141

src/views/mp/components/wx-account-select/main.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@
88
import * as MpAccountApi from '@/api/mp/account'
99
1010
const account: MpAccountApi.AccountVO = reactive({
11-
id: undefined,
11+
id: -1,
1212
name: ''
1313
})
14-
const accountList: Ref<MpAccountApi.AccountVO[]> = ref([])
14+
15+
const accountList = ref<MpAccountApi.AccountVO[]>([])
1516
1617
const emit = defineEmits<{
17-
(e: 'change', id: number, name: string): void
18+
(e: 'change', id: number, name: string)
1819
}>()
1920
2021
const handleQuery = async () => {

src/views/mp/draft/index.vue

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,14 @@ import {
7676
7777
const message = useMessage() // 消息
7878
79-
const accountId = ref<number>(-1)
79+
const accountId = ref(-1)
8080
provide('accountId', accountId)
8181
8282
const loading = ref(true) // 列表的加载中
8383
const list = ref<any[]>([]) // 列表的数据
8484
const total = ref(0) // 列表的总页数
85-
interface QueryParams {
86-
pageNo: number
87-
pageSize: number
88-
accountId: number
89-
}
90-
const queryParams: QueryParams = reactive({
85+
86+
const queryParams = reactive({
9187
pageNo: 1,
9288
pageSize: 10,
9389
accountId: accountId
@@ -102,7 +98,8 @@ const isSubmitting = ref(false)
10298
10399
/** 侦听公众号变化 **/
104100
const onAccountChanged = (id: number) => {
105-
setAccountId(id)
101+
accountId.value = id
102+
queryParams.pageNo = 1
106103
getList()
107104
}
108105
@@ -115,12 +112,6 @@ const onBeforeDialogClose = async (onDone: () => {}) => {
115112
}
116113
117114
// ======================== 列表查询 ========================
118-
/** 设置账号编号 */
119-
const setAccountId = (id: number) => {
120-
accountId.value = id
121-
// queryParams.accountId = id
122-
}
123-
124115
/** 查询列表 */
125116
const getList = async () => {
126117
loading.value = true
@@ -161,10 +152,10 @@ const onSubmitNewsItem = async () => {
161152
isSubmitting.value = true
162153
try {
163154
if (isCreating.value) {
164-
await MpDraftApi.createDraft(queryParams.accountId, newsList.value)
155+
await MpDraftApi.createDraft(accountId.value, newsList.value)
165156
message.notifySuccess('新增成功')
166157
} else {
167-
await MpDraftApi.updateDraft(queryParams.accountId, mediaId.value, newsList.value)
158+
await MpDraftApi.updateDraft(accountId.value, mediaId.value, newsList.value)
168159
message.notifySuccess('更新成功')
169160
}
170161
} finally {
@@ -176,27 +167,25 @@ const onSubmitNewsItem = async () => {
176167
177168
// ======================== 草稿箱发布 ========================
178169
const onPublish = async (item: Article) => {
179-
const accountId = queryParams.accountId
180170
const mediaId = item.mediaId
181171
const content =
182172
'你正在通过发布的方式发表内容。 发布不占用群发次数,一天可多次发布。' +
183173
'已发布内容不会推送给用户,也不会展示在公众号主页中。 ' +
184174
'发布后,你可以前往发表记录获取链接,也可以将发布内容添加到自定义菜单、自动回复、话题和页面模板中。'
185175
try {
186176
await message.confirm(content)
187-
await MpFreePublishApi.submitFreePublish(accountId, mediaId)
177+
await MpFreePublishApi.submitFreePublish(accountId.value, mediaId)
188178
message.notifySuccess('发布成功')
189179
await getList()
190180
} catch {}
191181
}
192182
193183
/** 删除按钮操作 */
194184
const onDelete = async (item: Article) => {
195-
const accountId = queryParams.accountId
196185
const mediaId = item.mediaId
197186
try {
198187
await message.confirm('此操作将永久删除该草稿, 是否继续?')
199-
await MpDraftApi.deleteDraft(accountId, mediaId)
188+
await MpDraftApi.deleteDraft(accountId.value, mediaId)
200189
message.notifySuccess('删除成功')
201190
await getList()
202191
} catch {}

src/views/mp/freePublish/index.vue

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,16 @@ const loading = ref(true) // 列表的加载中
5959
const total = ref(0) // 列表的总页数
6060
const list = ref<any[]>([]) // 列表的数据
6161
62-
interface QueryParams {
63-
pageNo: number
64-
pageSize: number
65-
accountId: number
66-
}
67-
const queryParams: QueryParams = reactive({
62+
const queryParams = reactive({
6863
pageNo: 1,
6964
pageSize: 10,
70-
accountId: 0
65+
accountId: -1
7166
})
7267
7368
/** 侦听公众号变化 **/
7469
const onAccountChanged = (id: number) => {
7570
queryParams.accountId = id
71+
queryParams.pageNo = 1
7672
getList()
7773
}
7874

src/views/mp/material/index.vue

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,23 +100,18 @@ const loading = ref(false) // 遮罩层
100100
const list = ref<any[]>([]) // 总条数
101101
const total = ref(0) // 数据列表
102102
// 查询参数
103-
interface QueryParams {
104-
pageNo: number
105-
pageSize: number
106-
accountId: number
107-
permanent: boolean
108-
}
109-
const queryParams: QueryParams = reactive({
103+
const queryParams = reactive({
110104
pageNo: 1,
111105
pageSize: 10,
112-
accountId: 0,
106+
accountId: -1,
113107
permanent: true
114108
})
115109
const showCreateVideo = ref(false) // 是否新建视频的弹窗
116110
117111
/** 侦听公众号变化 **/
118112
const onAccountChanged = (id: number) => {
119113
queryParams.accountId = id
114+
queryParams.pageNo = 1
120115
getList()
121116
}
122117

src/views/mp/menu/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ const MENU_NOT_SELECTED = '__MENU_NOT_SELECTED__'
6565
6666
// ======================== 列表查询 ========================
6767
const loading = ref(false) // 遮罩层
68-
const accountId = ref<number>(0)
68+
const accountId = ref(-1)
6969
const accountName = ref<string>('')
7070
const menuList = ref<Menu[]>([])
7171

src/views/mp/message/index.vue

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -93,20 +93,12 @@ const total = ref(0) // 数据的总页数
9393
const list = ref<any[]>([]) // 当前页的列表数据
9494
9595
// 搜索参数
96-
interface QueryParams {
97-
pageNo: number
98-
pageSize: number
99-
openid: string | undefined
100-
accountId: number
101-
type: MsgType | undefined
102-
createTime: string[] | []
103-
}
104-
const queryParams: QueryParams = reactive({
96+
const queryParams = reactive({
10597
pageNo: 1,
10698
pageSize: 10,
107-
openid: undefined,
108-
accountId: 0,
109-
type: undefined,
99+
openid: '',
100+
accountId: -1,
101+
type: MsgType.Text,
110102
createTime: []
111103
})
112104
const queryFormRef = ref<FormInstance | null>(null) // 搜索的表单
@@ -120,6 +112,7 @@ const messageBox = reactive({
120112
/** 侦听accountId */
121113
const onAccountChanged = (id: number) => {
122114
queryParams.accountId = id
115+
queryParams.pageNo = 1
123116
handleQuery()
124117
}
125118

src/views/mp/statistics/index.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ const dateRange = ref([
8484
beginOfDay(new Date(new Date().getTime() - 3600 * 1000 * 24 * 7)),
8585
endOfDay(new Date(new Date().getTime() - 3600 * 1000 * 24))
8686
])
87-
const accountId = ref() // 选中的公众号编号
87+
const accountId = ref(-1) // 选中的公众号编号
8888
const accountList = ref<MpAccountApi.AccountVO[]>([]) // 公众号账号列表
8989
9090
const xAxisDate = ref([] as any[]) // X 轴的日期范围
@@ -232,7 +232,7 @@ const getAccountList = async () => {
232232
accountList.value = await MpAccountApi.getSimpleAccountList()
233233
// 默认选中第一个
234234
if (accountList.value.length > 0) {
235-
accountId.value = accountList.value[0].id
235+
accountId.value = accountList.value[0].id!
236236
}
237237
}
238238

src/views/mp/tag/index.vue

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,23 +95,18 @@ const loading = ref(true) // 列表的加载中
9595
const total = ref(0) // 列表的总页数
9696
const list = ref<any[]>([]) // 列表的数据
9797
98-
interface QueryParams {
99-
pageNo: number
100-
pageSize: number
101-
accountId: number
102-
}
103-
const queryParams: QueryParams = reactive({
98+
const queryParams = reactive({
10499
pageNo: 1,
105100
pageSize: 10,
106-
accountId: 0
101+
accountId: -1
107102
})
108103
109104
const formRef = ref<InstanceType<typeof TagForm> | null>(null)
110105
111106
/** 侦听公众号变化 **/
112107
const onAccountChanged = (id: number) => {
113-
queryParams.pageNo = 1
114108
queryParams.accountId = id
109+
queryParams.pageNo = 1
115110
getList()
116111
}
117112

0 commit comments

Comments
 (0)