From df90c0c5cfa4de114798015b92120ad8ba8b4826 Mon Sep 17 00:00:00 2001 From: 潘志宝 <979469083@qq.com> Date: 星期五, 22 十一月 2024 10:45:40 +0800 Subject: [PATCH] MEASURE_VALUE_TYPE --- src/views/data/channel/kio/KioDeviceForm.vue | 49 +++++++++++++++++++++++++++++++++++-------------- 1 files changed, 35 insertions(+), 14 deletions(-) diff --git a/src/views/data/channel/kio/KioDeviceForm.vue b/src/views/data/channel/kio/KioDeviceForm.vue index c475a54..f74e346 100644 --- a/src/views/data/channel/kio/KioDeviceForm.vue +++ b/src/views/data/channel/kio/KioDeviceForm.vue @@ -10,31 +10,31 @@ <el-row> <el-col :span="12"> <el-form-item label="实例名称" prop="instanceName"> - <el-input v-model="formData.instanceName" placeholder="请输入实例名称" /> + <el-input v-model="formData.instanceName" placeholder="请输入实例名称"/> </el-form-item> </el-col> </el-row> <el-row> <el-col :span="12"> <el-form-item label="IP地址" prop="address"> - <el-input v-model="formData.address" placeholder="请输入IP地址" /> + <el-input v-model="formData.address" placeholder="请输入IP地址"/> </el-form-item> </el-col> <el-col :span="12"> <el-form-item label="端口" prop="port"> - <el-input v-model="formData.port" placeholder="请输入端口" /> + <el-input v-model="formData.port" placeholder="请输入端口"/> </el-form-item> </el-col> </el-row> <el-row> <el-col :span="12"> <el-form-item label="用户名" prop="username"> - <el-input v-model="formData.username" placeholder="请输入用户名" /> + <el-input v-model="formData.username" placeholder="请输入用户名"/> </el-form-item> </el-col> <el-col :span="12"> <el-form-item label="密码" prop="password"> - <el-input type = "password" v-model="formData.password" placeholder="请输入密码" /> + <el-input type="password" v-model="formData.password" placeholder="请输入密码"/> </el-form-item> </el-col> </el-row> @@ -46,11 +46,12 @@ </Dialog> </template> <script lang="ts" setup> -import * as KioApi from '@/api/data/channel/kio' + import * as KioApi from '@/api/data/channel/kio' + import {isIP, isPositiveInteger} from '@/utils/validate' -defineOptions({ name: 'DataKioDeviceForm' }) + defineOptions({name: 'DataKioDeviceForm'}) - const { t } = useI18n() // 国际化 + const {t} = useI18n() // 国际化 const message = useMessage() // 消息弹窗 const dialogVisible = ref(false) // 弹窗的是否展示 const dialogTitle = ref('') // 弹窗的标题 @@ -64,12 +65,32 @@ username: undefined, password: undefined, }) + const validateIP = (rule, value, callback) => { + if (!isIP(value)) { + callback(new Error('IP地址不正确')) + } else { + callback() + } + } + const validateNum = (rule, value, callback) => { + if (!isPositiveInteger(value)) { + callback(new Error('格式不正确')) + } else { + callback() + } + } const formRules = reactive({ - instanceName: [{ required: true, message: '设备名称不能为空', trigger: 'blur' }], - address: [{ required: true, message: 'IP地址不能为空', trigger: 'blur' }], - port: [{ required: true, message: '端口不能为空', trigger: 'blur' }], - username: [{ required: true, message: '用户名不能为空', trigger: 'blur' }], - password: [{ required: true, message: '密码不能为空', trigger: 'blur' }] + instanceName: [{required: true, message: '设备名称不能为空', trigger: 'blur'}], + address: [ + {required: true, message: 'IP地址不能为空', trigger: 'blur'}, + {validator: validateIP, trigger: 'blur'} + ], + port: [ + {required: true, message: '端口不能为空', trigger: 'blur'}, + {validator: validateNum, trigger: 'blur'} + ], + username: [{required: true, message: '用户名不能为空', trigger: 'blur'}], + password: [{required: true, message: '密码不能为空', trigger: 'blur'}] }) const formRef = ref() // 表单 Ref @@ -89,7 +110,7 @@ } } } - defineExpose({ open }) // 提供 open 方法,用于打开弹窗 + defineExpose({open}) // 提供 open 方法,用于打开弹窗 /** 提交表单 */ const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调 -- Gitblit v1.9.3