Просмотр исходного кода

检查类型编码和名称是否已注册

like 6 месяцев назад
Родитель
Сommit
75a9097286

+ 9 - 0
snowy-admin-web/src/api/basicset/devicetypeApi.js

@@ -24,5 +24,14 @@ export default {
 	// 详情
 	devicetypeDetail(data) {
 		return request('detail', data, 'get')
+	},
+
+	// 检查设备名是否已注册
+	submitDeviceTypeName(data) {
+		return request('getByTypeName', data, 'get')
+	},
+	// 检查设备名是否已注册
+	submitDeviceTypeCode(data) {
+		return request('getByTypeCode', data, 'get')
 	}
 }

+ 133 - 0
snowy-admin-web/src/utils/validate.js

@@ -0,0 +1,133 @@
+/**
+ * @description 判断是否是数组
+ * @param arg
+ */
+export function isArray(arg) {
+	if (typeof Array.isArray === 'undefined') {
+		return Object.prototype.toString.call(arg) === '[object Array]'
+	}
+	return Array.isArray(arg)
+}
+/**
+ * @description 判断是否是小写字母
+ * @param value
+ * @returns {boolean}
+ */
+export function isLowerCase(value) {
+	const reg = /^[a-z]+$/
+	return reg.test(value)
+}
+/**
+ * @description 判断是否是大写字母
+ * @param value
+ * @returns {boolean}
+ */
+export function isUpperCase(value) {
+	const reg = /^[A-Z]+$/
+	return reg.test(value)
+}
+
+/**
+ * @description 判断是否是大写字母开头
+ * @param value
+ * @returns {boolean}
+ */
+export function isAlphabets(value) {
+	const reg = /^[A-Za-z]+$/
+	return reg.test(value)
+}
+
+/**
+ * @description 判断是否是字符串
+ * @param value
+ * @returns {boolean}
+ */
+export function isString(value) {
+	return typeof value === 'string' || value instanceof String
+}
+/**
+ * @description 判断是否是端口号
+ * @param value
+ * @returns {boolean}
+ */
+export function isPort(value) {
+	const reg = /^([0-9]|[1-9]\d|[1-9]\d{2}|[1-9]\d{3}|[1-5]\d{4}|6[0-4]\d{3}|65[0-4]\d{2}|655[0-2]\d|6553[0-5])$/
+	return reg.test(value)
+}
+/**
+ * @description 判断是否中文
+ * @param value
+ * @returns {boolean}
+ */
+export function isChina(value) {
+	const reg = /^[\u4E00-\u9FA5]{2,4}$/
+	return reg.test(value)
+}
+
+/**
+ * @description 判断是否为空
+ * @param value
+ * @returns {boolean}
+ */
+export function isBlank(value) {
+	return value === null || false || value === '' || value.trim() === '' || value.toLocaleLowerCase().trim() === 'null'
+}
+/**
+ * @description 判断是否是手机号
+ * @param value
+ * @returns {boolean}
+ */
+
+export const isPhone = (reule, value, cb) => {
+	if (!value) {
+		cb()
+		return
+	}
+	// 手机的正则表达式
+	const regPhone = /^1(?:3\d|4[4-9]|5[0-35-9]|6[67]|7[013-8]|8\d|9\d)\d{8}$/
+	if (regPhone.test(value)) {
+		// 合法手机号
+		return cb()
+	} else {
+		cb(new Error('请输入合法的手机号'))
+	}
+}
+// 只能输入0-9数字型
+export const isNumber = (reule, value, cb) => {
+	const regNumber = /^[+-]?\d+(\.\d+)?$/
+
+	if (regNumber.test(value)) {
+		return cb()
+	}
+	cb(new Error('只能输入数字型'))
+}
+//由数字、26个英文字母或者下划线组成的
+export const isRuletype = (reule, value, cb) => {
+	const reg = /^[0-9a-zA-Z_-]{1,}$/
+	if (reg.test(value)) {
+		return cb()
+	}
+	cb(new Error('只允许输入字母或字母或者下划线_中划线-'))
+}
+// 年月日
+export const formatDate1 = (cellValue) => {
+	if (cellValue == null || cellValue == '') return ''
+	var date = new Date(cellValue)
+	var year = date.getFullYear()
+	var month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1
+	var day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate()
+	return year + '-' + month + '-' + day
+}
+
+// 年月日时分秒
+export const formatDate = (cellValue) => {
+	if (cellValue == null || cellValue == '') return ''
+	var date = new Date(cellValue)
+	var year = date.getFullYear()
+	var month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1
+	var day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate()
+	var hours = date.getHours() < 10 ? '0' + date.getHours() : date.getHours()
+	var minutes = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()
+	var seconds = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
+	return year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds
+}

+ 35 - 3
snowy-admin-web/src/views/basicset/devicetype/form.vue

@@ -21,7 +21,13 @@
 				</a-col>
 				<a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
 					<a-form-item label="型号编号" name="code">
-						<a-input v-model:value="formData.code" placeholder="请输入型号编号" allow-clear :maxlength="10" />
+						<a-input
+							v-model:value="formData.code"
+							placeholder="请输入型号编号"
+							allow-clear
+							:maxlength="10"
+							@blur="handleCodeBlur"
+						/>
 					</a-form-item>
 				</a-col>
 
@@ -120,13 +126,12 @@
 </template>
 
 <script setup>
-	import { required, rules } from '@/utils/formRules'
+	import { required } from '@/utils/formRules'
 	import devicetypeApi from '@/api/basicset/devicetypeApi'
 	const emit = defineEmits({ successful: null })
 	const visible = ref(false) // 默认是关闭状态
 	const formRef = ref()
 	const formData = ref({ sortCode: 99 }) // 表单数据
-	import { isNumber } from '@/utils/validate'
 	// 默认要校验的
 	const formRules = {
 		name: [required('请输入型号名称')],
@@ -190,6 +195,33 @@
 		}
 	}
 
+	// 检查型号编号是否已注册
+	const handleCodeBlur = () => {
+		if (formData.value.code) {
+			devicetypeApi
+				.submitDeviceTypeCode({ code: formData.value.code })
+				.then((res) => {})
+				.catch(() => {
+					formData.value.code = ''
+				})
+		}
+	}
+	// 检查型号名称是否已注册
+	watch(
+		() => formData.value.name,
+		(newVal) => {
+			if (newVal) {
+				devicetypeApi
+					.submitDeviceTypeName({ name: newVal })
+					.then((res) => {})
+					.catch(() => {
+						return (formData.value.name = '')
+					})
+			}
+		},
+		{ immediate: true, deep: true }
+	)
+
 	// 打开抽屉
 	const onOpen = (record) => {
 		visible.value = true

+ 2 - 2
snowy-admin-web/src/views/basicset/mem/form.vue

@@ -169,7 +169,7 @@
 		sensorCount: [required('请输入传感器路数')]
 	}
 
-	// 检查设备名是否已注册
+	// 检查设备名是否已注册
 	watch(
 		() => formData.value.deviceName,
 		(newVal) => {
@@ -197,7 +197,7 @@
 			})
 		})
 	}
-	// 检查设备是否已注册
+	// 检查设备编号是否已注册
 	const handleCodeBlur = () => {
 		if (formData.value.deviceCode) {
 			memApi