소스 검색

优化 crud 插件

神仙都没用 1 년 전
부모
커밋
f119e4cc1d
5개의 변경된 파일18개의 추가작업 그리고 6개의 파일을 삭제
  1. 2 1
      package.json
  2. 1 1
      packages/crud/package.json
  3. 10 1
      packages/crud/src/plugins/index.ts
  4. 2 0
      src/cool/hook/index.ts
  5. 3 3
      src/plugins/crud/config.ts

+ 2 - 1
package.json

@@ -9,7 +9,7 @@
 		"lint:eslint": "eslint \"./src/**/*.{vue,ts,tsx}\" --fix"
 	},
 	"dependencies": {
-		"@cool-vue/crud": "^7.1.11",
+		"@cool-vue/crud": "^7.1.12",
 		"@element-plus/icons-vue": "^2.1.0",
 		"@vueuse/core": "^10.4.0",
 		"@wangeditor/editor": "^5.1.23",
@@ -38,6 +38,7 @@
 		"xlsx": "^0.18.5"
 	},
 	"devDependencies": {
+		"@types/file-saver": "^2.0.7",
 		"@types/lodash-es": "^4.17.8",
 		"@types/mockjs": "^1.0.7",
 		"@types/node": "^20.5.6",

+ 1 - 1
packages/crud/package.json

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

+ 10 - 1
packages/crud/src/plugins/index.ts

@@ -10,13 +10,18 @@ export function setFocus(prop?: string): ClForm.Plugin {
 
 	return ({ exposed, onOpen }) => {
 		const name = prop || exposed.config.items[0].prop;
+		let _ref: any;
 
 		if (name) {
 			function deep(arr: ClForm.Item[]) {
 				arr.forEach((e) => {
 					if (e.prop == name && name) {
 						if (e.component) {
-							e.component.ref = setRefs(name);
+							if (e.component.ref) {
+								_ref = e.component.ref();
+							} else {
+								e.component.ref = setRefs(name);
+							}
 						}
 					} else {
 						deep(e.children || []);
@@ -27,6 +32,10 @@ export function setFocus(prop?: string): ClForm.Plugin {
 			deep(exposed.config.items);
 
 			onOpen(() => {
+				if (_ref) {
+					refs[name] = _ref();
+				}
+
 				refs[name]?.focus?.();
 			});
 		}

+ 2 - 0
src/cool/hook/index.ts

@@ -6,9 +6,11 @@ import { useMitt } from "./mitt";
 
 export function useRefs() {
 	const refs = reactive<{ [key: string]: any }>({});
+
 	function setRefs(name: string) {
 		return (el: any) => {
 			refs[name] = el;
+			return () => refs[name];
 		};
 	}
 

+ 3 - 3
src/plugins/crud/config.ts

@@ -5,7 +5,7 @@ import Crud, { locale, setFocus } from "@cool-vue/crud";
 import "@cool-vue/crud/dist/index.css";
 
 // 调试、自定义crud
-// import Crud, { locale } from "../../../packages/crud/src";
+// import Crud, { locale, setFocus } from "../../../packages/crud/src";
 // import "../../../packages/crud/src/static/index.scss";
 
 export default (): Merge<ModuleConfig, CrudOptions> => {
@@ -13,8 +13,8 @@ export default (): Merge<ModuleConfig, CrudOptions> => {
 		label: "CRUD",
 		description: "快速增删改查及一系列辅助组件",
 		author: "COOL",
-		version: "7.1.11",
-		updateTime: "2024-02-01",
+		version: "7.1.12",
+		updateTime: "2024-02-04",
 		demo: "/demo/crud",
 
 		// 组件全注册