Skip to content

Commit 0885f3f

Browse files
committed
mp:menu 前端接入菜单的保存、清空操作
1 parent 8454a38 commit 0885f3f

File tree

2 files changed

+51
-42
lines changed

2 files changed

+51
-42
lines changed

src/api/mp/menu.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,23 @@ export function getMenuList(accountId) {
77
method: 'get',
88
})
99
}
10+
11+
// 保存公众号菜单
12+
export function saveMenu(accountId, menus) {
13+
return request({
14+
url: '/mp/menu/save',
15+
method: 'post',
16+
data: {
17+
accountId,
18+
menus
19+
}
20+
})
21+
}
22+
23+
// 删除公众号菜单
24+
export function deleteMenu(accountId) {
25+
return request({
26+
url: '/mp/menu/delete?accountId=' + accountId,
27+
method: 'delete',
28+
})
29+
}

src/views/mp/menu/index.vue

Lines changed: 31 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ SOFTWARE.
6363
<div class="menu_bottom menu_addicon" v-if="this.menuList.length < 3" @click="addMenu"><i class="el-icon-plus"></i></div>
6464
</div>
6565
<div class="save_div">
66-
<!--<el-button class="save_btn" type="warning" size="small" @click="saveFun">保存菜单</el-button>-->
67-
<el-button class="save_btn" type="success" size="small" @click="handleSaveAndReleaseFun">保存并发布菜单</el-button>
66+
<el-button class="save_btn" type="success" size="small" @click="handleSave">保存并发布菜单</el-button>
67+
<el-button class="save_btn" type="danger" size="small" @click="handleDelete">清空菜单</el-button>
6868
</div>
6969
</div>
7070
<!--右边配置-->
@@ -141,7 +141,7 @@ SOFTWARE.
141141
import WxReplySelect from '@/views/mp/components/wx-news/main.vue'
142142
import WxNews from '@/views/mp/components/wx-news/main.vue';
143143
import WxMaterialSelect from '@/views/mp/components/wx-news/main.vue'
144-
import { getMenuList } from "@/api/mp/menu";
144+
import {deleteMenu, getMenuList, saveMenu} from "@/api/mp/menu";
145145
import { getSimpleAccounts } from "@/api/mp/account";
146146
147147
export default {
@@ -164,11 +164,6 @@ export default {
164164
children: [],
165165
},
166166
167-
menu:{ // 横向菜单
168-
button:[
169-
]
170-
},
171-
172167
// ======================== 菜单操作 ========================
173168
isActive: -1,// 一级菜单点中样式
174169
isSubMenuActive: -1, // 一级菜单点中样式
@@ -178,7 +173,7 @@ export default {
178173
showRightFlag: false, // 右边配置显示默认详情还是配置详情
179174
nameMaxLength: 0, // 菜单名称最大长度;1 级是 4 字符;2 级是 7 字符;
180175
showConfigureContent: true, // 是否展示配置内容;如果有子菜单,就不显示配置内容
181-
176+
hackResetWxReplySelect: false, // 重置 WxReplySelect 组件
182177
183178
tempObj:{}, // 右边临时变量,作为中间值牵引关系
184179
tempSelfObj: { // 一些临时值放在这里进行判断,如果放在 tempObj,由于引用关系,menu 也会多了多余的参数
@@ -218,7 +213,6 @@ export default {
218213
label: '选择地理位置'
219214
}],
220215
dialogNewsVisible: false,
221-
hackResetWxReplySelect: false,
222216
223217
// 公众号账号列表
224218
accounts: [],
@@ -246,7 +240,6 @@ export default {
246240
this.loading = false;
247241
getMenuList(this.accountId).then(response => {
248242
this.menuList = this.handleTree(response.data, "id");
249-
console.log(this.menuList)
250243
}).finally(() => {
251244
this.loading = false;
252245
})
@@ -354,31 +347,16 @@ export default {
354347
},
355348
356349
// ======================== 菜单编辑 ========================
357-
handleSaveAndReleaseFun(){
358-
this.$confirm('确定要保证并发布该菜单吗?', '提示', {
359-
confirmButtonText: '确定',
360-
cancelButtonText: '取消',
361-
type: 'warning'
362-
}).then(() => {
350+
handleSave() {
351+
this.$modal.confirm('确定要保证并发布该菜单吗?').then(() => {
363352
this.loading = true
364-
saveAndRelease({
365-
strWxMenu:this.menu
366-
}).then(response => {
367-
this.loading = false
368-
if(response.code == 200){
369-
this.$message({
370-
showClose: true,
371-
message: '发布成功',
372-
type: 'success'
373-
})
374-
}else{
375-
this.$message.error(response.data.msg)
376-
}
377-
}).catch(() => {
378-
this.loading = false
379-
})
380-
}).catch(() => {
381-
})
353+
return saveMenu(this.accountId, this.menuList);
354+
}).then(() => {
355+
this.getList();
356+
this.$modal.msgSuccess("发布成功");
357+
}).catch(() => {}).finally(() => {
358+
this.loading = false
359+
});
382360
},
383361
// 表单 Editor 重置
384362
resetEditor() {
@@ -387,6 +365,17 @@ export default {
387365
this.hackResetEditor = true // 重建组件
388366
})
389367
},
368+
handleDelete() {
369+
this.$modal.confirm('确定要清空所有菜单吗?').then(() => {
370+
this.loading = true
371+
return deleteMenu(this.accountId);
372+
}).then(() => {
373+
this.getList();
374+
this.$modal.msgSuccess("清空成功");
375+
}).catch(() => {}).finally(() => {
376+
this.loading = false
377+
});
378+
},
390379
391380
// TODO 芋艿:未归类
392381
@@ -431,7 +420,7 @@ div{
431420
left:0px;
432421
width: 300px;
433422
height:64px;
434-
background: transparent url(assets/menu_head.png) no-repeat 0 0;
423+
background: transparent url("assets/menu_head.png") no-repeat 0 0;
435424
background-position: 0 0;
436425
background-size: 100%
437426
}
@@ -445,7 +434,7 @@ div{
445434
left: 0px;
446435
}
447436
.weixin-menu{
448-
background: transparent url(assets/menu_foot.png) no-repeat 0 0;
437+
background: transparent url("assets/menu_foot.png") no-repeat 0 0;
449438
padding-left: 43px;
450439
font-size: 12px
451440
}
@@ -581,26 +570,26 @@ div{
581570
<!--</style>-->
582571
<!--素材样式-->
583572
<style lang="scss" scoped>
584-
.pagination{
573+
.pagination {
585574
text-align: right;
586575
margin-right: 25px;
587576
}
588-
.select-item{
577+
.select-item {
589578
width: 280px;
590579
padding: 10px;
591580
margin: 0 auto 10px auto;
592581
border: 1px solid #eaeaea;
593582
}
594-
.select-item2{
583+
.select-item2 {
595584
padding: 10px;
596585
margin: 0 auto 10px auto;
597586
border: 1px solid #eaeaea;
598587
}
599-
.ope-row{
588+
.ope-row {
600589
padding-top: 10px;
601590
text-align: center;
602591
}
603-
.item-name{
592+
.item-name {
604593
font-size: 12px;
605594
overflow: hidden;
606595
text-overflow:ellipsis;

0 commit comments

Comments
 (0)