index.vue
16.2 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
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
<template>
<div ref="getHeight" class="app-container tableMain">
<div class="main">
<h2 class="crumbsTitle">菜单管理</h2>
<div class="container scrollTable tabConLeft">
<!-- 搜索框 -->
<div class="conSearch">
<el-form ref="ruleForm" :inline="true" :model="searchData">
<el-row>
<el-col :span="24">
<el-form-item prop="name" label="菜单名称:">
<el-input
v-model="searchData.name"
placeholder="请输入"
suffix-icon="el-icon-search"
style="width: 197px;"
clearable
@click.native="handleSearch"
@keypress.native.enter="handleSearch"
/>
</el-form-item>
<el-button v-if="$hasPermission('menu:add')" type="primary" class="textRight" @click="handleAdd('')">
添加菜单
</el-button>
</el-col>
</el-row>
</el-form>
</div>
<module-tip :data-table="menuTreeData" :list-loading="listLoading" />
<div v-if="menuTreeData.length > 0" id="resultScroll" class="menuMain">
<el-table
ref="table"
v-loading="listLoading"
:data="menuTreeData"
:row-key="rowKey"
fit
:row-class-name="row => row.row.classs ===true ? 'current-row' : ''"
:expand-row-keys="expandRow"
:tree-props="treeProps"
class="orgTree"
style="width: 100%"
@row-click="handleClickRow"
>
<el-table-column
prop=""
width="220"
>
<template slot="header">
<span>
菜单名称
</span>
</template>
<template slot-scope="{ row }">
{{ ellipsis(row.name, 6) }}
</template>
</el-table-column>
<el-table-column>
<template slot="header">
<span>
状态
</span>
</template>
<template slot-scope="{ row }">
<div @click.stop>
<el-switch v-if="row.parentIsEnable===false&&row.isEnable===true" v-model="row.isEnable" :disabled="!$hasPermission('menu:update')" @change="handleState(row)" />
<el-switch v-else v-model="row.isEnable" :disabled="!$hasPermission('menu:update') || row.parentIsEnable===false" @change="handleState(row)" />
</div>
</template>
</el-table-column>
<el-table-column
prop="address"
width="150"
fixed="right"
>
<template slot="header">
<span>
操作
</span>
</template>
<template slot-scope="{ row }">
<div class="operation">
<el-button v-if="$hasPermission('menu:update')" class="inputText" :disabled="!row.isEnable" @click.stop="handleEdit(row)">修改</el-button>
<el-button v-if="$hasPermission('menu:delete')" class="inputText delect" :disabled="!row.isEnable" @click.stop="handleDelete(row)">删除</el-button>
</div>
</template>
</el-table-column>
</el-table>
</div>
<!-- 用户添加、编辑对话框 -->
<user-add-dialog
v-if="isShow"
ref="userDialog"
:menu-tree-data="menuTreeData"
:editdata="formData"
:dialog="dialog"
@close="handleClose"
@cleardata="clearData"
@getMenuList="getMenuList"
/>
<!-- end -->
<!-- 启用禁用 -->
<base-dialog
ref="status"
:dialog="dialog"
@handle-close="handleCloseStatus"
@state-submit="handleStateSubmit"
/>
<!-- end -->
<!-- 删除 -->
<delete
ref="delete"
:dialog="dialog"
@handleCloseDelete="handleCloseDelete"
@delete="deleteButton"
@cleardata="clearData"
/>
<!-- end -->
</div>
<div class="container tabConRight">
<jurisdiction
ref="menu"
:formdata="formData"
:data-table="dataTable"
:total="total"
:list-loading="listLoading"
:search-data="searchData"
@getlist="getList"
/>
</div>
</div>
</div>
</template>
<script lang="ts">
import { Component, Vue, Watch } from 'vue-property-decorator'
import { ElForm } from 'element-ui/types/form'
import { ellipsis } from '@/utils'
// 组件
// 删除
import Delete from './components/delete.vue'
// 添加
import UserAddDialog from './components/add.vue'
// import dragTreeTable from '@/components/treeTable/dragTreeTable.vue'
import ModuleTip from '@/components/ModuleTip/index.vue'
// 启用禁用
import BaseDialog from '@/components/BaseStatus/index.vue'
import Jurisdiction from './components/jurisdiction.vue'
// interface接口
import { MenuTableData, PageListEntity } from '@/pages/menu/interface/types'
// api
import { getRole, getAllTree } from '@/api/api'
import {
getmenuList,
getAllMenu,
deleteMenu,
move,
detailMenu,
editStatus
} from '@/pages/menu/api/index'
// import { log } from 'util'
@Component({
name: 'RoleList',
components: {
Delete,
UserAddDialog,
BaseDialog,
Jurisdiction,
// dragTreeTable,
ModuleTip
}
})
export default class extends Vue {
private ref = this.$refs as any
private dataTable: MenuTableData[] = []
private listLoading = true
private isShow = false
private delectData = []
// private roleData = {} as any
private roleIds = [] as any
private formData={
name: '', // 名称
path: '', // 路由
parentId: '', // 上级类目
icon: '', // 图标
isEnable: true, // 状态
sortValue: '' // 排序
} as any
private searchData = {
name: '',
size: 10,
current: 1,
menuId: ''
} as any
private dialog = {
id: '',
msg: '',
isVisible: false,
isDeleVisible: false,
isStatusVisible: false,
type: 'add',
isEnable: false,
name: '',
parentId: '',
title: ''
}
private treeData = {
treeShow: false,
valueId: '' // 初始ID(可选)
}
private treeDatas = {
columns: [],
lists: []
} as any
private menuTreeData = [] as any
private total = ''
private rowKey = 'id'
private expandRow = []
private newData = {} as any
private leave=1
private objdata= [] as any
private menuId='' as string
private treeProps = { children: 'children', hasChildren: 'hasChildren' }
/// 生命周期
created() {
this.getMenuList()
}
mounted() {
this.isShow = true
}
/// // 功能函数 /////
// 获取组织列表
private async getMenuList() {
this.listLoading = true
const parent = {
name: this.searchData.name
} as any
const { data } = await getAllMenu(parent)
if (data.isSuccess === true) {
const menuId = this.$store.state.baseMenuTreeId
if (menuId !== '') {
this.menuId = menuId
this.searchData.menuId = menuId
} else {
if (data.data.length > 0) {
this.menuId = data.data[0].id
this.searchData.menuId = data.data[0].id
}
}
this.getList(this.menuId) // 默认权限显示
this.menuTreeData = this.addMenuClass(data.data, this.menuId) // 添加highlight属性
}
setTimeout(() => {
this.listLoading = false
}, 0.1)
}
// 获取数据
private async getList(val: any) {
this.listLoading = true
const { data } = await getmenuList(this.searchData)
if (data.isSuccess === true) {
this.dataTable = data.data.records
this.total = data.data.total
}
setTimeout(() => {
this.listLoading = false
}, 0.001)
}
// 搜索
private handleSearch() {
this.searchData.current = 1
this.getMenuList()
}
async filterParent(arr: any, form: any) {
let arrRes = {} as any
for (let i = 0, length = arr.length; i < length; i++) {
let node = arr[i]
if (node.id === form.parentId) {
form.parentName = node.name
} else {
if (node.children) {
this.filterParent(node.children, form)
}
}
}
return arrRes
}
// 编辑用户
async filterMenu(arr: any, item: any) {
// let arrRes = []
for (let i = 0, length = arr.length; i < length; i++) {
let node = arr[i]
const parent = {
id: item.id,
name: item.name,
parentId: '',
sortValue: item.sortValue
} as any
if (node.id === item.id) {
parent.parentId = node.parent_id
if (node.parent_id === undefined) {
parent.parentId = node.parentId
}
const { data } = await move(parent)
if (data.isSuccess) {
this.getMenuList()
this.$message({
message: '操作成功!',
type: 'success'
})
}
} else {
if (node.children) {
this.filterMenu(node.children, item)
}
}
}
}
// 启用、禁用确认
private async handleStateSubmit() {
const parent = {
id: this.dialog.id,
isEnable: this.dialog.isEnable,
name: this.dialog.name,
parentId: this.dialog.parentId
}
const { data } = await editStatus(parent)
if (data.isSuccess) {
this.dialog.isStatusVisible = false
this.$message.success('操作成功')
this.getMenuList()
} else {
this.$message.error(data.msg)
}
}
// 删除
private async deleteButton() {
const ids: any[] = []
const { data } = await deleteMenu({ ids: this.roleIds })
if (data.isSuccess === true) {
this.$message.success('操作成功')
this.getMenuList()
} else {
this.$message.error(data.msg)
}
this.dialog.isDeleVisible = false
}
// 获取详情
private async getEdit(id: string) {
const { data } = await detailMenu(id)
this.formData = data.data
this.filterParent(this.menuTreeData, this.formData)
}
// 单个删除
private handleDelete(row: any) {
this.storeData(row.id)
this.roleIds.push(row.id)
if (row.children && row.children.length > 0) {
this.roleIds = this.roleIds.concat(this.deleteData(row.children))
}
this.dialog.isDeleVisible = true
}
deleteData(arr:any) {
let arrRow = [] as any
arr.forEach((element:any) => {
this.roleIds.push(element.id)
if (element.children) {
this.deleteData(element.children)
}
})
return arrRow
}
// 修改
private handleEdit(row: any) {
this.storeData(row.id)
this.dialog.type = 'edit'
this.dialog.title = '修改'
this.dialog.isVisible = true
this.getEdit(row.id)
}
/// // ui /////
// 启用,禁用
private async handleState(value: any) {
this.newData = value
this.storeData(value.id)
this.dialog.isStatusVisible = true
this.dialog.id = value.id
this.dialog.isEnable = value.isEnable
this.dialog.name = value.name
this.dialog.parentId = value.parentId
if (!value.isEnable) {
this.dialog.msg = `"${value.name}" 将被禁止登录!`
this.dialog.title = '确认禁用'
} else {
this.dialog.msg = `"${value.name}" 启用!`
this.dialog.title = '确认启用'
}
}
// 添加关闭弹层
handleClose() {
this.dialog.isVisible = false
}
// 启用,禁用筛选
filterHandler(value: string) {
this.searchData.isEnable = value
}
// 启用禁用弹层关闭
async handleCloseStatus() {
this.dialog.isStatusVisible = false
await this.filterstatus(this.menuTreeData, this.newData)
}
// 删除弹层关闭
handleCloseDelete() {
this.dialog.isDeleVisible = false
}
// 用户添加
handleAdd() {
this.clearData()
this.dialog.isVisible = true
this.dialog.type = 'add'
this.dialog.title = '添加'
this.searchData.name = ''
this.getMenuList()
}
// 内容控制字数,多出的用省略号
ellipsis(value: any, num: any) {
return ellipsis(value, num)
}
// 触发当行
handleClickRow(row: any) {
this.searchData.menuId = row.id
this.addMenuClass(this.menuTreeData, row.id)
this.getEdit(row.id)
this.getList(row.id)
}
clearData() {
this.formData = {}
}
// 递归状态取消,修改关闭状态
async filterstatus(data: any, obj: any) {
if (data !== null) {
let result = [] as any
for (let i = 0; i < data.length; i++) {
let item = data[i]
if (item.id === obj.id) {
item.isEnable = !item.isEnable
}
result.push(item)
if (item.children && item.children.length > 0) {
await this.filterstatus(item.children, obj)
}
}
return result
}
}
// 添加当前行样式class属性
addMenuClass(arr: any, id:string) {
let arrRes = [] as any
for (let i = 0, length = arr.length; i < length; i++) {
let node = arr[i]
// node.highlight = false
// node.open = true
if (id === node.id) {
node.classs = true
} else {
node.classs = false
}
arrRes.push(node)
if (node.children) {
this.addMenuClass(node.children, id)
}
}
return arrRes
}
// 删除数据筛选
async filterOpen(arr: any, obj?: any, add?:any) {
// const id = this.$store.state.baseMenuTreeId
let arrRes = [] as any
for (let i = 0, length = arr.length; i < length; i++) {
let node = arr[i]
if (node.id === obj.id) {
arr.splice(i, 1)
}
if (node.children) {
arrRes = arrRes.concat(await this.filterOpen(node.children, obj))
}
arrRes.push(node)
// }
}
return arrRes
}
// 数据筛选 编辑完数据之后列表默认展开open,当前行加背景色
async filterOpenSave(arr: any, newArr: any) {
const id = this.$store.state.baseMenuTreeId
let arrRes = [] as any
for (let i = 0; i < arr.length; i++) {
let node = arr[i]
for (let n = 0; n < newArr.length; n++) {
let nodes = newArr[n]
if (nodes.id === id) {
nodes.highlight = true
} else {
nodes.highlight = false
}
if (node.id === nodes.id) {
if (nodes.parentIsEnable === false && node.parentIsEnable === true) {
node.parentIsEnable = nodes.parentIsEnable
}
nodes.parentIsEnable = node.parentIsEnable
nodes.open = node.open
arrRes.push(nodes)
}
if (node.children && nodes.children) {
this.filterOpenSave(node.children, nodes.children)
}
}
}
return arrRes
}
// 拖拽修改状态关闭还是禁用
async filterData(arr?: any, obj?: any, child?:any, where?:any) {
let arrRes = [] as any
let objarrRes = [] as any
if (child) {
child.forEach((element:any) => {
if (where === 'top' || where === 'bottom') {
obj.parentIsEnable = null
if (obj.isEnable === false) {
element.parentIsEnable = false
} else {
element.parentIsEnable = obj.isEnable
// element.isEnable = obj.isEnable
}
} else {
element.parentIsEnable = obj.parentIsEnable
}
if (element.children) {
this.filterData(element.children, obj, element.children, where)
}
objarrRes.push(element)
})
obj.children = objarrRes
}
for (let i = 0, length = arr.length; i < length; i++) {
let node = arr[i]
if (node.id === obj.id) {
node = obj
}
if (node.children) {
this.filterData(node.children, obj)
}
arrRes.push(node)
}
return arrRes
}
// 存储数据
storeData(id: string) {
this.$store.commit('updatedDataTree', this.menuTreeData) // 当前菜单数据存储到数据池
this.$store.commit('updatedMenuTreeId', id) // 当前菜单数据存储到数据池
}
}
</script>
<style lang="scss" scoped>
.edit-input {
padding-right: 100px;
}
.cancel-btn {
position: absolute;
right: 15px;
top: 10px;
}
</style>