2
2
<doc-alert title =" 公众号菜单" url =" https://doc.iocoder.cn/mp/menu/" />
3
3
<!-- 搜索工作栏 -->
4
4
<ContentWrap >
5
- <el-form class =" -mb-15px" ref =" queryFormRef" :inline =" true" label-width =" 68px" >
6
- <el-form-item label =" 公众号" prop =" accountId" >
7
- <el-select v-model =" accountId" placeholder =" 请选择公众号" class =" !w-240px" >
8
- <el-option
9
- v-for =" item in accountList"
10
- :key =" item.id"
11
- :label =" item.name"
12
- :value =" item.id"
13
- />
14
- </el-select >
15
- </el-form-item >
16
- <el-form-item >
17
- <el-button @click =" handleQuery" ><Icon icon =" ep:search" />搜索</el-button >
18
- <el-button @click =" resetQuery" ><Icon icon =" ep:refresh" />重置</el-button >
19
- </el-form-item >
20
- </el-form >
5
+ <WxAccountSelect @change =" (accountId) => accountChanged(accountId)" />
21
6
</ContentWrap >
22
7
23
8
<!-- 列表 -->
@@ -204,17 +189,15 @@ import { handleTree } from '@/utils/tree'
204
189
import WxReplySelect from ' @/views/mp/components/wx-reply/main.vue'
205
190
import WxNews from ' @/views/mp/components/wx-news/main.vue'
206
191
import WxMaterialSelect from ' @/views/mp/components/wx-material-select/main.vue'
207
- import { deleteMenu , getMenuList , saveMenu } from ' @/api /mp/menu '
208
- import * as MpAccountApi from ' @/api/mp/account '
192
+ import WxAccountSelect from ' @/views /mp/components/wx-account-select/main.vue '
193
+ import * as MpMenuApi from ' @/api/mp/menu '
209
194
import menuOptions from ' ./menuOptions'
210
195
const message = useMessage () // 消息
211
196
212
197
// ======================== 列表查询 ========================
213
198
const loading = ref (true ) // 遮罩层
214
199
const accountId = ref (undefined ) // 公众号Id
215
- const name = ref (' ' ) // 公众号名
216
200
const menuList = ref ({ children: [] })
217
- const accountList = ref ([]) // 公众号账号列表
218
201
219
202
// ======================== 菜单操作 ========================
220
203
const isActive = ref (- 1 ) // 一级菜单点中样式
@@ -228,60 +211,34 @@ const showConfigureContent = ref(true) // 是否展示配置内容;如果有
228
211
const hackResetWxReplySelect = ref (false ) // 重置 WxReplySelect 组件
229
212
const tempObj = ref ({}) // 右边临时变量,作为中间值牵引关系
230
213
231
- const tempSelfObj = ref ({
232
- // 一些临时值放在这里进行判断,如果放在 tempObj,由于引用关系,menu 也会多了多余的参数
233
- })
214
+ // 一些临时值放在这里进行判断,如果放在 tempObj,由于引用关系,menu 也会多了多余的参数
215
+ const tempSelfObj = ref ({})
234
216
const dialogNewsVisible = ref (false ) // 跳转图文时的素材选择弹窗
235
217
236
- onMounted (async () => {
237
- accountList .value = await MpAccountApi .getSimpleAccountList ()
238
- // 选中第一个
239
- if (accountList .value .length > 0 ) {
240
- // @ts-ignore
241
- setAccountId (accountList .value [0 ].id )
242
- }
243
- await getList ()
244
- })
245
-
246
- // ======================== 列表查询 ========================
247
- /** 设置账号编号 */
248
- const setAccountId = (id ) => {
218
+ /** 侦听公众号变化 **/
219
+ const accountChanged = (accountId ) => {
249
220
accountId .value = id
250
- name . value = accountList . value . find (( item ) => item . id === accountId . value ) ? . name
221
+ getList ()
251
222
}
252
223
224
+ /** 查询并转换菜单 **/
253
225
const getList = async () => {
254
226
loading .value = false
255
- getMenuList (accountId .value )
256
- .then ((response ) => {
257
- const menuData = convertMenuList (response)
258
- menuList .value = handleTree (menuData, ' id' )
259
- })
260
- .finally (() => {
261
- loading .value = false
262
- })
227
+ try {
228
+ const data = await MpMenuApi .getMenuList (accountId .value )
229
+ const menuData = convertMenuList (data)
230
+ menuList .value = handleTree (menuData, ' id' )
231
+ } finally {
232
+ loading .value = false
233
+ }
263
234
}
264
235
265
236
/** 搜索按钮操作 */
266
237
const handleQuery = () => {
267
238
resetForm ()
268
- // 默认选中第一个
269
- if (accountId .value ) {
270
- setAccountId (accountId .value )
271
- }
272
239
getList ()
273
240
}
274
241
275
- /** 重置按钮操作 */
276
- const resetQuery = () => {
277
- resetForm ()
278
- // 默认选中第一个
279
- if (accountList .value .length > 0 ) {
280
- setAccountId (accountList .value [0 ].id )
281
- }
282
- handleQuery ()
283
- }
284
-
285
242
// 将后端返回的 menuList,转换成前端的 menuList
286
243
const convertMenuList = (list ) => {
287
244
if (! list) return []
@@ -443,7 +400,7 @@ const handleSave = async () => {
443
400
try {
444
401
await message .confirm (' 确定要删除吗?' )
445
402
loading .value = true
446
- await saveMenu (accountId .value , convertMenuFormList ())
403
+ await MpMenuApi . saveMenu (accountId .value , convertMenuFormList ())
447
404
getList ()
448
405
message .notifySuccess (' 发布成功' )
449
406
} finally {
@@ -464,7 +421,7 @@ const handleDelete = async () => {
464
421
try {
465
422
await message .confirm (' 确定要删除吗?' )
466
423
loading .value = true
467
- await deleteMenu (accountId .value )
424
+ await MpMenuApi . deleteMenu (accountId .value )
468
425
handleQuery ()
469
426
message .notifySuccess (' 清空成功' )
470
427
} finally {
@@ -546,6 +503,7 @@ const deleteMaterial = () => {
546
503
delete tempObj .value [' replyArticles' ]
547
504
}
548
505
</script >
506
+
549
507
<!-- 本组件样式-->
550
508
<style lang="scss" scoped="scoped">
551
509
/* 公共颜色变量 */
0 commit comments