预约记录
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run

This commit is contained in:
FLL 2025-07-10 17:31:58 +08:00
parent 2cd8d752eb
commit af0cfc3804
11 changed files with 1351 additions and 5 deletions

View File

@ -0,0 +1,61 @@
import type { InspectionPointVO, InspectionPointForm, InspectionPointQuery } from './model';
import type { ID, IDS } from '#/api/common';
import type { PageResult } from '#/api/common';
import { commonExport } from '#/api/helper';
import { requestClient } from '#/api/request';
/**
*
* @param params
* @returns
*/
export function inspectionPointList(params?: InspectionPointQuery) {
return requestClient.get<PageResult<InspectionPointVO>>('/property/inspectionPoint/list', { params });
}
/**
*
* @param params
* @returns
*/
export function inspectionPointExport(params?: InspectionPointQuery) {
return commonExport('/property/inspectionPoint/export', params ?? {});
}
/**
*
* @param id id
* @returns
*/
export function inspectionPointInfo(id: ID) {
return requestClient.get<InspectionPointVO>(`/property/inspectionPoint/${id}`);
}
/**
*
* @param data
* @returns void
*/
export function inspectionPointAdd(data: InspectionPointForm) {
return requestClient.postWithMsg<void>('/property/inspectionPoint', data);
}
/**
*
* @param data
* @returns void
*/
export function inspectionPointUpdate(data: InspectionPointForm) {
return requestClient.putWithMsg<void>('/property/inspectionPoint', data);
}
/**
*
* @param id id
* @returns void
*/
export function inspectionPointRemove(id: ID | IDS) {
return requestClient.deleteWithMsg<void>(`/property/inspectionPoint/${id}`);
}

View File

@ -0,0 +1,139 @@
import type { PageQuery, BaseEntity } from '#/api/common';
export interface InspectionPointVO {
/**
* id
*/
id: string | number;
/**
* id
*/
itemId: string | number;
/**
*
*/
pointName: string;
/**
*
*/
pointType: number;
/**
* nfc编码
*/
nfcCode: string;
/**
*
*/
remark: string;
/**
* id
*/
createById: string | number;
/**
* id
*/
updateById: string | number;
/**
*
*/
searchValue: string;
}
export interface InspectionPointForm extends BaseEntity {
/**
* id
*/
id?: string | number;
/**
* id
*/
itemId?: string | number;
/**
*
*/
pointName?: string;
/**
*
*/
pointType?: number;
/**
* nfc编码
*/
nfcCode?: string;
/**
*
*/
remark?: string;
/**
* id
*/
createById?: string | number;
/**
* id
*/
updateById?: string | number;
/**
*
*/
searchValue?: string;
}
export interface InspectionPointQuery extends PageQuery {
/**
* id
*/
itemId?: string | number;
/**
*
*/
pointName?: string;
/**
*
*/
pointType?: number;
/**
* nfc编码
*/
nfcCode?: string;
/**
* id
*/
createById?: string | number;
/**
* id
*/
updateById?: string | number;
/**
*
*/
searchValue?: string;
/**
*
*/
params?: any;
}

View File

@ -0,0 +1,61 @@
import type { InspectionTaskVO, InspectionTaskForm, InspectionTaskQuery } from './model';
import type { ID, IDS } from '#/api/common';
import type { PageResult } from '#/api/common';
import { commonExport } from '#/api/helper';
import { requestClient } from '#/api/request';
/**
*
* @param params
* @returns
*/
export function inspectionTaskList(params?: InspectionTaskQuery) {
return requestClient.get<PageResult<InspectionTaskVO>>('/property/inspectionTask/list', { params });
}
/**
*
* @param params
* @returns
*/
export function inspectionTaskExport(params?: InspectionTaskQuery) {
return commonExport('/property/inspectionTask/export', params ?? {});
}
/**
*
* @param id id
* @returns
*/
export function inspectionTaskInfo(id: ID) {
return requestClient.get<InspectionTaskVO>(`/property/inspectionTask/${id}`);
}
/**
*
* @param data
* @returns void
*/
export function inspectionTaskAdd(data: InspectionTaskForm) {
return requestClient.postWithMsg<void>('/property/inspectionTask', data);
}
/**
*
* @param data
* @returns void
*/
export function inspectionTaskUpdate(data: InspectionTaskForm) {
return requestClient.putWithMsg<void>('/property/inspectionTask', data);
}
/**
*
* @param id id
* @returns void
*/
export function inspectionTaskRemove(id: ID | IDS) {
return requestClient.deleteWithMsg<void>(`/property/inspectionTask/${id}`);
}

View File

@ -0,0 +1,169 @@
import type { PageQuery, BaseEntity } from '#/api/common';
export interface InspectionTaskVO {
/**
* id
*/
id: string | number;
/**
* id
*/
inspectionPlanId: string | number;
/**
*
*/
actInsTime: string;
/**
*
*/
actUserId: string | number;
/**
*
*/
taskType: string;
/**
*
*/
transferDesc: string;
/**
*
*/
status: string;
/**
*
*/
remark: string;
/**
* id
*/
createById: string | number;
/**
* id
*/
updateById: string | number;
/**
*
*/
searchValue: string;
}
export interface InspectionTaskForm extends BaseEntity {
/**
* id
*/
id?: string | number;
/**
* id
*/
inspectionPlanId?: string | number;
/**
*
*/
actInsTime?: string;
/**
*
*/
actUserId?: string | number;
/**
*
*/
taskType?: string;
/**
*
*/
transferDesc?: string;
/**
*
*/
status?: string;
/**
*
*/
remark?: string;
/**
* id
*/
createById?: string | number;
/**
* id
*/
updateById?: string | number;
/**
*
*/
searchValue?: string;
}
export interface InspectionTaskQuery extends PageQuery {
/**
* id
*/
inspectionPlanId?: string | number;
/**
*
*/
actInsTime?: string;
/**
*
*/
actUserId?: string | number;
/**
*
*/
taskType?: string;
/**
*
*/
transferDesc?: string;
/**
*
*/
status?: string;
/**
* id
*/
createById?: string | number;
/**
* id
*/
updateById?: string | number;
/**
*
*/
searchValue?: string;
/**
*
*/
params?: any;
}

View File

@ -3,10 +3,15 @@ import type { VxeGridProps } from '#/adapter/vxe-table';
export const querySchema: FormSchemaGetter = () => [
{
component: 'Input',
fieldName: 'id',
label: '编号',
},
{
component: 'Input',
fieldName: 'itemName',
label: '项目名称',
label: '巡检项目',
},
];
@ -15,13 +20,17 @@ export const querySchema: FormSchemaGetter = () => [
export const columns: VxeGridProps['columns'] = [
{ type: 'checkbox', width: 60 },
{
title: '主键id',
title: '编号',
field: 'id',
},
{
title: '项目名称',
title: '巡检项目',
field: 'itemName',
},
{
title: '创建时间',
field: 'createTime',
},
{
title: '备注',
field: 'remark',
@ -46,7 +55,7 @@ export const modalSchema: FormSchemaGetter = () => [
},
},
{
label: '项目名称',
label: '巡检项目',
fieldName: 'itemName',
component: 'Input',
rules: 'required',
@ -54,6 +63,6 @@ export const modalSchema: FormSchemaGetter = () => [
{
label: '备注',
fieldName: 'remark',
component: 'Input',
component: 'Textarea',
},
];

View File

@ -0,0 +1,149 @@
import type { FormSchemaGetter } from '#/adapter/form';
import type { VxeGridProps } from '#/adapter/vxe-table';
export const querySchema: FormSchemaGetter = () => [
{
component: 'Input',
fieldName: 'itemId',
label: '巡检项目id',
},
{
component: 'Input',
fieldName: 'pointName',
label: '巡检点名称',
},
{
component: 'Select',
componentProps: {
},
fieldName: 'pointType',
label: '巡检点类型',
},
{
component: 'Input',
fieldName: 'nfcCode',
label: 'nfc编码',
},
{
component: 'Input',
fieldName: 'createById',
label: '创建人id',
},
{
component: 'Input',
fieldName: 'updateById',
label: '更新人id',
},
{
component: 'Input',
fieldName: 'searchValue',
label: '搜索值',
},
];
// 需要使用i18n注意这里要改成getter形式 否则切换语言不会刷新
// export const columns: () => VxeGridProps['columns'] = () => [
export const columns: VxeGridProps['columns'] = [
{ type: 'checkbox', width: 60 },
{
title: '主键id',
field: 'id',
},
{
title: '巡检项目id',
field: 'itemId',
},
{
title: '巡检点名称',
field: 'pointName',
},
{
title: '巡检点类型',
field: 'pointType',
},
{
title: 'nfc编码',
field: 'nfcCode',
},
{
title: '备注',
field: 'remark',
},
{
title: '创建人id',
field: 'createById',
},
{
title: '更新人id',
field: 'updateById',
},
{
title: '搜索值',
field: 'searchValue',
},
{
field: 'action',
fixed: 'right',
slots: { default: 'action' },
title: '操作',
width: 180,
},
];
export const modalSchema: FormSchemaGetter = () => [
{
label: '主键id',
fieldName: 'id',
component: 'Input',
dependencies: {
show: () => false,
triggerFields: [''],
},
},
{
label: '巡检项目id',
fieldName: 'itemId',
component: 'Input',
rules: 'required',
},
{
label: '巡检点名称',
fieldName: 'pointName',
component: 'Input',
rules: 'required',
},
{
label: '巡检点类型',
fieldName: 'pointType',
component: 'Select',
componentProps: {
},
rules: 'selectRequired',
},
{
label: 'nfc编码',
fieldName: 'nfcCode',
component: 'Input',
},
{
label: '备注',
fieldName: 'remark',
component: 'Textarea',
},
{
label: '创建人id',
fieldName: 'createById',
component: 'Input',
},
{
label: '更新人id',
fieldName: 'updateById',
component: 'Input',
},
{
label: '搜索值',
fieldName: 'searchValue',
component: 'Input',
},
];

View File

@ -0,0 +1,182 @@
<script setup lang="ts">
import type { Recordable } from '@vben/types';
import { ref } from 'vue';
import { Page, useVbenModal, type VbenFormProps } from '@vben/common-ui';
import { getVxePopupContainer } from '@vben/utils';
import { Modal, Popconfirm, Space } from 'ant-design-vue';
import dayjs from 'dayjs';
import {
useVbenVxeGrid,
vxeCheckboxChecked,
type VxeGridProps
} from '#/adapter/vxe-table';
import {
inspectionPointExport,
inspectionPointList,
inspectionPointRemove,
} from '#/api/property/inspectionManagement/inspectionPoint';
import type { InspectionPointForm } from '#/api/property/inspectionManagement/inspectionPoint/model';
import { commonDownloadExcel } from '#/utils/file/download';
import inspectionPointModal from './inspectionPoint-modal.vue';
import { columns, querySchema } from './data';
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',
// RangePicker /
//
// fieldMappingTime: [
// [
// 'createTime',
// ['params[beginTime]', 'params[endTime]'],
// ['YYYY-MM-DD 00:00:00', 'YYYY-MM-DD 23:59:59'],
// ],
// ],
};
const gridOptions: VxeGridProps = {
checkboxConfig: {
//
highlight: true,
//
reserve: true,
//
// trigger: 'row',
},
// 使i18ngetter
// columns: columns(),
columns,
height: 'auto',
keepSource: true,
pagerConfig: {},
proxyConfig: {
ajax: {
query: async ({ page }, formValues = {}) => {
return await inspectionPointList({
pageNum: page.currentPage,
pageSize: page.pageSize,
...formValues,
});
},
},
},
rowConfig: {
keyField: 'id',
},
//
id: 'property-inspectionPoint-index'
};
const [BasicTable, tableApi] = useVbenVxeGrid({
formOptions,
gridOptions,
});
const [InspectionPointModal, modalApi] = useVbenModal({
connectedComponent: inspectionPointModal,
});
function handleAdd() {
modalApi.setData({});
modalApi.open();
}
async function handleEdit(row: Required<InspectionPointForm>) {
modalApi.setData({ id: row.id });
modalApi.open();
}
async function handleDelete(row: Required<InspectionPointForm>) {
await inspectionPointRemove(row.id);
await tableApi.query();
}
function handleMultiDelete() {
const rows = tableApi.grid.getCheckboxRecords();
const ids = rows.map((row: Required<InspectionPointForm>) => row.id);
Modal.confirm({
title: '提示',
okType: 'danger',
content: `确认删除选中的${ids.length}条记录吗?`,
onOk: async () => {
await inspectionPointRemove(ids);
await tableApi.query();
},
});
}
function handleDownloadExcel() {
commonDownloadExcel(inspectionPointExport, '巡检点数据', tableApi.formApi.form.values, {
fieldMappingTime: formOptions.fieldMappingTime,
});
}
</script>
<template>
<Page :auto-content-height="true">
<BasicTable table-title="巡检点列表">
<template #toolbar-tools>
<Space>
<a-button
v-access:code="['property:inspectionPoint:export']"
@click="handleDownloadExcel"
>
{{ $t('pages.common.export') }}
</a-button>
<a-button
:disabled="!vxeCheckboxChecked(tableApi)"
danger
type="primary"
v-access:code="['property:inspectionPoint:remove']"
@click="handleMultiDelete">
{{ $t('pages.common.delete') }}
</a-button>
<a-button
type="primary"
v-access:code="['property:inspectionPoint:add']"
@click="handleAdd"
>
{{ $t('pages.common.add') }}
</a-button>
</Space>
</template>
<template #action="{ row }">
<Space>
<ghost-button
v-access:code="['property:inspectionPoint:edit']"
@click.stop="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="['property:inspectionPoint:remove']"
@click.stop=""
>
{{ $t('pages.common.delete') }}
</ghost-button>
</Popconfirm>
</Space>
</template>
</BasicTable>
<InspectionPointModal @reload="tableApi.query()" />
</Page>
</template>

View File

@ -0,0 +1,101 @@
<script setup lang="ts">
import { computed, ref } from 'vue';
import { useVbenModal } from '@vben/common-ui';
import { $t } from '@vben/locales';
import { cloneDeep } from '@vben/utils';
import { useVbenForm } from '#/adapter/form';
import { inspectionPointAdd, inspectionPointInfo, inspectionPointUpdate } from '#/api/property/inspectionManagement/inspectionPoint';
import { defaultFormValueGetter, useBeforeCloseDiff } from '#/utils/popup';
import { modalSchema } 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',
// label px
labelWidth: 80,
//
componentProps: {
class: 'w-full',
}
},
schema: modalSchema(),
showDefaultActions: false,
wrapperClass: 'grid-cols-2',
});
const { onBeforeClose, markInitialized, resetInitialized } = useBeforeCloseDiff(
{
initializedGetter: defaultFormValueGetter(formApi),
currentGetter: defaultFormValueGetter(formApi),
},
);
const [BasicModal, modalApi] = useVbenModal({
//
class: 'w-[550px]',
fullscreenButton: false,
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 inspectionPointInfo(id);
await formApi.setValues(record);
}
await markInitialized();
modalApi.modalLoading(false);
},
});
async function handleConfirm() {
try {
modalApi.lock(true);
const { valid } = await formApi.validate();
if (!valid) {
return;
}
// getValuesreadonly
const data = cloneDeep(await formApi.getValues());
await (isUpdate.value ? inspectionPointUpdate(data) : inspectionPointAdd(data));
resetInitialized();
emit('reload');
modalApi.close();
} catch (error) {
console.error(error);
} finally {
modalApi.lock(false);
}
}
async function handleClosed() {
await formApi.resetForm();
resetInitialized();
}
</script>
<template>
<BasicModal :title="title">
<BasicForm />
</BasicModal>
</template>

View File

@ -0,0 +1,192 @@
import type { FormSchemaGetter } from '#/adapter/form';
import type { VxeGridProps } from '#/adapter/vxe-table';
export const querySchema: FormSchemaGetter = () => [
{
component: 'Input',
fieldName: 'inspectionPlanId',
label: '巡检计划id',
},
{
component: 'DatePicker',
componentProps: {
showTime: true,
format: 'YYYY-MM-DD HH:mm:ss',
valueFormat: 'YYYY-MM-DD HH:mm:ss',
},
fieldName: 'actInsTime',
label: '实际巡检时间',
},
{
component: 'Input',
fieldName: 'actUserId',
label: '当前巡检人',
},
{
component: 'Select',
componentProps: {
},
fieldName: 'taskType',
label: '巡检方式',
},
{
component: 'Textarea',
fieldName: 'transferDesc',
label: '转移描述',
},
{
component: 'RadioGroup',
componentProps: {
buttonStyle: 'solid',
optionType: 'button',
},
fieldName: 'status',
label: '巡检状态',
},
{
component: 'Input',
fieldName: 'createById',
label: '创建人id',
},
{
component: 'Input',
fieldName: 'updateById',
label: '更新人id',
},
{
component: 'Input',
fieldName: 'searchValue',
label: '搜索值',
},
];
// 需要使用i18n注意这里要改成getter形式 否则切换语言不会刷新
// export const columns: () => VxeGridProps['columns'] = () => [
export const columns: VxeGridProps['columns'] = [
{ type: 'checkbox', width: 60 },
{
title: '主键id',
field: 'id',
},
{
title: '巡检计划id',
field: 'inspectionPlanId',
},
{
title: '实际巡检时间',
field: 'actInsTime',
},
{
title: '当前巡检人',
field: 'actUserId',
},
{
title: '巡检方式',
field: 'taskType',
},
{
title: '转移描述',
field: 'transferDesc',
},
{
title: '巡检状态',
field: 'status',
},
{
title: '备注',
field: 'remark',
},
{
title: '创建人id',
field: 'createById',
},
{
title: '更新人id',
field: 'updateById',
},
{
title: '搜索值',
field: 'searchValue',
},
{
field: 'action',
fixed: 'right',
slots: { default: 'action' },
title: '操作',
width: 180,
},
];
export const modalSchema: FormSchemaGetter = () => [
{
label: '主键id',
fieldName: 'id',
component: 'Input',
dependencies: {
show: () => false,
triggerFields: [''],
},
},
{
label: '巡检计划id',
fieldName: 'inspectionPlanId',
component: 'Input',
},
{
label: '实际巡检时间',
fieldName: 'actInsTime',
component: 'DatePicker',
componentProps: {
showTime: true,
format: 'YYYY-MM-DD HH:mm:ss',
valueFormat: 'YYYY-MM-DD HH:mm:ss',
},
},
{
label: '当前巡检人',
fieldName: 'actUserId',
component: 'Input',
},
{
label: '巡检方式',
fieldName: 'taskType',
component: 'Select',
componentProps: {
},
},
{
label: '转移描述',
fieldName: 'transferDesc',
component: 'Textarea',
},
{
label: '巡检状态',
fieldName: 'status',
component: 'RadioGroup',
componentProps: {
buttonStyle: 'solid',
optionType: 'button',
},
},
{
label: '备注',
fieldName: 'remark',
component: 'Input',
},
{
label: '创建人id',
fieldName: 'createById',
component: 'Input',
},
{
label: '更新人id',
fieldName: 'updateById',
component: 'Input',
},
{
label: '搜索值',
fieldName: 'searchValue',
component: 'Input',
},
];

View File

@ -0,0 +1,182 @@
<script setup lang="ts">
import type { Recordable } from '@vben/types';
import { ref } from 'vue';
import { Page, useVbenModal, type VbenFormProps } from '@vben/common-ui';
import { getVxePopupContainer } from '@vben/utils';
import { Modal, Popconfirm, Space } from 'ant-design-vue';
import dayjs from 'dayjs';
import {
useVbenVxeGrid,
vxeCheckboxChecked,
type VxeGridProps
} from '#/adapter/vxe-table';
import {
inspectionTaskExport,
inspectionTaskList,
inspectionTaskRemove,
} from '#/api/property/inspectionManagement/inspectionTask';
import type { InspectionTaskForm } from '#/api/property/inspectionManagement/inspectionTask/model';
import { commonDownloadExcel } from '#/utils/file/download';
import inspectionTaskModal from './inspectionTask-modal.vue';
import { columns, querySchema } from './data';
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',
// RangePicker /
//
// fieldMappingTime: [
// [
// 'createTime',
// ['params[beginTime]', 'params[endTime]'],
// ['YYYY-MM-DD 00:00:00', 'YYYY-MM-DD 23:59:59'],
// ],
// ],
};
const gridOptions: VxeGridProps = {
checkboxConfig: {
//
highlight: true,
//
reserve: true,
//
// trigger: 'row',
},
// 使i18ngetter
// columns: columns(),
columns,
height: 'auto',
keepSource: true,
pagerConfig: {},
proxyConfig: {
ajax: {
query: async ({ page }, formValues = {}) => {
return await inspectionTaskList({
pageNum: page.currentPage,
pageSize: page.pageSize,
...formValues,
});
},
},
},
rowConfig: {
keyField: 'id',
},
//
id: 'property-inspectionTask-index'
};
const [BasicTable, tableApi] = useVbenVxeGrid({
formOptions,
gridOptions,
});
const [InspectionTaskModal, modalApi] = useVbenModal({
connectedComponent: inspectionTaskModal,
});
function handleAdd() {
modalApi.setData({});
modalApi.open();
}
async function handleEdit(row: Required<InspectionTaskForm>) {
modalApi.setData({ id: row.id });
modalApi.open();
}
async function handleDelete(row: Required<InspectionTaskForm>) {
await inspectionTaskRemove(row.id);
await tableApi.query();
}
function handleMultiDelete() {
const rows = tableApi.grid.getCheckboxRecords();
const ids = rows.map((row: Required<InspectionTaskForm>) => row.id);
Modal.confirm({
title: '提示',
okType: 'danger',
content: `确认删除选中的${ids.length}条记录吗?`,
onOk: async () => {
await inspectionTaskRemove(ids);
await tableApi.query();
},
});
}
function handleDownloadExcel() {
commonDownloadExcel(inspectionTaskExport, '巡检任务数据', tableApi.formApi.form.values, {
fieldMappingTime: formOptions.fieldMappingTime,
});
}
</script>
<template>
<Page :auto-content-height="true">
<BasicTable table-title="巡检任务列表">
<template #toolbar-tools>
<Space>
<a-button
v-access:code="['property:inspectionTask:export']"
@click="handleDownloadExcel"
>
{{ $t('pages.common.export') }}
</a-button>
<a-button
:disabled="!vxeCheckboxChecked(tableApi)"
danger
type="primary"
v-access:code="['property:inspectionTask:remove']"
@click="handleMultiDelete">
{{ $t('pages.common.delete') }}
</a-button>
<a-button
type="primary"
v-access:code="['property:inspectionTask:add']"
@click="handleAdd"
>
{{ $t('pages.common.add') }}
</a-button>
</Space>
</template>
<template #action="{ row }">
<Space>
<ghost-button
v-access:code="['property:inspectionTask:edit']"
@click.stop="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="['property:inspectionTask:remove']"
@click.stop=""
>
{{ $t('pages.common.delete') }}
</ghost-button>
</Popconfirm>
</Space>
</template>
</BasicTable>
<InspectionTaskModal @reload="tableApi.query()" />
</Page>
</template>

View File

@ -0,0 +1,101 @@
<script setup lang="ts">
import { computed, ref } from 'vue';
import { useVbenModal } from '@vben/common-ui';
import { $t } from '@vben/locales';
import { cloneDeep } from '@vben/utils';
import { useVbenForm } from '#/adapter/form';
import { inspectionTaskAdd, inspectionTaskInfo, inspectionTaskUpdate } from '#/api/property/inspectionManagement/inspectionTask';
import { defaultFormValueGetter, useBeforeCloseDiff } from '#/utils/popup';
import { modalSchema } 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',
// label px
labelWidth: 80,
//
componentProps: {
class: 'w-full',
}
},
schema: modalSchema(),
showDefaultActions: false,
wrapperClass: 'grid-cols-2',
});
const { onBeforeClose, markInitialized, resetInitialized } = useBeforeCloseDiff(
{
initializedGetter: defaultFormValueGetter(formApi),
currentGetter: defaultFormValueGetter(formApi),
},
);
const [BasicModal, modalApi] = useVbenModal({
//
class: 'w-[550px]',
fullscreenButton: false,
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 inspectionTaskInfo(id);
await formApi.setValues(record);
}
await markInitialized();
modalApi.modalLoading(false);
},
});
async function handleConfirm() {
try {
modalApi.lock(true);
const { valid } = await formApi.validate();
if (!valid) {
return;
}
// getValuesreadonly
const data = cloneDeep(await formApi.getValues());
await (isUpdate.value ? inspectionTaskUpdate(data) : inspectionTaskAdd(data));
resetInitialized();
emit('reload');
modalApi.close();
} catch (error) {
console.error(error);
} finally {
modalApi.lock(false);
}
}
async function handleClosed() {
await formApi.resetForm();
resetInitialized();
}
</script>
<template>
<BasicModal :title="title">
<BasicForm />
</BasicModal>
</template>