@lambo-design/shared 1.0.0-beta.1 → 1.0.0-beta.11

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 CHANGED
@@ -6,6 +6,17 @@ let config = {
6
6
  ssoLoginUrl: "/wdk?action=access.login&method=logout",
7
7
  homeName: 'home',
8
8
  homePageUrl: '/home',
9
+ homeRouter: {
10
+ "name": 'home',
11
+ "params": {},
12
+ "query": {},
13
+ "meta": {
14
+ "hideInMenu": true,
15
+ "title": "首页",
16
+ "icon": "md-home",
17
+ "appId": "home"
18
+ }
19
+ },
9
20
  upmsServerContext: '/upms-server',
10
21
  ossServerContext: '/upms-server',
11
22
  didaHost: "/dida-runtime-micro",
package/package.json CHANGED
@@ -1,20 +1,21 @@
1
- {
2
- "name": "@lambo-design/shared",
3
- "version": "1.0.0-beta.1",
4
- "description": "",
5
- "main": "index.js",
6
- "scripts": {},
7
- "author": "lambo",
8
- "license": "ISC",
9
- "publishConfig": {
10
- "access": "public"
11
- },
12
- "dependencies": {
13
- "axios": "^0.24.0",
14
- "axios-cache-plugin": "^0.1.0",
15
- "qs": "^6.11.0",
16
- "xlsx": "file:vendor\\xlsx-0.19.1.tgz",
17
- "classnames": "^2.3.1",
18
- "xlsx-style": "^0.8.13"
19
- }
20
- }
1
+ {
2
+ "name": "@lambo-design/shared",
3
+ "version": "1.0.0-beta.11",
4
+ "description": "",
5
+ "main": "index.js",
6
+ "author": "lambo",
7
+ "license": "ISC",
8
+ "publishConfig": {
9
+ "access": "public",
10
+ "registry": "https://registry.npmjs.org/"
11
+ },
12
+ "dependencies": {
13
+ "axios": "^0.24.0",
14
+ "axios-cache-plugin": "^0.1.0",
15
+ "qs": "^6.11.0",
16
+ "xlsx": "http://10.110.34.38/package/cdn/xlsx-0.19.1.tgz",
17
+ "classnames": "^2.3.1",
18
+ "xlsx-style": "^0.8.13"
19
+ },
20
+ "scripts": {}
21
+ }
@@ -1,90 +1,90 @@
1
- import qs from 'qs'
2
- import cacheRules from "./cacheconf";
3
- import {getToken,getUrlParams} from '../platform'
4
- import Bus from '../bus';
5
-
6
-
7
- let timer1, timer2;
8
-
9
- function requestInterceptors(config) {
10
- const params = getUrlParams();
11
-
12
- let token = getToken();
13
- if (token) {
14
- config.headers.token = token;
15
- }
16
-
17
- //sso_token认证
18
- if (params.hasOwnProperty('sso_token')||sessionStorage.getItem('sso_token')) {
19
- config.params = Object.assign({
20
- sso_token: params.sso_token||sessionStorage.getItem('sso_token') ,
21
- sso_id: params.sso_id
22
- }, config.params)
23
- }
24
-
25
- //oauth认证
26
- if (params.hasOwnProperty('token')) {
27
- if (config.url.indexOf('?') === -1) {
28
- config.url = config.url + "?token=" + params.token + "&ssoid=" + params.ssoid;
29
- } else {
30
- config.url = config.url + "&token=" + params.token + "&ssoid=" + params.ssoid;
31
- }
32
- }
33
-
34
- if (config.method === 'post') {
35
- // payload为自定义不使用qs.stringify序列化的标记,默认config.payload == undefined;
36
- // 为true时用于匹配@requestBody定义参数的接口
37
- // 使用方式:post(config.AAAServerContext + '/AAA/BBB/CCC', { ...paramRequestBody }, { payload: true })
38
- if (!config.payload) {
39
- config.data = qs.stringify(config.data)
40
- }
41
- } else if (config.method === 'get') {
42
- for (let rule of cacheRules) {
43
- if (rule.test(config.url)) {
44
- return config;
45
- }
46
- }
47
- if (config.url.indexOf('?') === -1) {
48
- config.url = config.url + "?t=" + new Date().getTime();
49
- } else {
50
- config.url = config.url + "&t=" + new Date().getTime();
51
- }
52
- }
53
- return config;
54
- }
55
-
56
- function requestError(error) {
57
- console.error("服务器内部异常,请稍候再试",error);
58
- return Promise.reject(error);
59
- }
60
-
61
- function responseInterceptors(response) {
62
- const data = response.data;
63
- if (data instanceof Object) {
64
- const code = data["code"];
65
- if (code === 10106) {
66
- clearTimeout(timer1);
67
- timer1 = setTimeout(function () {
68
- if (confirm("会话已失效,是否重新登录")) {
69
- Bus.$emit("needLogin");
70
- }
71
- }, 500)
72
- }
73
- }
74
- return response;
75
- }
76
-
77
- function responseError(error) {
78
- clearTimeout(timer2);
79
- timer2 = setTimeout(function () {
80
- console.error("服务器内部异常,请稍候再试");
81
- }, 500)
82
- return Promise.reject(error);
83
- }
84
-
85
- export default {
86
- requestInterceptors,
87
- responseInterceptors,
88
- requestError,
89
- responseError
90
- }
1
+ import qs from 'qs'
2
+ import cacheRules from "./cacheconf";
3
+ import {getToken,getUrlParams} from '../platform'
4
+ import Bus from '../bus';
5
+
6
+
7
+ let timer1, timer2;
8
+
9
+ function requestInterceptors(config) {
10
+ const params = getUrlParams();
11
+
12
+ let token = getToken();
13
+ if (token) {
14
+ config.headers.token = token;
15
+ }
16
+
17
+ //sso_token认证
18
+ if (params.hasOwnProperty('sso_token')||sessionStorage.getItem('sso_token')) {
19
+ config.params = Object.assign({
20
+ sso_token: params.sso_token||sessionStorage.getItem('sso_token') ,
21
+ sso_id: params.sso_id
22
+ }, config.params)
23
+ }
24
+
25
+ //oauth认证
26
+ if (params.hasOwnProperty('token')) {
27
+ if (config.url.indexOf('?') === -1) {
28
+ config.url = config.url + "?token=" + params.token + "&ssoid=" + params.ssoid;
29
+ } else {
30
+ config.url = config.url + "&token=" + params.token + "&ssoid=" + params.ssoid;
31
+ }
32
+ }
33
+
34
+ if (config.method === 'post') {
35
+ // payload为自定义不使用qs.stringify序列化的标记,默认config.payload == undefined;
36
+ // 为true时用于匹配@requestBody定义参数的接口
37
+ // 使用方式:post(config.AAAServerContext + '/AAA/BBB/CCC', { ...paramRequestBody }, { payload: true })
38
+ if (!config.payload) {
39
+ config.data = qs.stringify(config.data)
40
+ }
41
+ } else if (config.method === 'get') {
42
+ for (let rule of cacheRules) {
43
+ if (rule.test(config.url)) {
44
+ return config;
45
+ }
46
+ }
47
+ if (config.url.indexOf('?') === -1) {
48
+ config.url = config.url + "?t=" + new Date().getTime();
49
+ } else {
50
+ config.url = config.url + "&t=" + new Date().getTime();
51
+ }
52
+ }
53
+ return config;
54
+ }
55
+
56
+ function requestError(error) {
57
+ console.error("服务器内部异常,请稍候再试",error);
58
+ return Promise.reject(error);
59
+ }
60
+
61
+ function responseInterceptors(response) {
62
+ const data = response.data;
63
+ if (data instanceof Object) {
64
+ const code = data["code"];
65
+ if (code === 10106) {
66
+ clearTimeout(timer1);
67
+ timer1 = setTimeout(function () {
68
+ if (confirm("会话已失效,是否重新登录")) {
69
+ Bus.$emit("needLogin");
70
+ }
71
+ }, 500)
72
+ }
73
+ }
74
+ return response;
75
+ }
76
+
77
+ function responseError(error) {
78
+ clearTimeout(timer2);
79
+ timer2 = setTimeout(function () {
80
+ console.error("服务器内部异常,请稍候再试");
81
+ }, 500)
82
+ return Promise.reject(error);
83
+ }
84
+
85
+ export default {
86
+ requestInterceptors,
87
+ responseInterceptors,
88
+ requestError,
89
+ responseError
90
+ }
@@ -0,0 +1,17 @@
1
+ import { Modal } from '@lambo-design/core'
2
+
3
+ const beforeClose = {
4
+ before_close_normal: (resolve) => {
5
+ Modal.confirm({
6
+ title: '确定要关闭这一页吗?',
7
+ onOk: () => {
8
+ resolve(true)
9
+ },
10
+ onCancel: () => {
11
+ resolve(false)
12
+ }
13
+ })
14
+ }
15
+ }
16
+
17
+ export default beforeClose
@@ -0,0 +1,124 @@
1
+ /**
2
+ * 判断是否存在路由
3
+ * @param $router
4
+ * @param name
5
+ * @returns {*|boolean}
6
+ */
7
+ export const hasRoute = ($router, name) => {
8
+ let routes = $router.getRoutes();
9
+ let res = routes.filter(item => item.name === name)
10
+ return res && res.length > 0
11
+ }
12
+ /**
13
+ * 动态生成菜单
14
+ * @param permissionList
15
+ * @returns []
16
+ */
17
+ export const generatorMenuList = (permissionList,appId) => {
18
+ let menuData = [],
19
+ pageNode = {
20
+ path: "/page",
21
+ name: "page",
22
+ meta: {
23
+ hideInMenu: true,
24
+ notCache: true
25
+ },
26
+ component: "Main",
27
+ children: []
28
+ };
29
+ listToMenuTree(permissionList, menuData, pageNode, "0", [], true,appId);
30
+
31
+ /*if (pageNode.children.length > 0) {
32
+ menuData.push(pageNode);
33
+ }*/
34
+ return menuData;
35
+ };
36
+
37
+
38
+
39
+ /**
40
+ * 数组转树形结构
41
+ */
42
+ const listToMenuTree = (list, menuTree, pageNode, parentId, crumbs, root, appId) => {
43
+ if (list == null) {
44
+ return;
45
+ }
46
+ list.forEach(item => {
47
+ if (item.appId == appId) {
48
+ // 判断是否为父级菜单
49
+ if (item.pid === parentId) {
50
+ if (item.type === 1 || item.type === 2) {
51
+ let node = {
52
+ meta: {
53
+ appId: item.appId,
54
+ title: item.label,
55
+ icon: item.icon,
56
+ crumbs: [...crumbs],
57
+ activeName: item.name
58
+ },
59
+ type: item.type,
60
+ pid: item.pid,
61
+ component: item.name,
62
+ name: item.name,
63
+ uri: item.uri,
64
+ children: []
65
+ };
66
+ node.meta.crumbs.push({
67
+ icon: item.icon,
68
+ name: item.name,
69
+ title: item.label,
70
+ type: item.type
71
+ });
72
+
73
+ if (item.type === 1) {
74
+ if (root) {
75
+ node.component = "Main";
76
+ } else {
77
+ node.component = "parentView";
78
+ }
79
+ }
80
+ // 迭代 list, 找到当前菜单相符合的所有子菜单
81
+ listToMenuTree(
82
+ list,
83
+ node.children,
84
+ pageNode,
85
+ item.permissionId,
86
+ node.meta.crumbs,
87
+ false,
88
+ appId
89
+ );
90
+ // 删掉不存在 children 值的属性
91
+ if (node.children.length <= 0) {
92
+ delete node.children;
93
+ }
94
+ // 加入到树中
95
+ menuTree.push(node);
96
+ }
97
+ if (item.type === 4) {
98
+ let child = {
99
+ meta: {
100
+ title: item.label,
101
+ hideInMenu: true,
102
+ notCache: true,
103
+ crumbs: [...crumbs],
104
+ type: item.type
105
+ },
106
+ type: item.type,
107
+ pid: item.pid,
108
+ component: item.name,
109
+ name: item.name,
110
+ uri: item.uri
111
+ };
112
+ child.meta.crumbs.push({
113
+ icon: item.icon,
114
+ name: item.name,
115
+ title: item.label,
116
+ type: item.type
117
+ });
118
+ pageNode.children.push(child);
119
+ }
120
+ }
121
+ }
122
+ });
123
+ };
124
+ export default generatorMenuList;
package/utils/platform.js CHANGED
@@ -152,14 +152,20 @@ export const showTitle = (item, vm) => {
152
152
  /**
153
153
  * @description 本地存储和获取标签导航列表
154
154
  */
155
- export const setTagNavListInLocalstorage = list => {
156
- localStorage.tagNaveList = JSON.stringify(list)
155
+ export const setTagNavListInLocalstorage = (list , key) => {
156
+ if (!key) {
157
+ key = 'LD-tagNavList';
158
+ }
159
+ localStorage[key] = JSON.stringify(list)
157
160
  }
158
161
  /**
159
162
  * @returns {Array} 其中的每个元素只包含路由原信息中的name, path, meta三项
160
163
  */
161
- export const getTagNavListFromLocalstorage = () => {
162
- const list = localStorage.tagNaveList
164
+ export const getTagNavListFromLocalstorage = (key) => {
165
+ if (!key) {
166
+ key = 'LD-tagNavList';
167
+ }
168
+ const list = localStorage[key]
163
169
  return list ? JSON.parse(list) : []
164
170
  }
165
171
 
@@ -265,7 +271,7 @@ export const getArrayFromFile = (file) => {
265
271
  reader.readAsText(file) // 以文本格式读取
266
272
  let arr = []
267
273
  reader.onload = function (evt) {
268
- let data = evt.target.result // 读到的数据
274
+ let data = evt.target.card // 读到的数据
269
275
  let pasteData = data.trim()
270
276
  arr = pasteData.split((/[\n\u0085\u2028\u2029]|\r\n?/g)).map(row => {
271
277
  return row.split('\t')
@@ -357,7 +363,7 @@ export const routeEqual = (route1, route2) => {
357
363
  const params2 = route2.params || {}
358
364
  const query1 = route1.query || {}
359
365
  const query2 = route2.query || {}
360
- return (route1.name === route2.name) //&& objEqual(params1, params2) && objEqual(query1, query2)
366
+ return (route1.name === route2.name) && objEqual(params1, params2) && objEqual(query1, query2)
361
367
  }
362
368
 
363
369
  /**
@@ -517,3 +523,48 @@ export function oneOf (value, validList) {
517
523
  }
518
524
  return false
519
525
  }
526
+
527
+ export const recursionKeyFindItem = (arr, filterKey, filterValue, recursionKey) => {
528
+ for (const item of arr) {
529
+ if (item[filterKey] && item[filterKey] == filterValue) {
530
+ return item;
531
+ }
532
+ let result = null;
533
+ if (item[recursionKey]) {
534
+ result = recursionKeyFindItem(item[recursionKey], filterKey, filterValue, recursionKey);
535
+ if (result) {
536
+ return result;
537
+ }
538
+ }
539
+ }
540
+ return null;
541
+ };
542
+
543
+ export const filterMenuName = (menuList, name) => {
544
+ return recursionKeyFindItem(menuList, 'name', name, 'children')
545
+ };
546
+
547
+ export const filterMenuUri = (menuList, name) => {
548
+ return recursionKeyFindItem(menuList, 'uri', name, 'children')
549
+ };
550
+
551
+ export const tagExists = (taglist, name) => {
552
+ return taglist && taglist.filter(item => item.name === name).length > 0;
553
+ };
554
+
555
+ export const getPreviousTagIndex = (tagList, name) => {
556
+ let count = 0;
557
+ if (tagList && name) {
558
+ for (let i = 0 ;i < tagList.length; i++) {
559
+ let item = tagList[i];
560
+ if (item.name == name) {
561
+ count = i - 1;
562
+ if (count < 0) {
563
+ count = 0;
564
+ }
565
+ return count;
566
+ }
567
+ }
568
+ }
569
+ return count;
570
+ }
package/utils/theme.js CHANGED
@@ -35,7 +35,7 @@ const changeByTheme = (theme) => {
35
35
  styleTag.id = "customStyle";
36
36
  document.body.appendChild(styleTag);
37
37
  }
38
- if (theme?.style) {
38
+ if (theme&&theme.style) {
39
39
  styleTag.innerHTML = theme.style;
40
40
  }
41
41
  };
@@ -0,0 +1,25 @@
1
+ export const setParentRefs = (parentVm, targetVm, refKey) => {
2
+ let hasFind = false;
3
+ if (parentVm.$refs) {
4
+ //遍历父组件的refs里注册的组件
5
+ Object.entries(parentVm.$refs).forEach(([parentKey, parentValue]) => {
6
+ //找到targetVm组件
7
+ if (parentValue === targetVm) {
8
+ hasFind = true;
9
+ //遍历targetVm组件上注册的refKey组件
10
+ Object.entries(targetVm.$refs[refKey]).forEach(([key, value])=>{
11
+ //找到refKey组件methods里面的function
12
+ if(key.charAt(0) !== '$'
13
+ && key.charAt(0) !== '_'
14
+ && typeof value == 'function'){
15
+ //将function添加到targetVm组件
16
+ parentVm.$refs[parentKey][key] = value
17
+ }
18
+ })
19
+ }
20
+ })
21
+ }
22
+ if (!hasFind && parentVm.$parent) {
23
+ setParentRefs(parentVm.$parent, targetVm, refKey)
24
+ }
25
+ }