From 96a7aa0939e00f5c3ff078b426bf5b9cd9d42c57 Mon Sep 17 00:00:00 2001 From: icssoa <2570063477@qq.com> Date: Tue, 13 Jun 2023 13:31:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build/cool/temp/eps.d.ts | 460 +++++++++++++++++- build/cool/temp/eps.json | 2 +- package.json | 2 +- packages/crud/index.d.ts | 5 +- packages/crud/package.json | 2 +- packages/crud/src/components/crud/index.tsx | 2 +- packages/crud/src/components/dialog/index.tsx | 2 +- packages/crud/src/components/filter/group.tsx | 2 +- packages/crud/src/components/filter/index.tsx | 2 +- packages/crud/src/components/form-card.tsx | 22 +- packages/crud/src/components/form/helper.tsx | 96 ++-- packages/crud/src/components/form/index.tsx | 19 +- packages/crud/src/demo/app.vue | 3 +- packages/crud/src/demo/upsert.vue | 21 +- packages/crud/src/hooks/plugins.ts | 18 +- packages/crud/src/static/index.scss | 9 +- packages/crud/types/components/form-card.d.ts | 25 + packages/crud/types/utils/vnode.d.ts | 1 + src/modules/crud/config.ts | 6 +- src/modules/recycle/views/data.vue | 4 +- yarn.lock | 8 +- 21 files changed, 628 insertions(+), 83 deletions(-) create mode 100644 packages/crud/types/components/form-card.d.ts diff --git a/build/cool/temp/eps.d.ts b/build/cool/temp/eps.d.ts index eadb6d0..ec86158 100644 --- a/build/cool/temp/eps.d.ts +++ b/build/cool/temp/eps.d.ts @@ -69,6 +69,13 @@ declare namespace Eps { [key: string]: any; } + interface DemoUserEntity { + /** + * 任意键值 + */ + [key: string]: any; + } + interface DictInfoEntity { /** * 任意键值 @@ -83,6 +90,27 @@ declare namespace Eps { [key: string]: any; } + interface FinanceDrawEntity { + /** + * 任意键值 + */ + [key: string]: any; + } + + interface FinanceInvoiceInfoEntity { + /** + * 任意键值 + */ + [key: string]: any; + } + + interface InfoCarEntity { + /** + * 任意键值 + */ + [key: string]: any; + } + interface IotDeviceEntity { /** * 任意键值 @@ -125,6 +153,27 @@ declare namespace Eps { [key: string]: any; } + interface UserAddressEntity { + /** + * 任意键值 + */ + [key: string]: any; + } + + interface UserAuthEntity { + /** + * 任意键值 + */ + [key: string]: any; + } + + interface UserCreditEntity { + /** + * 任意键值 + */ + [key: string]: any; + } + interface UserInfoEntity { /** * 任意键值 @@ -1118,6 +1167,63 @@ declare namespace Eps { request: Service["request"]; } + interface DemoUser { + /** + * delete + */ + delete(data?: any): Promise; + /** + * update + */ + update(data?: any): Promise; + /** + * info + */ + info(data?: any): Promise; + /** + * list + */ + list(data?: any): Promise; + /** + * page + */ + page(data?: any): Promise<{ + pagination: { size: number; page: number; total: number }; + list: DemoUserEntity[]; + [key: string]: any; + }>; + /** + * add + */ + add(data?: any): Promise; + /** + * 权限标识 + */ + permission: { + delete: string; + update: string; + info: string; + list: string; + page: string; + add: string; + }; + /** + * 权限状态 + */ + _permission: { + delete: boolean; + update: boolean; + info: boolean; + list: boolean; + page: boolean; + add: boolean; + }; + /** + * 请求 + */ + request: Service["request"]; + } + interface DictInfo { /** * delete @@ -1238,6 +1344,183 @@ declare namespace Eps { request: Service["request"]; } + interface FinanceDraw { + /** + * update + */ + update(data?: any): Promise; + /** + * info + */ + info(data?: any): Promise; + /** + * list + */ + list(data?: any): Promise; + /** + * page + */ + page(data?: any): Promise<{ + pagination: { size: number; page: number; total: number }; + list: FinanceDrawEntity[]; + [key: string]: any; + }>; + /** + * delete + */ + delete(data?: any): Promise; + /** + * add + */ + add(data?: any): Promise; + /** + * 权限标识 + */ + permission: { + update: string; + info: string; + list: string; + page: string; + delete: string; + add: string; + }; + /** + * 权限状态 + */ + _permission: { + update: boolean; + info: boolean; + list: boolean; + page: boolean; + delete: boolean; + add: boolean; + }; + /** + * 请求 + */ + request: Service["request"]; + } + + interface FinanceInvoice { + /** + * orders + */ + orders(data?: any): Promise; + /** + * delete + */ + delete(data?: any): Promise; + /** + * update + */ + update(data?: any): Promise; + /** + * info + */ + info(data?: any): Promise; + /** + * list + */ + list(data?: any): Promise; + /** + * page + */ + page(data?: any): Promise<{ + pagination: { size: number; page: number; total: number }; + list: FinanceInvoiceInfoEntity[]; + [key: string]: any; + }>; + /** + * add + */ + add(data?: any): Promise; + /** + * 权限标识 + */ + permission: { + orders: string; + delete: string; + update: string; + info: string; + list: string; + page: string; + add: string; + }; + /** + * 权限状态 + */ + _permission: { + orders: boolean; + delete: boolean; + update: boolean; + info: boolean; + list: boolean; + page: boolean; + add: boolean; + }; + /** + * 请求 + */ + request: Service["request"]; + } + + interface InfoCar { + /** + * delete + */ + delete(data?: any): Promise; + /** + * update + */ + update(data?: any): Promise; + /** + * info + */ + info(data?: any): Promise; + /** + * list + */ + list(data?: any): Promise; + /** + * page + */ + page(data?: any): Promise<{ + pagination: { size: number; page: number; total: number }; + list: InfoCarEntity[]; + [key: string]: any; + }>; + /** + * add + */ + add(data?: any): Promise; + /** + * 权限标识 + */ + permission: { + delete: string; + update: string; + info: string; + list: string; + page: string; + add: string; + }; + /** + * 权限状态 + */ + _permission: { + delete: boolean; + update: boolean; + info: boolean; + list: boolean; + page: boolean; + add: boolean; + }; + /** + * 请求 + */ + request: Service["request"]; + } + interface IotDevice { /** * delete @@ -1685,6 +1968,177 @@ declare namespace Eps { request: Service["request"]; } + interface UserAddress { + /** + * delete + */ + delete(data?: any): Promise; + /** + * update + */ + update(data?: any): Promise; + /** + * info + */ + info(data?: any): Promise; + /** + * list + */ + list(data?: any): Promise; + /** + * page + */ + page(data?: any): Promise<{ + pagination: { size: number; page: number; total: number }; + list: UserAddressEntity[]; + [key: string]: any; + }>; + /** + * add + */ + add(data?: any): Promise; + /** + * 权限标识 + */ + permission: { + delete: string; + update: string; + info: string; + list: string; + page: string; + add: string; + }; + /** + * 权限状态 + */ + _permission: { + delete: boolean; + update: boolean; + info: boolean; + list: boolean; + page: boolean; + add: boolean; + }; + /** + * 请求 + */ + request: Service["request"]; + } + + interface UserAuth { + /** + * update + */ + update(data?: any): Promise; + /** + * info + */ + info(data?: any): Promise; + /** + * list + */ + list(data?: any): Promise; + /** + * page + */ + page(data?: any): Promise<{ + pagination: { size: number; page: number; total: number }; + list: UserAuthEntity[]; + [key: string]: any; + }>; + /** + * delete + */ + delete(data?: any): Promise; + /** + * add + */ + add(data?: any): Promise; + /** + * 权限标识 + */ + permission: { + update: string; + info: string; + list: string; + page: string; + delete: string; + add: string; + }; + /** + * 权限状态 + */ + _permission: { + update: boolean; + info: boolean; + list: boolean; + page: boolean; + delete: boolean; + add: boolean; + }; + /** + * 请求 + */ + request: Service["request"]; + } + + interface UserCredit { + /** + * delete + */ + delete(data?: any): Promise; + /** + * update + */ + update(data?: any): Promise; + /** + * info + */ + info(data?: any): Promise; + /** + * list + */ + list(data?: any): Promise; + /** + * page + */ + page(data?: any): Promise<{ + pagination: { size: number; page: number; total: number }; + list: UserCreditEntity[]; + [key: string]: any; + }>; + /** + * add + */ + add(data?: any): Promise; + /** + * 权限标识 + */ + permission: { + delete: string; + update: string; + info: string; + list: string; + page: string; + add: string; + }; + /** + * 权限状态 + */ + _permission: { + delete: boolean; + update: boolean; + info: boolean; + list: boolean; + page: boolean; + add: boolean; + }; + /** + * 请求 + */ + request: Service["request"]; + } + interface UserInfo { /** * delete @@ -1766,12 +2220,14 @@ declare namespace Eps { }; }; cloud: { db: CloudDb; func: { info: CloudFuncInfo; log: CloudFuncLog } }; - demo: { goods: DemoGoods }; + demo: { goods: DemoGoods; user: DemoUser }; dict: { info: DictInfo; type: DictType }; + finance: { draw: FinanceDraw; invoice: FinanceInvoice }; + info: { car: InfoCar }; iot: { device: IotDevice; message: IotMessage; mqtt: IotMqtt }; recycle: { data: RecycleData }; space: { info: SpaceInfo; type: SpaceType }; task: { info: TaskInfo }; - user: { info: UserInfo }; + user: { address: UserAddress; auth: UserAuth; credit: UserCredit; info: UserInfo }; }; } diff --git a/build/cool/temp/eps.json b/build/cool/temp/eps.json index ca5ceff..9592884 100644 --- a/build/cool/temp/eps.json +++ b/build/cool/temp/eps.json @@ -1 +1 @@ -[["/admin/base/comm","",[["/personUpdate","post"],["/uploadMode","get"],["/permmenu","get"],["/person","get"],["/upload","post"],["/logout","post"],["/list"],["/page"],["/info"],["/update"],["/delete"],["/add"]]],["/admin/base/open","",[["/refreshToken","get"],["/captcha","get"],["/login","post"],["/html","get"],["/eps","get"],["/list"],["/page"],["/info"],["/update"],["/delete"],["/add"]]],["/admin/base/sys/department","BaseSysDepartmentEntity",[["/delete","post"],["/update","post"],["/order","post"],["/list","post"],["/add","post"],["/page"],["/info"]]],["/admin/base/sys/log","BaseSysLogEntity",[["/setKeep","post"],["/getKeep","get"],["/clear","post"],["/page","post"],["/list"],["/info"],["/update"],["/delete"],["/add"]]],["/admin/base/sys/menu","BaseSysMenuEntity",[["/create","post"],["/delete","post"],["/update","post"],["/parse","post"],["/info","get"],["/list","post"],["/page","post"],["/add","post"]]],["/admin/base/sys/param","BaseSysParamEntity",[["/delete","post"],["/update","post"],["/html","get"],["/info","get"],["/page","post"],["/add","post"],["/list"]]],["/admin/base/sys/role","BaseSysRoleEntity",[["/delete","post"],["/update","post"],["/info","get"],["/list","post"],["/page","post"],["/add","post"]]],["/admin/base/sys/user","BaseSysUserEntity",[["/delete","post"],["/update","post"],["/move","post"],["/info","get"],["/list","post"],["/page","post"],["/add","post"]]],["/admin/cloud/db","CloudDBEntity",[["/initEntity","post"],["/delete","post"],["/update","post"],["/data","post"],["/info","get"],["/list","post"],["/page","post"],["/add","post"]]],["/admin/cloud/func/info","CloudFuncInfoEntity",[["/invoke","post"],["/delete","post"],["/update","post"],["/info","get"],["/list","post"],["/page","post"],["/add","post"]]],["/admin/cloud/func/log","CloudFuncLogEntity",[["/delete","post"],["/update","post"],["/info","get"],["/list","post"],["/page","post"],["/add","post"]]],["/admin/demo/goods","DemoGoodsEntity",[["/delete","post"],["/update","post"],["/info","get"],["/list","post"],["/page","post"],["/add","post"]]],["/admin/dict/info","DictInfoEntity",[["/delete","post"],["/update","post"],["/data","post"],["/info","get"],["/list","post"],["/page","post"],["/add","post"]]],["/admin/dict/type","DictTypeEntity",[["/delete","post"],["/update","post"],["/info","get"],["/list","post"],["/page","post"],["/add","post"]]],["/admin/iot/device","IotDeviceEntity",[["/delete","post"],["/update","post"],["/info","get"],["/list","post"],["/page","post"],["/add","post"]]],["/admin/iot/message","IotMessageEntity",[["/page","post"],["/list"],["/info"],["/update"],["/delete"],["/add"]]],["/admin/iot/mqtt","",[["/publish","post"],["/config","get"],["/list"],["/page"],["/info"],["/update"],["/delete"],["/add"]]],["/admin/recycle/data","RecycleDataEntity",[["/restore","post"],["/info","get"],["/page","post"],["/list"],["/update"],["/delete"],["/add"]]],["/admin/space/info","SpaceInfoEntity",[["/getConfig","get"],["/delete","post"],["/update","post"],["/info","get"],["/list","post"],["/page","post"],["/add","post"]]],["/admin/space/type","SpaceTypeEntity",[["/delete","post"],["/update","post"],["/info","get"],["/list","post"],["/page","post"],["/add","post"]]],["/admin/task/info","TaskInfoEntity",[["/delete","post"],["/update","post"],["/start","post"],["/once","post"],["/stop","post"],["/info","get"],["/page","post"],["/log","get"],["/add","post"],["/list"]]],["/admin/user/info","UserInfoEntity",[["/delete","post"],["/update","post"],["/info","get"],["/list","post"],["/page","post"],["/add","post"]]],["/chat/message","",[["/list"],["/page"],["/info"],["/update"],["/delete"],["/add"]]],["/chat/session","",[["/list"],["/page"],["/info"],["/update"],["/delete"],["/add"]]],["/test","",[["/list"],["/page"],["/info"],["/update"],["/delete"],["/add"]]]] \ No newline at end of file +[["/admin/base/comm","",[["/personUpdate","post"],["/uploadMode","get"],["/permmenu","get"],["/person","get"],["/upload","post"],["/logout","post"],["/list"],["/page"],["/info"],["/update"],["/delete"],["/add"]]],["/admin/base/open","",[["/refreshToken","get"],["/captcha","get"],["/login","post"],["/html","get"],["/eps","get"],["/list"],["/page"],["/info"],["/update"],["/delete"],["/add"]]],["/admin/base/sys/department","BaseSysDepartmentEntity",[["/delete","post"],["/update","post"],["/order","post"],["/list","post"],["/add","post"],["/page"],["/info"]]],["/admin/base/sys/log","BaseSysLogEntity",[["/setKeep","post"],["/getKeep","get"],["/clear","post"],["/page","post"],["/list"],["/info"],["/update"],["/delete"],["/add"]]],["/admin/base/sys/menu","BaseSysMenuEntity",[["/create","post"],["/delete","post"],["/update","post"],["/parse","post"],["/info","get"],["/list","post"],["/page","post"],["/add","post"]]],["/admin/base/sys/param","BaseSysParamEntity",[["/delete","post"],["/update","post"],["/html","get"],["/info","get"],["/page","post"],["/add","post"],["/list"]]],["/admin/base/sys/role","BaseSysRoleEntity",[["/delete","post"],["/update","post"],["/info","get"],["/list","post"],["/page","post"],["/add","post"]]],["/admin/base/sys/user","BaseSysUserEntity",[["/delete","post"],["/update","post"],["/move","post"],["/info","get"],["/list","post"],["/page","post"],["/add","post"]]],["/admin/cloud/db","CloudDBEntity",[["/initEntity","post"],["/delete","post"],["/update","post"],["/data","post"],["/info","get"],["/list","post"],["/page","post"],["/add","post"]]],["/admin/cloud/func/info","CloudFuncInfoEntity",[["/invoke","post"],["/delete","post"],["/update","post"],["/info","get"],["/list","post"],["/page","post"],["/add","post"]]],["/admin/cloud/func/log","CloudFuncLogEntity",[["/delete","post"],["/update","post"],["/info","get"],["/list","post"],["/page","post"],["/add","post"]]],["/admin/demo/goods","DemoGoodsEntity",[["/delete","post"],["/update","post"],["/info","get"],["/list","post"],["/page","post"],["/add","post"]]],["/admin/demo/user","DemoUserEntity",[["/delete","post"],["/update","post"],["/info","get"],["/list","post"],["/page","post"],["/add","post"]]],["/admin/dict/info","DictInfoEntity",[["/delete","post"],["/update","post"],["/data","post"],["/info","get"],["/list","post"],["/page","post"],["/add","post"]]],["/admin/dict/type","DictTypeEntity",[["/delete","post"],["/update","post"],["/info","get"],["/list","post"],["/page","post"],["/add","post"]]],["/admin/finance/draw","FinanceDrawEntity",[["/update","post"],["/info","get"],["/list","post"],["/page","post"],["/delete"],["/add"]]],["/admin/finance/invoice","FinanceInvoiceInfoEntity",[["/orders","get"],["/delete","post"],["/update","post"],["/info","get"],["/list","post"],["/page","post"],["/add","post"]]],["/admin/info/car","InfoCarEntity",[["/delete","post"],["/update","post"],["/info","get"],["/list","post"],["/page","post"],["/add","post"]]],["/admin/iot/device","IotDeviceEntity",[["/delete","post"],["/update","post"],["/info","get"],["/list","post"],["/page","post"],["/add","post"]]],["/admin/iot/message","IotMessageEntity",[["/page","post"],["/list"],["/info"],["/update"],["/delete"],["/add"]]],["/admin/iot/mqtt","",[["/publish","post"],["/config","get"],["/list"],["/page"],["/info"],["/update"],["/delete"],["/add"]]],["/admin/recycle/data","RecycleDataEntity",[["/restore","post"],["/info","get"],["/page","post"],["/list"],["/update"],["/delete"],["/add"]]],["/admin/space/info","SpaceInfoEntity",[["/getConfig","get"],["/delete","post"],["/update","post"],["/info","get"],["/list","post"],["/page","post"],["/add","post"]]],["/admin/space/type","SpaceTypeEntity",[["/delete","post"],["/update","post"],["/info","get"],["/list","post"],["/page","post"],["/add","post"]]],["/admin/task/info","TaskInfoEntity",[["/delete","post"],["/update","post"],["/start","post"],["/once","post"],["/stop","post"],["/info","get"],["/page","post"],["/log","get"],["/add","post"],["/list"]]],["/admin/user/address","UserAddressEntity",[["/delete","post"],["/update","post"],["/info","get"],["/list","post"],["/page","post"],["/add","post"]]],["/admin/user/auth","UserAuthEntity",[["/update","post"],["/info","get"],["/list","post"],["/page","post"],["/delete"],["/add"]]],["/admin/user/credit","UserCreditEntity",[["/delete","post"],["/update","post"],["/info","get"],["/list","post"],["/page","post"],["/add","post"]]],["/admin/user/info","UserInfoEntity",[["/delete","post"],["/update","post"],["/info","get"],["/list","post"],["/page","post"],["/add","post"]]],["/chat/message","",[["/list"],["/page"],["/info"],["/update"],["/delete"],["/add"]]],["/chat/session","",[["/list"],["/page"],["/info"],["/update"],["/delete"],["/add"]]],["/test","",[["/list"],["/page"],["/info"],["/update"],["/delete"],["/add"]]]] \ No newline at end of file diff --git a/package.json b/package.json index 5a84e34..ebefb8b 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "lint:eslint": "eslint \"{src}/**/*.{vue,ts,tsx}\" --fix" }, "dependencies": { - "@cool-vue/crud": "^6.2.2", + "@cool-vue/crud": "^6.3.1", "@element-plus/icons-vue": "^2.0.10", "@vueuse/core": "^9.1.0", "@wangeditor/editor": "^5.1.23", diff --git a/packages/crud/index.d.ts b/packages/crud/index.d.ts index 0685e6f..27f33df 100644 --- a/packages/crud/index.d.ts +++ b/packages/crud/index.d.ts @@ -517,10 +517,11 @@ declare namespace ClForm { hideLoading(): void; setData(prop: string, value: any): void; bindForm(data: obj): void; - setOptions(prop: string, list: Array<{ label: string; value?: any }>): void; - setProps(prop: string, value: any): void; getForm(prop?: string): any; setForm(prop: string, value: any): void; + setOptions(prop: string, list: { label: string; value?: any; [key: string]: any }[]): void; + setProps(prop: string, value: any): void; + setConfig(path: string, value: any): void; showItem(props: string[] | string): void; hideItem(props: string[] | string): void; toggleItem(prop: string, flag?: boolean): void; diff --git a/packages/crud/package.json b/packages/crud/package.json index d5266bd..51556f0 100644 --- a/packages/crud/package.json +++ b/packages/crud/package.json @@ -1,6 +1,6 @@ { "name": "@cool-vue/crud", - "version": "6.2.2", + "version": "6.3.1", "private": false, "main": "./dist/index.umd.min.js", "typings": "types/index.d.ts", diff --git a/packages/crud/src/components/crud/index.tsx b/packages/crud/src/components/crud/index.tsx index 97b4f2d..82dbb08 100644 --- a/packages/crud/src/components/crud/index.tsx +++ b/packages/crud/src/components/crud/index.tsx @@ -80,7 +80,7 @@ export default defineComponent({
- {slots.default && slots.default()} + {slots.default?.()}
); }; diff --git a/packages/crud/src/components/dialog/index.tsx b/packages/crud/src/components/dialog/index.tsx index 3175b07..09a7d51 100644 --- a/packages/crud/src/components/dialog/index.tsx +++ b/packages/crud/src/components/dialog/index.tsx @@ -253,7 +253,7 @@ export default defineComponent({ class="cl-dialog__container" style={{ height: props.height }} key={cacheKey.value}> - {slots.default && slots.default()} + {slots.default?.()} ); }, diff --git a/packages/crud/src/components/filter/group.tsx b/packages/crud/src/components/filter/group.tsx index 8c7b1c7..05718c6 100644 --- a/packages/crud/src/components/filter/group.tsx +++ b/packages/crud/src/components/filter/group.tsx @@ -116,7 +116,7 @@ export default defineComponent({ ); }, default: () => { - slots.default && slots.default(); + slots.default?.(); } } )} diff --git a/packages/crud/src/components/filter/index.tsx b/packages/crud/src/components/filter/index.tsx index ed8e0b7..851c270 100644 --- a/packages/crud/src/components/filter/index.tsx +++ b/packages/crud/src/components/filter/index.tsx @@ -15,7 +15,7 @@ export default defineComponent({ {props.label} - {slots.default && slots.default()} + {slots.default?.()} ); }; diff --git a/packages/crud/src/components/form-card.tsx b/packages/crud/src/components/form-card.tsx index dacd2dc..b3fdde4 100644 --- a/packages/crud/src/components/form-card.tsx +++ b/packages/crud/src/components/form-card.tsx @@ -11,6 +11,12 @@ export default defineComponent({ props: { label: String, + // 展开状态 + expand: { + type: Boolean, + default: true + }, + // 是否能展开、收起 isExpand: { type: Boolean, default: true @@ -18,21 +24,23 @@ export default defineComponent({ }, setup(props, { slots }) { - const isExpand = ref(props.isExpand); + const visible = ref(props.expand); - async function toExpand() { - isExpand.value = !isExpand.value; + function toExpand() { + if (props.isExpand) { + visible.value = !visible.value; + } } return () => { return ( -
+
{props.label} - - - + + +
{slots.default?.()}
diff --git a/packages/crud/src/components/form/helper.tsx b/packages/crud/src/components/form/helper.tsx index 7e2bbc4..fe43cca 100644 --- a/packages/crud/src/components/form/helper.tsx +++ b/packages/crud/src/components/form/helper.tsx @@ -8,37 +8,63 @@ declare type Form = Vue.Ref; // 操作 export function useAction({ config, form, Form }: { config: Config; form: obj; Form: Form }) { // 设置数据 - function set({ prop, options, hidden, path, props }: any, data?: any): any { + function set( + { + prop, + key, + path + }: { prop?: string; key?: "options" | "props" | "hidden" | "hidden-toggle"; path?: string }, + data?: any + ) { let p: string = path || ""; - if (prop) { - p = `items[prop:${prop}]`; + if (path) { + dataset(config, p, data); + } else { + let d: any; + + if (prop) { + function deep(arr: ClForm.Item[]) { + arr.forEach((e) => { + if (e.prop == prop) { + d = e; + } else { + if (e.children) { + deep(e.children); + } + } + }); + } + + deep(config.items); + } + + if (d) { + switch (key) { + case "options": + d.component.options = data; + break; + + case "props": + Object.assign(d.component.props, data); + break; + + case "hidden": + d.hidden = data; + break; + + case "hidden-toggle": + d.hidden = data === undefined ? !d.hidden : !data; + break; + + default: + Object.assign(d, data); + break; + } + } else { + console.error(`prop "${prop}" not found`); + } } - - if (options) { - p += `.component.options`; - } - - if (props) { - p += `.component.props`; - } - - if (hidden) { - p += ".hidden"; - } - - return dataset(config, p, data); - } - - // 合并数据 - function merge(options: any, value: any): any { - return set( - { - ...options, - isMerge: true - }, - value - ); } // 获取表单值 @@ -63,33 +89,30 @@ export function useAction({ config, form, Form }: { config: Config; form: obj; F // 设置表单项的下拉数据列表 function setOptions(prop: string, value: any[]) { - set({ options: true, prop }, value); + set({ prop, key: "options" }, value); } // 设置表单项的组件参数 function setProps(prop: string, value: any) { - merge({ props: true, prop }, value); + set({ prop, key: "props" }, value); } // 切换表单项的显示、隐藏 function toggleItem(prop: string, value?: boolean) { - if (value === undefined) { - value = set({ prop, hidden: true }); - } - set({ hidden: true, prop }, !value); + set({ prop, key: "hidden-toggle" }, value); } // 对部分表单项隐藏 function hideItem(...props: string[]) { props.forEach((prop) => { - set({ hidden: true, prop }, true); + set({ prop, key: "hidden" }, true); }); } // 对部分表单项显示 function showItem(...props: string[]) { props.forEach((prop) => { - set({ hidden: true, prop }, false); + set({ prop, key: "hidden" }, false); }); } @@ -221,6 +244,7 @@ export function useApi({ Form }: { Form: Form }) { "getForm", "setForm", "setData", + "setConfig", "setOptions", "setProps", "toggleItem", diff --git a/packages/crud/src/components/form/index.tsx b/packages/crud/src/components/form/index.tsx index 765d8b3..b1c4854 100644 --- a/packages/crud/src/components/form/index.tsx +++ b/packages/crud/src/components/form/index.tsx @@ -244,11 +244,22 @@ export default defineComponent({ // 合并配置 for (const i in config) { switch (i) { - // 动态处理 + // 表单项 case "items": - config.items = (options.items || []).map((e) => getValue(e)); + function deep(arr: any[]): any[] { + return arr.map((e) => { + const d = getValue(e); + + return { + ...d, + children: d?.children ? deep(d.children) : undefined + }; + }); + } + + config.items = deep(options.items || []); break; - // 合并处理 + // 事件、参数、操作 case "on": case "op": case "props": @@ -256,7 +267,7 @@ export default defineComponent({ case "_data": deepMerge(config[i], options[i] || {}); break; - // 赋值 + // 标题、宽度 case "title": case "width": default: diff --git a/packages/crud/src/demo/app.vue b/packages/crud/src/demo/app.vue index 4b2ba43..9c325b7 100644 --- a/packages/crud/src/demo/app.vue +++ b/packages/crud/src/demo/app.vue @@ -209,7 +209,8 @@ const Table = useTable({ { label: "创建时间", prop: "createTime", - sortable: "desc" + sortable: "desc", + width: 160 }, { type: "op", diff --git a/packages/crud/src/demo/upsert.vue b/packages/crud/src/demo/upsert.vue index ba01a9e..e5f2ae3 100644 --- a/packages/crud/src/demo/upsert.vue +++ b/packages/crud/src/demo/upsert.vue @@ -47,12 +47,15 @@ const Upsert = useUpsert({ } } }, - { - label: "手机号", - prop: "phone", - component: { - name: "el-input" - } + () => { + return { + label: "手机号", + prop: "phone", + hidden: Upsert.value?.mode == "update", + component: { + name: "el-input" + } + }; } ] }, @@ -102,7 +105,7 @@ const Upsert = useUpsert({ } ], - plugins: [setFocus()], + plugins: [setFocus("account")], onOpened() { Upsert.value?.setOptions("work", [ @@ -115,6 +118,10 @@ const Upsert = useUpsert({ value: 2 } ]); + + // Upsert.value?.setProps("account", { + // disabled: Upsert.value?.mode == "update" + // }); }, onClose(action, done) { diff --git a/packages/crud/src/hooks/plugins.ts b/packages/crud/src/hooks/plugins.ts index 5a2e0b9..fc6868a 100644 --- a/packages/crud/src/hooks/plugins.ts +++ b/packages/crud/src/hooks/plugins.ts @@ -12,13 +12,19 @@ export function setFocus(prop?: string): ClForm.Plugin { const name = prop || exposed.config.items[0].prop; if (name) { - exposed.config.items.find((e) => { - if (e.prop == name) { - if (e.component) { - e.component.ref = setRefs(name); + function deep(arr: ClForm.Item[]) { + arr.forEach((e) => { + if (e.prop == name && name) { + if (e.component) { + e.component.ref = setRefs(name); + } + } else { + deep(e.children || []); } - } - }); + }); + } + + deep(exposed.config.items); onOpen(() => { refs[name]?.focus(); diff --git a/packages/crud/src/static/index.scss b/packages/crud/src/static/index.scss index 9a708e9..dfdc91c 100644 --- a/packages/crud/src/static/index.scss +++ b/packages/crud/src/static/index.scss @@ -297,7 +297,6 @@ &.no-label { & > .el-form-item__label { padding: 0; - width: 0 !important; } } } @@ -455,7 +454,7 @@ display: grid; grid-template-rows: 0fr; - .cl-form-item__children { + > .cl-form-item__children { margin: 10px 10px 10px 0px; min-height: 0; overflow: hidden; @@ -463,12 +462,16 @@ } &.is-expand { - .cl-form-card__container { + > .cl-form-card__container { border: 1px solid var(--el-border-color); border-radius: var(--el-border-radius-base); grid-template-rows: 1fr; } } + + .cl-form-card { + margin-left: 10px; + } } .cl-dialog { diff --git a/packages/crud/types/components/form-card.d.ts b/packages/crud/types/components/form-card.d.ts new file mode 100644 index 0000000..3a5b163 --- /dev/null +++ b/packages/crud/types/components/form-card.d.ts @@ -0,0 +1,25 @@ +declare const _default: import("vue").DefineComponent<{ + label: StringConstructor; + expand: { + type: BooleanConstructor; + default: boolean; + }; + isExpand: { + type: BooleanConstructor; + default: boolean; + }; +}, () => JSX.Element, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly>, { + expand: boolean; + isExpand: boolean; +}>; +export default _default; diff --git a/packages/crud/types/utils/vnode.d.ts b/packages/crud/types/utils/vnode.d.ts index ed29332..ae8af82 100644 --- a/packages/crud/types/utils/vnode.d.ts +++ b/packages/crud/types/utils/vnode.d.ts @@ -4,6 +4,7 @@ interface Options { scope?: any; item?: any; slots?: any; + children?: any[] & any; custom?: (vnode: any) => any; render?: "slot" | null; [key: string]: any; diff --git a/src/modules/crud/config.ts b/src/modules/crud/config.ts index a36e788..8ec3b40 100644 --- a/src/modules/crud/config.ts +++ b/src/modules/crud/config.ts @@ -1,9 +1,11 @@ import { Merge, ModuleConfig } from "/@/cool"; import Crud from "@cool-vue/crud"; -// 调试或者自定义crud -// import Crud from "../../../packages/crud/src"; import "@cool-vue/crud/dist/index.css"; +// 调试、自定义crud +// import Crud from "../../../packages/crud/src"; +// import "../../../packages/crud/src/static/index.scss"; + export default (): Merge => { return { options: { diff --git a/src/modules/recycle/views/data.vue b/src/modules/recycle/views/data.vue index 890174c..a1b9e6b 100644 --- a/src/modules/recycle/views/data.vue +++ b/src/modules/recycle/views/data.vue @@ -67,11 +67,11 @@ const Table = useTable({ } } }, - { label: "删除条数", prop: "count", minWidth: 120, sortable: "custom" }, + { label: "删除条数", prop: "count", minWidth: 100, sortable: "custom" }, { label: "创建时间", prop: "createTime", minWidth: 160, sortable: "desc" }, { type: "op", - minWidth: 150, + width: 120, buttons: [ { label: "恢复", diff --git a/yarn.lock b/yarn.lock index c5b6635..96c40f2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -280,10 +280,10 @@ "@babel/helper-validator-identifier" "^7.19.1" to-fast-properties "^2.0.0" -"@cool-vue/crud@^6.2.2": - version "6.2.2" - resolved "https://registry.yarnpkg.com/@cool-vue/crud/-/crud-6.2.2.tgz#4e24bfb157307b5aef249476b4a41acd61217e30" - integrity sha512-0NBn8ZtbjJ85HkuVWueEmJ8+Uvc+yNezGO12f3AuHn0Ru1uVk5Dmy3EFDK5XhoWurOmTgk1lDaG3/G+CCgtCtw== +"@cool-vue/crud@^6.3.1": + version "6.3.1" + resolved "https://registry.yarnpkg.com/@cool-vue/crud/-/crud-6.3.1.tgz#871d9788d43576337af92ebae5b770dd16ee7826" + integrity sha512-mbAaumXavoVW4wtShZpQb0lKG9VHGfvrsUgnVt78zi7TVB32+9duasMjf2Y3gz6HM1p1FODMPhfkCOXGbpOHyA== dependencies: array.prototype.flat "^1.2.4" core-js "^3.21.1"