Fixes bug add baseModal | baseForm 组件

This commit is contained in:
Ah jung
2021-08-05 17:24:24 +08:00
parent 98e1bf0227
commit 8a5f237630
59 changed files with 2056 additions and 106 deletions

View File

@@ -1,7 +1,8 @@
import { h } from 'vue';
import { h, unref } from 'vue';
import type { App, Plugin } from 'vue';
import { NIcon } from 'naive-ui';
import { NIcon, NTag } from 'naive-ui';
import { PageEnum } from '@/enums/pageEnum';
import { isObject } from './is/index';
/**
* render 图标
@@ -10,6 +11,24 @@ export function renderIcon(icon) {
return () => h(NIcon, null, { default: () => h(icon) });
}
/**
* render new Tag
* */
const newTagColors = { color: '#f90', textColor: '#fff', borderColor: '#f90' };
export function renderNew(type = 'warning', text = 'New', color: object = newTagColors) {
return () =>
h(
NTag as any,
{
type,
round: true,
size: 'small',
color,
},
{ default: () => text }
);
}
/**
* 递归组装菜单格式
*/
@@ -17,21 +36,23 @@ export function generatorMenu(routerMap: Array<any>) {
return routerMap
.filter((item) => {
return (
item.meta.hidden != true &&
(item.meta?.hidden || false) != true &&
!['/:path(.*)*', '/', PageEnum.REDIRECT, PageEnum.BASE_LOGIN].includes(item.path)
);
})
.map((item) => {
const info =
item.meta?.alwaysShow != true && item.children?.length === 1 ? item.children[0] : item;
const currentMenu = {
...item,
...item.meta,
label: item.meta.title,
key: item.name,
...info,
...info.meta,
label: info.meta?.title,
key: info.name,
};
// 是否有子菜单,并递归处理
if (item.children && item.children.length > 0) {
if (info.children && info.children.length > 0) {
// Recursion
currentMenu.children = generatorMenu(item.children);
currentMenu.children = generatorMenu(info.children);
}
return currentMenu;
});
@@ -78,3 +99,49 @@ export function getTreeAll(data: any[]): any[] {
});
return treeAll;
}
// dynamic use hook props
export function getDynamicProps<T, U>(props: T): Partial<U> {
const ret: Recordable = {};
Object.keys(props).map((key) => {
ret[key] = unref((props as Recordable)[key]);
});
return ret as Partial<U>;
}
export function deepMerge<T = any>(src: any = {}, target: any = {}): T {
let key: string;
for (key in target) {
src[key] = isObject(src[key]) ? deepMerge(src[key], target[key]) : (src[key] = target[key]);
}
return src;
}
/**
* Sums the passed percentage to the R, G or B of a HEX color
* @param {string} color The color to change
* @param {number} amount The amount to change the color by
* @returns {string} The processed part of the color
*/
function addLight(color: string, amount: number) {
const cc = parseInt(color, 16) + amount;
const c = cc > 255 ? 255 : cc;
return c.toString(16).length > 1 ? c.toString(16) : `0${c.toString(16)}`;
}
/**
* Lightens a 6 char HEX color according to the passed percentage
* @param {string} color The color to change
* @param {number} amount The amount to change the color by
* @returns {string} The processed color represented as HEX
*/
export function lighten(color: string, amount: number) {
color = color.indexOf('#') >= 0 ? color.substring(1, color.length) : color;
amount = Math.trunc((255 * amount) / 100);
return `#${addLight(color.substring(0, 2), amount)}${addLight(
color.substring(2, 4),
amount
)}${addLight(color.substring(4, 6), amount)}`;
}