fix: 修复设备更新面板中错误的表单校验逻辑

This commit is contained in:
yangsy
2025-12-17 14:36:10 +08:00
parent ec4dd8917f
commit 742d561c33
8 changed files with 40 additions and 16 deletions

View File

@@ -55,6 +55,9 @@ const { mutateAsync: validateDeviceIdDuplicated } = useMutation({
const deviceIdPattern = /^\d{4}01\d{4}$/;
if (!deviceIdPattern.test(deviceId)) throw new Error('设备ID不符合规范');
// 如果没有修改设备ID则不做ID唯一性校验
if (deviceId === ndmDevice.value.deviceId) return;
validatorAbortController.value.abort();
validatorAbortController.value = new AbortController();
@@ -69,8 +72,7 @@ const { mutateAsync: validateDeviceIdDuplicated } = useMutation({
const { mutate: updateDevice, isPending: loading } = useMutation({
mutationFn: async () => {
await formInst.value?.validate().catch(() => {
window.$message.error('表单验失败');
return;
throw new Error('表单验失败');
});
abortController.value.abort();
@@ -85,6 +87,7 @@ const { mutate: updateDevice, isPending: loading } = useMutation({
onSuccess: (newDevice) => {
localDevice.value = { ...newDevice };
deviceStore.patchDevice(station.value.code, { ...newDevice });
window.$message.success('更新成功');
},
onError: (error) => {
if (isCancel(error)) return;

View File

@@ -54,6 +54,9 @@ const { mutateAsync: validateDeviceIdDuplicated } = useMutation({
const deviceIdPattern = /^\d{4}06\d{4}$/;
if (!deviceIdPattern.test(deviceId)) throw new Error('设备ID不符合规范');
// 如果没有修改设备ID则不做ID唯一性校验
if (deviceId === ndmDevice.value.deviceId) return;
validatorAbortController.value.abort();
validatorAbortController.value = new AbortController();
@@ -68,8 +71,7 @@ const { mutateAsync: validateDeviceIdDuplicated } = useMutation({
const { mutate: updateDevice, isPending: loading } = useMutation({
mutationFn: async () => {
await formInst.value?.validate().catch(() => {
window.$message.error('表单验失败');
return;
throw new Error('表单验失败');
});
abortController.value.abort();
@@ -84,6 +86,7 @@ const { mutate: updateDevice, isPending: loading } = useMutation({
onSuccess: (newDevice) => {
localDevice.value = { ...newDevice };
deviceStore.patchDevice(station.value.code, { ...newDevice });
window.$message.success('更新成功');
},
onError: (error) => {
if (isCancel(error)) return;

View File

@@ -54,6 +54,9 @@ const { mutateAsync: validateDeviceIdDuplicated } = useMutation({
const deviceIdPattern = /^\d{4}07\d{4}$/;
if (!deviceIdPattern.test(deviceId)) throw new Error('设备ID不符合规范');
// 如果没有修改设备ID则不做ID唯一性校验
if (deviceId === ndmDevice.value.deviceId) return;
validatorAbortController.value.abort();
validatorAbortController.value = new AbortController();
@@ -68,8 +71,7 @@ const { mutateAsync: validateDeviceIdDuplicated } = useMutation({
const { mutate: updateDevice, isPending: loading } = useMutation({
mutationFn: async () => {
await formInst.value?.validate().catch(() => {
window.$message.error('表单验失败');
return;
throw new Error('表单验失败');
});
abortController.value.abort();
@@ -84,6 +86,7 @@ const { mutate: updateDevice, isPending: loading } = useMutation({
onSuccess: (newDevice) => {
localDevice.value = { ...newDevice };
deviceStore.patchDevice(station.value.code, { ...newDevice });
window.$message.success('更新成功');
},
onError: (error) => {
if (isCancel(error)) return;

View File

@@ -54,6 +54,9 @@ const { mutateAsync: validateDeviceIdDuplicated } = useMutation({
const deviceIdPattern = /^\d{4}08\d{4}$/;
if (!deviceIdPattern.test(deviceId)) throw new Error('设备ID不符合规范');
// 如果没有修改设备ID则不做ID唯一性校验
if (deviceId === ndmDevice.value.deviceId) return;
validatorAbortController.value.abort();
validatorAbortController.value = new AbortController();
@@ -68,8 +71,7 @@ const { mutateAsync: validateDeviceIdDuplicated } = useMutation({
const { mutate: updateDevice, isPending: loading } = useMutation({
mutationFn: async () => {
await formInst.value?.validate().catch(() => {
window.$message.error('表单验失败');
return;
throw new Error('表单验失败');
});
abortController.value.abort();
@@ -84,6 +86,7 @@ const { mutate: updateDevice, isPending: loading } = useMutation({
onSuccess: (newDevice) => {
localDevice.value = { ...newDevice };
deviceStore.patchDevice(station.value.code, { ...newDevice });
window.$message.success('更新成功');
},
onError: (error) => {
if (isCancel(error)) return;

View File

@@ -54,6 +54,9 @@ const { mutateAsync: validateDeviceIdDuplicated } = useMutation({
const deviceIdPattern = /^\d{4}05\d{4}$/;
if (!deviceIdPattern.test(deviceId)) throw new Error('设备ID不符合规范');
// 如果没有修改设备ID则不做ID唯一性校验
if (deviceId === ndmDevice.value.deviceId) return;
validatorAbortController.value.abort();
validatorAbortController.value = new AbortController();
@@ -68,8 +71,7 @@ const { mutateAsync: validateDeviceIdDuplicated } = useMutation({
const { mutate: updateDevice, isPending } = useMutation({
mutationFn: async () => {
await formInst.value?.validate().catch(() => {
window.$message.error('表单验失败');
return;
throw new Error('表单验失败');
});
abortController.value.abort();
@@ -84,6 +86,7 @@ const { mutate: updateDevice, isPending } = useMutation({
onSuccess: (newDevice) => {
localDevice.value = { ...newDevice };
deviceStore.patchDevice(station.value.code, { ...newDevice });
window.$message.success('更新成功');
},
onError: (error) => {
if (isCancel(error)) return;

View File

@@ -54,6 +54,9 @@ const { mutateAsync: validateDeviceIdDuplicated } = useMutation({
const deviceIdPattern = /^\d{4}03\d{4}$/;
if (!deviceIdPattern.test(deviceId)) throw new Error('设备ID不符合规范');
// 如果没有修改设备ID则不做ID唯一性校验
if (deviceId === ndmDevice.value.deviceId) return;
validatorAbortController.value.abort();
validatorAbortController.value = new AbortController();
@@ -68,8 +71,7 @@ const { mutateAsync: validateDeviceIdDuplicated } = useMutation({
const { mutate: updateDevice, isPending } = useMutation({
mutationFn: async () => {
await formInst.value?.validate().catch(() => {
window.$message.error('表单验失败');
return;
throw new Error('表单验失败');
});
abortController.value.abort();
@@ -84,6 +86,7 @@ const { mutate: updateDevice, isPending } = useMutation({
onSuccess: (newDevice) => {
localDevice.value = { ...newDevice };
deviceStore.patchDevice(station.value.code, { ...newDevice });
window.$message.success('更新成功');
},
onError: (error) => {
if (isCancel(error)) return;

View File

@@ -66,6 +66,9 @@ const { mutateAsync: validateDeviceIdDuplicated } = useMutation({
const deviceIdPattern = /^\d{4}(09|11)\d{4}$/;
if (!deviceIdPattern.test(deviceId)) throw new Error('设备ID不符合规范');
// 如果没有修改设备ID则不做ID唯一性校验
if (deviceId === ndmDevice.value.deviceId) return;
validatorAbortController.value.abort();
validatorAbortController.value = new AbortController();
@@ -80,8 +83,7 @@ const { mutateAsync: validateDeviceIdDuplicated } = useMutation({
const { mutate: updateDevice, isPending } = useMutation({
mutationFn: async () => {
await formInst.value?.validate().catch(() => {
window.$message.error('表单验失败');
return;
throw new Error('表单验失败');
});
abortController.value.abort();
@@ -103,6 +105,7 @@ const { mutate: updateDevice, isPending } = useMutation({
onSuccess: (newDevice) => {
localDevice.value = { ...newDevice };
deviceStore.patchDevice(station.value.code, { ...newDevice });
window.$message.success('更新成功');
},
onError: (error) => {
if (isCancel(error)) return;

View File

@@ -54,6 +54,9 @@ const { mutateAsync: validateDeviceIdDuplicated } = useMutation({
const deviceIdPattern = /^\d{4}04\d{4}$/;
if (!deviceIdPattern.test(deviceId)) throw new Error('设备ID不符合规范');
// 如果没有修改设备ID则不做ID唯一性校验
if (deviceId === ndmDevice.value.deviceId) return;
validatorAbortController.value.abort();
validatorAbortController.value = new AbortController();
@@ -68,8 +71,7 @@ const { mutateAsync: validateDeviceIdDuplicated } = useMutation({
const { mutate: updateDevice, isPending: loading } = useMutation({
mutationFn: async () => {
await formInst.value?.validate().catch(() => {
window.$message.error('表单验失败');
return;
throw new Error('表单验失败');
});
abortController.value.abort();
@@ -84,6 +86,7 @@ const { mutate: updateDevice, isPending: loading } = useMutation({
onSuccess: (newDevice) => {
localDevice.value = { ...newDevice };
deviceStore.patchDevice(station.value.code, { ...newDevice });
window.$message.success('更新成功');
},
onError: (error) => {
if (isCancel(error)) return;