mirror of
https://github.com/jekip/naive-ui-admin.git
synced 2026-02-10 08:22:27 +08:00
Fixes bug add baseModal | baseForm 组件
This commit is contained in:
98
src/utils/Drag.ts
Normal file
98
src/utils/Drag.ts
Normal file
@@ -0,0 +1,98 @@
|
||||
//获取相关CSS属性
|
||||
const getCss = function (o, key) {
|
||||
return o.currentStyle
|
||||
? o.currentStyle[key]
|
||||
: document.defaultView.getComputedStyle(o, false)[key];
|
||||
};
|
||||
|
||||
const params = {
|
||||
left: 0,
|
||||
top: 0,
|
||||
currentX: 0,
|
||||
currentY: 0,
|
||||
flag: false,
|
||||
};
|
||||
|
||||
const startDrag = function (bar, target, callback) {
|
||||
const screenWidth = document.body.clientWidth; // body当前宽度
|
||||
const screenHeight = document.documentElement.clientHeight; // 可见区域高度
|
||||
|
||||
const dragDomW = target.offsetWidth; // 对话框宽度
|
||||
const dragDomH = target.offsetHeight; // 对话框高度
|
||||
|
||||
const minDomLeft = target.offsetLeft;
|
||||
const minDomTop = target.offsetTop;
|
||||
|
||||
const maxDragDomLeft = screenWidth - minDomLeft - dragDomW;
|
||||
const maxDragDomTop = screenHeight - minDomTop - dragDomH;
|
||||
|
||||
if (getCss(target, 'left') !== 'auto') {
|
||||
params.left = getCss(target, 'left');
|
||||
}
|
||||
if (getCss(target, 'top') !== 'auto') {
|
||||
params.top = getCss(target, 'top');
|
||||
}
|
||||
|
||||
//o是移动对象
|
||||
bar.onmousedown = function (event) {
|
||||
params.flag = true;
|
||||
if (!event) {
|
||||
event = window.event;
|
||||
//防止IE文字选中
|
||||
bar.onselectstart = function () {
|
||||
return false;
|
||||
};
|
||||
}
|
||||
const e = event;
|
||||
params.currentX = e.clientX;
|
||||
params.currentY = e.clientY;
|
||||
};
|
||||
document.onmouseup = function () {
|
||||
params.flag = false;
|
||||
if (getCss(target, 'left') !== 'auto') {
|
||||
params.left = getCss(target, 'left');
|
||||
}
|
||||
if (getCss(target, 'top') !== 'auto') {
|
||||
params.top = getCss(target, 'top');
|
||||
}
|
||||
};
|
||||
document.onmousemove = function (event) {
|
||||
const e = event ? event : window.event;
|
||||
if (params.flag) {
|
||||
const nowX = e.clientX,
|
||||
nowY = e.clientY;
|
||||
const disX = nowX - params.currentX,
|
||||
disY = nowY - params.currentY;
|
||||
|
||||
let left = parseInt(params.left) + disX;
|
||||
let top = parseInt(params.top) + disY;
|
||||
|
||||
// 拖出屏幕边缘
|
||||
if (-left > minDomLeft) {
|
||||
left = -minDomLeft;
|
||||
} else if (left > maxDragDomLeft) {
|
||||
left = maxDragDomLeft;
|
||||
}
|
||||
|
||||
if (-top > minDomTop) {
|
||||
top = -minDomTop;
|
||||
} else if (top > maxDragDomTop) {
|
||||
top = maxDragDomTop;
|
||||
}
|
||||
|
||||
target.style.left = left + 'px';
|
||||
target.style.top = top + 'px';
|
||||
|
||||
if (typeof callback == 'function') {
|
||||
callback((parseInt(params.left) || 0) + disX, (parseInt(params.top) || 0) + disY);
|
||||
}
|
||||
|
||||
if (event.preventDefault) {
|
||||
event.preventDefault();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
export default startDrag;
|
||||
12
src/utils/dateUtil.ts
Normal file
12
src/utils/dateUtil.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { format } from 'date-fns';
|
||||
|
||||
const DATE_TIME_FORMAT = 'YYYY-MM-DD HH:mm';
|
||||
const DATE_FORMAT = 'YYYY-MM-DD ';
|
||||
|
||||
export function formatToDateTime(date: null, formatStr = DATE_TIME_FORMAT): string {
|
||||
return format(date, formatStr);
|
||||
}
|
||||
|
||||
export function formatToDate(date: null, formatStr = DATE_FORMAT): string {
|
||||
return format(date, formatStr);
|
||||
}
|
||||
@@ -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)}`;
|
||||
}
|
||||
|
||||
@@ -112,3 +112,7 @@ export function isNull(val: unknown): val is null {
|
||||
export function isNullAndUnDef(val: unknown): val is null | undefined {
|
||||
return isUnDef(val) && isNull(val);
|
||||
}
|
||||
|
||||
export function isNullOrUnDef(val: unknown): val is null | undefined {
|
||||
return isUnDef(val) || isNull(val);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user