提交 | 用户 | 时间
|
1c14d6
|
1 |
<template> |
L |
2 |
<Dialog v-model="dialogVisible" :title="dialogTitle" width="50%"> |
|
3 |
<el-form |
|
4 |
ref="formRef" |
|
5 |
v-loading="formLoading" |
|
6 |
:model="formData" |
|
7 |
:rules="formRules" |
|
8 |
label-width="120px" |
|
9 |
> |
|
10 |
<el-row> |
|
11 |
<el-col :span="12"> |
|
12 |
<el-form-item label="测点编码" prop="pointNo"> |
|
13 |
<el-input v-model="formData.pointNo" placeholder="请输入测点编码" /> |
|
14 |
</el-form-item> |
|
15 |
</el-col> |
|
16 |
</el-row> |
|
17 |
<el-row> |
|
18 |
<el-col :span="12"> |
|
19 |
<el-form-item label="测点名称" prop="pointName"> |
|
20 |
<el-input v-model="formData.pointName" placeholder="请输入测点名称" /> |
|
21 |
</el-form-item> |
|
22 |
</el-col> |
|
23 |
<el-col :span="12"> |
|
24 |
<el-form-item label="测点类型" prop="pointType"> |
|
25 |
<el-input v-model="formData.pointType" placeholder="请输入测点类型" /> |
|
26 |
</el-form-item> |
|
27 |
</el-col> |
|
28 |
</el-row> |
|
29 |
<el-row> |
|
30 |
<el-col :span="12"> |
|
31 |
<el-form-item label="数据类型" prop="dataType"> |
|
32 |
<el-input v-model="formData.dataType" placeholder="请输入数据类型" /> |
|
33 |
</el-form-item> |
|
34 |
</el-col> |
|
35 |
<el-col :span="12"> |
|
36 |
<el-form-item label="值类型" prop="valueType"> |
|
37 |
<el-input v-model="formData.valueType" placeholder="请输入值类型" /> |
|
38 |
</el-form-item> |
|
39 |
</el-col> |
|
40 |
</el-row> |
|
41 |
<el-row> |
|
42 |
<el-col :span="12"> |
|
43 |
<el-form-item label="存储类型" prop="storeType"> |
|
44 |
<el-input v-model="formData.storeType" placeholder="请输入存储类型" /> |
|
45 |
</el-form-item> |
|
46 |
</el-col> |
|
47 |
<el-col :span="12"> |
|
48 |
<el-form-item label="测量单位" prop="unit"> |
|
49 |
<el-input v-model="formData.unit" placeholder="请输入测量单位" /> |
|
50 |
</el-form-item> |
|
51 |
</el-col> |
|
52 |
</el-row> |
|
53 |
<el-row> |
|
54 |
<el-col :span="12"> |
|
55 |
<el-form-item label="单位转换" prop="unittransfactor"> |
|
56 |
<el-input v-model="formData.unittransfactor" placeholder="请输入单位转换" /> |
|
57 |
</el-form-item> |
|
58 |
</el-col> |
|
59 |
<el-col :span="12"> |
|
60 |
<el-form-item label="默认值" prop="defaultValue"> |
|
61 |
<el-input v-model="formData.defaultValue" placeholder="请输入默认值" /> |
|
62 |
</el-form-item> |
|
63 |
</el-col> |
|
64 |
</el-row> |
|
65 |
<el-row> |
|
66 |
<el-col :span="12"> |
|
67 |
<el-form-item label="最大值" prop="maxValue"> |
|
68 |
<el-input v-model="formData.maxValue" placeholder="请输入最大值" /> |
|
69 |
</el-form-item> |
|
70 |
</el-col> |
|
71 |
<el-col :span="12"> |
|
72 |
<el-form-item label="最小值" prop="minValue"> |
|
73 |
<el-input v-model="formData.minValue" placeholder="请输入最小值" /> |
|
74 |
</el-form-item> |
|
75 |
</el-col> |
|
76 |
</el-row> |
|
77 |
<el-row> |
|
78 |
<el-col :span="12"> |
|
79 |
<el-form-item label="采集频率" prop="minfreqid"> |
|
80 |
<el-input v-model="formData.minfreqid" placeholder="请输入采集频率" /> |
|
81 |
</el-form-item> |
|
82 |
</el-col> |
|
83 |
<el-col :span="12"> |
|
84 |
<el-form-item label="备注" prop="remark"> |
|
85 |
<el-input v-model="formData.remark" placeholder="请输入备注" /> |
|
86 |
</el-form-item> |
|
87 |
</el-col> |
|
88 |
</el-row> |
|
89 |
<el-row> |
|
90 |
<el-col :span="12"> |
|
91 |
<el-form-item label="是否启用" prop="isEnable"> |
|
92 |
<el-input v-model="formData.isEnable" placeholder="请输入是否启用" /> |
|
93 |
</el-form-item> |
|
94 |
</el-col> |
|
95 |
</el-row> |
|
96 |
</el-form> |
|
97 |
<template #footer> |
|
98 |
<el-button :disabled="formLoading" type="primary" @click="submitForm">确 定</el-button> |
|
99 |
<el-button @click="dialogVisible = false">取 消</el-button> |
|
100 |
</template> |
|
101 |
</Dialog> |
|
102 |
</template> |
|
103 |
<script lang="ts" setup> |
|
104 |
import * as DaPoint from '@/api/data/da/point' |
|
105 |
|
|
106 |
defineOptions({ name: 'DataDaPointForm' }) |
|
107 |
|
|
108 |
const { t } = useI18n() // 国际化 |
|
109 |
const message = useMessage() // 消息弹窗 |
|
110 |
const dialogVisible = ref(false) // 弹窗的是否展示 |
|
111 |
const dialogTitle = ref('') // 弹窗的标题 |
|
112 |
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用 |
|
113 |
const formType = ref('') // 表单的类型:create - 新增;update - 修改 |
|
114 |
const formData = ref({ |
|
115 |
id: undefined, |
|
116 |
pointNo: undefined, |
|
117 |
pointName: undefined, |
|
118 |
pointType: undefined, |
|
119 |
dataType: undefined, |
|
120 |
valueType: undefined, |
|
121 |
storeType: undefined, |
|
122 |
unit: undefined, |
|
123 |
unittransfactor: undefined, |
|
124 |
defaultValue: undefined, |
|
125 |
maxValue: undefined, |
|
126 |
minValue: undefined, |
|
127 |
minfreqid: undefined, |
|
128 |
remark: undefined, |
|
129 |
isEnable: undefined, |
|
130 |
}) |
|
131 |
const formRules = reactive({ |
|
132 |
pointNo: [{ required: true, message: '测点编码不能为空', trigger: 'blur' }], |
|
133 |
pointName: [{ required: true, message: '测点名称不能为空', trigger: 'blur' }], |
|
134 |
}) |
|
135 |
const formRef = ref() // 表单 Ref |
|
136 |
|
|
137 |
/** 打开弹窗 */ |
|
138 |
const open = async (type: string, id?: number) => { |
|
139 |
dialogVisible.value = true |
|
140 |
dialogTitle.value = t('action.' + type) |
|
141 |
formType.value = type |
|
142 |
resetForm() |
|
143 |
// 修改时,设置数据 |
|
144 |
if (id) { |
|
145 |
formLoading.value = true |
|
146 |
try { |
|
147 |
formData.value = await DaPoint.getDaPoint(id) |
|
148 |
} finally { |
|
149 |
formLoading.value = false |
|
150 |
} |
|
151 |
} |
|
152 |
} |
|
153 |
defineExpose({ open }) // 提供 open 方法,用于打开弹窗 |
|
154 |
|
|
155 |
/** 提交表单 */ |
|
156 |
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调 |
|
157 |
const submitForm = async () => { |
|
158 |
// 校验表单 |
|
159 |
if (!formRef) return |
|
160 |
const valid = await formRef.value.validate() |
|
161 |
if (!valid) return |
|
162 |
// 提交请求 |
|
163 |
formLoading.value = true |
|
164 |
try { |
|
165 |
const data = formData.value as unknown as DaPoint.DaPointVO |
|
166 |
if (formType.value === 'create') { |
|
167 |
await DaPoint.createDaPoint(data) |
|
168 |
message.success(t('common.createSuccess')) |
|
169 |
} else { |
|
170 |
await DaPoint.updateDaPoint(data) |
|
171 |
message.success(t('common.updateSuccess')) |
|
172 |
} |
|
173 |
dialogVisible.value = false |
|
174 |
// 发送操作成功的事件 |
|
175 |
emit('success') |
|
176 |
} finally { |
|
177 |
formLoading.value = false |
|
178 |
} |
|
179 |
} |
|
180 |
|
|
181 |
/** 重置表单 */ |
|
182 |
const resetForm = () => { |
|
183 |
formData.value = { |
|
184 |
id: undefined, |
|
185 |
pointNo: undefined, |
|
186 |
pointName: undefined, |
|
187 |
pointType: undefined, |
|
188 |
dataType: undefined, |
|
189 |
valueType: undefined, |
|
190 |
storeType: undefined, |
|
191 |
unit: undefined, |
|
192 |
unittransfactor: undefined, |
|
193 |
defaultValue: undefined, |
|
194 |
maxValue: undefined, |
|
195 |
minValue: undefined, |
|
196 |
minfreqid: undefined, |
|
197 |
remark: undefined, |
|
198 |
isEnable: undefined, |
|
199 |
} |
|
200 |
formRef.value?.resetFields() |
|
201 |
} |
|
202 |
</script> |