物业代码生成

This commit is contained in:
2025-06-18 11:03:42 +08:00
commit 1262d4c745
1881 changed files with 249599 additions and 0 deletions

View File

@@ -0,0 +1,128 @@
import type { FormSchemaGetter } from '#/adapter/form';
import type { VxeGridProps } from '#/adapter/vxe-table';
import { DictEnum } from '@vben/constants';
import { getPopupContainer } from '@vben/utils';
import { getDictOptions } from '#/utils/dict';
import { renderDict } from '#/utils/render';
export const querySchema: FormSchemaGetter = () => [
{
component: 'Input',
fieldName: 'noticeTitle',
label: '公告标题',
},
{
component: 'Input',
fieldName: 'createBy',
label: '创建人',
},
{
component: 'Select',
componentProps: {
getPopupContainer,
options: getDictOptions(DictEnum.SYS_NOTICE_TYPE),
},
fieldName: 'noticeType',
label: '公告类型',
},
];
export const columns: VxeGridProps['columns'] = [
{ type: 'checkbox', width: 60 },
{
title: '公告标题',
field: 'noticeTitle',
},
{
title: '公告类型',
field: 'noticeType',
width: 120,
slots: {
default: ({ row }) => {
return renderDict(row.noticeType, DictEnum.SYS_NOTICE_TYPE);
},
},
},
{
title: '状态',
field: 'status',
width: 120,
slots: {
default: ({ row }) => {
return renderDict(row.status, DictEnum.SYS_NOTICE_STATUS);
},
},
},
{
title: '创建人',
field: 'createByName',
width: 150,
},
{
title: '创建时间',
field: 'createTime',
},
{
field: 'action',
fixed: 'right',
slots: { default: 'action' },
title: '操作',
resizable: false,
width: 'auto',
},
];
export const modalSchema: FormSchemaGetter = () => [
{
component: 'Input',
dependencies: {
show: () => false,
triggerFields: [''],
},
fieldName: 'noticeId',
label: '主键',
},
{
component: 'Input',
fieldName: 'noticeTitle',
label: '公告标题',
rules: 'required',
},
{
component: 'RadioGroup',
componentProps: {
buttonStyle: 'solid',
options: getDictOptions(DictEnum.SYS_NOTICE_STATUS),
optionType: 'button',
},
defaultValue: '0',
fieldName: 'status',
label: '公告状态',
rules: 'required',
formItemClass: 'col-span-1',
},
{
component: 'RadioGroup',
componentProps: {
buttonStyle: 'solid',
options: getDictOptions(DictEnum.SYS_NOTICE_TYPE),
optionType: 'button',
},
defaultValue: '1',
fieldName: 'noticeType',
label: '公告类型',
rules: 'required',
formItemClass: 'col-span-1',
},
{
component: 'RichTextarea',
componentProps: {
width: '100%',
},
fieldName: 'noticeContent',
label: '公告内容',
rules: 'required',
},
];

View File

@@ -0,0 +1,148 @@
<script setup lang="ts">
import type { VbenFormProps } from '@vben/common-ui';
import type { VxeGridProps } from '#/adapter/vxe-table';
import type { Notice } from '#/api/system/notice/model';
import { Page, useVbenModal } 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 { noticeList, noticeRemove } from '#/api/system/notice';
import { columns, querySchema } from './data';
import noticeModal from './notice-modal.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',
},
columns,
height: 'auto',
keepSource: true,
pagerConfig: {},
proxyConfig: {
ajax: {
query: async ({ page }, formValues = {}) => {
return await noticeList({
pageNum: page.currentPage,
pageSize: page.pageSize,
...formValues,
});
},
},
},
rowConfig: {
keyField: 'noticeId',
},
id: 'system-notice-index',
};
const [BasicTable, tableApi] = useVbenVxeGrid({
formOptions,
gridOptions,
});
const [NoticeModal, modalApi] = useVbenModal({
connectedComponent: noticeModal,
});
function handleAdd() {
modalApi.setData({});
modalApi.open();
}
async function handleEdit(record: Notice) {
modalApi.setData({ id: record.noticeId });
modalApi.open();
}
async function handleDelete(row: Notice) {
await noticeRemove([row.noticeId]);
await tableApi.query();
}
function handleMultiDelete() {
const rows = tableApi.grid.getCheckboxRecords();
const ids = rows.map((row: Notice) => row.noticeId);
Modal.confirm({
title: '提示',
okType: 'danger',
content: `确认删除选中的${ids.length}条记录吗?`,
onOk: async () => {
await noticeRemove(ids);
await tableApi.query();
},
});
}
</script>
<template>
<Page :auto-content-height="true">
<BasicTable table-title="通知公告列表">
<template #toolbar-tools>
<Space>
<a-button
:disabled="!vxeCheckboxChecked(tableApi)"
danger
type="primary"
v-access:code="['system:notice:remove']"
@click="handleMultiDelete"
>
{{ $t('pages.common.delete') }}
</a-button>
<a-button
type="primary"
v-access:code="['system:notice:add']"
@click="handleAdd"
>
{{ $t('pages.common.add') }}
</a-button>
</Space>
</template>
<template #action="{ row }">
<Space>
<ghost-button
v-access:code="['system:notice:edit']"
@click="handleEdit(row)"
>
{{ $t('pages.common.edit') }}
</ghost-button>
<Popconfirm
:get-popup-container="getVxePopupContainer"
placement="left"
title="确认删除?"
@confirm="handleDelete(row)"
>
<ghost-button
danger
v-access:code="['system:notice:remove']"
@click.stop=""
>
{{ $t('pages.common.delete') }}
</ghost-button>
</Popconfirm>
</Space>
</template>
</BasicTable>
<NoticeModal @reload="tableApi.query()" />
</Page>
</template>

View File

@@ -0,0 +1,171 @@
<!--
2025年03月08日重构为原生表单(反向重构??)
该文件作为例子 使用原生表单而非useVbenForm
-->
<script setup lang="ts">
import type { RuleObject } from 'ant-design-vue/es/form';
import { computed, ref } from 'vue';
import { useVbenModal } from '@vben/common-ui';
import { DictEnum } from '@vben/constants';
import { $t } from '@vben/locales';
import { cloneDeep } from '@vben/utils';
import { Form, FormItem, Input, RadioGroup } from 'ant-design-vue';
import { pick } from 'lodash-es';
import { noticeAdd, noticeInfo, noticeUpdate } from '#/api/system/notice';
import { Tinymce } from '#/components/tinymce';
import { getDictOptions } from '#/utils/dict';
import { useBeforeCloseDiff } from '#/utils/popup';
const emit = defineEmits<{ reload: [] }>();
const isUpdate = ref(false);
const title = computed(() => {
return isUpdate.value ? $t('pages.common.edit') : $t('pages.common.add');
});
/**
* 定义表单数据类型
*/
interface FormData {
noticeId?: number;
noticeTitle?: string;
status?: string;
noticeType?: string;
noticeContent?: string;
}
/**
* 定义默认值 用于reset
*/
const defaultValues: FormData = {
noticeId: undefined,
noticeTitle: '',
status: '0',
noticeType: '1',
noticeContent: '',
};
/**
* 表单数据ref
*/
const formData = ref(defaultValues);
type AntdFormRules<T> = Partial<Record<keyof T, RuleObject[]>> & {
[key: string]: RuleObject[];
};
/**
* 表单校验规则
*/
const formRules = ref<AntdFormRules<FormData>>({
status: [{ required: true, message: $t('ui.formRules.selectRequired') }],
noticeContent: [{ required: true, message: $t('ui.formRules.required') }],
noticeType: [{ required: true, message: $t('ui.formRules.selectRequired') }],
noticeTitle: [{ required: true, message: $t('ui.formRules.required') }],
});
/**
* useForm解构出表单方法
*/
const { validate, validateInfos, resetFields } = Form.useForm(
formData,
formRules,
);
function customFormValueGetter() {
return JSON.stringify(formData.value);
}
const { onBeforeClose, markInitialized, resetInitialized } = useBeforeCloseDiff(
{
initializedGetter: customFormValueGetter,
currentGetter: customFormValueGetter,
},
);
const [BasicModal, modalApi] = useVbenModal({
class: 'w-[800px]',
fullscreenButton: true,
onBeforeClose,
onClosed: handleClosed,
onConfirm: handleConfirm,
onOpenChange: async (isOpen) => {
if (!isOpen) {
return null;
}
modalApi.modalLoading(true);
const { id } = modalApi.getData() as { id?: number | string };
isUpdate.value = !!id;
if (isUpdate.value && id) {
const record = await noticeInfo(id);
// 只赋值存在的字段
const filterRecord = pick(record, Object.keys(defaultValues));
formData.value = filterRecord;
}
await markInitialized();
modalApi.modalLoading(false);
},
});
async function handleConfirm() {
try {
modalApi.lock(true);
await validate();
// 可能会做数据处理 使用cloneDeep深拷贝
const data = cloneDeep(formData.value);
await (isUpdate.value ? noticeUpdate(data) : noticeAdd(data));
resetInitialized();
emit('reload');
modalApi.close();
} catch (error) {
console.error(error);
} finally {
modalApi.lock(false);
}
}
async function handleClosed() {
formData.value = defaultValues;
resetFields();
resetInitialized();
}
</script>
<template>
<BasicModal :title="title">
<Form layout="vertical">
<FormItem label="公告标题" v-bind="validateInfos.noticeTitle">
<Input
:placeholder="$t('ui.formRules.required')"
v-model:value="formData.noticeTitle"
/>
</FormItem>
<div class="grid sm:grid-cols-1 lg:grid-cols-2">
<FormItem label="公告状态" v-bind="validateInfos.status">
<RadioGroup
button-style="solid"
option-type="button"
v-model:value="formData.status"
:options="getDictOptions(DictEnum.SYS_NOTICE_STATUS)"
/>
</FormItem>
<FormItem label="公告类型" v-bind="validateInfos.noticeType">
<RadioGroup
button-style="solid"
option-type="button"
v-model:value="formData.noticeType"
:options="getDictOptions(DictEnum.SYS_NOTICE_TYPE)"
/>
</FormItem>
</div>
<FormItem label="公告内容" v-bind="validateInfos.noticeContent">
<Tinymce v-model="formData.noticeContent" />
</FormItem>
</Form>
</BasicModal>
</template>