refactor(tenant): 替换 TableSwitch 为 ApiSwitch 并统一状态切换逻辑
将租户和租户套餐列表中的 TableSwitch 组件替换为 ApiSwitch,并统一处理状态切换逻辑。使用 EnableStatus 常量来管理状态值,提高代码可维护性。
This commit is contained in:
parent
1f643874a9
commit
2a5c45e15c
@ -8,6 +8,7 @@ import { computed } from 'vue';
|
||||
|
||||
import { useAccess } from '@vben/access';
|
||||
import { Fallback, Page, useVbenDrawer } from '@vben/common-ui';
|
||||
import { EnableStatus } from '@vben/constants';
|
||||
|
||||
import { Popconfirm, Space } from 'antdv-next';
|
||||
|
||||
@ -21,7 +22,7 @@ import {
|
||||
tenantStatusChange,
|
||||
tenantSyncPackage,
|
||||
} from '#/api/system/tenant';
|
||||
import { TableSwitch } from '#/components/table';
|
||||
import { ApiSwitch } from '#/components/global';
|
||||
import { useTenantStore } from '#/store/tenant';
|
||||
import { commonDownloadExcel } from '#/utils/file/download';
|
||||
|
||||
@ -154,6 +155,15 @@ function handleSyncTenantConfig() {
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async function handleChangeStatus(checked: boolean, row: Tenant) {
|
||||
console.log(checked);
|
||||
await tenantStatusChange({
|
||||
id: row.id,
|
||||
tenantId: row.tenantId,
|
||||
status: checked ? EnableStatus.Enable : EnableStatus.Disable,
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@ -198,9 +208,9 @@ function handleSyncTenantConfig() {
|
||||
</Space>
|
||||
</template>
|
||||
<template #status="{ row }">
|
||||
<TableSwitch
|
||||
v-model:value="row.status"
|
||||
:api="() => tenantStatusChange(row)"
|
||||
<ApiSwitch
|
||||
:value="row.status === EnableStatus.Enable"
|
||||
:api="(checked) => handleChangeStatus(checked, row)"
|
||||
:disabled="row.id === 1 || !hasAccessByCodes(['system:tenant:edit'])"
|
||||
@reload="tableApi.query()"
|
||||
/>
|
||||
|
||||
@ -8,6 +8,7 @@ import { computed } from 'vue';
|
||||
|
||||
import { useAccess } from '@vben/access';
|
||||
import { Fallback, Page, useVbenDrawer } from '@vben/common-ui';
|
||||
import { EnableStatus } from '@vben/constants';
|
||||
|
||||
import { Popconfirm, Space } from 'antdv-next';
|
||||
|
||||
@ -18,7 +19,7 @@ import {
|
||||
packageList,
|
||||
packageRemove,
|
||||
} from '#/api/system/tenant-package';
|
||||
import { TableSwitch } from '#/components/table';
|
||||
import { ApiSwitch } from '#/components/global';
|
||||
import { commonDownloadExcel } from '#/utils/file/download';
|
||||
|
||||
import { columns, querySchema } from './data';
|
||||
@ -120,6 +121,13 @@ const { hasAccessByCodes, hasAccessByRoles } = useAccess();
|
||||
const isSuperAdmin = computed(() => {
|
||||
return hasAccessByRoles(['superadmin']);
|
||||
});
|
||||
|
||||
async function handleChangeStatus(checked: boolean, row: TenantPackage) {
|
||||
await packageChangeStatus({
|
||||
packageId: row.packageId,
|
||||
status: checked ? EnableStatus.Enable : EnableStatus.Disable,
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@ -152,9 +160,9 @@ const isSuperAdmin = computed(() => {
|
||||
</Space>
|
||||
</template>
|
||||
<template #status="{ row }">
|
||||
<TableSwitch
|
||||
<ApiSwitch
|
||||
v-model:value="row.status"
|
||||
:api="() => packageChangeStatus(row)"
|
||||
:api="(checked) => handleChangeStatus(checked, row)"
|
||||
:disabled="!hasAccessByCodes(['system:tenantPackage:edit'])"
|
||||
@reload="tableApi.query()"
|
||||
/>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user