feat(project): 添加vben5前端
This commit is contained in:
268
Yi.Vben5.Vue3/apps/web-antd/src/views/system/tenant/data.tsx
Normal file
268
Yi.Vben5.Vue3/apps/web-antd/src/views/system/tenant/data.tsx
Normal file
@@ -0,0 +1,268 @@
|
||||
import type { FormSchemaGetter } from '#/adapter/form';
|
||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||
|
||||
import { getPopupContainer } from '@vben/utils';
|
||||
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
import { z } from '#/adapter/form';
|
||||
|
||||
export const querySchema: FormSchemaGetter = () => [
|
||||
{
|
||||
component: 'Input',
|
||||
fieldName: 'id',
|
||||
label: '租户编号',
|
||||
},
|
||||
{
|
||||
component: 'Input',
|
||||
fieldName: 'name',
|
||||
label: '租户名称',
|
||||
},
|
||||
{
|
||||
component: 'Input',
|
||||
fieldName: 'contactUserName',
|
||||
label: '联系人',
|
||||
},
|
||||
{
|
||||
component: 'Input',
|
||||
fieldName: 'contactPhone',
|
||||
label: '联系电话',
|
||||
},
|
||||
];
|
||||
|
||||
export const columns: VxeGridProps['columns'] = [
|
||||
{ type: 'checkbox', width: 60 },
|
||||
{
|
||||
title: '租户编号',
|
||||
field: 'id',
|
||||
},
|
||||
{
|
||||
title: '租户名称',
|
||||
field: 'name',
|
||||
},
|
||||
{
|
||||
title: '联系人',
|
||||
field: 'contactUserName',
|
||||
},
|
||||
{
|
||||
title: '联系电话',
|
||||
field: 'contactPhone',
|
||||
},
|
||||
{
|
||||
title: '到期时间',
|
||||
field: 'expireTime',
|
||||
formatter: ({ cellValue }) => {
|
||||
if (!cellValue) {
|
||||
return '无期限';
|
||||
}
|
||||
return cellValue;
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '租户状态',
|
||||
field: 'status',
|
||||
slots: { default: 'status' },
|
||||
},
|
||||
{
|
||||
field: 'action',
|
||||
fixed: 'right',
|
||||
slots: { default: 'action' },
|
||||
title: '操作',
|
||||
resizable: false,
|
||||
width: 'auto',
|
||||
},
|
||||
];
|
||||
|
||||
const defaultExpireTime = dayjs()
|
||||
.add(365, 'days')
|
||||
.startOf('day')
|
||||
.format('YYYY-MM-DD HH:mm:ss');
|
||||
|
||||
export const drawerSchema: FormSchemaGetter = () => [
|
||||
{
|
||||
component: 'Input',
|
||||
dependencies: {
|
||||
show: () => false,
|
||||
triggerFields: [''],
|
||||
},
|
||||
fieldName: 'id',
|
||||
label: 'id',
|
||||
},
|
||||
{
|
||||
component: 'Input',
|
||||
dependencies: {
|
||||
show: () => false,
|
||||
triggerFields: [''],
|
||||
},
|
||||
fieldName: 'tenantId',
|
||||
label: 'tenantId',
|
||||
},
|
||||
{
|
||||
component: 'Divider',
|
||||
componentProps: {
|
||||
orientation: 'center',
|
||||
},
|
||||
fieldName: 'divider1',
|
||||
hideLabel: true,
|
||||
renderComponentContent: () => ({
|
||||
default: () => '基本信息',
|
||||
}),
|
||||
},
|
||||
{
|
||||
component: 'Input',
|
||||
fieldName: 'name',
|
||||
label: '租户名称',
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
component: 'Input',
|
||||
fieldName: 'contactUserName',
|
||||
label: '联系人',
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
component: 'Input',
|
||||
fieldName: 'contactPhone',
|
||||
label: '联系电话',
|
||||
rules: z
|
||||
.string()
|
||||
.regex(/^1[3-9]\d{9}$/, { message: '请输入正确的联系电话' }),
|
||||
},
|
||||
{
|
||||
component: 'Divider',
|
||||
componentProps: {
|
||||
orientation: 'center',
|
||||
},
|
||||
fieldName: 'divider2',
|
||||
hideLabel: true,
|
||||
renderComponentContent: () => ({
|
||||
default: () => '管理员信息',
|
||||
}),
|
||||
dependencies: {
|
||||
if: (values) => !values?.tenantId,
|
||||
triggerFields: ['tenantId'],
|
||||
},
|
||||
},
|
||||
{
|
||||
component: 'Input',
|
||||
fieldName: 'username',
|
||||
label: '用户账号',
|
||||
rules: 'required',
|
||||
dependencies: {
|
||||
if: (values) => !values?.tenantId,
|
||||
triggerFields: ['tenantId'],
|
||||
},
|
||||
},
|
||||
{
|
||||
component: 'InputPassword',
|
||||
fieldName: 'password',
|
||||
label: '用户密码',
|
||||
rules: 'required',
|
||||
dependencies: {
|
||||
if: (values) => !values?.tenantId,
|
||||
triggerFields: ['tenantId'],
|
||||
},
|
||||
},
|
||||
{
|
||||
component: 'Divider',
|
||||
componentProps: {
|
||||
orientation: 'center',
|
||||
},
|
||||
fieldName: 'divider3',
|
||||
hideLabel: true,
|
||||
renderComponentContent: () => ({
|
||||
default: () => '租户设置',
|
||||
}),
|
||||
},
|
||||
// {
|
||||
// component: 'Select',
|
||||
// componentProps: {
|
||||
// getPopupContainer,
|
||||
// },
|
||||
// fieldName: 'packageId',
|
||||
// label: '租户套餐',
|
||||
// rules: 'selectRequired',
|
||||
// },
|
||||
{
|
||||
component: 'DatePicker',
|
||||
componentProps: {
|
||||
format: 'YYYY-MM-DD HH:mm:ss',
|
||||
showTime: true,
|
||||
valueFormat: 'YYYY-MM-DD HH:mm:ss',
|
||||
getPopupContainer,
|
||||
},
|
||||
defaultValue: defaultExpireTime,
|
||||
fieldName: 'expireTime',
|
||||
help: `已经设置过期时间不允许重置为'无期限'\n即在开通时未设置无期限 以后都不允许设置`,
|
||||
label: '过期时间',
|
||||
},
|
||||
{
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
min: -1,
|
||||
},
|
||||
defaultValue: -1,
|
||||
fieldName: 'accountCount',
|
||||
help: '-1不限制用户数量',
|
||||
label: '用户数量',
|
||||
renderComponentContent(model) {
|
||||
return {
|
||||
addonBefore: () =>
|
||||
model.accountCount === -1 ? '不限制数量' : '输入数量',
|
||||
};
|
||||
},
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
component: 'Input',
|
||||
fieldName: 'domain',
|
||||
help: '可填写域名/端口 填写域名如: www.test.com 或者 www.test.com:8080 填写ip:端口如: 127.0.0.1:8080',
|
||||
label: '绑定域名',
|
||||
renderComponentContent() {
|
||||
return {
|
||||
addonBefore: () => 'http(s)://',
|
||||
};
|
||||
},
|
||||
rules: z
|
||||
.string()
|
||||
.refine(
|
||||
(domain) =>
|
||||
!(domain.startsWith('http://') || domain.startsWith('https://')),
|
||||
{ message: '请输入正确的域名, 不需要http(s)' },
|
||||
)
|
||||
.optional(),
|
||||
},
|
||||
{
|
||||
component: 'Divider',
|
||||
componentProps: {
|
||||
orientation: 'center',
|
||||
},
|
||||
fieldName: 'divider4',
|
||||
hideLabel: true,
|
||||
renderComponentContent: () => ({
|
||||
default: () => '企业信息',
|
||||
}),
|
||||
},
|
||||
{
|
||||
component: 'Input',
|
||||
fieldName: 'address',
|
||||
label: '企业地址',
|
||||
},
|
||||
{
|
||||
component: 'Input',
|
||||
fieldName: 'licenseNumber',
|
||||
label: '企业代码',
|
||||
},
|
||||
{
|
||||
component: 'Textarea',
|
||||
fieldName: 'intro',
|
||||
formItemClass: 'items-start',
|
||||
label: '企业介绍',
|
||||
},
|
||||
{
|
||||
component: 'Textarea',
|
||||
fieldName: 'remark',
|
||||
formItemClass: 'items-start',
|
||||
label: '备注',
|
||||
},
|
||||
];
|
||||
236
Yi.Vben5.Vue3/apps/web-antd/src/views/system/tenant/index.vue
Normal file
236
Yi.Vben5.Vue3/apps/web-antd/src/views/system/tenant/index.vue
Normal file
@@ -0,0 +1,236 @@
|
||||
<script setup lang="ts">
|
||||
import type { VbenFormProps } from '@vben/common-ui';
|
||||
|
||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||
import type { Tenant } from '#/api/system/tenant/model';
|
||||
|
||||
import { computed } from 'vue';
|
||||
|
||||
import { useAccess } from '@vben/access';
|
||||
import { Fallback, Page, useVbenDrawer } from '@vben/common-ui';
|
||||
import { getVxePopupContainer } from '@vben/utils';
|
||||
|
||||
import { Modal, Popconfirm, Space } from 'ant-design-vue';
|
||||
|
||||
import { useVbenVxeGrid, vxeCheckboxChecked } from '#/adapter/vxe-table';
|
||||
import {
|
||||
dictSyncTenant,
|
||||
tenantExport,
|
||||
tenantList,
|
||||
tenantRemove,
|
||||
tenantUpdate,
|
||||
// tenantSyncPackage,
|
||||
} from '#/api/system/tenant';
|
||||
import { TableSwitch } from '#/components/table';
|
||||
import { useTenantStore } from '#/store/tenant';
|
||||
import { commonDownloadExcel } from '#/utils/file/download';
|
||||
|
||||
import { columns, querySchema } from './data';
|
||||
import tenantDrawer from './tenant-drawer.vue';
|
||||
|
||||
const formOptions: VbenFormProps = {
|
||||
commonConfig: {
|
||||
labelWidth: 80,
|
||||
componentProps: {
|
||||
allowClear: true,
|
||||
},
|
||||
},
|
||||
schema: querySchema(),
|
||||
wrapperClass: 'grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4',
|
||||
};
|
||||
|
||||
const gridOptions: VxeGridProps = {
|
||||
checkboxConfig: {
|
||||
// 高亮
|
||||
highlight: true,
|
||||
// 翻页时保留选中状态
|
||||
reserve: true,
|
||||
// 点击行选中
|
||||
// trigger: 'row',
|
||||
checkMethod: ({ row }) => row?.id !== '00000000-0000-0000-0000-000000000001',
|
||||
},
|
||||
columns,
|
||||
height: 'auto',
|
||||
keepSource: true,
|
||||
pagerConfig: {},
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }, formValues = {}) => {
|
||||
return await tenantList({
|
||||
SkipCount: page.currentPage,
|
||||
MaxResultCount: page.pageSize,
|
||||
...formValues,
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
},
|
||||
id: 'system-tenant-index',
|
||||
};
|
||||
|
||||
const [BasicTable, tableApi] = useVbenVxeGrid({
|
||||
formOptions,
|
||||
gridOptions,
|
||||
});
|
||||
|
||||
const [TenantDrawer, drawerApi] = useVbenDrawer({
|
||||
connectedComponent: tenantDrawer,
|
||||
});
|
||||
|
||||
function handleAdd() {
|
||||
drawerApi.setData({});
|
||||
drawerApi.open();
|
||||
}
|
||||
|
||||
async function handleEdit(record: Tenant) {
|
||||
drawerApi.setData({ id: record.id });
|
||||
drawerApi.open();
|
||||
}
|
||||
|
||||
// async function handleSync(record: Tenant) {
|
||||
// const tenantId = record.tenantId || record.id;
|
||||
// const packageId = record.packageId;
|
||||
// if (tenantId && packageId) {
|
||||
// await tenantSyncPackage(tenantId, packageId);
|
||||
// await tableApi.query();
|
||||
// }
|
||||
// }
|
||||
|
||||
const tenantStore = useTenantStore();
|
||||
async function handleDelete(row: Tenant) {
|
||||
await tenantRemove([row.id]);
|
||||
await tableApi.query();
|
||||
// 重新加载租户信息
|
||||
tenantStore.initTenant();
|
||||
}
|
||||
|
||||
function handleMultiDelete() {
|
||||
const rows = tableApi.grid.getCheckboxRecords();
|
||||
const ids = rows.map((row: Tenant) => row.id);
|
||||
Modal.confirm({
|
||||
title: '提示',
|
||||
okType: 'danger',
|
||||
content: `确认删除选中的${ids.length}条记录吗?`,
|
||||
onOk: async () => {
|
||||
await tenantRemove(ids);
|
||||
await tableApi.query();
|
||||
// 重新加载租户信息
|
||||
tenantStore.initTenant();
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function handleDownloadExcel() {
|
||||
commonDownloadExcel(tenantExport, '租户数据', tableApi.formApi.form.values);
|
||||
}
|
||||
|
||||
/**
|
||||
* 与后台逻辑相同
|
||||
* 只有超级管理员能访问租户相关
|
||||
*/
|
||||
const { hasAccessByCodes, hasAccessByRoles } = useAccess();
|
||||
|
||||
const isSuperAdmin = computed(() => {
|
||||
return hasAccessByRoles(['superadmin']);
|
||||
});
|
||||
|
||||
function handleSyncTenantDict() {
|
||||
Modal.confirm({
|
||||
title: '提示',
|
||||
iconType: 'warning',
|
||||
content: '确认同步租户字典?',
|
||||
onOk: async () => {
|
||||
await dictSyncTenant();
|
||||
await tableApi.query();
|
||||
},
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page v-if="isSuperAdmin" :auto-content-height="true">
|
||||
<BasicTable table-title="租户列表">
|
||||
<template #toolbar-tools>
|
||||
<Space>
|
||||
<!-- <a-button
|
||||
v-access:code="['system:tenant:edit']"
|
||||
@click="handleSyncTenantDict"
|
||||
>
|
||||
同步租户字典
|
||||
</a-button> -->
|
||||
<a-button
|
||||
v-access:code="['system:tenant:export']"
|
||||
@click="handleDownloadExcel"
|
||||
>
|
||||
{{ $t('pages.common.export') }}
|
||||
</a-button>
|
||||
<a-button
|
||||
:disabled="!vxeCheckboxChecked(tableApi)"
|
||||
danger
|
||||
type="primary"
|
||||
v-access:code="['system:tenant:remove']"
|
||||
@click="handleMultiDelete"
|
||||
>
|
||||
{{ $t('pages.common.delete') }}
|
||||
</a-button>
|
||||
<a-button
|
||||
type="primary"
|
||||
v-access:code="['system:tenant:add']"
|
||||
@click="handleAdd"
|
||||
>
|
||||
{{ $t('pages.common.add') }}
|
||||
</a-button>
|
||||
</Space>
|
||||
</template>
|
||||
<template #status="{ row }">
|
||||
<TableSwitch
|
||||
v-model:value="row.status"
|
||||
:api="() => tenantUpdate(row)"
|
||||
:disabled="row.id === '00000000-0000-0000-0000-000000000001' || !hasAccessByCodes(['system:tenant:edit'])"
|
||||
@reload="tableApi.query()"
|
||||
/>
|
||||
</template>
|
||||
<template #action="{ row }">
|
||||
<Space v-if="row.id !== '00000000-0000-0000-0000-000000000001'">
|
||||
<ghost-button
|
||||
v-access:code="['system:tenant:edit']"
|
||||
@click="handleEdit(row)"
|
||||
>
|
||||
{{ $t('pages.common.edit') }}
|
||||
</ghost-button>
|
||||
<!-- <Popconfirm
|
||||
:get-popup-container="getVxePopupContainer"
|
||||
:title="`确认同步[${row.name || row.companyName}]的套餐吗?`"
|
||||
placement="left"
|
||||
@confirm="handleSync(row)"
|
||||
>
|
||||
<ghost-button
|
||||
class="btn-success"
|
||||
v-access:code="['system:tenant:edit']"
|
||||
>
|
||||
{{ $t('pages.common.sync') }}
|
||||
</ghost-button>
|
||||
</Popconfirm> -->
|
||||
<Popconfirm
|
||||
:get-popup-container="getVxePopupContainer"
|
||||
placement="left"
|
||||
title="确认删除?"
|
||||
@confirm="handleDelete(row)"
|
||||
>
|
||||
<ghost-button
|
||||
danger
|
||||
v-access:code="['system:tenant:remove']"
|
||||
@click.stop=""
|
||||
>
|
||||
{{ $t('pages.common.delete') }}
|
||||
</ghost-button>
|
||||
</Popconfirm>
|
||||
</Space>
|
||||
</template>
|
||||
</BasicTable>
|
||||
<TenantDrawer @reload="tableApi.query()" />
|
||||
</Page>
|
||||
<Fallback v-else description="您没有租户的访问权限" status="403" />
|
||||
</template>
|
||||
@@ -0,0 +1,134 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { useVbenDrawer } from '@vben/common-ui';
|
||||
import { $t } from '@vben/locales';
|
||||
import { cloneDeep } from '@vben/utils';
|
||||
|
||||
import { useVbenForm } from '#/adapter/form';
|
||||
import { tenantAdd, tenantInfo, tenantUpdate } from '#/api/system/tenant';
|
||||
// import { packageSelectList } from '#/api/system/tenant-package';
|
||||
import { useTenantStore } from '#/store/tenant';
|
||||
import { defaultFormValueGetter, useBeforeCloseDiff } from '#/utils/popup';
|
||||
|
||||
import { drawerSchema } from './data';
|
||||
|
||||
const emit = defineEmits<{ reload: [] }>();
|
||||
|
||||
const isUpdate = ref(false);
|
||||
const title = computed(() => {
|
||||
return isUpdate.value ? $t('pages.common.edit') : $t('pages.common.add');
|
||||
});
|
||||
|
||||
const [BasicForm, formApi] = useVbenForm({
|
||||
commonConfig: {
|
||||
formItemClass: 'col-span-2',
|
||||
labelWidth: 100,
|
||||
componentProps: {
|
||||
class: 'w-full',
|
||||
},
|
||||
},
|
||||
schema: drawerSchema(),
|
||||
showDefaultActions: false,
|
||||
wrapperClass: 'grid-cols-2',
|
||||
});
|
||||
|
||||
// async function setupPackageSelect() {
|
||||
// const tenantPackageList = await packageSelectList();
|
||||
// const options = tenantPackageList.map((item) => ({
|
||||
// label: item.packageName,
|
||||
// value: item.packageId,
|
||||
// }));
|
||||
// formApi.updateSchema([
|
||||
// {
|
||||
// componentProps: {
|
||||
// optionFilterProp: 'label',
|
||||
// optionLabelProp: 'label',
|
||||
// options,
|
||||
// showSearch: true,
|
||||
// },
|
||||
// fieldName: 'packageId',
|
||||
// },
|
||||
// ]);
|
||||
// }
|
||||
|
||||
const { onBeforeClose, markInitialized, resetInitialized } = useBeforeCloseDiff(
|
||||
{
|
||||
initializedGetter: defaultFormValueGetter(formApi),
|
||||
currentGetter: defaultFormValueGetter(formApi),
|
||||
},
|
||||
);
|
||||
|
||||
const [BasicDrawer, drawerApi] = useVbenDrawer({
|
||||
onBeforeClose,
|
||||
onClosed: handleClosed,
|
||||
onConfirm: handleConfirm,
|
||||
async onOpenChange(isOpen) {
|
||||
if (!isOpen) {
|
||||
return null;
|
||||
}
|
||||
drawerApi.drawerLoading(true);
|
||||
|
||||
const { id } = drawerApi.getData() as { id?: string };
|
||||
isUpdate.value = !!id;
|
||||
// 初始化
|
||||
// await setupPackageSelect();
|
||||
|
||||
if (isUpdate.value && id) {
|
||||
const record = await tenantInfo(id);
|
||||
await formApi.setValues(record);
|
||||
}
|
||||
|
||||
// formApi.updateSchema([
|
||||
// {
|
||||
// fieldName: 'packageId',
|
||||
// componentProps: {
|
||||
// disabled: isUpdate.value,
|
||||
// },
|
||||
// },
|
||||
// ]);
|
||||
await markInitialized();
|
||||
|
||||
drawerApi.drawerLoading(false);
|
||||
},
|
||||
});
|
||||
|
||||
const tenantStore = useTenantStore();
|
||||
async function handleConfirm() {
|
||||
try {
|
||||
drawerApi.lock(true);
|
||||
const { valid } = await formApi.validate();
|
||||
if (!valid) {
|
||||
return;
|
||||
}
|
||||
const data = cloneDeep(await formApi.getValues());
|
||||
await (isUpdate.value ? tenantUpdate(data) : tenantAdd(data));
|
||||
resetInitialized();
|
||||
emit('reload');
|
||||
drawerApi.close();
|
||||
// 重新加载租户信息
|
||||
tenantStore.initTenant();
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
} finally {
|
||||
drawerApi.lock(false);
|
||||
}
|
||||
}
|
||||
|
||||
async function handleClosed() {
|
||||
await formApi.resetForm();
|
||||
resetInitialized();
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<BasicDrawer :title="title" class="w-[600px]">
|
||||
<BasicForm />
|
||||
</BasicDrawer>
|
||||
</template>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
:deep(.ant-divider) {
|
||||
margin: 8px 0;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user