fix: tenant tenantPackage

This commit is contained in:
xingyu4j
2025-10-09 18:38:13 +08:00
parent 378cdd4c38
commit b2ba1d9d37
4 changed files with 18 additions and 48 deletions

View File

@@ -8,6 +8,8 @@ import { z } from '#/adapter/form';
import { getTenantPackageList } from '#/api/system/tenant-package'; import { getTenantPackageList } from '#/api/system/tenant-package';
import { getRangePickerDefaultProps } from '#/utils'; import { getRangePickerDefaultProps } from '#/utils';
const tenantPackageList = await getTenantPackageList();
/** 新增/修改的表单 */ /** 新增/修改的表单 */
export function useFormSchema(): VbenFormSchema[] { export function useFormSchema(): VbenFormSchema[] {
return [ return [
@@ -163,9 +165,7 @@ export function useGridFormSchema(): VbenFormSchema[] {
} }
/** 列表的字段 */ /** 列表的字段 */
export function useGridColumns( export function useGridColumns(): VxeTableGridOptions['columns'] {
getPackageName?: (packageId: number) => string | undefined,
): VxeTableGridOptions['columns'] {
return [ return [
{ type: 'checkbox', width: 40 }, { type: 'checkbox', width: 40 },
{ {
@@ -182,8 +182,10 @@ export function useGridColumns(
field: 'packageId', field: 'packageId',
title: '租户套餐', title: '租户套餐',
minWidth: 180, minWidth: 180,
formatter: (row: { cellValue: number }) => { formatter: ({ cellValue }) => {
return getPackageName?.(row.cellValue) || '-'; return cellValue === 0
? '系统租户'
: tenantPackageList.find((pkg) => pkg.id === cellValue)?.name || '-';
}, },
}, },
{ {

View File

@@ -1,9 +1,8 @@
<script lang="ts" setup> <script lang="ts" setup>
import type { VxeTableGridOptions } from '#/adapter/vxe-table'; import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { SystemTenantApi } from '#/api/system/tenant'; import type { SystemTenantApi } from '#/api/system/tenant';
import type { SystemTenantPackageApi } from '#/api/system/tenant-package';
import { onMounted, ref } from 'vue'; import { ref } from 'vue';
import { confirm, DocAlert, Page, useVbenModal } from '@vben/common-ui'; import { confirm, DocAlert, Page, useVbenModal } from '@vben/common-ui';
import { downloadFileFromBlobPart, isEmpty } from '@vben/utils'; import { downloadFileFromBlobPart, isEmpty } from '@vben/utils';
@@ -17,22 +16,11 @@ import {
exportTenant, exportTenant,
getTenantPage, getTenantPage,
} from '#/api/system/tenant'; } from '#/api/system/tenant';
import { getTenantPackageList } from '#/api/system/tenant-package';
import { $t } from '#/locales'; import { $t } from '#/locales';
import { useGridColumns, useGridFormSchema } from './data'; import { useGridColumns, useGridFormSchema } from './data';
import Form from './modules/form.vue'; import Form from './modules/form.vue';
const tenantPackageList = ref<SystemTenantPackageApi.TenantPackage[]>([]);
/** 获取套餐名称 */
const getPackageName = (packageId: number) => {
if (packageId === 0) {
return '系统租户';
}
return tenantPackageList.value.find((pkg) => pkg.id === packageId)?.name;
};
const [FormModal, formModalApi] = useVbenModal({ const [FormModal, formModalApi] = useVbenModal({
connectedComponent: Form, connectedComponent: Form,
destroyOnClose: true, destroyOnClose: true,
@@ -105,7 +93,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
schema: useGridFormSchema(), schema: useGridFormSchema(),
}, },
gridOptions: { gridOptions: {
columns: useGridColumns(getPackageName), columns: useGridColumns(),
height: 'auto', height: 'auto',
keepSource: true, keepSource: true,
proxyConfig: { proxyConfig: {
@@ -133,11 +121,6 @@ const [Grid, gridApi] = useVbenVxeGrid({
checkboxChange: handleRowCheckboxChange, checkboxChange: handleRowCheckboxChange,
}, },
}); });
/** 初始化 */
onMounted(async () => {
tenantPackageList.value = await getTenantPackageList();
});
</script> </script>
<template> <template>
<Page auto-content-height> <Page auto-content-height>

View File

@@ -8,6 +8,8 @@ import { z } from '#/adapter/form';
import { getTenantPackageList } from '#/api/system/tenant-package'; import { getTenantPackageList } from '#/api/system/tenant-package';
import { getRangePickerDefaultProps } from '#/utils'; import { getRangePickerDefaultProps } from '#/utils';
const tenantPackageList = await getTenantPackageList();
/** 新增/修改的表单 */ /** 新增/修改的表单 */
export function useFormSchema(): VbenFormSchema[] { export function useFormSchema(): VbenFormSchema[] {
return [ return [
@@ -164,9 +166,7 @@ export function useGridFormSchema(): VbenFormSchema[] {
} }
/** 列表的字段 */ /** 列表的字段 */
export function useGridColumns( export function useGridColumns(): VxeTableGridOptions['columns'] {
getPackageName?: (packageId: number) => string | undefined,
): VxeTableGridOptions['columns'] {
return [ return [
{ type: 'checkbox', width: 40 }, { type: 'checkbox', width: 40 },
{ {
@@ -183,8 +183,10 @@ export function useGridColumns(
field: 'packageId', field: 'packageId',
title: '租户套餐', title: '租户套餐',
minWidth: 180, minWidth: 180,
formatter: (row: { cellValue: number }) => { formatter: ({ cellValue }) => {
return getPackageName?.(row.cellValue) || '-'; return cellValue === 0
? '系统租户'
: tenantPackageList.find((pkg) => pkg.id === cellValue)?.name || '-';
}, },
}, },
{ {

View File

@@ -1,9 +1,8 @@
<script lang="ts" setup> <script lang="ts" setup>
import type { VxeTableGridOptions } from '#/adapter/vxe-table'; import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { SystemTenantApi } from '#/api/system/tenant'; import type { SystemTenantApi } from '#/api/system/tenant';
import type { SystemTenantPackageApi } from '#/api/system/tenant-package';
import { onMounted, ref } from 'vue'; import { ref } from 'vue';
import { confirm, DocAlert, Page, useVbenModal } from '@vben/common-ui'; import { confirm, DocAlert, Page, useVbenModal } from '@vben/common-ui';
import { downloadFileFromBlobPart, isEmpty } from '@vben/utils'; import { downloadFileFromBlobPart, isEmpty } from '@vben/utils';
@@ -17,22 +16,11 @@ import {
exportTenant, exportTenant,
getTenantPage, getTenantPage,
} from '#/api/system/tenant'; } from '#/api/system/tenant';
import { getTenantPackageList } from '#/api/system/tenant-package';
import { $t } from '#/locales'; import { $t } from '#/locales';
import { useGridColumns, useGridFormSchema } from './data'; import { useGridColumns, useGridFormSchema } from './data';
import Form from './modules/form.vue'; import Form from './modules/form.vue';
const tenantPackageList = ref<SystemTenantPackageApi.TenantPackage[]>([]);
/** 获取套餐名称 */
const getPackageName = (packageId: number) => {
if (packageId === 0) {
return '系统租户';
}
return tenantPackageList.value.find((pkg) => pkg.id === packageId)?.name;
};
const [FormModal, formModalApi] = useVbenModal({ const [FormModal, formModalApi] = useVbenModal({
connectedComponent: Form, connectedComponent: Form,
destroyOnClose: true, destroyOnClose: true,
@@ -103,7 +91,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
schema: useGridFormSchema(), schema: useGridFormSchema(),
}, },
gridOptions: { gridOptions: {
columns: useGridColumns(getPackageName), columns: useGridColumns(),
height: 'auto', height: 'auto',
keepSource: true, keepSource: true,
proxyConfig: { proxyConfig: {
@@ -131,11 +119,6 @@ const [Grid, gridApi] = useVbenVxeGrid({
checkboxChange: handleRowCheckboxChange, checkboxChange: handleRowCheckboxChange,
}, },
}); });
/** 初始化 */
onMounted(async () => {
tenantPackageList.value = await getTenantPackageList();
});
</script> </script>
<template> <template>
<Page auto-content-height> <Page auto-content-height>