UNPKG

el-plus-powerful-table

Version:

## [DOCS](https://peng-xiao-shuai.github.io/vite-vue-admin-docs/zh-CN/component_directive/component/powerful-table-doc.html)

1 lines 3.81 kB
{"version":3,"file":"index.mjs","sources":["../packages/index.ts"],"sourcesContent":["import components from './components'\nimport powerfulTable from './powerful-table'\nimport fComponents from './filter'\nimport BtnPlus from './btn-plus'\nimport { PowerfulTableSymbol } from './keys'\nimport type { PowerfulTableHeaderProps, SetDataType, _TYPE } from '#/index'\nimport type { App, Plugin } from 'vue'\nexport type * from '../typings/index'\nexport { default as PTBtnPlus } from './btn-plus'\nexport * from './powerful-table'\nexport * from './filter'\nexport * from './components'\nexport { EmitEnum } from './powerful-table/src/powerful-table-data'\n// 获取类型\nexport const getType = <T>(target: T) =>\n Object.prototype.toString.call(target).slice(8, -1)\n\nexport const getPropType = <T>(\n prop: PowerfulTableHeaderProps<T>,\n scope: {\n row: T\n index: number\n }\n) => {\n function isFunction<T>(\n value: T | ((...args: any[]) => any)\n ): value is Extract<T, (...args: any[]) => any> {\n return typeof value === 'function'\n }\n\n const { type } = prop\n if (type !== undefined && isFunction(type)) {\n return type(scope.row, scope.index)\n } else {\n return type\n }\n}\n\n// 深度克隆\nexport const deepClone = <T>(target: T) => {\n let result\n if (getType(target) === 'Object') {\n result = {} as T\n } else if (getType(target) === 'Array') {\n result = [] as T\n } else result = target\n\n for (const i in target) {\n const item = target[i]\n if (getType(item) === 'Object' || getType(item) === 'Array') {\n result[i] = deepClone(item)\n } else result[i] = item\n }\n return result\n}\n\n/**\n * @description 类型保护\n * @see https://www.tslang.cn/docs/handbook/advanced-types.html 搜索 “自定义类型保护”\n * @param {T} obj 值,它必须是联合类型\n * @param {(obj: T) => boolean} cb 回调函数,返回一个布尔值\n * @example\n * const a = [] | string\n * a.push() // 报错\n * if (isTypeProtect<typeof a, []>(a, (a) => Array.isArray(a))) {\n * a.push() // 正常\n * }\n * @returns {boolean}\n */\nexport const isTypeProtect = <T, P extends T>(\n obj: T,\n cb: (obj: T) => boolean\n): obj is P => cb(obj)\n\n// 不同类型的data数据类型提示\nexport const setData = <T extends keyof _TYPE<L>, L = any>(\n data: SetDataType<T, L>\n): SetDataType<T, L> => data\n\nconst makeInstaller = (components: Plugin[] = []) => {\n const install = (app: App, options?: import('~/index').InjectProps) => {\n components.forEach((c) => {\n app.use(c)\n })\n app.provide(PowerfulTableSymbol, options ? options : {})\n app.config.globalProperties.$deepClone = deepClone\n }\n\n return install\n}\n\nexport default {\n install: makeInstaller([\n ...components,\n ...fComponents,\n BtnPlus,\n powerfulTable,\n ]),\n}\n"],"names":["getType","target","getPropType","prop","scope","isFunction","value","type","deepClone","result","i","item","isTypeProtect","obj","cb","setData","data","makeInstaller","components2","app","options","c"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CI,MAASA,IAAC,CAAAC,MAAA,OAAA,UAAA,SAAA,KAAAA,CAAA,EAAA,MAAA,GAAA,EAAA,GACDC,IAAc,CAAAC,GAAeC,MAAA;AACtC,WAAAC,EAAUC,GAAA;AACZ,WAAA,OAAAA,KAAA;AAAA,EAAgB;AAEhB,QAAA,EAAA,MAAAC,MAAwBJ;AAChB,SAAAI,MAAA,UAAeF,EAAAE,CAAA,MACTH,EAAI,YAAkB,IAElCG;AAAmB,GAEdC,IAAA,CAAAP,MAAA;AACT,MAAAQ;AAeO,EAAAT,EAAsBC,CAAA,MAAA,WAMhBQ,IAAA,CAAA,IAIST,EAAAC,CAAwB,MAAA,UACtCQ,IAAA,CAAA,IAEFA;AAAS,aACVC,KAAAT,GAAA;AACD,UAAYU,IAAAV,EAAAS,CAAA;AACR,IAAAV,qBAAqCA,EAAAW,CAAA,MAAA,UAC3CF,EAAAC,CAAA,IAAAF,EAAAG,CAAA,IAGFF,EAAAC,CAAA,IAAAC;AAAA,EAEe;AACb;AAAuB,GAElBC,IAAA,CAAAC,GAAAC,MAAAA,EAAAD,CAAA,GACHE,IAAA,CAAAC,MAAAA,GACAC,IAAA,CAAAC,IAAA,OACD,CAAAC,GAAAC,MAAA;AACH,EAAAF,EAAA,QAAA,CAAAG,MAAA;;;;;;;;;;;"}