index.vue
18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
<!-- -->
<template>
<div class="userStyleMenus">
<!-- 搜索 -->
<FixedNav class="formSearch" :height="200">
<div class="searchInput">
<span>菜单名:</span>
<el-input v-model="formInline.permissionName" placeholder="请输入菜单名" />
</div>
<el-button style="background-color: #3F9B6A;color: #fff;" @click="search">查询</el-button>
<el-button class="buttonHover"
style="color: #606266;border: 1px solid #dddfe5;background-color: #fff;" @click="clear">重置</el-button>
<el-button style="background-color: #3F9B6A;color: #fff;" @click="add(1)">新增父级目录</el-button>
<el-button style="background-color: #3F9B6A;color: #fff;" @click="add(2)">新增子级菜单</el-button>
<el-button style="background-color: #3F9B6A;color: #fff;" @click="add(3)">新增子级按钮</el-button>
<el-button style="background-color: #3F9B6A;color: #fff;" @click="syncMenu()">同步菜单</el-button>
</FixedNav>
<!-- 表 格 default-expand-all -->
<div class="tableBox">
<el-table
ref="menuList"
:data="tableData"
style=" margin-bottom: 20px"
row-key="permissionId"
:header-cell-style="{fontSize: '14px',color:'#0009',fontWeight: 'normal',backgroundColor:'#F2F3F5'}"
:tree-props="{ children: 'childs', hasChildren: 'hasChildren' }"
@select="select"
@select-all="selectAll"
@selection-change="handleSelectionChange"
>
<el-table-column type="selection" width="55" />
<el-table-column prop="permissionName" label="菜单名称" />
<el-table-column label="图标">
<template slot-scope="scope">
<div>
<i :class="scope.row.icon" />
</div>
</template>
</el-table-column>
<el-table-column prop="permission" label="菜单标识" />
<el-table-column prop="createTime" label="创建时间" />
<el-table-column label="操作" show-overflow-tooltip>
<template slot-scope="scope">
<div class="btnList">
<div class="tableBtn greens" @click="edit(scope.row)">编辑</div>
<div class="tableBtn greens" @click="del(scope.row)">删除</div>
</div>
</template>
</el-table-column>
</el-table>
<div class="fenye">
<el-pagination
:current-page="currentPage"
:page-sizes="[10, 20, 50, 100]"
:page-size="10"
layout="total, sizes, prev, pager, next, jumper"
:total="total"
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
/>
</div>
</div>
<!-- *************对话框开始************* -->
<el-dialog
:title="userState ? '新增菜单' : '修改菜单'"
:visible.sync="addFormDialog"
width="30%"
center
:close-on-click-modal="false"
>
<!-- 新增角色 -->
<div>
<el-form ref="ruleForm" :model="addForm" label-width="80px" :rules="userRules">
<el-form-item label="父节点ID">
<el-input v-model="addForm.permissionPid" :disabled="true" placeholder="请输入角色名称" />
</el-form-item>
<el-form-item label="菜单名称" prop="permissionName">
<el-input v-model="addForm.permissionName" placeholder="请输入菜单名称" />
</el-form-item>
<el-form-item label="菜单路径" prop="permission">
<el-input v-model="addForm.permission" placeholder="请输入菜单路径" />
</el-form-item>
<el-form-item label="图标地址" prop="icon">
<el-input
v-model="addForm.icon"
:prefix-icon="addForm.icon"
placeholder="请输入图片地址"
@focus="getFocus"
/>
</el-form-item>
<el-form-item label="菜单描述">
<el-input v-model="addForm.describe" placeholder="请输入菜单描述" />
</el-form-item>
<el-form-item label="排序值" prop="sort">
<el-input v-model="addForm.sort" type="number" placeholder="请输入排序值" />
</el-form-item>
<el-form-item label="权限类型" prop="resourceType">
<el-select v-model="addForm.resourceType" placeholder="请选择活动区域">
<el-option label="菜单" value="menu" />
<el-option label="按钮" value="button" />
<el-option label="目录" value="catalog" />
</el-select>
</el-form-item>
</el-form>
</div>
<span slot="footer" class="dialog-footer">
<el-button @click="addFormDialog = false" class="buttonHover"
style="color: #606266;border: 1px solid #dddfe5;background-color: #fff;">取 消</el-button>
<el-button style="background-color: #3F9B6A;color: #fff;" @click="addForm_enter('ruleForm')">确 定</el-button>
</span>
</el-dialog>
<!-- *************同步菜单对话框开始************* -->
<el-dialog
:title="'同步菜单'"
:visible.sync="syncMenuDialog"
width="30%"
center
:close-on-click-modal="false"
>
<!-- 新增角色 -->
<div>
<el-form ref="syncMenuForm" :model="syncMenuForm" label-width="80px" :rules="syncMenuRules">
<el-form-item label="同步范围" prop="syncAll">
<el-radio-group v-model="syncMenuForm.syncAll">
<el-radio :label="true">同步所有</el-radio>
<el-radio :label="false">同步指定商家</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="删除菜单">
<el-checkbox v-model="syncMenuForm.delMenu" />
</el-form-item>
<el-form-item v-if="syncMenuForm.syncAll==false" label="商家账号">
<el-input v-model="syncMenuForm.syncBusinessUsername" placeholder="请输入商家账号" />
</el-form-item>
</el-form>
</div>
<span slot="footer" class="dialog-footer">
<el-button @click="syncMenuDialog = false" class="buttonHover"
style="color: #606266;border: 1px solid #dddfe5;background-color: #fff;">取 消</el-button>
<el-button style="background-color: #3F9B6A;color: #fff;" :loading="loading" @click="submitSyncMenu('syncMenuForm')">确 定</el-button>
</span>
</el-dialog>
<Icons :dialog-visible="iconVisible" @choose="chooseIcon" @close="iconVisible = false" />
</div>
</template>
<script>
import {
businessTabsGetAll,
businessTabsAdd,
businessTabsGetById,
businessTabsUpdate,
businessTabsDelete,
businessGetMaxSort,
businessSyncMenu
} from '@/api/setup'
import Icons from './Icons'
import { Message } from 'element-ui'
import FixedNav from '@/components/FixedNav/index.vue'
export default {
// import引入的组件需要注入到对象中才能使用
components: {
Icons,
FixedNav
},
data () {
// 这里存放数据
return {
formInline: {
permissionName: '', // 搜索字段
page: '1', // 当前页
pageSize: '10' // 每页记录数
},
total: 1,
tableData: [],
currentPage: 1,
userState: 1,
addForm: {
permissionPid: '', // 父节点id
permissionName: '', // 权限名称
permissionUri: '', // URI
permission: '', // 组件
icon: '', // 图标地址
describe: '', // 描述
resourceType: 'menu', // 权限类型 menu-菜单 button-按钮 catalog-目录
sort: '' // 排序值
},
syncMenuForm: {
syncAll: false,
syncBusinessUsername: '',
delMenu: false
},
addFormDialog: false,
syncMenuDialog: false,
userRules: {
permissionName: [
{ required: true, message: '请输入权限名称', trigger: 'blur' }
],
permission: [
{ required: true, message: '请输入菜单路径', trigger: 'blur' }
],
resourceType: [
{ required: true, message: '请选择活动区域', trigger: 'change' }
],
sort: [{ required: true, message: '请输入菜单路径', trigger: 'blur' }],
icon: [{ required: true, message: '请输入图标地址', trigger: 'blur' }]
},
syncMenuRules: {},
iconVisible: false,
multipleSelection: [],
loading: false
}
},
mounted () {
this.getAll(this.formInline)
},
// 方法集合
methods: {
handleSelectionChange (val) {
// console.dir(this.$refs.menuList.selection)
// const sel = this.extract(val)
this.multipleSelection = val
// console.dir(this.$refs.menuList)
},
setChildren (children, type) {
// 编辑多个子层级
children.map(j => {
this.toggleSelection(j, type)
if (j.childs) {
this.setChildren(j.childs, type)
}
})
},
// 选中父节点时,子节点一起选中取消
select (selection, row) {
if (selection.some(el => { return row.permissionId === el.permissionId })) {
if (row.childs) {
// row.childList.map(j => {
// this.toggleSelection(j, true)
// })
// 解决子组件没有被勾选到
this.setChildren(row.childs, true)
}
} else {
if (row.childs) {
// row.childList.map(j => {
// this.toggleSelection(j, false)
// })
this.setChildren(row.childs, false)
}
}
},
toggleSelection (row, select) {
if (row) {
this.$nextTick(() => {
this.$refs.menuList && this.$refs.menuList.toggleRowSelection(row, select)
})
}
},
// 选择全部
selectAll (selection) {
// tabledata第一层只要有在selection里面就是全选
const isSelect = selection.some(el => {
const tableDataIds = this.tableData.map(j => j.permissionId)
return tableDataIds.includes(el.permissionId)
})
// tableDate第一层只要有不在selection里面就是全不选
const isCancel = !this.tableData.every(el => {
const selectIds = selection.map(j => j.permissionId)
return selectIds.includes(el.permissionId)
})
console.log(isSelect, 'isSelect')
if (isSelect) {
selection.map(el => {
if (el.childs) {
// el.childList.map(j => {
// this.toggleSelection(j, true)
// })
// 解决子组件没有被勾选到
this.setChildren(el.childs, true)
}
})
}
if (isCancel) {
this.tableData.map(el => {
if (el.childs) {
// el.childList.map(j => {
// this.toggleSelection(j, false)
// })
// 解决子组件没有被勾选到
this.setChildren(el.childs, false)
}
})
}
this.$emit('handleSelect', this.tableData)
},
handleSizeChange (val) {
this.formInline.pageSize = val
this.getAll(this.formInline)
},
handleCurrentChange (val) {
this.formInline.page = val
this.getAll(this.formInline)
},
// 查询
search () {
this.total = 1
this.formInline.page = 1
this.getAll(this.formInline)
},
// 清除
clear () {
this.formInline = {
permissionName: '', // 搜索字段
page: '1', // 当前页
pageSize: '10' // 每页记录数
}
this.getAll(this.formInline)
},
// 新增角色
add (index) {
this.userState = 1
businessGetMaxSort().then(res => {
if (index === 1) {
if (this.multipleSelection.length >= 1) {
this.$message({
message: '请勿选择节点进行操作'
})
return
}
this.addForm = {
permissionPid: '', // 父节点id
permissionName: '', // 权限名称
permissionUri: '', // URI
permission: '', // 组件
icon: '', // 图标地址
describe: '', // 描述
resourceType: 'catalog', // 权限类型 menu-菜单 button-按钮 catalog-目录
sort: parseInt(res.data) // 排序值
}
this.addFormDialog = true
} else if (index === 2) {
if (this.multipleSelection.length === 0) {
this.$message({
message: '请选择父节点'
})
return
}
if (this.multipleSelection[0].permissionPid !== 0) {
this.$message({
message: '请选择父节点进行操作'
})
return
}
this.addForm = {
permissionPid: this.multipleSelection[0].permissionId, // 父节点id
permissionName: '', // 权限名称
permissionUri: '', // URI
permission: '', // 组件
icon: '', // 图标地址
describe: '', // 描述
resourceType: 'menu', // 权限类型 menu-菜单 button-按钮 catalog-目录
sort: parseInt(res.data) // 排序值
}
this.addFormDialog = true
} else if (index === 3) {
if (this.multipleSelection.length === 0) {
this.$message({
message: '请选择子节点'
})
return
}
if (
this.multipleSelection[0].permissionPid === 0 &&
this.multipleSelection[0].childs.length !== 0
) {
this.$message({
message: '请勿选择父节点进行操作'
})
return
}
this.addForm = {
permissionPid: this.multipleSelection[0].permissionId, // 父节点id
permissionName: '', // 权限名称
permissionUri: '', // URI
permission: '', // 组件
icon: 'el-icon-minus', // 图标地址
describe: '', // 描述
resourceType: 'button', // 权限类型 menu-菜单 button-按钮 catalog-目录
sort: parseInt(res.data) // 排序值
}
this.addFormDialog = true
}
})
},
syncMenu () {
if (this.multipleSelection.length === 0) {
this.$message({
message: '请选择要同步的节点'
})
return
}
this.syncMenuForm.syncAll = true
this.syncMenuForm.syncBusinessUsername = ''
this.syncMenuForm.delMenu = false
this.syncMenuDialog = true
},
submitSyncMenu (syncMenuForm) {
const that = this
this.$refs[syncMenuForm].validate(valid => {
if (valid) {
if (that.syncMenuForm.syncAll === false && that.syncMenuForm.syncBusinessUsername === '') {
this.$message({
message: '请输入要同步的商家账号'
})
return
}
this.loading = true
businessSyncMenu(Object.assign({}, this.syncMenuForm, { syncMenu: this.multipleSelection })).then(res => {
if (res.code === '') {
this.$message({
message: '同步成功',
type: 'success'
})
}
this.loading = false
this.syncMenuDialog = false
}).catch(error => {
if (error && error.message.includes('timeout')) {
Message({
message: '后台正在异步处理,请关注商家端菜单变化',
type: 'error',
duration: 2 * 1000
})
}
this.loading = false
this.syncMenuDialog = false
})
}
})
},
// 确认新增角色
addForm_enter (ruleForm) {
this.$refs[ruleForm].validate(valid => {
if (valid) {
if (this.userState) {
businessTabsAdd(this.addForm).then(res => {
if (res.code === '') {
this.$message({
message: '新增成功',
type: 'success'
})
}
this.getAll(this.formInline)
this.addFormDialog = false
})
} else {
businessTabsUpdate(this.addForm).then(res => {
if (res.code === '') {
this.$message({
message: '修改成功',
type: 'success'
})
}
this.getAll(this.formInline)
this.addFormDialog = false
})
}
} else {
console.log('error submit!!')
return false
}
})
},
// 编辑角色
edit (row) {
this.userState = 0
this.addFormDialog = true
businessTabsGetById({ permissionId: row.permissionId }).then(res => {
this.addForm = res.data
// this.addForm.roleIds = [1];
})
},
// 删除角色
async del (row) {
const res = await businessTabsDelete({ permissionId: row.permissionId })
if (res.code === '') {
this.$message({
message: '删除成功',
type: 'success'
})
}
this.getAll(this.formInline)
},
// 组件传回值
chooseIcon (icon) {
this.addForm.icon = icon
this.iconVisible = false
},
getFocus () {
this.iconVisible = true
},
// 初始化查询所有数据
async getAll (formInline) {
const res = await businessTabsGetAll(formInline)
this.tableData = res.data.list
this.total = res.data.total
}
}
}
</script>
<style lang='scss' scoped>
//@import url(); 引入公共css类
@import url("../../../styles/elDialog.scss");
.userStyleMenus {
padding: 20px;
background-color: #Fff;
min-height: calc(100vh - 50px - 20px);
.formSearch{
margin-bottom:20px;
display: flex;
.searchInput{
margin-right: 20px;
display: flex;
align-items: center;
span{
min-width: 80px;
}
}
}
}
::v-deep .buttonHover:hover {
color: #3f9b6a !important;
border-color: #c5e1d2 !important;
background-color: #ecf5f0 !important;
outline: none;
}
.greens {
color: #3F9B6A;
}
</style>