feat: 租户

This commit is contained in:
dap 2024-10-05 23:23:21 +08:00
parent 936fa01b08
commit 74d56ddd82
2 changed files with 223 additions and 36 deletions

View File

@ -2,7 +2,7 @@ import { getPopupContainer } from '@vben/utils';
import dayjs from 'dayjs';
import { type FormSchemaGetter, z } from '#/adapter';
import { type FormSchemaGetter, type VxeGridProps, z } from '#/adapter';
export const querySchema: FormSchemaGetter = () => [
{
@ -27,6 +27,48 @@ export const querySchema: FormSchemaGetter = () => [
},
];
export const columns: VxeGridProps['columns'] = [
{ type: 'checkbox', width: 60 },
{
title: '租户编号',
field: 'tenantId',
},
{
title: '租户名称',
field: 'companyName',
},
{
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: '操作',
width: 180,
},
];
const defaultExpireTime = dayjs()
.add(365, 'days')
.startOf('day')

View File

@ -1,55 +1,200 @@
<script setup lang="ts">
import { Page, useVbenDrawer } from '@vben/common-ui';
import { $t } from '@vben/locales';
import type { Recordable } from '@vben/types';
import { Card } from 'ant-design-vue';
import { ref } from 'vue';
import { useVbenForm } from '#/adapter';
import { useAccess } from '@vben/access';
import { Page, useVbenDrawer, type VbenFormProps } from '@vben/common-ui';
import { querySchema } from './data';
import { Modal, Popconfirm, Space } from 'ant-design-vue';
import dayjs from 'dayjs';
import { useVbenVxeGrid, type VxeGridProps } from '#/adapter';
import {
tenantExport,
tenantList,
tenantRemove,
tenantStatusChange,
} from '#/api/system/tenant';
import { TableSwitch } from '#/components/table';
import { downloadExcel } from '#/utils/file/download';
import { columns, querySchema } from './data';
import tenantDrawer from './tenant-drawer.vue';
const formOptions: VbenFormProps = {
commonConfig: {
labelWidth: 80,
},
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',
},
columns,
height: 'auto',
keepSource: true,
pagerConfig: {},
proxyConfig: {
ajax: {
query: async ({ page }, formValues) => {
//
if (formValues?.createTime) {
formValues.params = {
beginTime: dayjs(formValues.createTime[0]).format(
'YYYY-MM-DD 00:00:00',
),
endTime: dayjs(formValues.createTime[1]).format(
'YYYY-MM-DD 23:59:59',
),
};
Reflect.deleteProperty(formValues, 'createTime');
} else {
Reflect.deleteProperty(formValues, 'params');
}
return await tenantList({
pageNum: page.currentPage,
pageSize: page.pageSize,
...formValues,
});
},
},
},
rowConfig: {
isHover: true,
keyField: 'id',
},
round: true,
align: 'center',
showOverflow: true,
};
const checked = ref(false);
const [BasicTable, tableApi] = useVbenVxeGrid({
formOptions,
gridOptions,
gridEvents: {
checkboxChange: (e: any) => {
checked.value = e.records.length > 0;
},
checkboxAll: (e: any) => {
checked.value = e.records.length > 0;
},
},
});
const [TenantDrawer, drawerApi] = useVbenDrawer({
connectedComponent: tenantDrawer,
});
function handleAdd() {
drawerApi.setData({ update: false });
drawerApi.setData({});
drawerApi.open();
}
const [QueryForm] = useVbenForm({
//
collapsed: false,
//
commonConfig: {
//
componentProps: {
class: 'w-full',
async function handleEdit(record: Recordable<any>) {
drawerApi.setData({ id: record.id });
drawerApi.open();
}
async function handleDelete(row: Recordable<any>) {
await tenantRemove(row.id);
await tableApi.query();
}
function handleMultiDelete() {
const rows = tableApi.grid.getCheckboxRecords();
const ids = rows.map((row: any) => row.id);
Modal.confirm({
title: '提示',
okType: 'danger',
content: `确认删除选中的${ids.length}条记录吗?`,
onOk: async () => {
await tenantRemove(ids);
await tableApi.query();
checked.value = false;
},
},
schema: querySchema(),
//
showCollapseButton: true,
submitButtonOptions: {
text: '查询',
},
wrapperClass: 'grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4',
});
});
}
const { hasAccessByCodes } = useAccess();
</script>
<template>
<Page>
<Card>
<QueryForm />
</Card>
<a-button
type="primary"
v-access:code="['system:tenant:add']"
@click="handleAdd"
>
{{ $t('pages.common.add') }}
</a-button>
<TenantDrawer />
<Page :auto-content-height="true">
todo 新增修改删除与store同步 修改不显示密码
<BasicTable>
<template #toolbar-actions>
<span class="pl-[7px] text-[16px]">租户列表 </span>
</template>
<template #toolbar-tools>
<Space>
<a-button
v-access:code="['system:tenant:export']"
@click="downloadExcel(tenantExport, '租户数据', {})"
>
{{ $t('pages.common.export') }}
</a-button>
<a-button
:disabled="!checked"
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="row.status"
:api="() => tenantStatusChange(row)"
:disabled="row.id === 1 || !hasAccessByCodes(['system:tenant:edit'])"
:reload="() => tableApi.query()"
/>
</template>
<template #action="{ row }">
<a-button
size="small"
type="link"
v-access:code="['system:tenant:edit']"
@click="handleEdit(row)"
>
{{ $t('pages.common.edit') }}
</a-button>
<Popconfirm
placement="left"
title="确认删除?"
@confirm="handleDelete(row)"
>
<a-button
danger
size="small"
type="link"
v-access:code="['system:tenant:remove']"
@click.stop=""
>
{{ $t('pages.common.delete') }}
</a-button>
</Popconfirm>
</template>
</BasicTable>
<TenantDrawer @reload="tableApi.query()" />
</Page>
</template>