reactor:【system 系统管理】tenant 进一步统一代码风格

This commit is contained in:
YunaiV
2025-09-06 20:46:33 +08:00
parent 35bd5adf45
commit 942c4ef389
6 changed files with 112 additions and 146 deletions

View File

@@ -89,10 +89,10 @@ export function useFormSchema(): VbenFormSchema[] {
{
label: '绑定域名',
fieldName: 'websites',
component: 'Textarea',
component: 'Select',
componentProps: {
placeholder: '请输入绑定域名,多个域名请换行分隔',
rows: 3,
placeholder: '请输入绑定域名',
mode: 'tags',
allowClear: true,
},
},
@@ -118,6 +118,7 @@ export function useGridFormSchema(): VbenFormSchema[] {
label: '租户名',
component: 'Input',
componentProps: {
placeholder: '请输入租户名',
allowClear: true,
},
},
@@ -126,6 +127,7 @@ export function useGridFormSchema(): VbenFormSchema[] {
label: '联系人',
component: 'Input',
componentProps: {
placeholder: '请输入联系人',
allowClear: true,
},
},
@@ -134,6 +136,7 @@ export function useGridFormSchema(): VbenFormSchema[] {
label: '联系手机',
component: 'Input',
componentProps: {
placeholder: '请输入联系手机',
allowClear: true,
},
},
@@ -142,6 +145,7 @@ export function useGridFormSchema(): VbenFormSchema[] {
label: '状态',
component: 'Select',
componentProps: {
placeholder: '请选择状态',
allowClear: true,
options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'),
},
@@ -167,14 +171,17 @@ export function useGridColumns(
{
field: 'id',
title: '租户编号',
minWidth: 100,
},
{
field: 'name',
title: '租户名',
minWidth: 180,
},
{
field: 'packageId',
title: '租户套餐',
minWidth: 180,
formatter: (row: { cellValue: number }) => {
return getPackageName?.(row.cellValue) || '-';
},
@@ -182,27 +189,33 @@ export function useGridColumns(
{
field: 'contactName',
title: '联系人',
minWidth: 100,
},
{
field: 'contactMobile',
title: '联系手机',
minWidth: 180,
},
{
field: 'accountCount',
title: '账号额度',
minWidth: 100,
},
{
field: 'expireTime',
title: '过期时间',
minWidth: 180,
formatter: 'formatDateTime',
},
{
field: 'websites',
title: '绑定域名',
minWidth: 180,
},
{
field: 'status',
title: '租户状态',
minWidth: 100,
cellRender: {
name: 'CellDict',
props: { type: DICT_TYPE.COMMON_STATUS },
@@ -211,6 +224,7 @@ export function useGridColumns(
{
field: 'createTime',
title: '创建时间',
minWidth: 180,
formatter: 'formatDateTime',
},
{

View File

@@ -5,7 +5,7 @@ import type { SystemTenantPackageApi } from '#/api/system/tenant-package';
import { onMounted, ref } from 'vue';
import { DocAlert, Page, useVbenModal } from '@vben/common-ui';
import { confirm, DocAlert, Page, useVbenModal } from '@vben/common-ui';
import { downloadFileFromBlobPart, isEmpty } from '@vben/utils';
import { message } from 'ant-design-vue';
@@ -39,7 +39,7 @@ const [FormModal, formModalApi] = useVbenModal({
});
/** 刷新表格 */
function onRefresh() {
function handleRefresh() {
gridApi.query();
}
@@ -63,15 +63,29 @@ function handleEdit(row: SystemTenantApi.Tenant) {
async function handleDelete(row: SystemTenantApi.Tenant) {
const hideLoading = message.loading({
content: $t('ui.actionMessage.deleting', [row.name]),
key: 'action_key_msg',
duration: 0,
});
try {
await deleteTenant(row.id as number);
message.success({
content: $t('ui.actionMessage.deleteSuccess', [row.name]),
key: 'action_key_msg',
});
onRefresh();
message.success($t('ui.actionMessage.deleteSuccess', [row.name]));
handleRefresh();
} finally {
hideLoading();
}
}
/** 批量删除租户 */
async function handleDeleteBatch() {
await confirm($t('ui.actionMessage.deleteBatchConfirm'));
const hideLoading = message.loading({
content: $t('ui.actionMessage.deletingBatch'),
duration: 0,
});
try {
await deleteTenantList(checkedIds.value);
checkedIds.value = [];
message.success($t('ui.actionMessage.deleteSuccess'));
handleRefresh();
} finally {
hideLoading();
}
@@ -86,23 +100,6 @@ function handleRowCheckboxChange({
checkedIds.value = records.map((item) => item.id!);
}
/** 批量删除租户 */
async function handleDeleteBatch() {
const hideLoading = message.loading({
content: $t('ui.actionMessage.deleting'),
duration: 0,
key: 'action_process_msg',
});
try {
await deleteTenantList(checkedIds.value);
checkedIds.value = [];
message.success($t('ui.actionMessage.deleteSuccess'));
onRefresh();
} finally {
hideLoading();
}
}
const [Grid, gridApi] = useVbenVxeGrid({
formOptions: {
schema: useGridFormSchema(),
@@ -148,7 +145,7 @@ onMounted(async () => {
<DocAlert title="SaaS 多租户" url="https://doc.iocoder.cn/saas-tenant/" />
</template>
<FormModal @success="onRefresh" />
<FormModal @success="handleRefresh" />
<Grid table-title="租户列表">
<template #toolbar-tools>
<TableAction
@@ -168,11 +165,11 @@ onMounted(async () => {
onClick: handleExport,
},
{
label: '批量删除',
label: $t('ui.actionTitle.deleteBatch'),
type: 'primary',
danger: true,
disabled: isEmpty(checkedIds),
icon: ACTION_ICON.DELETE,
disabled: isEmpty(checkedIds),
auth: ['system:tenant:delete'],
onClick: handleDeleteBatch,
},

View File

@@ -27,7 +27,7 @@ const [Form, formApi] = useVbenForm({
class: 'w-full',
},
},
wrapperClass: 'grid-cols-2',
wrapperClass: 'grid-cols-1',
layout: 'horizontal',
schema: useFormSchema(),
showDefaultActions: false,
@@ -41,16 +41,7 @@ const [Modal, modalApi] = useVbenModal({
}
modalApi.lock();
// 提交表单
const formValues = (await formApi.getValues()) as SystemTenantApi.Tenant & {
websites: string;
};
// 将换行符分隔的字符串转换为数组
const data: SystemTenantApi.Tenant = {
...formValues,
websites: formValues.websites
? formValues.websites.split('\n').filter((item) => item.trim())
: [],
};
const data = (await formApi.getValues()) as SystemTenantApi.Tenant;
try {
await (formData.value ? updateTenant(data) : createTenant(data));
// 关闭并提示
@@ -74,15 +65,8 @@ const [Modal, modalApi] = useVbenModal({
modalApi.lock();
try {
formData.value = await getTenant(data.id);
// 将数组转换为换行符分隔的字符串
const formValues = {
...formData.value,
websites: Array.isArray(formData.value.websites)
? formData.value.websites.join('\n')
: formData.value.websites || '',
};
// 设置到 values
await formApi.setValues(formValues);
await formApi.setValues(formData.value);
} finally {
modalApi.unlock();
}
@@ -90,7 +74,7 @@ const [Modal, modalApi] = useVbenModal({
});
</script>
<template>
<Modal :title="getTitle" class="w-1/2">
<Modal :title="getTitle">
<Form class="mx-4" />
</Modal>
</template>