icssoa пре 1 година
родитељ
комит
31d65496e6

+ 1 - 1
package.json

@@ -9,7 +9,7 @@
 		"lint:eslint": "eslint \"{src}/**/*.{vue,ts,tsx}\" --fix"
 	},
 	"dependencies": {
-		"@cool-vue/crud": "^7.0.5",
+		"@cool-vue/crud": "^7.0.6",
 		"@element-plus/icons-vue": "^2.1.0",
 		"@vueuse/core": "^10.4.0",
 		"@wangeditor/editor": "^5.1.23",

+ 1 - 1
packages/crud/package.json

@@ -1,6 +1,6 @@
 {
 	"name": "@cool-vue/crud",
-	"version": "7.0.5",
+	"version": "7.0.6",
 	"private": false,
 	"main": "./dist/index.umd.min.js",
 	"typings": "types/index.d.ts",

+ 22 - 12
packages/crud/src/components/form/helper/tabs.ts

@@ -27,22 +27,32 @@ export function useTabs({ config, Form }: { config: ClForm.Config; Form: Vue.Ref
 	}
 
 	// 查找分组
-	function findGroup(list: ClForm.Item[], prop: string) {
-		let name;
+	function toGroup(opts: { config: ClForm.Config; prop: string; refs: any }) {
+		if (active.value) {
+			let name;
 
-		function deep(d: ClForm.Item) {
-			if (d.prop == prop) {
-				name = d.group;
+			// 查找标签上绑定的数据
+			const el = opts.refs.form.querySelector(`[data-prop="${opts.prop}"]`);
+
+			// 各自判断
+			if (el) {
+				name = el?.getAttribute("data-group");
 			} else {
-				if (d.children) {
-					d.children.forEach(deep);
+				function deep(d: ClForm.Item) {
+					if (d.prop == opts.prop) {
+						name = d.group;
+					} else {
+						if (d.children) {
+							d.children.forEach(deep);
+						}
+					}
 				}
-			}
-		}
 
-		list.forEach(deep);
+				config.items.forEach(deep);
+			}
 
-		return name;
+			set(name);
+		}
 	}
 
 	// 获取参数
@@ -134,6 +144,6 @@ export function useTabs({ config, Form }: { config: ClForm.Config; Form: Vue.Ref
 		change,
 		clear,
 		mergeProp,
-		findGroup
+		toGroup
 	};
 }

+ 6 - 8
packages/crud/src/components/form/index.tsx

@@ -181,14 +181,12 @@ export default defineComponent({
 						done();
 					}
 				} else {
-					// 判断是否使用 cl-form-tabs,切换到对应的选项卡
-					if (Tabs.active.value) {
-						const group = Tabs.findGroup(config.items, Object.keys(error)[0]);
-
-						if (group) {
-							Tabs.set(group);
-						}
-					}
+					// 切换到对应的选项卡
+					Tabs.toGroup({
+						refs,
+						config,
+						prop: Object.keys(error)[0]
+					});
 				}
 			});
 		}

+ 5 - 1
packages/crud/types/components/form/helper/tabs.d.ts

@@ -12,5 +12,9 @@ export declare function useTabs({ config, Form }: {
     change: (value: any, isValid?: boolean) => Promise<unknown>;
     clear: () => void;
     mergeProp: (item: ClForm.Item) => void;
-    findGroup: (list: ClForm.Item[], prop: string) => undefined;
+    toGroup: (opts: {
+        config: ClForm.Config;
+        prop: string;
+        refs: any;
+    }) => void;
 };

+ 4 - 4
yarn.lock

@@ -295,10 +295,10 @@
     mitt "^3.0.1"
     vue "^3.3.4"
 
-"@cool-vue/crud@^7.0.5":
-  version "7.0.5"
-  resolved "https://registry.yarnpkg.com/@cool-vue/crud/-/crud-7.0.5.tgz#63cf8794241ec639ac802cc443d05d82ecf9c442"
-  integrity sha512-PWR/yeJh9EfhKDDiiK1bfrCUpY9vtIMTQ/MsLzaKnKsTTALisOfimvSxaA6dVS2jb9LsfhIKcB3WQinJnI/GIQ==
+"@cool-vue/crud@^7.0.6":
+  version "7.0.6"
+  resolved "https://registry.yarnpkg.com/@cool-vue/crud/-/crud-7.0.6.tgz#32e49364dd3ded9d97d0551d1f381a6632d39f57"
+  integrity sha512-NQvsXPixIAynwjiTj0ivNjC8EOWq9ChHPJZHsvjJZrchTKyEajjUr14w4Q1OupZa/AKDN6SOGuNkY/Lj1dNHpg==
   dependencies:
     "@cool-vue/crud" "^7.0.1-beta14"
     array.prototype.flat "^1.2.4"