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