fix: 修复打包错误
This commit is contained in:
parent
9053b6db3c
commit
ea352b35fd
@ -1,103 +0,0 @@
|
||||
import type { VbenFormSchema } from '#/adapter/form';
|
||||
|
||||
import { getDeptOptions } from '#/api';
|
||||
import { SendHandlerEnum } from '#/enum/SendHandler';
|
||||
|
||||
export function useSubmitFormSchema(): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
component: 'Input',
|
||||
fieldName: 'deviceId',
|
||||
label: '设备id',
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入同步key',
|
||||
},
|
||||
fieldName: 'syncKey',
|
||||
label: '同步key',
|
||||
},
|
||||
{
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入同步密钥',
|
||||
},
|
||||
fieldName: 'syncSecret',
|
||||
label: '同步密钥',
|
||||
},
|
||||
{
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请选择同步平台',
|
||||
options: SendHandlerEnum,
|
||||
clearable: true,
|
||||
},
|
||||
fieldName: 'sendHandlerClass',
|
||||
label: '同步平台',
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
export function useSearchFormSchema(): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入观测点名称',
|
||||
},
|
||||
fieldName: 'displayName',
|
||||
label: '观测点名称',
|
||||
},
|
||||
{
|
||||
component: 'ApiSelect',
|
||||
fieldName: 'deptId',
|
||||
componentProps: {
|
||||
api: getDeptOptions,
|
||||
clearable: true,
|
||||
labelField: 'deptName',
|
||||
valueField: 'id',
|
||||
},
|
||||
label: '部门',
|
||||
},
|
||||
];
|
||||
}
|
||||
export function useGridSchema() {
|
||||
return [
|
||||
{
|
||||
field: 'id',
|
||||
title: '序号',
|
||||
width: 120,
|
||||
fixed: 'left',
|
||||
},
|
||||
{
|
||||
field: 'displayName',
|
||||
title: '点位名称',
|
||||
slots: { default: 'displayName' },
|
||||
width: 120,
|
||||
},
|
||||
{
|
||||
field: 'locationName',
|
||||
title: '行政区划',
|
||||
width: 150,
|
||||
},
|
||||
{
|
||||
field: 'deptIds',
|
||||
title: '部门',
|
||||
slots: { default: 'deptIds' },
|
||||
width: 150,
|
||||
},
|
||||
{
|
||||
field: 'remark',
|
||||
title: '备注',
|
||||
},
|
||||
{
|
||||
field: 'actions',
|
||||
title: '操作',
|
||||
fixed: 'right',
|
||||
width: 120,
|
||||
slots: { default: 'actions' },
|
||||
},
|
||||
];
|
||||
}
|
||||
@ -1,101 +0,0 @@
|
||||
<script lang="ts" setup>
|
||||
import { computed, nextTick, ref } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { areaList } from '@vant/area-data';
|
||||
|
||||
import { useVbenForm } from '#/adapter/form';
|
||||
import { createPoint, updatePoint } from '#/api';
|
||||
|
||||
import { useSubmitFormSchema } from './data';
|
||||
|
||||
const emits = defineEmits(['success']);
|
||||
|
||||
const formData = ref();
|
||||
|
||||
const codeToText = (code: string): string => {
|
||||
const { province_list, city_list, county_list } = areaList;
|
||||
if (!code) return '';
|
||||
|
||||
// 自动根据位数推断 (代码通常为6位)
|
||||
const provinceCode = `${code.slice(0, 2)}0000`;
|
||||
const cityCode = `${code.slice(0, 4)}00`;
|
||||
const countyCode = code;
|
||||
|
||||
const province = province_list[provinceCode] || '';
|
||||
const city = city_list[cityCode] || '';
|
||||
const county = county_list[countyCode] || '';
|
||||
|
||||
// 过滤空值并用空格拼接
|
||||
return [province, city, county].filter(Boolean).join(' ');
|
||||
};
|
||||
|
||||
const [Form, formApi] = useVbenForm({
|
||||
schema: useSubmitFormSchema(),
|
||||
showDefaultActions: false,
|
||||
});
|
||||
|
||||
const id = ref();
|
||||
const [Model, modelApi] = useVbenModal({
|
||||
async onConfirm() {
|
||||
const { valid } = await formApi.validate();
|
||||
if (!valid) return;
|
||||
const values = await formApi.getValues();
|
||||
|
||||
modelApi.lock();
|
||||
(id.value
|
||||
? updatePoint({
|
||||
id: id.value,
|
||||
...values,
|
||||
...(!!values.locationCode && {
|
||||
locationName: codeToText(values.locationCode),
|
||||
}),
|
||||
})
|
||||
: createPoint({
|
||||
...values,
|
||||
...(!!values.locationCode && {
|
||||
locationName: codeToText(values.locationCode),
|
||||
}),
|
||||
})
|
||||
)
|
||||
.then(() => {
|
||||
emits('success');
|
||||
modelApi.close();
|
||||
})
|
||||
.catch(() => {
|
||||
modelApi.unlock();
|
||||
});
|
||||
},
|
||||
|
||||
async onOpenChange(isOpen) {
|
||||
if (isOpen) {
|
||||
const data = modelApi.getData();
|
||||
await formApi.resetForm();
|
||||
|
||||
if (data) {
|
||||
formData.value = data;
|
||||
id.value = data.id;
|
||||
} else {
|
||||
id.value = undefined;
|
||||
}
|
||||
|
||||
// Wait for Vue to flush DOM updates (form fields mounted)
|
||||
await nextTick();
|
||||
if (data) {
|
||||
await formApi.setValues(data);
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
const getDrawerTitle = computed(() => {
|
||||
return formData.value?.id ? '编辑用户' : '新建用户';
|
||||
});
|
||||
</script>
|
||||
<template>
|
||||
<Model :title="getDrawerTitle">
|
||||
<Form />
|
||||
</Model>
|
||||
</template>
|
||||
<style scoped></style>
|
||||
@ -1,113 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
|
||||
import { Page, useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { NButton, NSpace, NTag } from 'naive-ui';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { getPointListByPage } from '#/api';
|
||||
import { toObject } from '#/enum';
|
||||
import { router } from '#/router';
|
||||
|
||||
import { useGridSchema, useSearchFormSchema } from './data';
|
||||
import Form from './form.vue';
|
||||
|
||||
const [FormModel, formModelApi] = useVbenModal({
|
||||
connectedComponent: Form,
|
||||
destroyOnClose: true,
|
||||
});
|
||||
|
||||
const [Grid, GridApi] = useVbenVxeGrid({
|
||||
formOptions: {
|
||||
schema: useSearchFormSchema(),
|
||||
showCollapseButton: false,
|
||||
submitButtonOptions: {
|
||||
content: '查询',
|
||||
},
|
||||
submitOnChange: true,
|
||||
submitOnEnter: true,
|
||||
},
|
||||
gridOptions: {
|
||||
minHeight: 600,
|
||||
columns: useGridSchema(),
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }, formValues) => {
|
||||
return await getPointListByPage({
|
||||
current: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
...formValues,
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
// 完全移除分隔条
|
||||
separator: false,
|
||||
// 你也可以使用下面的代码来移除分隔条
|
||||
// separator: { show: false },
|
||||
// 或者使用下面的代码来改变分隔条的颜色
|
||||
// separator: { backgroundColor: 'rgba(100,100,0,0.5)' },
|
||||
});
|
||||
|
||||
const addEvent = () => {
|
||||
formModelApi.setData({}).open();
|
||||
};
|
||||
const editEvent = (row) => {
|
||||
formModelApi.setData(row).open();
|
||||
};
|
||||
const onRefresh = () => {
|
||||
GridApi.reload();
|
||||
};
|
||||
|
||||
const deptOptionsMap = computed(() => {
|
||||
return toObject(
|
||||
GridApi.formApi.getFieldComponentRef('deptId')?.getOptions() ?? [],
|
||||
'value',
|
||||
'label',
|
||||
);
|
||||
});
|
||||
|
||||
const jumpToDevice = (row: any) => {
|
||||
router.push({
|
||||
name: 'Device',
|
||||
query: {
|
||||
pointId: row.id,
|
||||
},
|
||||
});
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page auto-content-height>
|
||||
<Grid table-title="监测点列表">
|
||||
<template #toolbar-tools>
|
||||
<NButton class="mr-2" type="primary" @click="addEvent">
|
||||
新增监测点
|
||||
</NButton>
|
||||
</template>
|
||||
|
||||
<template #displayName="{ row }">
|
||||
<NButton type="primary" text @click="jumpToDevice(row)">
|
||||
{{ row.displayName }}
|
||||
</NButton>
|
||||
</template>
|
||||
<template #deptIds="{ row }">
|
||||
<NSpace>
|
||||
<NTag v-for="id in row.deptIds" :key="id">
|
||||
{{ deptOptionsMap[id] }}
|
||||
</NTag>
|
||||
</NSpace>
|
||||
</template>
|
||||
|
||||
<template #actions="{ row }">
|
||||
<NSpace>
|
||||
<NButton text type="primary" @click="editEvent(row)">编辑</NButton>
|
||||
</NSpace>
|
||||
</template>
|
||||
</Grid>
|
||||
|
||||
<FormModel @success="onRefresh" />
|
||||
</Page>
|
||||
</template>
|
||||
Loading…
Reference in New Issue
Block a user