@lambo-design/shared 1.0.0-beta.1
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/config/config.js +25 -0
- package/config/env.js +4 -0
- package/config/index.js +3 -0
- package/config/themes/default/default.css +241 -0
- package/config/themes/default/default.less +319 -0
- package/config/themes/default/var.less +314 -0
- package/config/themes/gold/default.css +241 -0
- package/config/themes/gold/default.less +319 -0
- package/config/themes/gold/var.less +314 -0
- package/config/themes/index.js +10 -0
- package/config/themes/lime/default.css +241 -0
- package/config/themes/lime/default.less +319 -0
- package/config/themes/lime/var.less +314 -0
- package/config/themes/theme-default.js +252 -0
- package/config/themes/theme-gold.js +252 -0
- package/config/themes/theme-lime.js +252 -0
- package/index.js +3 -0
- package/package.json +20 -0
- package/styles/variables.less +21 -0
- package/utils/ajax/cacheconf.js +19 -0
- package/utils/ajax/index.js +12 -0
- package/utils/ajax/interceptors.js +90 -0
- package/utils/assist.js +79 -0
- package/utils/bus.js +3 -0
- package/utils/crypto/index.js +38 -0
- package/utils/crypto/md5.js +152 -0
- package/utils/crypto/sm3.js +235 -0
- package/utils/date.js +352 -0
- package/utils/dom.js +38 -0
- package/utils/excel.js +523 -0
- package/utils/index.js +5 -0
- package/utils/lodop.js +160 -0
- package/utils/modelerUtil.js +224 -0
- package/utils/number.js +123 -0
- package/utils/platform.js +519 -0
- package/utils/theme.js +43 -0
- package/utils/zoomScroll.js +9 -0
- package/vendor/xlsx-0.19.1.tgz +0 -0
|
@@ -0,0 +1,519 @@
|
|
|
1
|
+
|
|
2
|
+
export const TOKEN_KEY = 'v8-token'
|
|
3
|
+
|
|
4
|
+
export const COOKIE_KEY = 'lambo-sso-key'
|
|
5
|
+
|
|
6
|
+
export function objEqual(obj1, obj2) {
|
|
7
|
+
const keysArr1 = Object.keys(obj1)
|
|
8
|
+
const keysArr2 = Object.keys(obj2)
|
|
9
|
+
if (keysArr1.length !== keysArr2.length) return false
|
|
10
|
+
else if (keysArr1.length === 0 && keysArr2.length === 0) return true
|
|
11
|
+
/* eslint-disable-next-line */
|
|
12
|
+
else return !keysArr1.some(key => obj1[key] !== obj2[key])
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @param {Array} list 标签列表
|
|
17
|
+
* @param {String} name 当前关闭的标签的name
|
|
18
|
+
*/
|
|
19
|
+
export function getNextRoute(list, route) {
|
|
20
|
+
let res = {}
|
|
21
|
+
if (list.length === 2) {
|
|
22
|
+
res = getHomeRoute(list)
|
|
23
|
+
} else {
|
|
24
|
+
const index = list.findIndex(item => routeEqual(item, route))
|
|
25
|
+
if (index === list.length - 1) res = list[list.length - 2]
|
|
26
|
+
else res = list[index + 1]
|
|
27
|
+
}
|
|
28
|
+
return res
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
export const setToken = (token) => {
|
|
33
|
+
sessionStorage.setItem(TOKEN_KEY, token)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const getToken = () => {
|
|
37
|
+
const token = sessionStorage.getItem(TOKEN_KEY)
|
|
38
|
+
if (token) return token
|
|
39
|
+
else return false
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export const setSessionStorage = (key, value) => {
|
|
43
|
+
sessionStorage.setItem(key, JSON.stringify(value))
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export const getSessionStorage = (key) => {
|
|
47
|
+
const value = sessionStorage.getItem(key)
|
|
48
|
+
if (value) return JSON.parse(value)
|
|
49
|
+
else return null
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export const removeSessionStorage = (key) => {
|
|
53
|
+
return sessionStorage.removeItem(key)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export const clearSessionStorage = () => {
|
|
57
|
+
return sessionStorage.clear()
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export const setLocalStorage = (key, localstorage) => {
|
|
61
|
+
localStorage.setItem(key, localstorage)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export const getLocalStorage = (key) => {
|
|
65
|
+
return localStorage.getItem(key)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export const removeLocalStorage = (key) => {
|
|
69
|
+
return localStorage.removeItem(key)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export const clearLocalStorage = () => {
|
|
73
|
+
return localStorage.clear()
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export const hasChild = (item) => {
|
|
77
|
+
return item.children && item.children.length !== 0
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const showThisMenuEle = (item, access) => {
|
|
81
|
+
if (item.meta && item.meta.access && item.meta.access.length) {
|
|
82
|
+
if (hasOneOf(item.meta.access, access)) return true
|
|
83
|
+
else return false
|
|
84
|
+
} else return true
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* @param {Array} list 通过路由列表得到菜单列表
|
|
88
|
+
* @returns {Array}
|
|
89
|
+
*/
|
|
90
|
+
export const getMenuByRouter = (list, access) => {
|
|
91
|
+
let res = []
|
|
92
|
+
forEach(list, item => {
|
|
93
|
+
if (!item.meta || (item.meta && !item.meta.hideInMenu)) {
|
|
94
|
+
let obj = {
|
|
95
|
+
icon: (item.meta && item.meta.icon) || '',
|
|
96
|
+
name: item.name,
|
|
97
|
+
meta: item.meta
|
|
98
|
+
}
|
|
99
|
+
if ((hasChild(item) || (item.meta && item.meta.showAlways)) && showThisMenuEle(item, access)) {
|
|
100
|
+
obj.children = getMenuByRouter(item.children, access)
|
|
101
|
+
}
|
|
102
|
+
if (item.meta && item.meta.href) obj.href = item.meta.href
|
|
103
|
+
if (showThisMenuEle(item, access)) res.push(obj)
|
|
104
|
+
}
|
|
105
|
+
})
|
|
106
|
+
return res
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* @param {Array} routeMetched 当前路由metched
|
|
111
|
+
* @returns {Array}
|
|
112
|
+
*/
|
|
113
|
+
export const getBreadCrumbList = (route, homeRoute) => {
|
|
114
|
+
let homeItem = {...homeRoute, icon: homeRoute.meta.icon}
|
|
115
|
+
const {crumbs} = route.meta
|
|
116
|
+
if (crumbs && crumbs.length > 0) {
|
|
117
|
+
crumbs.forEach(item => {
|
|
118
|
+
item.meta = {
|
|
119
|
+
title: item.title
|
|
120
|
+
}
|
|
121
|
+
if (item.type === 2) {
|
|
122
|
+
item.to = item.name
|
|
123
|
+
}
|
|
124
|
+
})
|
|
125
|
+
}
|
|
126
|
+
let breadCrumbList = [{...homeItem, to: homeRoute.name}]
|
|
127
|
+
if (crumbs && crumbs.length > 0) {
|
|
128
|
+
breadCrumbList = breadCrumbList.concat(crumbs)
|
|
129
|
+
}
|
|
130
|
+
return breadCrumbList
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export const getRouteTitleHandled = (route) => {
|
|
134
|
+
let router = {...route}
|
|
135
|
+
let meta = {...route.meta}
|
|
136
|
+
let title = ''
|
|
137
|
+
if (meta.title) {
|
|
138
|
+
if (typeof meta.title === 'function') {
|
|
139
|
+
meta.__titleIsFunction__ = true
|
|
140
|
+
title = meta.title(router)
|
|
141
|
+
} else title = meta.title
|
|
142
|
+
}
|
|
143
|
+
meta.title = title
|
|
144
|
+
router.meta = meta
|
|
145
|
+
return router
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export const showTitle = (item, vm) => {
|
|
149
|
+
return item.meta.title
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* @description 本地存储和获取标签导航列表
|
|
154
|
+
*/
|
|
155
|
+
export const setTagNavListInLocalstorage = list => {
|
|
156
|
+
localStorage.tagNaveList = JSON.stringify(list)
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* @returns {Array} 其中的每个元素只包含路由原信息中的name, path, meta三项
|
|
160
|
+
*/
|
|
161
|
+
export const getTagNavListFromLocalstorage = () => {
|
|
162
|
+
const list = localStorage.tagNaveList
|
|
163
|
+
return list ? JSON.parse(list) : []
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* @param {Array} routers 路由列表数组
|
|
168
|
+
* @description 用于找到路由列表中name为home的对象
|
|
169
|
+
*/
|
|
170
|
+
export const getHomeRoute = (routers, homeName = 'home') => {
|
|
171
|
+
let i = -1
|
|
172
|
+
let len = routers.length
|
|
173
|
+
let homeRoute = {}
|
|
174
|
+
while (++i < len) {
|
|
175
|
+
let item = routers[i]
|
|
176
|
+
if (item.children && item.children.length) {
|
|
177
|
+
let res = getHomeRoute(item.children, homeName)
|
|
178
|
+
if (res.name) return res
|
|
179
|
+
} else {
|
|
180
|
+
if (item.name === homeName) homeRoute = item
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return homeRoute
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* @param {*} list 现有标签导航列表
|
|
188
|
+
* @param {*} newRoute 新添加的路由原信息对象
|
|
189
|
+
* @description 如果该newRoute已经存在则不再添加
|
|
190
|
+
*/
|
|
191
|
+
export const getNewTagList = (list, newRoute) => {
|
|
192
|
+
const {name, path, meta} = newRoute
|
|
193
|
+
let newList = [...list]
|
|
194
|
+
if (newList.findIndex(item => item.name === name) >= 0) return newList
|
|
195
|
+
else newList.push({name, path, meta})
|
|
196
|
+
return newList
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* @param {*} access 用户权限数组,如 ['super_admin', 'admin']
|
|
201
|
+
* @param {*} route 路由列表
|
|
202
|
+
*/
|
|
203
|
+
const hasAccess = (access, route) => {
|
|
204
|
+
if (route.meta && route.meta.access) return hasOneOf(access, route.meta.access)
|
|
205
|
+
else return true
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* 权鉴
|
|
210
|
+
* @param {*} name 即将跳转的路由name
|
|
211
|
+
* @param {*} access 用户权限数组
|
|
212
|
+
* @param {*} routes 路由列表
|
|
213
|
+
* @description 用户是否可跳转到该页
|
|
214
|
+
*/
|
|
215
|
+
export const canTurnTo = (name, access, routes) => {
|
|
216
|
+
const routePermissionJudge = (list) => {
|
|
217
|
+
return list.some(item => {
|
|
218
|
+
if (item.children && item.children.length) {
|
|
219
|
+
return routePermissionJudge(item.children)
|
|
220
|
+
} else if (item.name === name) {
|
|
221
|
+
return hasAccess(access, item)
|
|
222
|
+
}
|
|
223
|
+
})
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return routePermissionJudge(routes)
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* @param {String} url
|
|
231
|
+
* @description 从URL中解析参数
|
|
232
|
+
*/
|
|
233
|
+
export const getParams = url => {
|
|
234
|
+
const keyValueArr = url.split('?')[1].split('&')
|
|
235
|
+
let paramObj = {}
|
|
236
|
+
keyValueArr.forEach(item => {
|
|
237
|
+
const keyValue = item.split('=')
|
|
238
|
+
paramObj[keyValue[0]] = keyValue[1]
|
|
239
|
+
})
|
|
240
|
+
return paramObj
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* @param {Number} times 回调函数需要执行的次数
|
|
246
|
+
* @param {Function} callback 回调函数
|
|
247
|
+
*/
|
|
248
|
+
export const doCustomTimes = (times, callback) => {
|
|
249
|
+
let i = -1
|
|
250
|
+
while (++i < times) {
|
|
251
|
+
callback(i)
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* @param {Object} file 从上传组件得到的文件对象
|
|
257
|
+
* @returns {Promise} resolve参数是解析后的二维数组
|
|
258
|
+
* @description 从Csv文件中解析出表格,解析成二维数组
|
|
259
|
+
*/
|
|
260
|
+
export const getArrayFromFile = (file) => {
|
|
261
|
+
let nameSplit = file.name.split('.')
|
|
262
|
+
let format = nameSplit[nameSplit.length - 1]
|
|
263
|
+
return new Promise((resolve, reject) => {
|
|
264
|
+
let reader = new FileReader()
|
|
265
|
+
reader.readAsText(file) // 以文本格式读取
|
|
266
|
+
let arr = []
|
|
267
|
+
reader.onload = function (evt) {
|
|
268
|
+
let data = evt.target.result // 读到的数据
|
|
269
|
+
let pasteData = data.trim()
|
|
270
|
+
arr = pasteData.split((/[\n\u0085\u2028\u2029]|\r\n?/g)).map(row => {
|
|
271
|
+
return row.split('\t')
|
|
272
|
+
}).map(item => {
|
|
273
|
+
return item[0].split(',')
|
|
274
|
+
})
|
|
275
|
+
if (format === 'csv') resolve(arr)
|
|
276
|
+
else reject(new Error('[Format Error]:你上传的不是Csv文件'))
|
|
277
|
+
}
|
|
278
|
+
})
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* @param {Array} array 表格数据二维数组
|
|
283
|
+
* @returns {Object} { columns, tableData }
|
|
284
|
+
* @description 从二维数组中获取表头和表格数据,将第一行作为表头,用于在iView的表格中展示数据
|
|
285
|
+
*/
|
|
286
|
+
export const getTableDataFromArray = (array) => {
|
|
287
|
+
let columns = []
|
|
288
|
+
let tableData = []
|
|
289
|
+
if (array.length > 1) {
|
|
290
|
+
let titles = array.shift()
|
|
291
|
+
columns = titles.map(item => {
|
|
292
|
+
return {
|
|
293
|
+
title: item,
|
|
294
|
+
key: item
|
|
295
|
+
}
|
|
296
|
+
})
|
|
297
|
+
tableData = array.map(item => {
|
|
298
|
+
let res = {}
|
|
299
|
+
item.forEach((col, i) => {
|
|
300
|
+
res[titles[i]] = col
|
|
301
|
+
})
|
|
302
|
+
return res
|
|
303
|
+
})
|
|
304
|
+
}
|
|
305
|
+
return {
|
|
306
|
+
columns,
|
|
307
|
+
tableData
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
export const findNodeUpper = (ele, tag) => {
|
|
312
|
+
if (ele.parentNode) {
|
|
313
|
+
if (ele.parentNode.tagName === tag.toUpperCase()) {
|
|
314
|
+
return ele.parentNode
|
|
315
|
+
} else {
|
|
316
|
+
return findNodeUpper(ele.parentNode, tag)
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
export const findNodeUpperByClasses = (ele, classes) => {
|
|
322
|
+
let parentNode = ele.parentNode
|
|
323
|
+
if (parentNode) {
|
|
324
|
+
let classList = parentNode.classList
|
|
325
|
+
if (classList && classes.every(className => classList.contains(className))) {
|
|
326
|
+
return parentNode
|
|
327
|
+
} else {
|
|
328
|
+
return findNodeUpperByClasses(parentNode, classes)
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
export const findNodeDownward = (ele, tag) => {
|
|
334
|
+
const tagName = tag.toUpperCase()
|
|
335
|
+
if (ele.childNodes.length) {
|
|
336
|
+
let i = -1
|
|
337
|
+
let len = ele.childNodes.length
|
|
338
|
+
while (++i < len) {
|
|
339
|
+
let child = ele.childNodes[i]
|
|
340
|
+
if (child.tagName === tagName) return child
|
|
341
|
+
else return findNodeDownward(child, tag)
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
export const showByAccess = (access, canViewAccess) => {
|
|
347
|
+
return hasOneOf(canViewAccess, access)
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* @description 根据name/params/query判断两个路由对象是否相等
|
|
352
|
+
* @param {*} route1 路由对象
|
|
353
|
+
* @param {*} route2 路由对象
|
|
354
|
+
*/
|
|
355
|
+
export const routeEqual = (route1, route2) => {
|
|
356
|
+
const params1 = route1.params || {}
|
|
357
|
+
const params2 = route2.params || {}
|
|
358
|
+
const query1 = route1.query || {}
|
|
359
|
+
const query2 = route2.query || {}
|
|
360
|
+
return (route1.name === route2.name) //&& objEqual(params1, params2) && objEqual(query1, query2)
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* 判断打开的标签列表里是否已存在这个新添加的路由对象
|
|
365
|
+
*/
|
|
366
|
+
export const routeHasExist = (tagNavList, routeItem) => {
|
|
367
|
+
let len = tagNavList.length
|
|
368
|
+
let res = false
|
|
369
|
+
doCustomTimes(len, (index) => {
|
|
370
|
+
if (routeEqual(tagNavList[index], routeItem)) res = true
|
|
371
|
+
})
|
|
372
|
+
return res
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
// scrollTop animation
|
|
376
|
+
export const scrollTop = (el, from = 0, to, duration = 500, endCallback) => {
|
|
377
|
+
if (!window.requestAnimationFrame) {
|
|
378
|
+
window.requestAnimationFrame = (
|
|
379
|
+
window.webkitRequestAnimationFrame ||
|
|
380
|
+
window.mozRequestAnimationFrame ||
|
|
381
|
+
window.msRequestAnimationFrame ||
|
|
382
|
+
function (callback) {
|
|
383
|
+
return window.setTimeout(callback, 1000 / 60)
|
|
384
|
+
}
|
|
385
|
+
)
|
|
386
|
+
}
|
|
387
|
+
const difference = Math.abs(from - to)
|
|
388
|
+
const step = Math.ceil(difference / duration * 50)
|
|
389
|
+
|
|
390
|
+
const scroll = (start, end, step) => {
|
|
391
|
+
if (start === end) {
|
|
392
|
+
endCallback && endCallback()
|
|
393
|
+
return
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
let d = (start + step > end) ? end : start + step
|
|
397
|
+
if (start > end) {
|
|
398
|
+
d = (start - step < end) ? end : start - step
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
if (el === window) {
|
|
402
|
+
window.scrollTo(d, d)
|
|
403
|
+
} else {
|
|
404
|
+
el.scrollTop = d
|
|
405
|
+
}
|
|
406
|
+
window.requestAnimationFrame(() => scroll(d, end, step))
|
|
407
|
+
}
|
|
408
|
+
scroll(from, to, step)
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
/**
|
|
412
|
+
* @description 根据当前跳转的路由设置显示在浏览器标签的title
|
|
413
|
+
* @param {String} configTitle 配置标题
|
|
414
|
+
* @param {Object} routeItem 路由对象
|
|
415
|
+
* @param {Object} vm Vue实例
|
|
416
|
+
*/
|
|
417
|
+
export const setTitle = (configTitle,routeItem, vm) => {
|
|
418
|
+
const handledRoute = getRouteTitleHandled(routeItem)
|
|
419
|
+
const pageTitle = showTitle(handledRoute, vm)
|
|
420
|
+
const resTitle = pageTitle ? `${configTitle} - ${pageTitle}` : configTitle
|
|
421
|
+
window.document.title = resTitle
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
export const getUrlParams = () => {
|
|
425
|
+
const url = location.search; //获取url中"?"符后的字串
|
|
426
|
+
const theRequest = new Object();
|
|
427
|
+
if (url.indexOf("?") != -1) {
|
|
428
|
+
const str = url.substr(1);
|
|
429
|
+
let strs = str.split("&");
|
|
430
|
+
for (let i = 0; i < strs.length; i++) {
|
|
431
|
+
theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
return theRequest;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
|
|
438
|
+
export const getChangeTableDatas = (oldData, newData) => {
|
|
439
|
+
let list = []
|
|
440
|
+
for (let i = 0; i < newData.length; i++) {
|
|
441
|
+
if (oldData[i].checked != newData[i].checked) {
|
|
442
|
+
let tmpData = {
|
|
443
|
+
"id": newData[i].id,
|
|
444
|
+
"checked": newData[i].checked
|
|
445
|
+
}
|
|
446
|
+
if (newData[i].dpType) {
|
|
447
|
+
tmpData.dpType = newData[i].dpType
|
|
448
|
+
}
|
|
449
|
+
if (newData[i].employeeJobIdentityId) {
|
|
450
|
+
tmpData.employeeJobIdentityId = newData[i].employeeJobIdentityId
|
|
451
|
+
}
|
|
452
|
+
if (newData[i].userId) {
|
|
453
|
+
tmpData.userId = newData[i].userId
|
|
454
|
+
}
|
|
455
|
+
list.push(tmpData);
|
|
456
|
+
}
|
|
457
|
+
if (newData[i].children) {
|
|
458
|
+
list = list.concat(getChangeTableDatas(oldData[i].children, newData[i].children))
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
return list
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
/**
|
|
465
|
+
* @param {Array} arr1
|
|
466
|
+
* @param {Array} arr2
|
|
467
|
+
* @description 得到两个数组的交集, 两个数组的元素为数值或字符串
|
|
468
|
+
*/
|
|
469
|
+
export const getIntersection = (arr1, arr2) => {
|
|
470
|
+
let len = Math.min(arr1.length, arr2.length)
|
|
471
|
+
let i = -1
|
|
472
|
+
let res = []
|
|
473
|
+
while (++i < len) {
|
|
474
|
+
const item = arr2[i]
|
|
475
|
+
if (arr1.indexOf(item) > -1) res.push(item)
|
|
476
|
+
}
|
|
477
|
+
return res
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
/**
|
|
481
|
+
* @param {Array} arr1
|
|
482
|
+
* @param {Array} arr2
|
|
483
|
+
* @description 得到两个数组的并集, 两个数组的元素为数值或字符串
|
|
484
|
+
*/
|
|
485
|
+
export const getUnion = (arr1, arr2) => {
|
|
486
|
+
return Array.from(new Set([...arr1, ...arr2]))
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
/**
|
|
490
|
+
* @param {Array} target 目标数组
|
|
491
|
+
* @param {Array} arr 需要查询的数组
|
|
492
|
+
* @description 判断要查询的数组是否至少有一个元素包含在目标数组中
|
|
493
|
+
*/
|
|
494
|
+
const hasOneOf = (targetarr, arr) => {
|
|
495
|
+
return targetarr.some(_ => arr.indexOf(_) > -1)
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
const forEach = (arr, fn) => {
|
|
499
|
+
if (!arr.length || !fn) return
|
|
500
|
+
let i = -1
|
|
501
|
+
let len = arr.length
|
|
502
|
+
while (++i < len) {
|
|
503
|
+
let item = arr[i]
|
|
504
|
+
fn(item, i, arr)
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
/**
|
|
509
|
+
* @param {String|Number} value 要验证的字符串或数值
|
|
510
|
+
* @param {*} validList 用来验证的列表
|
|
511
|
+
*/
|
|
512
|
+
export function oneOf (value, validList) {
|
|
513
|
+
for (let i = 0; i < validList.length; i++) {
|
|
514
|
+
if (value === validList[i]) {
|
|
515
|
+
return true
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
return false
|
|
519
|
+
}
|
package/utils/theme.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import themes from "../config/themes";
|
|
2
|
+
const changeByThemeKey = (themeKey) => {
|
|
3
|
+
if (themeKey) {
|
|
4
|
+
themes.forEach((theme) => {
|
|
5
|
+
if (theme.key === themeKey) {
|
|
6
|
+
changeByTheme(theme);
|
|
7
|
+
localStorage.setItem("theme", themeKey);
|
|
8
|
+
}
|
|
9
|
+
});
|
|
10
|
+
} else {
|
|
11
|
+
themeKey = localStorage.getItem("theme");
|
|
12
|
+
if (!themeKey) {
|
|
13
|
+
themeKey = themes[0].key;
|
|
14
|
+
}
|
|
15
|
+
changeByThemeKey(themeKey);
|
|
16
|
+
}
|
|
17
|
+
return themeKey;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const changeByTheme = (theme) => {
|
|
21
|
+
// 加入自定义变量
|
|
22
|
+
let varStyleTag = document.getElementById("customVars");
|
|
23
|
+
if (!varStyleTag) {
|
|
24
|
+
varStyleTag = document.createElement("style");
|
|
25
|
+
varStyleTag.id = "customVars";
|
|
26
|
+
document.body.appendChild(varStyleTag);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
varStyleTag.innerHTML = `:root {${theme["vars"]}}`;
|
|
30
|
+
|
|
31
|
+
// 加入自定义样式
|
|
32
|
+
let styleTag = document.getElementById("customStyle");
|
|
33
|
+
if (!styleTag) {
|
|
34
|
+
styleTag = document.createElement("style");
|
|
35
|
+
styleTag.id = "customStyle";
|
|
36
|
+
document.body.appendChild(styleTag);
|
|
37
|
+
}
|
|
38
|
+
if (theme?.style) {
|
|
39
|
+
styleTag.innerHTML = theme.style;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export { changeByThemeKey, changeByTheme };
|
|
Binary file
|