鞍钢鲅鱼圈能源管控系统前端代码
houzhongjian
2024-12-26 cb6cd26221d8bb2c4b1dca44a87332e9fe6f56ab
提交 | 用户 | 时间
cb6cd2 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'
119 import { CACHE_KEY, useCache } from '@/hooks/web/useCache'
120
121 defineOptions({ name: 'SystemAppMenu' })
122
123 const { wsCache } = useCache()
124 const { t } = useI18n() // 国际化
125 const message = useMessage() // 消息弹窗
126
127 const loading = ref(true) // 列表的加载中
128 const list = ref<any>([]) // 列表的数据
129 const queryParams = reactive({
130   name: undefined,
131   status: undefined
132 })
133 const queryFormRef = ref() // 搜索的表单
134 const isExpandAll = ref(false) // 是否展开,默认全部折叠
135 const refreshTable = ref(true) // 重新渲染表格状态
136
137 /** 查询列表 */
138 const getList = async () => {
139   loading.value = true
140   try {
141     const data = await MenuApi.getAppMenuList(queryParams)
142     list.value = handleTree(data)
143   } finally {
144     loading.value = false
145   }
146 }
147
148 /** 搜索按钮操作 */
149 const handleQuery = () => {
150   getList()
151 }
152
153 /** 重置按钮操作 */
154 const resetQuery = () => {
155   queryFormRef.value.resetFields()
156   handleQuery()
157 }
158
159 /** 添加/修改操作 */
160 const formRef = ref()
161 const openForm = (type: string, id?: number, parentId?: number) => {
162   formRef.value.open(type, id, parentId)
163 }
164
165 /** 展开/折叠操作 */
166 const toggleExpandAll = () => {
167   refreshTable.value = false
168   isExpandAll.value = !isExpandAll.value
169   nextTick(() => {
170     refreshTable.value = true
171   })
172 }
173
174 /** 删除按钮操作 */
175 const handleDelete = async (id: number) => {
176   try {
177     // 删除的二次确认
178     await message.delConfirm()
179     // 发起删除
180     await MenuApi.deleteAppMenu(id)
181     message.success(t('common.delSuccess'))
182     // 刷新列表
183     await getList()
184   } catch {}
185 }
186
187 /** 刷新菜单缓存按钮操作 */
188 const refreshMenu = async () => {
189   try {
190     await message.confirm('即将更新缓存刷新浏览器!', '刷新菜单缓存')
191     // 清空,从而触发刷新
192     wsCache.delete(CACHE_KEY.USER)
193     wsCache.delete(CACHE_KEY.ROLE_ROUTERS)
194     // 刷新浏览器
195     location.reload()
196   } catch {}
197 }
198
199 /** 初始化 **/
200 onMounted(() => {
201   getList()
202 })
203 </script>