|
@@ -6,31 +6,38 @@
|
|
|
:label-col="{ span: 9 }"
|
|
|
:wrapper-col="{ span: 15 }"
|
|
|
:showActionButtonGroup="false"
|
|
|
+ :disabled="!editable"
|
|
|
size="small"
|
|
|
label-align="right"
|
|
|
@register="register"
|
|
|
>
|
|
|
<template #create-btn>
|
|
|
- <Button type="primary" :rounded="true" @click="createSite">新建测点</Button>
|
|
|
+ <Button v-if="editable" type="primary" :rounded="true" :disabled="false" @click="save">
|
|
|
+ 保 存
|
|
|
+ </Button>
|
|
|
+ <Button v-else type="primary" :rounded="true" :disabled="false" @click="createSite">
|
|
|
+ 新建测点
|
|
|
+ </Button>
|
|
|
</template>
|
|
|
<template #edit-btn>
|
|
|
- <Button type="primary" :rounded="true" @click="editSite">编辑测点</Button>
|
|
|
+ <Button v-if="editable" type="primary" :rounded="true" :disabled="false" @click="cancel">
|
|
|
+ 取 消
|
|
|
+ </Button>
|
|
|
+ <Button v-else type="primary" :rounded="true" :disabled="false" @click="editSite">
|
|
|
+ 编辑测点
|
|
|
+ </Button>
|
|
|
</template>
|
|
|
<!-- <template #copy-btn>
|
|
|
<Button type="primary" :rounded="true" @click="copySite">复制测点</Button>
|
|
|
</template> -->
|
|
|
<template #pick-btn>
|
|
|
- <Button type="primary" :rounded="true" @click="pickSite">拾取坐标</Button>
|
|
|
+ <Button type="primary" :rounded="true" :disabled="false" @click="pickSite">拾取坐标</Button>
|
|
|
</template>
|
|
|
</BasicForm>
|
|
|
</template>
|
|
|
<script setup lang="ts">
|
|
|
- import {
|
|
|
- MonitorSiteTreeNode,
|
|
|
- MonitorSiteOperationParams,
|
|
|
- SaveMonitorSiteParams,
|
|
|
- } from '@/api/sys/model/monitorModel';
|
|
|
- import { defineProps } from 'vue';
|
|
|
+ import { MonitorSiteTreeNode, MonitorSiteOperationParams } from '@/api/sys/model/monitorModel';
|
|
|
+ import { defineProps, ref } from 'vue';
|
|
|
import { BasicForm, FormSchema, useForm } from '@/components/Form/index';
|
|
|
import { Button } from 'ant-design-vue';
|
|
|
import { SensorDict, SystemSourceDict } from '../const';
|
|
@@ -38,7 +45,7 @@
|
|
|
// props & emits
|
|
|
const props = defineProps<{ site: Partial<MonitorSiteTreeNode> }>();
|
|
|
const emit = defineEmits<{
|
|
|
- save: [value: SaveMonitorSiteParams];
|
|
|
+ save: [value: Required<MonitorSiteTreeNode>];
|
|
|
operation: [value: MonitorSiteOperationParams];
|
|
|
}>();
|
|
|
|
|
@@ -82,9 +89,6 @@
|
|
|
colProps: {
|
|
|
span: 1,
|
|
|
},
|
|
|
- componentProps: {
|
|
|
- size: 'small',
|
|
|
- },
|
|
|
};
|
|
|
}
|
|
|
|
|
@@ -127,7 +131,12 @@
|
|
|
const schemas: FormSchema[] = [
|
|
|
generateButtonSchema({ slot: 'create-btn' }),
|
|
|
generateInputSchema({ field: 'id', label: '测点编号', required: true }),
|
|
|
- generateSelectSchema({ field: 'sensorType', label: '测点类型', dict: SensorDict }),
|
|
|
+ generateSelectSchema({
|
|
|
+ field: 'sensorType',
|
|
|
+ label: '测点类型',
|
|
|
+ dict: SensorDict,
|
|
|
+ required: false,
|
|
|
+ }),
|
|
|
generateInputSchema({ field: 'sensorStatus', label: '测点使用状态' }),
|
|
|
generateInputSchema({ field: 'label', label: '所属位置', required: true }),
|
|
|
generateInputSchema({ field: 'x', label: 'X', required: true, span: 3 }),
|
|
@@ -146,30 +155,37 @@
|
|
|
generateInputSchema({ field: 'z', label: 'Z', span: 3 }),
|
|
|
];
|
|
|
|
|
|
+ // 表单是否可以编辑
|
|
|
+ const editable = ref(false);
|
|
|
+
|
|
|
// 后续操作表单必要的函数
|
|
|
- const [register, { validate }] = useForm();
|
|
|
+ const [register, { validate, setFieldsValue }] = useForm();
|
|
|
|
|
|
- // 提交创建测点所需的数据
|
|
|
+ // 新建测点,设置表单的数据、状态
|
|
|
function createSite() {
|
|
|
- validate().then((v) => {
|
|
|
- emit('save', { ...props.site, ...v } as SaveMonitorSiteParams);
|
|
|
- });
|
|
|
+ setFieldsValue({ id: '' });
|
|
|
+ editable.value = true;
|
|
|
}
|
|
|
|
|
|
- // 提交复制测点所需的数据
|
|
|
- // function copySite() {
|
|
|
- // validate().then((v) => {
|
|
|
- // emit('save', { ...props.site, ...v } as SaveMonitorSiteParams);
|
|
|
- // });
|
|
|
- // }
|
|
|
-
|
|
|
- // 提交编辑测点所需的数据
|
|
|
+ // 编辑测点,设置表单的数据、状态
|
|
|
function editSite() {
|
|
|
+ editable.value = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 保存测点,提交表单
|
|
|
+ function save() {
|
|
|
validate().then((v) => {
|
|
|
- emit('save', { ...props.site, ...v } as SaveMonitorSiteParams);
|
|
|
+ cancel();
|
|
|
+ emit('save', { ...props.site, ...v } as Required<MonitorSiteTreeNode>);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ // 取消编辑,表单回到默认状态
|
|
|
+ function cancel() {
|
|
|
+ setFieldsValue(props.site);
|
|
|
+ editable.value = false;
|
|
|
+ }
|
|
|
+
|
|
|
// 拾取测点
|
|
|
function pickSite() {
|
|
|
emit('operation', {
|
|
@@ -177,9 +193,4 @@
|
|
|
from: 'tank',
|
|
|
});
|
|
|
}
|
|
|
-
|
|
|
- defineExpose({
|
|
|
- schemas,
|
|
|
- register,
|
|
|
- });
|
|
|
</script>
|