ztz-table
Version:
ZTZ Table,一个为开发者准备的基于 Vue 3.0 和 Element Plus 的数据表格二次封装的组件库,旨在通过配置文件快速生成表格。集成CRUD功能,通过简单配置,快速完成一个基本的增删查改功能。
63 lines (62 loc) • 2.26 kB
JavaScript
// eslint-disable-next-line
import '../table-element-plus/interface';
export const getProp = (column = {}) => column?.prop ?? column?.dataIndex ?? column?.key;
export const getLabel = (column = {}) => column?.label ?? column?.title ?? column?.name;
export const sortCurdVNodeBtn = (vnodeList = []) => vnodeList.sort((a, b) => {
const v1 = a?.props?.['crud-sort'] ?? a?.props?.crudSort ?? 500;
const v2 = b?.props?.['crud-sort'] ?? b?.props?.crudSort ?? 500;
return v2 - v1;
});
export const checkType = (target, value) => Object.prototype.toString.call(target) === `[object ${value}]`;
export const uuid = function () {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
const r = Math.random() * 16 | 0;
const v = c === 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
};
// paramCase -> param-case
const paramCase = (value = '') => value.replace(/[A-Z]/, (s, i, str) => {
const l = s.toLowerCase();
return (i === 0 || i === str.length - 1) ? l : `-${l}`;
});
// camel-case -> camelCase
const camelCase = (value = '') => value.replace(/(-(.+?|$))/, (s) => s.charAt(1).toUpperCase());
export const getObjectValue = (target, path = '') => {
if (!path) {
return undefined;
}
let res = target;
try {
const pathList = path.replace(/\[/gim, '.').replace(']', '').split('.').map((s) => [camelCase(s), paramCase(s)]);
// eslint-disable-next-line
for (const p of pathList) {
// @ts-ignore
res = res[p[0]] ?? res[p[1]];
}
}
catch {
return undefined;
}
return res;
};
/**
const a = { label: 1 }
const b = { label: 2, c: 20 }
mergeDifference(a, b) => a === { label: 1, c: 20 }
*/
export function mergeDifference(b = {}, s = {}) {
if (checkType(b, 'Object') && checkType(s, 'Object')) {
for (const [k, v] of Object.entries(s)) {
if (b.hasOwnProperty(k)) {
if (checkType(b[k], 'Object') && checkType(v, 'Object')) {
mergeDifference(b[k], v);
}
}
else {
b[k] = v;
}
}
}
return b;
}