【代码优化】SYSTEM:快速开关菜单的按钮

pull/537/MERGE
YunaiV 2024-09-06 09:20:32 +08:00
parent 15ed1cf5c2
commit fd6fd9e520
1 changed files with 14 additions and 8 deletions

View File

@ -84,9 +84,8 @@
<el-table-column :show-overflow-tooltip="true" label="权限标识" prop="permission" />
<el-table-column :show-overflow-tooltip="true" label="组件路径" prop="component" />
<el-table-column :show-overflow-tooltip="true" label="组件名称" prop="componentName" />
<el-table-column label="状态" prop="status" width="160">
<el-table-column label="状态" prop="status">
<template #default="scope">
<dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status" />
<el-switch
class="ml-4px"
v-model="scope.row.status"
@ -94,7 +93,7 @@
:active-value="CommonStatusEnum.ENABLE"
:inactive-value="CommonStatusEnum.DISABLE"
:loading="menuStatusUpdating[scope.row.id]"
@change="(val) => onMenuStatusChanged(scope.row, val as number)"
@change="(val) => handleStatusChanged(scope.row, val as number)"
/>
</template>
</el-table-column>
@ -148,7 +147,6 @@ const { t } = useI18n() // 国际化
const message = useMessage() //
const loading = ref(true) //
const menuStatusUpdating = ref({}) //
const list = ref<any>([]) //
const queryParams = reactive({
name: undefined,
@ -220,11 +218,19 @@ const handleDelete = async (id: number) => {
} catch {}
}
const onMenuStatusChanged = async (menu: MenuVO, val: number) => {
/** 开启/关闭菜单的状态 */
const menuStatusUpdating = ref({}) // menu keyvalue
const handleStatusChanged = async (menu: MenuVO, val: number) => {
// 1. menu.id
menuStatusUpdating.value[menu.id] = true
menu.status = val
await MenuApi.updateMenu(menu)
menuStatusUpdating.value[menu.id] = false
try {
// 2.
menu.status = val
await MenuApi.updateMenu(menu)
} finally {
// 3. menu.id
menuStatusUpdating.value[menu.id] = false
}
}
/** 初始化 **/