提交 | 用户 | 时间
|
820397
|
1 |
<template> |
H |
2 |
<!-- 搜索工作栏 --> |
|
3 |
<ContentWrap> |
|
4 |
<el-form |
|
5 |
ref="queryFormRef" |
|
6 |
:inline="true" |
|
7 |
:model="queryParams" |
|
8 |
class="-mb-15px" |
|
9 |
label-width="68px" |
|
10 |
> |
|
11 |
<el-form-item label="菜单名称" prop="name"> |
|
12 |
<el-input |
|
13 |
v-model="queryParams.name" |
|
14 |
class="!w-240px" |
|
15 |
clearable |
|
16 |
placeholder="请输入菜单名称" |
|
17 |
@keyup.enter="handleQuery" |
|
18 |
/> |
|
19 |
</el-form-item> |
|
20 |
<el-form-item label="状态" prop="status"> |
|
21 |
<el-select |
|
22 |
v-model="queryParams.status" |
|
23 |
class="!w-240px" |
|
24 |
clearable |
|
25 |
placeholder="请选择菜单状态" |
|
26 |
> |
|
27 |
<el-option |
|
28 |
v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)" |
|
29 |
:key="dict.value" |
|
30 |
:label="dict.label" |
|
31 |
:value="dict.value" |
|
32 |
/> |
|
33 |
</el-select> |
|
34 |
</el-form-item> |
|
35 |
<el-form-item> |
|
36 |
<el-button @click="handleQuery"> |
|
37 |
<Icon class="mr-5px" icon="ep:search" /> |
|
38 |
搜索 |
|
39 |
</el-button> |
|
40 |
<el-button @click="resetQuery"> |
|
41 |
<Icon class="mr-5px" icon="ep:refresh" /> |
|
42 |
重置 |
|
43 |
</el-button> |
|
44 |
<el-button |
|
45 |
v-hasPermi="['system:menu:create']" |
|
46 |
plain |
|
47 |
type="primary" |
|
48 |
@click="openForm('create')" |
|
49 |
> |
|
50 |
<Icon class="mr-5px" icon="ep:plus" /> |
|
51 |
新增 |
|
52 |
</el-button> |
|
53 |
<el-button plain type="danger" @click="toggleExpandAll"> |
|
54 |
<Icon class="mr-5px" icon="ep:sort" /> |
|
55 |
展开/折叠 |
|
56 |
</el-button> |
|
57 |
<el-button plain @click="refreshMenu"> |
|
58 |
<Icon class="mr-5px" icon="ep:refresh" /> |
|
59 |
刷新菜单缓存 |
|
60 |
</el-button> |
|
61 |
</el-form-item> |
|
62 |
</el-form> |
|
63 |
</ContentWrap> |
|
64 |
|
|
65 |
<!-- 列表 --> |
|
66 |
<ContentWrap> |
|
67 |
<el-table |
|
68 |
v-if="refreshTable" |
|
69 |
v-loading="loading" |
|
70 |
:data="list" |
|
71 |
:default-expand-all="isExpandAll" |
|
72 |
row-key="id" |
|
73 |
> |
|
74 |
<el-table-column :show-overflow-tooltip="true" label="菜单名称" prop="name" width="250" /> |
|
75 |
<el-table-column align="center" label="图标" prop="icon" width="100"> |
|
76 |
<template #default="scope"> |
|
77 |
<Icon :icon="scope.row.icon" /> |
|
78 |
</template> |
|
79 |
</el-table-column> |
|
80 |
<el-table-column label="排序" prop="sort" width="60" /> |
|
81 |
<el-table-column :show-overflow-tooltip="true" label="权限标识" prop="permission" /> |
|
82 |
<el-table-column :show-overflow-tooltip="true" label="组件路径" prop="component" /> |
|
83 |
<el-table-column :show-overflow-tooltip="true" label="组件名称" prop="componentName" /> |
|
84 |
<el-table-column label="状态" prop="status" width="80"> |
|
85 |
<template #default="scope"> |
|
86 |
<dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status" /> |
|
87 |
</template> |
|
88 |
</el-table-column> |
|
89 |
<el-table-column align="center" label="操作"> |
|
90 |
<template #default="scope"> |
|
91 |
<el-button |
|
92 |
v-hasPermi="['system:menu:update']" |
|
93 |
link |
|
94 |
type="primary" |
|
95 |
@click="openForm('update', scope.row.id)" |
|
96 |
> |
|
97 |
修改 |
|
98 |
</el-button> |
|
99 |
<el-button |
|
100 |
v-hasPermi="['system:menu:create']" |
|
101 |
link |
|
102 |
type="primary" |
|
103 |
@click="openForm('create', undefined, scope.row.id)" |
|
104 |
> |
|
105 |
新增 |
|
106 |
</el-button> |
|
107 |
<el-button |
|
108 |
v-hasPermi="['system:menu:delete']" |
|
109 |
link |
|
110 |
type="danger" |
|
111 |
@click="handleDelete(scope.row.id)" |
|
112 |
> |
|
113 |
删除 |
|
114 |
</el-button> |
|
115 |
</template> |
|
116 |
</el-table-column> |
|
117 |
</el-table> |
|
118 |
</ContentWrap> |
|
119 |
|
|
120 |
<!-- 表单弹窗:添加/修改 --> |
|
121 |
<MenuForm ref="formRef" @success="getList" /> |
|
122 |
</template> |
|
123 |
<script lang="ts" setup> |
|
124 |
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict' |
|
125 |
import { handleTree } from '@/utils/tree' |
|
126 |
import * as MenuApi from '@/api/system/menu' |
|
127 |
import MenuForm from './MenuForm.vue' |
271781
|
128 |
import {CACHE_KEY, useCache, useSessionCache} from '@/hooks/web/useCache' |
820397
|
129 |
|
H |
130 |
defineOptions({ name: 'SystemMenu' }) |
|
131 |
|
|
132 |
const { wsCache } = useCache() |
271781
|
133 |
const { wsSessionCache } = useSessionCache() |
820397
|
134 |
const { t } = useI18n() // 国际化 |
H |
135 |
const message = useMessage() // 消息弹窗 |
|
136 |
|
|
137 |
const loading = ref(true) // 列表的加载中 |
|
138 |
const list = ref<any>([]) // 列表的数据 |
|
139 |
const queryParams = reactive({ |
|
140 |
name: undefined, |
|
141 |
status: undefined |
|
142 |
}) |
|
143 |
const queryFormRef = ref() // 搜索的表单 |
|
144 |
const isExpandAll = ref(false) // 是否展开,默认全部折叠 |
|
145 |
const refreshTable = ref(true) // 重新渲染表格状态 |
|
146 |
|
|
147 |
/** 查询列表 */ |
|
148 |
const getList = async () => { |
|
149 |
loading.value = true |
|
150 |
try { |
|
151 |
const data = await MenuApi.getMenuList(queryParams) |
|
152 |
list.value = handleTree(data) |
|
153 |
} finally { |
|
154 |
loading.value = false |
|
155 |
} |
|
156 |
} |
|
157 |
|
|
158 |
/** 搜索按钮操作 */ |
|
159 |
const handleQuery = () => { |
|
160 |
getList() |
|
161 |
} |
|
162 |
|
|
163 |
/** 重置按钮操作 */ |
|
164 |
const resetQuery = () => { |
|
165 |
queryFormRef.value.resetFields() |
|
166 |
handleQuery() |
|
167 |
} |
|
168 |
|
|
169 |
/** 添加/修改操作 */ |
|
170 |
const formRef = ref() |
|
171 |
const openForm = (type: string, id?: number, parentId?: number) => { |
|
172 |
formRef.value.open(type, id, parentId) |
|
173 |
} |
|
174 |
|
|
175 |
/** 展开/折叠操作 */ |
|
176 |
const toggleExpandAll = () => { |
|
177 |
refreshTable.value = false |
|
178 |
isExpandAll.value = !isExpandAll.value |
|
179 |
nextTick(() => { |
|
180 |
refreshTable.value = true |
|
181 |
}) |
|
182 |
} |
|
183 |
|
|
184 |
/** 刷新菜单缓存按钮操作 */ |
|
185 |
const refreshMenu = async () => { |
|
186 |
try { |
|
187 |
await message.confirm('即将更新缓存刷新浏览器!', '刷新菜单缓存') |
|
188 |
// 清空,从而触发刷新 |
|
189 |
wsCache.delete(CACHE_KEY.USER) |
271781
|
190 |
wsSessionCache.delete(CACHE_KEY.ROLE_ROUTERS) |
820397
|
191 |
// 刷新浏览器 |
H |
192 |
location.reload() |
|
193 |
} catch {} |
|
194 |
} |
|
195 |
|
|
196 |
/** 删除按钮操作 */ |
|
197 |
const handleDelete = async (id: number) => { |
|
198 |
try { |
|
199 |
// 删除的二次确认 |
|
200 |
await message.delConfirm() |
|
201 |
// 发起删除 |
|
202 |
await MenuApi.deleteMenu(id) |
|
203 |
message.success(t('common.delSuccess')) |
|
204 |
// 刷新列表 |
|
205 |
await getList() |
|
206 |
} catch {} |
|
207 |
} |
|
208 |
|
|
209 |
/** 初始化 **/ |
|
210 |
onMounted(() => { |
|
211 |
getList() |
|
212 |
}) |
|
213 |
</script> |