y-admin-ui 6.1.7 → 6.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/lang/zh-cn.ts +37 -37
- package/lib/lang/zh-tw.ts +37 -37
- package/lib/style/common.scss +20 -0
- package/lib/style/extension/index.scss +1 -0
- package/lib/style/extension/y-message.scss +54 -0
- package/lib/style/fonts/iconfont.ttf +0 -0
- package/lib/style/fonts/iconfont.woff +0 -0
- package/lib/style/icon.scss +9 -3
- package/lib/style/index.scss +3 -1
- package/lib/style/tailwind.scss +3 -0
- package/lib/style/themes/dark.scss +60 -0
- package/lib/style/themes/defaults.scss +62 -0
- package/lib/style.css +1 -1
- package/lib/style.css.gz +0 -0
- package/lib/utils/core.ts +48 -25
- package/lib/utils/data.ts +63 -0
- package/lib/utils/element/message.ts +98 -0
- package/lib/utils/getStyleSheets.ts +101 -0
- package/lib/utils/other.ts +32 -0
- package/lib/y-admin-ui.js +14703 -7061
- package/lib/y-admin-ui.js.gz +0 -0
- package/lib/y-admin-ui.umd.cjs +29 -19
- package/package.json +7 -3
- package/typings/global.d.ts +6 -0
package/lib/style.css.gz
CHANGED
|
Binary file
|
package/lib/utils/core.ts
CHANGED
|
@@ -4,23 +4,46 @@
|
|
|
4
4
|
* @param callback 回调
|
|
5
5
|
* @param childrenField children字段名
|
|
6
6
|
*/
|
|
7
|
-
export function eachTreeData(
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
7
|
+
export function eachTreeData(data: any[], callback: Function, childrenField = 'children', parent: any = '') {
|
|
8
|
+
if (data) {
|
|
9
|
+
data.forEach((d, i) => {
|
|
10
|
+
if (callback && callback(d, i, parent) !== false && d[childrenField]?.length) {
|
|
11
|
+
eachTreeData(d[childrenField], callback, childrenField, d);
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* 遍历每一项,并可修改节点
|
|
19
|
+
* @param data 数据数组
|
|
20
|
+
* @param callback 回调,可修改节点
|
|
21
|
+
* @param options 配置选项
|
|
22
|
+
* - childrenField: children 字段名,默认 'children'
|
|
23
|
+
* - mutate: 是否直接修改原始对象,默认 false
|
|
24
|
+
* @returns 返回处理后的数组(根据 mutate 决定是原对象还是新对象)
|
|
25
|
+
*/
|
|
26
|
+
export function eachTreeItemData(data: any[], callback: (node: any) => void, options: { childrenField?: string; mutate?: boolean } = {}) {
|
|
27
|
+
const { childrenField = 'children', mutate = false } = options;
|
|
28
|
+
|
|
29
|
+
const result: any[] = [];
|
|
30
|
+
|
|
31
|
+
data.forEach((item) => {
|
|
32
|
+
// 决定是克隆还是直接修改原始对象
|
|
33
|
+
const node = mutate ? item : { ...item };
|
|
34
|
+
|
|
35
|
+
// 执行回调,可修改 node
|
|
36
|
+
callback(node);
|
|
37
|
+
|
|
38
|
+
// 如果有 children,递归处理
|
|
39
|
+
if (node[childrenField]?.length) {
|
|
40
|
+
node[childrenField] = eachTreeItemData(node[childrenField], callback, options);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
result.push(node);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
return result;
|
|
24
47
|
}
|
|
25
48
|
|
|
26
49
|
/**
|
|
@@ -29,17 +52,17 @@ export function eachTreeData(
|
|
|
29
52
|
* @param radix 基数
|
|
30
53
|
*/
|
|
31
54
|
export function uuid(length = 32, radix: any) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
55
|
+
const num = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
|
|
56
|
+
let result = '';
|
|
57
|
+
for (let i = 0; i < length; i++) {
|
|
58
|
+
result += num.charAt(Math.floor(Math.random() * (radix || num.length)));
|
|
59
|
+
}
|
|
60
|
+
return result;
|
|
38
61
|
}
|
|
39
62
|
|
|
40
63
|
/**
|
|
41
64
|
* 获取屏幕宽度
|
|
42
65
|
*/
|
|
43
66
|
export function screenWidth() {
|
|
44
|
-
|
|
45
|
-
}
|
|
67
|
+
return document.documentElement.clientWidth || document.body.clientWidth;
|
|
68
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// 申明 数组
|
|
2
|
+
declare type EmptyArrayType<T = any> = T[];
|
|
3
|
+
// 申明 对象
|
|
4
|
+
declare type EmptyObjectType<T = any> = {
|
|
5
|
+
[key: string]: T;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* 对象深克隆
|
|
10
|
+
* @param obj 源对象
|
|
11
|
+
* @returns 克隆后的对象
|
|
12
|
+
*/
|
|
13
|
+
export function deepClone(obj: EmptyObjectType) {
|
|
14
|
+
let newObj: EmptyObjectType;
|
|
15
|
+
try {
|
|
16
|
+
newObj = obj.push ? [] : {};
|
|
17
|
+
} catch (error) {
|
|
18
|
+
newObj = {};
|
|
19
|
+
}
|
|
20
|
+
for (let attr in obj) {
|
|
21
|
+
if (obj[attr] && typeof obj[attr] === 'object') {
|
|
22
|
+
newObj[attr] = deepClone(obj[attr]);
|
|
23
|
+
} else {
|
|
24
|
+
newObj[attr] = obj[attr];
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return newObj;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* 判断是否是移动端
|
|
32
|
+
*/
|
|
33
|
+
export function isMobile() {
|
|
34
|
+
if (
|
|
35
|
+
navigator.userAgent.match(
|
|
36
|
+
/('phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone')/i
|
|
37
|
+
)
|
|
38
|
+
) {
|
|
39
|
+
return true;
|
|
40
|
+
} else {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* 判断数组对象中所有属性是否为空,为空则删除当前行对象
|
|
47
|
+
* @param list 数组对象
|
|
48
|
+
* @returns 删除空值后的数组对象
|
|
49
|
+
*/
|
|
50
|
+
export function handleEmpty(list: EmptyArrayType) {
|
|
51
|
+
const arr = [];
|
|
52
|
+
for (const i in list) {
|
|
53
|
+
const d = [];
|
|
54
|
+
for (const j in list[i]) {
|
|
55
|
+
d.push(list[i][j]);
|
|
56
|
+
}
|
|
57
|
+
const leng = d.filter((item) => item === '').length;
|
|
58
|
+
if (leng !== d.length) {
|
|
59
|
+
arr.push(list[i]);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return arr;
|
|
63
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 消息提示,二次封装
|
|
3
|
+
*/
|
|
4
|
+
import { ElMessage, ElLoading, type MessageOptions } from 'element-plus';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 通用消息封装
|
|
8
|
+
* 用于统一项目内消息提示风格
|
|
9
|
+
*/
|
|
10
|
+
type MessageType = 'primary' | 'success' | 'warning' | 'info' | 'error';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* MessageExtensionOptions 拓展消息提示参数
|
|
14
|
+
*/
|
|
15
|
+
export interface MessageExtensionOptions extends MessageOptions {
|
|
16
|
+
// 是否显示遮罩
|
|
17
|
+
mask: boolean;
|
|
18
|
+
// 是否显示边框-清新模式
|
|
19
|
+
border: boolean;
|
|
20
|
+
// 是否loading模式
|
|
21
|
+
loading: boolean;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* 默认参数
|
|
26
|
+
* @param mask 是否显示遮罩(额外拓展)
|
|
27
|
+
* @param border 是否显示边框-清新模式(额外拓展)
|
|
28
|
+
* @param loading 是否loading模式(额外拓展)
|
|
29
|
+
* @param placement 消息放置位置(原先element就有,新增 'center' 居中)
|
|
30
|
+
*/
|
|
31
|
+
const defaultOptions: MessageExtensionOptions = {
|
|
32
|
+
mask: false,
|
|
33
|
+
border: false,
|
|
34
|
+
loading: false,
|
|
35
|
+
customClass: '',
|
|
36
|
+
dangerouslyUseHTMLString: false,
|
|
37
|
+
duration: 3000,
|
|
38
|
+
icon: undefined,
|
|
39
|
+
message: '这是一条提示内容',
|
|
40
|
+
onClose: undefined,
|
|
41
|
+
showClose: false,
|
|
42
|
+
type: 'primary' as MessageType,
|
|
43
|
+
plain: false,
|
|
44
|
+
offset: 16,
|
|
45
|
+
placement: 'top',
|
|
46
|
+
zIndex: 0,
|
|
47
|
+
grouping: false,
|
|
48
|
+
repeatNum: 1,
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
function message(options: MessageExtensionOptions) {
|
|
52
|
+
const merged = { ...defaultOptions, ...options };
|
|
53
|
+
/** 是否要边框风格 */
|
|
54
|
+
if (merged.border) {
|
|
55
|
+
merged.customClass = [merged.customClass, 'y-message-border'].filter(Boolean).join(' ');
|
|
56
|
+
}
|
|
57
|
+
/** 是否要loading风格 */
|
|
58
|
+
if (merged.loading) {
|
|
59
|
+
merged.customClass = [merged.customClass, 'y-message-loading'].filter(Boolean).join(' ');
|
|
60
|
+
}
|
|
61
|
+
/** 是否要遮罩层 */
|
|
62
|
+
let loadingInstance: ReturnType<typeof ElLoading.service> | null = null;
|
|
63
|
+
if (merged.mask) {
|
|
64
|
+
loadingInstance = ElLoading.service({
|
|
65
|
+
lock: true,
|
|
66
|
+
background: 'rgba(0, 0, 0, 0.3)',
|
|
67
|
+
spinner: '1', // 不显示默认加载图标
|
|
68
|
+
text: '', // 不显示文字
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
/** 位置 */
|
|
72
|
+
if ((merged.placement as string) === 'center') {
|
|
73
|
+
merged.customClass = [merged.customClass, 'y-center'].filter(Boolean).join(' ');
|
|
74
|
+
}
|
|
75
|
+
// 创建消息实例
|
|
76
|
+
const msg = ElMessage({
|
|
77
|
+
...merged,
|
|
78
|
+
onClose: () => {
|
|
79
|
+
// 先执行用户自定义的 onClose
|
|
80
|
+
merged.onClose?.();
|
|
81
|
+
// 再关闭遮罩层
|
|
82
|
+
if (loadingInstance) {
|
|
83
|
+
loadingInstance.close();
|
|
84
|
+
loadingInstance = null;
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
return msg;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export const Ymessage = Object.assign(message, {
|
|
93
|
+
primary: (options: MessageExtensionOptions) => message(options),
|
|
94
|
+
success: (options: MessageExtensionOptions) => message(options),
|
|
95
|
+
warning: (options: MessageExtensionOptions) => message(options),
|
|
96
|
+
info: (options: MessageExtensionOptions) => message(options),
|
|
97
|
+
error: (options: MessageExtensionOptions) => message(options),
|
|
98
|
+
});
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { nextTick } from 'vue';
|
|
2
|
+
import * as svg from '@element-plus/icons-vue';
|
|
3
|
+
|
|
4
|
+
// 获取阿里字体图标
|
|
5
|
+
const getAlicdnIconfont = () => {
|
|
6
|
+
return new Promise((resolve, reject) => {
|
|
7
|
+
nextTick(() => {
|
|
8
|
+
const styles: any = document.styleSheets;
|
|
9
|
+
let sheetsList = [] as any;
|
|
10
|
+
let sheetsIconList = [] as any;
|
|
11
|
+
for (let i = 0; i < styles.length; i++) {
|
|
12
|
+
if (styles[i].href && styles[i].href.indexOf('at.alicdn.com') > -1) {
|
|
13
|
+
sheetsList.push(styles[i]);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
for (let i = 0; i < sheetsList.length; i++) {
|
|
17
|
+
for (let j = 0; j < sheetsList[i].cssRules.length; j++) {
|
|
18
|
+
if (sheetsList[i].cssRules[j].selectorText && sheetsList[i].cssRules[j].selectorText.indexOf('.icon-') > -1) {
|
|
19
|
+
sheetsIconList.push(
|
|
20
|
+
`${sheetsList[i].cssRules[j].selectorText.substring(1, sheetsList[i].cssRules[j].selectorText.length).replace(/\:\:before/gi, '')}`
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (sheetsIconList.length > 0) resolve(sheetsIconList);
|
|
26
|
+
else reject('未获取到值,请刷新重试');
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
// 初始化获取 css 样式,获取 element plus 自带 svg 图标,增加了 ele- 前缀,使用时:ele-Aim
|
|
32
|
+
const getElementPlusIconfont = () => {
|
|
33
|
+
return new Promise((resolve, reject) => {
|
|
34
|
+
nextTick(() => {
|
|
35
|
+
const icons = svg as any;
|
|
36
|
+
const sheetsIconList = [] as any;
|
|
37
|
+
for (const i in icons) {
|
|
38
|
+
sheetsIconList.push(`ele-${icons[i].name}`);
|
|
39
|
+
}
|
|
40
|
+
if (sheetsIconList.length > 0) resolve(sheetsIconList);
|
|
41
|
+
else reject('未获取到值,请刷新重试');
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
// 初始化获取 css 样式,这里使用 fontawesome 的图标
|
|
47
|
+
const getAwesomeIconfont = () => {
|
|
48
|
+
return new Promise((resolve, reject) => {
|
|
49
|
+
nextTick(() => {
|
|
50
|
+
const styles: any = document.styleSheets;
|
|
51
|
+
let sheetsList = [] as any;
|
|
52
|
+
let sheetsIconList = [] as any;
|
|
53
|
+
for (let i = 0; i < styles.length; i++) {
|
|
54
|
+
if (styles[i].href && styles[i].href.indexOf('https://cdn.jsdelivr.net') > -1) {
|
|
55
|
+
sheetsList.push(styles[i]);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
for (let i = 0; i < sheetsList.length; i++) {
|
|
59
|
+
for (let j = 0; j < sheetsList[i].cssRules.length; j++) {
|
|
60
|
+
if (
|
|
61
|
+
sheetsList[i].cssRules[j].selectorText &&
|
|
62
|
+
sheetsList[i].cssRules[j].selectorText.indexOf('.fa-') === 0 &&
|
|
63
|
+
sheetsList[i].cssRules[j].selectorText.indexOf(',') === -1
|
|
64
|
+
) {
|
|
65
|
+
if (/::before/.test(sheetsList[i].cssRules[j].selectorText)) {
|
|
66
|
+
sheetsIconList.push(
|
|
67
|
+
`${sheetsList[i].cssRules[j].selectorText.substring(1, sheetsList[i].cssRules[j].selectorText.length).replace(/\:\:before/gi, '')}`
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (sheetsIconList.length > 0) resolve(sheetsIconList.reverse());
|
|
74
|
+
else reject('未获取到值,请刷新重试');
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* 获取字体图标 `document.styleSheets`
|
|
81
|
+
* @method ali 获取阿里字体图标 `<i class="iconfont 图标类名"></i>`
|
|
82
|
+
* @method ele 获取 element plus 自带图标 `<i class="图标类名"></i>`
|
|
83
|
+
* @method ali 获取 fontawesome 的图标 `<i class="fa 图标类名"></i>`
|
|
84
|
+
*/
|
|
85
|
+
const initIconfont = {
|
|
86
|
+
// iconfont
|
|
87
|
+
ali: () => {
|
|
88
|
+
return getAlicdnIconfont();
|
|
89
|
+
},
|
|
90
|
+
// element plus
|
|
91
|
+
ele: () => {
|
|
92
|
+
return getElementPlusIconfont();
|
|
93
|
+
},
|
|
94
|
+
// fontawesome
|
|
95
|
+
awe: () => {
|
|
96
|
+
return getAwesomeIconfont();
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
// 导出方法
|
|
101
|
+
export default initIconfont;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { defineAsyncComponent } from 'vue';
|
|
2
|
+
import type { App } from 'vue';
|
|
3
|
+
import * as svg from '@element-plus/icons-vue';
|
|
4
|
+
|
|
5
|
+
// 引入组件
|
|
6
|
+
const SvgIcon = defineAsyncComponent(() => import('./../y-svg-icon/index.vue'));
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* 导出全局注册 element plus svg 图标
|
|
10
|
+
* @param app vue 实例
|
|
11
|
+
* @description 使用:https://element-plus.gitee.io/zh-CN/component/icon.html
|
|
12
|
+
*/
|
|
13
|
+
export function elSvg(app: App) {
|
|
14
|
+
const icons = svg as any;
|
|
15
|
+
for (const i in icons) {
|
|
16
|
+
app.component(`ele-${icons[i].name}`, icons[i]);
|
|
17
|
+
}
|
|
18
|
+
app.component('SvgIcon', SvgIcon);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* 统一批量导出
|
|
23
|
+
* @method elSvg 导出全局注册 element plus svg 图标
|
|
24
|
+
*/
|
|
25
|
+
const other = {
|
|
26
|
+
elSvg: (app: App) => {
|
|
27
|
+
elSvg(app);
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
// 统一批量导出
|
|
32
|
+
export default other;
|