神仙都没用 1 year ago
parent
commit
e3cd18d991
1 changed files with 17 additions and 15 deletions
  1. 17 15
      src/plugins/crud/components/switch/index.tsx

+ 17 - 15
src/plugins/crud/components/switch/index.tsx

@@ -60,23 +60,25 @@ export default defineComponent({
 		function onChange(val: boolean | string | number) {
 		function onChange(val: boolean | string | number) {
 			if (props.column && props.scope) {
 			if (props.column && props.scope) {
 				if (val !== undefined) {
 				if (val !== undefined) {
-					const params = {
-						id: props.scope.id,
-						[props.column.property]: val
-					};
+					if (val === activeValue.value || val === inactiveValue.value) {
+						const params = {
+							id: props.scope.id,
+							[props.column.property]: val
+						};
 
 
-					const req: Promise<any> = isFunction(props.api)
-						? props.api(params)
-						: Crud.value?.service.update(params);
+						const req: Promise<any> = isFunction(props.api)
+							? props.api(params)
+							: Crud.value?.service.update(params);
 
 
-					if (req) {
-						req.then(() => {
-							emit("update:modelValue", val);
-							emit("change", val);
-							ElMessage.success("更新成功");
-						}).catch((err) => {
-							ElMessage.error(err.message);
-						});
+						if (req) {
+							req.then(() => {
+								emit("update:modelValue", val);
+								emit("change", val);
+								ElMessage.success("更新成功");
+							}).catch((err) => {
+								ElMessage.error(err.message);
+							});
+						}
 					}
 					}
 				}
 				}
 			} else {
 			} else {