reactor:【system 系统管理】tenant 进一步统一代码风格
parent
35bd5adf45
commit
942c4ef389
|
@ -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',
|
||||
},
|
||||
{
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
import type { VbenFormSchema } from '#/adapter/form';
|
||||
import type { OnActionClickFn, VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { SystemTenantApi } from '#/api/system/tenant';
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
|
||||
import { useAccess } from '@vben/access';
|
||||
import { CommonStatusEnum, DICT_TYPE } from '@vben/constants';
|
||||
import { getDictOptions } from '@vben/hooks';
|
||||
|
||||
|
@ -10,8 +8,6 @@ import { z } from '#/adapter/form';
|
|||
import { getTenantPackageList } from '#/api/system/tenant-package';
|
||||
import { getRangePickerDefaultProps } from '#/utils';
|
||||
|
||||
const { hasAccessByCodes } = useAccess();
|
||||
|
||||
/** 新增/修改的表单 */
|
||||
export function useFormSchema(): VbenFormSchema[] {
|
||||
return [
|
||||
|
@ -93,11 +89,9 @@ export function useFormSchema(): VbenFormSchema[] {
|
|||
{
|
||||
label: '绑定域名',
|
||||
fieldName: 'websites',
|
||||
component: 'Textarea',
|
||||
component: 'InputTag',
|
||||
componentProps: {
|
||||
placeholder: '请输入绑定域名,多个域名请换行分隔',
|
||||
rows: 3,
|
||||
clearable: true,
|
||||
placeholder: '请输入绑定域名',
|
||||
},
|
||||
},
|
||||
{
|
||||
|
@ -122,6 +116,7 @@ export function useGridFormSchema(): VbenFormSchema[] {
|
|||
label: '租户名',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入租户名',
|
||||
clearable: true,
|
||||
},
|
||||
},
|
||||
|
@ -130,6 +125,7 @@ export function useGridFormSchema(): VbenFormSchema[] {
|
|||
label: '联系人',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入联系人',
|
||||
clearable: true,
|
||||
},
|
||||
},
|
||||
|
@ -138,6 +134,7 @@ export function useGridFormSchema(): VbenFormSchema[] {
|
|||
label: '联系手机',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入联系手机',
|
||||
clearable: true,
|
||||
},
|
||||
},
|
||||
|
@ -146,6 +143,7 @@ export function useGridFormSchema(): VbenFormSchema[] {
|
|||
label: '状态',
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
placeholder: '请选择状态',
|
||||
clearable: true,
|
||||
options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'),
|
||||
},
|
||||
|
@ -163,15 +161,11 @@ export function useGridFormSchema(): VbenFormSchema[] {
|
|||
}
|
||||
|
||||
/** 列表的字段 */
|
||||
export function useGridColumns<T = SystemTenantApi.Tenant>(
|
||||
onActionClick: OnActionClickFn<T>,
|
||||
export function useGridColumns(
|
||||
getPackageName?: (packageId: number) => string | undefined,
|
||||
): VxeTableGridOptions['columns'] {
|
||||
return [
|
||||
{
|
||||
type: 'checkbox',
|
||||
width: 40,
|
||||
},
|
||||
{ type: 'checkbox', width: 40 },
|
||||
{
|
||||
field: 'id',
|
||||
title: '租户编号',
|
||||
|
@ -232,29 +226,10 @@ export function useGridColumns<T = SystemTenantApi.Tenant>(
|
|||
formatter: 'formatDateTime',
|
||||
},
|
||||
{
|
||||
field: 'operation',
|
||||
title: '操作',
|
||||
minWidth: 130,
|
||||
align: 'center',
|
||||
width: 130,
|
||||
fixed: 'right',
|
||||
cellRender: {
|
||||
attrs: {
|
||||
nameField: 'name',
|
||||
nameTitle: '租户',
|
||||
onClick: onActionClick,
|
||||
},
|
||||
name: 'CellOperation',
|
||||
options: [
|
||||
{
|
||||
code: 'edit',
|
||||
show: hasAccessByCodes(['system:tenant:update']),
|
||||
},
|
||||
{
|
||||
code: 'delete',
|
||||
show: hasAccessByCodes(['system:tenant:delete']),
|
||||
},
|
||||
],
|
||||
},
|
||||
slots: { default: 'actions' },
|
||||
},
|
||||
];
|
||||
}
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
<script lang="ts" setup>
|
||||
import type {
|
||||
OnActionClickParams,
|
||||
VxeTableGridOptions,
|
||||
} from '#/adapter/vxe-table';
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { SystemTenantApi } from '#/api/system/tenant';
|
||||
import type { SystemTenantPackageApi } from '#/api/system/tenant-package';
|
||||
|
||||
|
@ -42,47 +39,54 @@ const [FormModal, formModalApi] = useVbenModal({
|
|||
});
|
||||
|
||||
/** 刷新表格 */
|
||||
function onRefresh() {
|
||||
function handleRefresh() {
|
||||
gridApi.query();
|
||||
}
|
||||
|
||||
/** 导出表格 */
|
||||
async function onExport() {
|
||||
async function handleExport() {
|
||||
const data = await exportTenant(await gridApi.formApi.getValues());
|
||||
downloadFileFromBlobPart({ fileName: '租户.xls', source: data });
|
||||
}
|
||||
|
||||
/** 创建租户 */
|
||||
function onCreate() {
|
||||
function handleCreate() {
|
||||
formModalApi.setData(null).open();
|
||||
}
|
||||
|
||||
/** 编辑租户 */
|
||||
function onEdit(row: SystemTenantApi.Tenant) {
|
||||
function handleEdit(row: SystemTenantApi.Tenant) {
|
||||
formModalApi.setData(row).open();
|
||||
}
|
||||
|
||||
/** 删除租户 */
|
||||
async function onDelete(row: SystemTenantApi.Tenant) {
|
||||
async function handleDelete(row: SystemTenantApi.Tenant) {
|
||||
const loadingInstance = ElLoading.service({
|
||||
text: $t('ui.actionMessage.deleting', [row.name]),
|
||||
});
|
||||
try {
|
||||
await deleteTenant(row.id as number);
|
||||
ElMessage.success($t('ui.actionMessage.deleteSuccess', [row.name]));
|
||||
onRefresh();
|
||||
handleRefresh();
|
||||
} finally {
|
||||
loadingInstance.close();
|
||||
}
|
||||
}
|
||||
|
||||
/** 批量删除租户 */
|
||||
async function onDeleteBatch() {
|
||||
await confirm('确定要批量删除该租户吗?');
|
||||
await deleteTenantList(checkedIds.value);
|
||||
checkedIds.value = [];
|
||||
ElMessage.success($t('ui.actionMessage.deleteSuccess'));
|
||||
onRefresh();
|
||||
async function handleDeleteBatch() {
|
||||
await confirm($t('ui.actionMessage.deleteBatchConfirm'));
|
||||
const loadingInstance = ElLoading.service({
|
||||
text: $t('ui.actionMessage.deletingBatch'),
|
||||
});
|
||||
try {
|
||||
await deleteTenantList(checkedIds.value);
|
||||
checkedIds.value = [];
|
||||
ElMessage.success($t('ui.actionMessage.deleteSuccess'));
|
||||
handleRefresh();
|
||||
} finally {
|
||||
loadingInstance.close();
|
||||
}
|
||||
}
|
||||
|
||||
const checkedIds = ref<number[]>([]);
|
||||
|
@ -94,29 +98,12 @@ function handleRowCheckboxChange({
|
|||
checkedIds.value = records.map((item) => item.id!);
|
||||
}
|
||||
|
||||
/** 表格操作按钮的回调函数 */
|
||||
function onActionClick({
|
||||
code,
|
||||
row,
|
||||
}: OnActionClickParams<SystemTenantApi.Tenant>) {
|
||||
switch (code) {
|
||||
case 'delete': {
|
||||
onDelete(row);
|
||||
break;
|
||||
}
|
||||
case 'edit': {
|
||||
onEdit(row);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
formOptions: {
|
||||
schema: useGridFormSchema(),
|
||||
},
|
||||
gridOptions: {
|
||||
columns: useGridColumns(onActionClick, getPackageName),
|
||||
columns: useGridColumns(getPackageName),
|
||||
height: 'auto',
|
||||
keepSource: true,
|
||||
proxyConfig: {
|
||||
|
@ -132,6 +119,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
|||
},
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
isHover: true,
|
||||
},
|
||||
toolbarConfig: {
|
||||
refresh: true,
|
||||
|
@ -155,7 +143,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
|
||||
|
@ -165,14 +153,14 @@ onMounted(async () => {
|
|||
type: 'primary',
|
||||
icon: ACTION_ICON.ADD,
|
||||
auth: ['system:tenant:create'],
|
||||
onClick: onCreate,
|
||||
onClick: handleCreate,
|
||||
},
|
||||
{
|
||||
label: $t('ui.actionTitle.export'),
|
||||
type: 'primary',
|
||||
icon: ACTION_ICON.DOWNLOAD,
|
||||
auth: ['system:tenant:export'],
|
||||
onClick: onExport,
|
||||
onClick: handleExport,
|
||||
},
|
||||
{
|
||||
label: $t('ui.actionTitle.deleteBatch'),
|
||||
|
@ -180,7 +168,32 @@ onMounted(async () => {
|
|||
icon: ACTION_ICON.DELETE,
|
||||
disabled: isEmpty(checkedIds),
|
||||
auth: ['system:tenant:delete'],
|
||||
onClick: onDeleteBatch,
|
||||
onClick: handleDeleteBatch,
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
<template #actions="{ row }">
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: $t('common.edit'),
|
||||
type: 'primary',
|
||||
link: true,
|
||||
icon: ACTION_ICON.EDIT,
|
||||
auth: ['system:tenant:update'],
|
||||
onClick: handleEdit.bind(null, row),
|
||||
},
|
||||
{
|
||||
label: $t('common.delete'),
|
||||
type: 'danger',
|
||||
link: true,
|
||||
icon: ACTION_ICON.DELETE,
|
||||
auth: ['system:tenant:delete'],
|
||||
popConfirm: {
|
||||
title: $t('ui.actionMessage.deleteConfirm', [row.name]),
|
||||
confirm: handleDelete.bind(null, row),
|
||||
},
|
||||
},
|
||||
]"
|
||||
/>
|
||||
|
|
|
@ -26,9 +26,8 @@ const [Form, formApi] = useVbenForm({
|
|||
componentProps: {
|
||||
class: 'w-full',
|
||||
},
|
||||
formItemClass: 'col-span-2',
|
||||
labelWidth: 80,
|
||||
},
|
||||
wrapperClass: 'grid-cols-1',
|
||||
layout: 'horizontal',
|
||||
schema: useFormSchema(),
|
||||
showDefaultActions: false,
|
||||
|
@ -42,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));
|
||||
// 关闭并提示
|
||||
|
@ -75,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();
|
||||
}
|
||||
|
@ -91,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>
|
||||
|
|
Loading…
Reference in New Issue