feat: 租户
This commit is contained in:
parent
936fa01b08
commit
74d56ddd82
@ -2,7 +2,7 @@ import { getPopupContainer } from '@vben/utils';
|
|||||||
|
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
|
|
||||||
import { type FormSchemaGetter, z } from '#/adapter';
|
import { type FormSchemaGetter, type VxeGridProps, z } from '#/adapter';
|
||||||
|
|
||||||
export const querySchema: FormSchemaGetter = () => [
|
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()
|
const defaultExpireTime = dayjs()
|
||||||
.add(365, 'days')
|
.add(365, 'days')
|
||||||
.startOf('day')
|
.startOf('day')
|
||||||
|
@ -1,48 +1,157 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { Page, useVbenDrawer } from '@vben/common-ui';
|
import type { Recordable } from '@vben/types';
|
||||||
import { $t } from '@vben/locales';
|
|
||||||
|
|
||||||
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';
|
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({
|
const [TenantDrawer, drawerApi] = useVbenDrawer({
|
||||||
connectedComponent: tenantDrawer,
|
connectedComponent: tenantDrawer,
|
||||||
});
|
});
|
||||||
|
|
||||||
function handleAdd() {
|
function handleAdd() {
|
||||||
drawerApi.setData({ update: false });
|
drawerApi.setData({});
|
||||||
drawerApi.open();
|
drawerApi.open();
|
||||||
}
|
}
|
||||||
|
|
||||||
const [QueryForm] = useVbenForm({
|
async function handleEdit(record: Recordable<any>) {
|
||||||
// 默认展开
|
drawerApi.setData({ id: record.id });
|
||||||
collapsed: false,
|
drawerApi.open();
|
||||||
// 所有表单项共用,可单独在表单内覆盖
|
}
|
||||||
commonConfig: {
|
|
||||||
// 所有表单项
|
async function handleDelete(row: Recordable<any>) {
|
||||||
componentProps: {
|
await tenantRemove(row.id);
|
||||||
class: 'w-full',
|
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>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<Page>
|
<Page :auto-content-height="true">
|
||||||
<Card>
|
todo 新增修改删除与store同步 修改不显示密码
|
||||||
<QueryForm />
|
<BasicTable>
|
||||||
</Card>
|
<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
|
<a-button
|
||||||
type="primary"
|
type="primary"
|
||||||
v-access:code="['system:tenant:add']"
|
v-access:code="['system:tenant:add']"
|
||||||
@ -50,6 +159,42 @@ const [QueryForm] = useVbenForm({
|
|||||||
>
|
>
|
||||||
{{ $t('pages.common.add') }}
|
{{ $t('pages.common.add') }}
|
||||||
</a-button>
|
</a-button>
|
||||||
<TenantDrawer />
|
</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>
|
</Page>
|
||||||
</template>
|
</template>
|
||||||
|
Loading…
Reference in New Issue
Block a user