-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathindex.vue
More file actions
161 lines (152 loc) · 4.84 KB
/
index.vue
File metadata and controls
161 lines (152 loc) · 4.84 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
// 菜单管理页面,用于创建菜单关系:菜单名、菜单页面、二级菜单。。。等等
<template>
<el-row style="width:300px" :gutter="5">
<el-col :span="18">
<el-input v-model="search" placeholder="搜索" clearable>
<template #append>
<el-button @click="getMenuInfo">
<el-icon>
<Search/>
</el-icon>
</el-button>
</template>
</el-input>
</el-col>
<el-col :span="6">
<el-button v-permission="'menu:add'" type="primary" @click="handleAdd">新建菜单</el-button>
</el-col>
</el-row>
<div style="padding-top:10px">
<el-table :data="menuData"
style="width: 100%; margin-bottom: 20px;" row-key="id" border stripe
:header-cell-style="{background:'#eef1f6',color:'#606266'}">
<!-- <el-table-column prop="id" label="主键" width="180"/>-->
<el-table-column prop="name" label="菜单名称" width="180"/>
<el-table-column prop="type" label="菜单类型" width="100" align="center">
<template #default="scope">
<el-tag effect="dark" v-if="scope.row.type === 'page'" type='info'>
一级菜单
</el-tag>
<el-tag effect="dark" v-else-if="scope.row.type === 'subPage'" type='success'>
子菜单
</el-tag>
<el-tag effect="dark" v-else type="warning">按钮</el-tag>
</template>
</el-table-column>
<el-table-column prop="path" label="路径" width="180"/>
<el-table-column prop="component" label="组件" width="180"/>
<el-table-column prop="sort" label="排序" align="center"/>
<el-table-column prop="enable" label="状态" width="80">
<template #default="scope">
<el-tag effect="dark" :type="scope.row.enable === true?'success':'danger'">
{{ scope.row.enable === true ? '启用' : '禁用' }}
</el-tag>
</template>
</el-table-column>
<el-table-column label="操作">
<template #default="scope">
<el-dropdown @command="handleCommand">
<span style="color: deepskyblue">
更多<el-icon>
<arrow-down/>
</el-icon>
</span>
<template #dropdown>
<el-dropdown-menu>
<el-dropdown-item :command="beforeHandleCommand(scope.row,'detail')">编辑
</el-dropdown-item>
<el-dropdown-item :command="beforeHandleCommand(scope.row,'addSubPage')">添加子菜单
</el-dropdown-item>
<el-dropdown-item :command="beforeHandleCommand(scope.row,'delete')">删除
</el-dropdown-item>
</el-dropdown-menu>
</template>
</el-dropdown>
</template>
</el-table-column>
>
</el-table>
</div>
<el-drawer v-model="dialogVisible" title="添加子菜单" destroy-on-close>
<menu-dialog :data="selectData" v-model:visible="dialogVisible"></menu-dialog>
</el-drawer>
</template>
<script setup>
import {Search, ArrowDown} from '@element-plus/icons-vue'
import {ElMessageBox} from 'element-plus'
import {
DeleteMenu,
GetAllMenus
} from '@/api/menus'
import MenuDialog from './MenuDialog'
import {provide, reactive, ref, watch} from 'vue'
const search = ref(null)
const dialogVisible = ref(false)
const menuInfo = reactive({
name: '',
status: ''
})
const menuData = ref([])
const selectData = reactive({})
provide('menuData', menuData)
watch(dialogVisible, (newValue) => {
if (newValue === false) {
getMenuInfo()
}
})
const beforeHandleCommand = (row, command) => {
return {
row,
command
}
}
const handleCommand = (command) => {
let row = command.row
switch (command.command) {
case 'detail':
dialogVisible.value = true
Object.assign(selectData, row)
break
case 'addSubPage':
handleAdd(row.id, 'subPage')
break
case 'delete':
ElMessageBox.confirm('是否删除菜单:' + row.name, '删除菜单', {
type: 'warning'
}).then(() => {
DeleteMenu(row.id)
getMenuInfo()
}).catch()
break
}
}
const handleAdd = (parentId = null, menuType = 'page') => {
Object.assign(selectData, {
id: null,
parent_id: parentId,
name: '',
path: '',
component: null,
auth: '',
enable: '',
type: menuType
})
dialogVisible.value = true
}
const getMenuInfo = () => {
console.log('get menu info')
GetAllMenus(search.value).then(response => {
console.log(response)
menuData.value = response
}).catch(error => {
this.$notify({
title: '错误',
message: error,
type: 'error'
})
})
}
getMenuInfo()
</script>
<style lang="">
</style>