fix: 修复设备更新面板中错误的表单校验逻辑
This commit is contained in:
@@ -55,6 +55,9 @@ const { mutateAsync: validateDeviceIdDuplicated } = useMutation({
|
|||||||
const deviceIdPattern = /^\d{4}01\d{4}$/;
|
const deviceIdPattern = /^\d{4}01\d{4}$/;
|
||||||
if (!deviceIdPattern.test(deviceId)) throw new Error('设备ID不符合规范');
|
if (!deviceIdPattern.test(deviceId)) throw new Error('设备ID不符合规范');
|
||||||
|
|
||||||
|
// 如果没有修改设备ID,则不做ID唯一性校验
|
||||||
|
if (deviceId === ndmDevice.value.deviceId) return;
|
||||||
|
|
||||||
validatorAbortController.value.abort();
|
validatorAbortController.value.abort();
|
||||||
validatorAbortController.value = new AbortController();
|
validatorAbortController.value = new AbortController();
|
||||||
|
|
||||||
@@ -69,8 +72,7 @@ const { mutateAsync: validateDeviceIdDuplicated } = useMutation({
|
|||||||
const { mutate: updateDevice, isPending: loading } = useMutation({
|
const { mutate: updateDevice, isPending: loading } = useMutation({
|
||||||
mutationFn: async () => {
|
mutationFn: async () => {
|
||||||
await formInst.value?.validate().catch(() => {
|
await formInst.value?.validate().catch(() => {
|
||||||
window.$message.error('表单验证失败');
|
throw new Error('表单校验失败');
|
||||||
return;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
abortController.value.abort();
|
abortController.value.abort();
|
||||||
@@ -85,6 +87,7 @@ const { mutate: updateDevice, isPending: loading } = useMutation({
|
|||||||
onSuccess: (newDevice) => {
|
onSuccess: (newDevice) => {
|
||||||
localDevice.value = { ...newDevice };
|
localDevice.value = { ...newDevice };
|
||||||
deviceStore.patchDevice(station.value.code, { ...newDevice });
|
deviceStore.patchDevice(station.value.code, { ...newDevice });
|
||||||
|
window.$message.success('更新成功');
|
||||||
},
|
},
|
||||||
onError: (error) => {
|
onError: (error) => {
|
||||||
if (isCancel(error)) return;
|
if (isCancel(error)) return;
|
||||||
|
|||||||
@@ -54,6 +54,9 @@ const { mutateAsync: validateDeviceIdDuplicated } = useMutation({
|
|||||||
const deviceIdPattern = /^\d{4}06\d{4}$/;
|
const deviceIdPattern = /^\d{4}06\d{4}$/;
|
||||||
if (!deviceIdPattern.test(deviceId)) throw new Error('设备ID不符合规范');
|
if (!deviceIdPattern.test(deviceId)) throw new Error('设备ID不符合规范');
|
||||||
|
|
||||||
|
// 如果没有修改设备ID,则不做ID唯一性校验
|
||||||
|
if (deviceId === ndmDevice.value.deviceId) return;
|
||||||
|
|
||||||
validatorAbortController.value.abort();
|
validatorAbortController.value.abort();
|
||||||
validatorAbortController.value = new AbortController();
|
validatorAbortController.value = new AbortController();
|
||||||
|
|
||||||
@@ -68,8 +71,7 @@ const { mutateAsync: validateDeviceIdDuplicated } = useMutation({
|
|||||||
const { mutate: updateDevice, isPending: loading } = useMutation({
|
const { mutate: updateDevice, isPending: loading } = useMutation({
|
||||||
mutationFn: async () => {
|
mutationFn: async () => {
|
||||||
await formInst.value?.validate().catch(() => {
|
await formInst.value?.validate().catch(() => {
|
||||||
window.$message.error('表单验证失败');
|
throw new Error('表单校验失败');
|
||||||
return;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
abortController.value.abort();
|
abortController.value.abort();
|
||||||
@@ -84,6 +86,7 @@ const { mutate: updateDevice, isPending: loading } = useMutation({
|
|||||||
onSuccess: (newDevice) => {
|
onSuccess: (newDevice) => {
|
||||||
localDevice.value = { ...newDevice };
|
localDevice.value = { ...newDevice };
|
||||||
deviceStore.patchDevice(station.value.code, { ...newDevice });
|
deviceStore.patchDevice(station.value.code, { ...newDevice });
|
||||||
|
window.$message.success('更新成功');
|
||||||
},
|
},
|
||||||
onError: (error) => {
|
onError: (error) => {
|
||||||
if (isCancel(error)) return;
|
if (isCancel(error)) return;
|
||||||
|
|||||||
@@ -54,6 +54,9 @@ const { mutateAsync: validateDeviceIdDuplicated } = useMutation({
|
|||||||
const deviceIdPattern = /^\d{4}07\d{4}$/;
|
const deviceIdPattern = /^\d{4}07\d{4}$/;
|
||||||
if (!deviceIdPattern.test(deviceId)) throw new Error('设备ID不符合规范');
|
if (!deviceIdPattern.test(deviceId)) throw new Error('设备ID不符合规范');
|
||||||
|
|
||||||
|
// 如果没有修改设备ID,则不做ID唯一性校验
|
||||||
|
if (deviceId === ndmDevice.value.deviceId) return;
|
||||||
|
|
||||||
validatorAbortController.value.abort();
|
validatorAbortController.value.abort();
|
||||||
validatorAbortController.value = new AbortController();
|
validatorAbortController.value = new AbortController();
|
||||||
|
|
||||||
@@ -68,8 +71,7 @@ const { mutateAsync: validateDeviceIdDuplicated } = useMutation({
|
|||||||
const { mutate: updateDevice, isPending: loading } = useMutation({
|
const { mutate: updateDevice, isPending: loading } = useMutation({
|
||||||
mutationFn: async () => {
|
mutationFn: async () => {
|
||||||
await formInst.value?.validate().catch(() => {
|
await formInst.value?.validate().catch(() => {
|
||||||
window.$message.error('表单验证失败');
|
throw new Error('表单校验失败');
|
||||||
return;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
abortController.value.abort();
|
abortController.value.abort();
|
||||||
@@ -84,6 +86,7 @@ const { mutate: updateDevice, isPending: loading } = useMutation({
|
|||||||
onSuccess: (newDevice) => {
|
onSuccess: (newDevice) => {
|
||||||
localDevice.value = { ...newDevice };
|
localDevice.value = { ...newDevice };
|
||||||
deviceStore.patchDevice(station.value.code, { ...newDevice });
|
deviceStore.patchDevice(station.value.code, { ...newDevice });
|
||||||
|
window.$message.success('更新成功');
|
||||||
},
|
},
|
||||||
onError: (error) => {
|
onError: (error) => {
|
||||||
if (isCancel(error)) return;
|
if (isCancel(error)) return;
|
||||||
|
|||||||
@@ -54,6 +54,9 @@ const { mutateAsync: validateDeviceIdDuplicated } = useMutation({
|
|||||||
const deviceIdPattern = /^\d{4}08\d{4}$/;
|
const deviceIdPattern = /^\d{4}08\d{4}$/;
|
||||||
if (!deviceIdPattern.test(deviceId)) throw new Error('设备ID不符合规范');
|
if (!deviceIdPattern.test(deviceId)) throw new Error('设备ID不符合规范');
|
||||||
|
|
||||||
|
// 如果没有修改设备ID,则不做ID唯一性校验
|
||||||
|
if (deviceId === ndmDevice.value.deviceId) return;
|
||||||
|
|
||||||
validatorAbortController.value.abort();
|
validatorAbortController.value.abort();
|
||||||
validatorAbortController.value = new AbortController();
|
validatorAbortController.value = new AbortController();
|
||||||
|
|
||||||
@@ -68,8 +71,7 @@ const { mutateAsync: validateDeviceIdDuplicated } = useMutation({
|
|||||||
const { mutate: updateDevice, isPending: loading } = useMutation({
|
const { mutate: updateDevice, isPending: loading } = useMutation({
|
||||||
mutationFn: async () => {
|
mutationFn: async () => {
|
||||||
await formInst.value?.validate().catch(() => {
|
await formInst.value?.validate().catch(() => {
|
||||||
window.$message.error('表单验证失败');
|
throw new Error('表单校验失败');
|
||||||
return;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
abortController.value.abort();
|
abortController.value.abort();
|
||||||
@@ -84,6 +86,7 @@ const { mutate: updateDevice, isPending: loading } = useMutation({
|
|||||||
onSuccess: (newDevice) => {
|
onSuccess: (newDevice) => {
|
||||||
localDevice.value = { ...newDevice };
|
localDevice.value = { ...newDevice };
|
||||||
deviceStore.patchDevice(station.value.code, { ...newDevice });
|
deviceStore.patchDevice(station.value.code, { ...newDevice });
|
||||||
|
window.$message.success('更新成功');
|
||||||
},
|
},
|
||||||
onError: (error) => {
|
onError: (error) => {
|
||||||
if (isCancel(error)) return;
|
if (isCancel(error)) return;
|
||||||
|
|||||||
@@ -54,6 +54,9 @@ const { mutateAsync: validateDeviceIdDuplicated } = useMutation({
|
|||||||
const deviceIdPattern = /^\d{4}05\d{4}$/;
|
const deviceIdPattern = /^\d{4}05\d{4}$/;
|
||||||
if (!deviceIdPattern.test(deviceId)) throw new Error('设备ID不符合规范');
|
if (!deviceIdPattern.test(deviceId)) throw new Error('设备ID不符合规范');
|
||||||
|
|
||||||
|
// 如果没有修改设备ID,则不做ID唯一性校验
|
||||||
|
if (deviceId === ndmDevice.value.deviceId) return;
|
||||||
|
|
||||||
validatorAbortController.value.abort();
|
validatorAbortController.value.abort();
|
||||||
validatorAbortController.value = new AbortController();
|
validatorAbortController.value = new AbortController();
|
||||||
|
|
||||||
@@ -68,8 +71,7 @@ const { mutateAsync: validateDeviceIdDuplicated } = useMutation({
|
|||||||
const { mutate: updateDevice, isPending } = useMutation({
|
const { mutate: updateDevice, isPending } = useMutation({
|
||||||
mutationFn: async () => {
|
mutationFn: async () => {
|
||||||
await formInst.value?.validate().catch(() => {
|
await formInst.value?.validate().catch(() => {
|
||||||
window.$message.error('表单验证失败');
|
throw new Error('表单校验失败');
|
||||||
return;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
abortController.value.abort();
|
abortController.value.abort();
|
||||||
@@ -84,6 +86,7 @@ const { mutate: updateDevice, isPending } = useMutation({
|
|||||||
onSuccess: (newDevice) => {
|
onSuccess: (newDevice) => {
|
||||||
localDevice.value = { ...newDevice };
|
localDevice.value = { ...newDevice };
|
||||||
deviceStore.patchDevice(station.value.code, { ...newDevice });
|
deviceStore.patchDevice(station.value.code, { ...newDevice });
|
||||||
|
window.$message.success('更新成功');
|
||||||
},
|
},
|
||||||
onError: (error) => {
|
onError: (error) => {
|
||||||
if (isCancel(error)) return;
|
if (isCancel(error)) return;
|
||||||
|
|||||||
@@ -54,6 +54,9 @@ const { mutateAsync: validateDeviceIdDuplicated } = useMutation({
|
|||||||
const deviceIdPattern = /^\d{4}03\d{4}$/;
|
const deviceIdPattern = /^\d{4}03\d{4}$/;
|
||||||
if (!deviceIdPattern.test(deviceId)) throw new Error('设备ID不符合规范');
|
if (!deviceIdPattern.test(deviceId)) throw new Error('设备ID不符合规范');
|
||||||
|
|
||||||
|
// 如果没有修改设备ID,则不做ID唯一性校验
|
||||||
|
if (deviceId === ndmDevice.value.deviceId) return;
|
||||||
|
|
||||||
validatorAbortController.value.abort();
|
validatorAbortController.value.abort();
|
||||||
validatorAbortController.value = new AbortController();
|
validatorAbortController.value = new AbortController();
|
||||||
|
|
||||||
@@ -68,8 +71,7 @@ const { mutateAsync: validateDeviceIdDuplicated } = useMutation({
|
|||||||
const { mutate: updateDevice, isPending } = useMutation({
|
const { mutate: updateDevice, isPending } = useMutation({
|
||||||
mutationFn: async () => {
|
mutationFn: async () => {
|
||||||
await formInst.value?.validate().catch(() => {
|
await formInst.value?.validate().catch(() => {
|
||||||
window.$message.error('表单验证失败');
|
throw new Error('表单校验失败');
|
||||||
return;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
abortController.value.abort();
|
abortController.value.abort();
|
||||||
@@ -84,6 +86,7 @@ const { mutate: updateDevice, isPending } = useMutation({
|
|||||||
onSuccess: (newDevice) => {
|
onSuccess: (newDevice) => {
|
||||||
localDevice.value = { ...newDevice };
|
localDevice.value = { ...newDevice };
|
||||||
deviceStore.patchDevice(station.value.code, { ...newDevice });
|
deviceStore.patchDevice(station.value.code, { ...newDevice });
|
||||||
|
window.$message.success('更新成功');
|
||||||
},
|
},
|
||||||
onError: (error) => {
|
onError: (error) => {
|
||||||
if (isCancel(error)) return;
|
if (isCancel(error)) return;
|
||||||
|
|||||||
@@ -66,6 +66,9 @@ const { mutateAsync: validateDeviceIdDuplicated } = useMutation({
|
|||||||
const deviceIdPattern = /^\d{4}(09|11)\d{4}$/;
|
const deviceIdPattern = /^\d{4}(09|11)\d{4}$/;
|
||||||
if (!deviceIdPattern.test(deviceId)) throw new Error('设备ID不符合规范');
|
if (!deviceIdPattern.test(deviceId)) throw new Error('设备ID不符合规范');
|
||||||
|
|
||||||
|
// 如果没有修改设备ID,则不做ID唯一性校验
|
||||||
|
if (deviceId === ndmDevice.value.deviceId) return;
|
||||||
|
|
||||||
validatorAbortController.value.abort();
|
validatorAbortController.value.abort();
|
||||||
validatorAbortController.value = new AbortController();
|
validatorAbortController.value = new AbortController();
|
||||||
|
|
||||||
@@ -80,8 +83,7 @@ const { mutateAsync: validateDeviceIdDuplicated } = useMutation({
|
|||||||
const { mutate: updateDevice, isPending } = useMutation({
|
const { mutate: updateDevice, isPending } = useMutation({
|
||||||
mutationFn: async () => {
|
mutationFn: async () => {
|
||||||
await formInst.value?.validate().catch(() => {
|
await formInst.value?.validate().catch(() => {
|
||||||
window.$message.error('表单验证失败');
|
throw new Error('表单校验失败');
|
||||||
return;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
abortController.value.abort();
|
abortController.value.abort();
|
||||||
@@ -103,6 +105,7 @@ const { mutate: updateDevice, isPending } = useMutation({
|
|||||||
onSuccess: (newDevice) => {
|
onSuccess: (newDevice) => {
|
||||||
localDevice.value = { ...newDevice };
|
localDevice.value = { ...newDevice };
|
||||||
deviceStore.patchDevice(station.value.code, { ...newDevice });
|
deviceStore.patchDevice(station.value.code, { ...newDevice });
|
||||||
|
window.$message.success('更新成功');
|
||||||
},
|
},
|
||||||
onError: (error) => {
|
onError: (error) => {
|
||||||
if (isCancel(error)) return;
|
if (isCancel(error)) return;
|
||||||
|
|||||||
@@ -54,6 +54,9 @@ const { mutateAsync: validateDeviceIdDuplicated } = useMutation({
|
|||||||
const deviceIdPattern = /^\d{4}04\d{4}$/;
|
const deviceIdPattern = /^\d{4}04\d{4}$/;
|
||||||
if (!deviceIdPattern.test(deviceId)) throw new Error('设备ID不符合规范');
|
if (!deviceIdPattern.test(deviceId)) throw new Error('设备ID不符合规范');
|
||||||
|
|
||||||
|
// 如果没有修改设备ID,则不做ID唯一性校验
|
||||||
|
if (deviceId === ndmDevice.value.deviceId) return;
|
||||||
|
|
||||||
validatorAbortController.value.abort();
|
validatorAbortController.value.abort();
|
||||||
validatorAbortController.value = new AbortController();
|
validatorAbortController.value = new AbortController();
|
||||||
|
|
||||||
@@ -68,8 +71,7 @@ const { mutateAsync: validateDeviceIdDuplicated } = useMutation({
|
|||||||
const { mutate: updateDevice, isPending: loading } = useMutation({
|
const { mutate: updateDevice, isPending: loading } = useMutation({
|
||||||
mutationFn: async () => {
|
mutationFn: async () => {
|
||||||
await formInst.value?.validate().catch(() => {
|
await formInst.value?.validate().catch(() => {
|
||||||
window.$message.error('表单验证失败');
|
throw new Error('表单校验失败');
|
||||||
return;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
abortController.value.abort();
|
abortController.value.abort();
|
||||||
@@ -84,6 +86,7 @@ const { mutate: updateDevice, isPending: loading } = useMutation({
|
|||||||
onSuccess: (newDevice) => {
|
onSuccess: (newDevice) => {
|
||||||
localDevice.value = { ...newDevice };
|
localDevice.value = { ...newDevice };
|
||||||
deviceStore.patchDevice(station.value.code, { ...newDevice });
|
deviceStore.patchDevice(station.value.code, { ...newDevice });
|
||||||
|
window.$message.success('更新成功');
|
||||||
},
|
},
|
||||||
onError: (error) => {
|
onError: (error) => {
|
||||||
if (isCancel(error)) return;
|
if (isCancel(error)) return;
|
||||||
|
|||||||
Reference in New Issue
Block a user