Skip to content

Commit fd6fd9e

Browse files
committed
【代码优化】SYSTEM:快速开关菜单的按钮
1 parent 15ed1cf commit fd6fd9e

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

src/views/system/menu/index.vue

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,16 @@
8484
<el-table-column :show-overflow-tooltip="true" label="权限标识" prop="permission" />
8585
<el-table-column :show-overflow-tooltip="true" label="组件路径" prop="component" />
8686
<el-table-column :show-overflow-tooltip="true" label="组件名称" prop="componentName" />
87-
<el-table-column label="状态" prop="status" width="160">
87+
<el-table-column label="状态" prop="status">
8888
<template #default="scope">
89-
<dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status" />
9089
<el-switch
9190
class="ml-4px"
9291
v-model="scope.row.status"
9392
v-hasPermi="['system:menu:update']"
9493
:active-value="CommonStatusEnum.ENABLE"
9594
:inactive-value="CommonStatusEnum.DISABLE"
9695
:loading="menuStatusUpdating[scope.row.id]"
97-
@change="(val) => onMenuStatusChanged(scope.row, val as number)"
96+
@change="(val) => handleStatusChanged(scope.row, val as number)"
9897
/>
9998
</template>
10099
</el-table-column>
@@ -148,7 +147,6 @@ const { t } = useI18n() // 国际化
148147
const message = useMessage() // 消息弹窗
149148
150149
const loading = ref(true) // 列表的加载中
151-
const menuStatusUpdating = ref({}) // 列表的加载中
152150
const list = ref<any>([]) // 列表的数据
153151
const queryParams = reactive({
154152
name: undefined,
@@ -220,11 +218,19 @@ const handleDelete = async (id: number) => {
220218
} catch {}
221219
}
222220
223-
const onMenuStatusChanged = async (menu: MenuVO, val: number) => {
221+
/** 开启/关闭菜单的状态 */
222+
const menuStatusUpdating = ref({}) // 菜单状态更新中的 menu 映射。key:菜单编号,value:是否更新中
223+
const handleStatusChanged = async (menu: MenuVO, val: number) => {
224+
// 1. 标记 menu.id 更新中
224225
menuStatusUpdating.value[menu.id] = true
225-
menu.status = val
226-
await MenuApi.updateMenu(menu)
227-
menuStatusUpdating.value[menu.id] = false
226+
try {
227+
// 2. 发起更新状态
228+
menu.status = val
229+
await MenuApi.updateMenu(menu)
230+
} finally {
231+
// 3. 标记 menu.id 更新完成
232+
menuStatusUpdating.value[menu.id] = false
233+
}
228234
}
229235
230236
/** 初始化 **/

0 commit comments

Comments
 (0)