diff --git a/package.json b/package.json index 7de075f..17598a6 100644 --- a/package.json +++ b/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", diff --git a/packages/crud/package.json b/packages/crud/package.json index 270dfa8..a440612 100644 --- a/packages/crud/package.json +++ b/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", diff --git a/packages/crud/src/plugins/index.ts b/packages/crud/src/plugins/index.ts index 71e188d..56700c9 100644 --- a/packages/crud/src/plugins/index.ts +++ b/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?.(); }); } diff --git a/src/cool/hook/index.ts b/src/cool/hook/index.ts index 858b671..31a5a00 100644 --- a/src/cool/hook/index.ts +++ b/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]; }; } diff --git a/src/plugins/crud/config.ts b/src/plugins/crud/config.ts index 5d5a1ca..e77357e 100644 --- a/src/plugins/crud/config.ts +++ b/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 => { @@ -13,8 +13,8 @@ export default (): Merge => { label: "CRUD", description: "快速增删改查及一系列辅助组件", author: "COOL", - version: "7.1.11", - updateTime: "2024-02-01", + version: "7.1.12", + updateTime: "2024-02-04", demo: "/demo/crud", // 组件全注册