@yy-common/shared 1.0.0-beta.6
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/.versionrc +23 -0
- package/CHANGELOG.md +42 -0
- package/api/dict.js +60 -0
- package/api/index.js +1 -0
- package/config/config.js +65 -0
- package/config/index.js +1 -0
- package/directive/directives.js +9 -0
- package/directive/index.js +26 -0
- package/directive/module/draggable.js +44 -0
- package/directive/module/permission.js +15 -0
- package/index.js +4 -0
- package/package.json +26 -0
- package/router/basic-routes.js +28 -0
- package/router/generator-routers.js +260 -0
- package/router/guard.js +283 -0
- package/router/index.js +9 -0
- package/utils/column-setting.js +72 -0
- package/utils/com.js +8 -0
- package/utils/dict-cache.js +11 -0
- package/utils/dynamicSetting.js +45 -0
- package/utils/enum.js +137 -0
- package/utils/errorLog.js +39 -0
- package/utils/excel.js +789 -0
- package/utils/index.js +26 -0
- package/utils/is-type.js +164 -0
- package/utils/item.js +14 -0
- package/utils/metric.js +135 -0
- package/utils/number.js +12 -0
- package/utils/request/axiosN.js +142 -0
- package/utils/request/content-type.js +19 -0
- package/utils/request/index.js +2 -0
- package/utils/request/interceptors.js +156 -0
- package/utils/request/url-params.js +12 -0
- package/utils/router.js +27 -0
- package/utils/storage.js +51 -0
- package/utils/table.js +348 -0
- package/utils/token.js +51 -0
- package/utils/tree.js +39 -0
- package/utils/user.js +8 -0
- package/utils/wps.js +16 -0
package/.versionrc
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"tagPrefix": "@yy-common/shared@",
|
|
3
|
+
"releaseCommitMessageFormat": "chore(release): @yy-common/shared@{{currentTag}}",
|
|
4
|
+
"path": ".",
|
|
5
|
+
"header": "# Changelog",
|
|
6
|
+
"types": [
|
|
7
|
+
{"type": "chore", "section":"'🎫 Chores | 其他更新", "hidden": false},
|
|
8
|
+
{"type": "revert", "section":"⏪ Reverts | 回退", "hidden": false},
|
|
9
|
+
{"type": "feat", "section": "✨ Features | 新功能", "hidden": false},
|
|
10
|
+
{"type": "fix", "section": "🐛 Bug Fixes | Bug 修复", "hidden": false},
|
|
11
|
+
{"type": "improvement", "section": "Feature Improvements", "hidden": false},
|
|
12
|
+
{"type": "docs", "section":"📝 Documentation | 文档", "hidden": false},
|
|
13
|
+
{"type": "style", "section":"💄 Styles | 风格", "hidden": false},
|
|
14
|
+
{"type": "refactor", "section":"💄 Styles | 风格", "hidden": false},
|
|
15
|
+
{"type": "perf", "section":"⚡ Performance Improvements | 性能优化", "hidden": false},
|
|
16
|
+
{"type": "test", "section":"✅ Tests | 测试", "hidden": false},
|
|
17
|
+
{"type": "build", "section":"👷 Build System | 构建", "hidden": false},
|
|
18
|
+
{"type": "ci", "section":"🔧 Continuous Integration | CI 配置", "hidden":false}
|
|
19
|
+
],
|
|
20
|
+
"commitUrlFormat": "http://git.inspur.com/ecbh/lambo-design/lambo-design/-/commit/{{hash}}",
|
|
21
|
+
"compareUrlFormat": "http://git.inspur.com/ecbh/lambo-design/lambo-design/-/compare/{{previousTag}}...{{currentTag}}",
|
|
22
|
+
"issueUrlFormat": "http://git.inspur.com/ecbh/lambo-design/lambo-design/-/issues/{{id}}"
|
|
23
|
+
}
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
## [1.0.0-beta.6](http://git.inspur.com/ecbh/lambo-design/lambo-design/-/compare/@gy-common/shared@1.0.0-beta.5...@gy-common/shared@1.0.0-beta.6) (2024-08-05)
|
|
3
|
+
|
|
4
|
+
## [1.0.0-beta.5](http://git.inspur.com/ecbh/lambo-design/lambo-design/-/compare/@gy-common/shared@1.0.0-beta.4...@gy-common/shared@1.0.0-beta.5) (2024-08-05)
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
### ✨ Features | 新功能
|
|
8
|
+
|
|
9
|
+
* 三棵树 ([866a9d0](http://git.inspur.com/ecbh/lambo-design/lambo-design/-/commit/866a9d07a8b622ee48515ce99b473fee919d13bd))
|
|
10
|
+
|
|
11
|
+
## [1.0.0-beta.4](http://git.inspur.com/ecbh/lambo-design/lambo-design/-/compare/@gy-common/shared@1.0.0-beta.3...@gy-common/shared@1.0.0-beta.4) (2024-06-29)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### ✨ Features | 新功能
|
|
15
|
+
|
|
16
|
+
* 迁移axios ([56cc2f6](http://git.inspur.com/ecbh/lambo-design/lambo-design/-/commit/56cc2f629a9d70bdfdf1788f8e923f66428e3650))
|
|
17
|
+
|
|
18
|
+
## [1.0.0-beta.3](http://git.inspur.com/ecbh/lambo-design/lambo-design/-/compare/@gy-common/shared@1.0.0-beta.2...@gy-common/shared@1.0.0-beta.3) (2024-06-20)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### 🐛 Bug Fixes | Bug 修复
|
|
22
|
+
|
|
23
|
+
* 部分项目引用方式修改 ([42641d6](http://git.inspur.com/ecbh/lambo-design/lambo-design/-/commit/42641d67db11af8a409f8225e3e95bb77071cb67))
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
### ✨ Features | 新功能
|
|
27
|
+
|
|
28
|
+
* 初始化 ([b58b88c](http://git.inspur.com/ecbh/lambo-design/lambo-design/-/commit/b58b88cf66a97dc5a1775ae358fa51d7b6d5390b))
|
|
29
|
+
* 删除?. ([17bc428](http://git.inspur.com/ecbh/lambo-design/lambo-design/-/commit/17bc428439b5c540ef47b34419b49b82d8328e37))
|
|
30
|
+
|
|
31
|
+
## 1.0.0-beta.2 (2024-06-19)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
### ✨ Features | 新功能
|
|
35
|
+
|
|
36
|
+
* **@gy-common/shared:** 新增shared文件 ([3745801](http://git.inspur.com/ecbh/lambo-design/lambo-design/-/commit/37458015b535580175b127b486e8cfbb0f0411c9))
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
### 🐛 Bug Fixes | Bug 修复
|
|
40
|
+
|
|
41
|
+
* **@gy-common/shared:** .versionrc文件修改 ([d35c8f7](http://git.inspur.com/ecbh/lambo-design/lambo-design/-/commit/d35c8f7c34a75800807991fa11283a12120f4c28))
|
|
42
|
+
* **@gy-common/shared:** api引用config相关修改 ([ab74960](http://git.inspur.com/ecbh/lambo-design/lambo-design/-/commit/ab749603bb7ba0a535976ded7434012946dc16ee))
|
package/api/dict.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { IS_OR_NOT_ENUM_KEY, IS_OR_NOT_ENUM_LIST } from '../utils/enum'
|
|
2
|
+
import { axios } from '../utils/request'
|
|
3
|
+
import { getDictCache, setDictCache } from '../utils/dict-cache'
|
|
4
|
+
import config from '@yy-common/shared/config/config'
|
|
5
|
+
|
|
6
|
+
const CONTEXT = config.authServerContext
|
|
7
|
+
|
|
8
|
+
export function getDictsMapApi(dictId) {
|
|
9
|
+
return axios.get(`${CONTEXT}/anon/dict/getDictsMap`, { params: { dictId } })
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export async function getDictApi(dictId) {
|
|
13
|
+
if (dictId === IS_OR_NOT_ENUM_KEY) {
|
|
14
|
+
return IS_OR_NOT_ENUM_LIST
|
|
15
|
+
}
|
|
16
|
+
const dictValue = getDictCache(dictId)
|
|
17
|
+
if (!!dictValue) {
|
|
18
|
+
return dictValue
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
try {
|
|
22
|
+
const { data } = await axios.get(`${CONTEXT}/dict/getDicts`, { params: { dictId } })
|
|
23
|
+
setDictCache(dictId, data)
|
|
24
|
+
return data
|
|
25
|
+
} catch (error) {
|
|
26
|
+
console.error(`getDict error dictId=${dictId}`, error)
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/*
|
|
31
|
+
入参:枚举ID数组,如['IMP_YES_NO', 'IMP_TRANS_TYPE']
|
|
32
|
+
输出:{
|
|
33
|
+
'IMP_YES_NO': {
|
|
34
|
+
data: {
|
|
35
|
+
'0': '否',
|
|
36
|
+
'1': '是'
|
|
37
|
+
},
|
|
38
|
+
renderData: [
|
|
39
|
+
{K: '1', V: '是'},
|
|
40
|
+
{K: '0', V: '否'},
|
|
41
|
+
]
|
|
42
|
+
},
|
|
43
|
+
...
|
|
44
|
+
}
|
|
45
|
+
*/
|
|
46
|
+
export async function getDictMapApi(dictIdArr) {
|
|
47
|
+
const resultMap = {}
|
|
48
|
+
const result = await Promise.all(dictIdArr.map((dictId) => getDictApi(dictId)))
|
|
49
|
+
dictIdArr.forEach((dictId, i) => {
|
|
50
|
+
if (result[i]) {
|
|
51
|
+
const resultValue = {}
|
|
52
|
+
result[i].forEach((item) => {
|
|
53
|
+
resultValue[item.K] = item.V
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
resultMap[dictId] = { data: resultValue, renderData: result[i] }
|
|
57
|
+
}
|
|
58
|
+
})
|
|
59
|
+
return resultMap
|
|
60
|
+
}
|
package/api/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './dict'
|
package/config/config.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
|
|
2
|
+
export default {
|
|
3
|
+
// 配置显示在浏览器标签的title
|
|
4
|
+
title: '',
|
|
5
|
+
// icomId
|
|
6
|
+
icomId: '',
|
|
7
|
+
// 是否展示菜单
|
|
8
|
+
showMenus: false,
|
|
9
|
+
// 路由base路径
|
|
10
|
+
routerBase: 'ind',
|
|
11
|
+
// 登录页的路由name
|
|
12
|
+
loginRouteName: 'login',
|
|
13
|
+
// 根路由name
|
|
14
|
+
rootRouteName: 'root',
|
|
15
|
+
// 首页的路由name
|
|
16
|
+
homeRouteName: 'home',
|
|
17
|
+
|
|
18
|
+
// 从云庭复制过来的配置 --------------------begin------------------------
|
|
19
|
+
//title: '云庭',
|
|
20
|
+
serverContext: '/ibp-sc',
|
|
21
|
+
loginName: 'login',
|
|
22
|
+
loginPagePath: '/login',
|
|
23
|
+
homeName: 'home',
|
|
24
|
+
|
|
25
|
+
//errorMessage: '数据请求出错,请稍后尝试',
|
|
26
|
+
LeftLockDays: 7,
|
|
27
|
+
themeColor: 'orange',
|
|
28
|
+
parentServerContext: '/ibp-sc',
|
|
29
|
+
parentLoginPath: '/login',
|
|
30
|
+
parentHomePath: '/home',
|
|
31
|
+
anonName: [
|
|
32
|
+
'404'
|
|
33
|
+
],
|
|
34
|
+
// 从云庭复制过来的配置 --------------------end------------------------
|
|
35
|
+
|
|
36
|
+
// auth-server 登录认证组件
|
|
37
|
+
authServerContext: '/user-manage-server',
|
|
38
|
+
upmsServerContext: '/user-manage-server',
|
|
39
|
+
// 文件上传组件
|
|
40
|
+
ossServerContext: '/ind-uc-ext-server',
|
|
41
|
+
|
|
42
|
+
// 数智烟叶服务列表 --- begin ----
|
|
43
|
+
crmServerContext: '/crm-server',
|
|
44
|
+
// 数智烟叶服务列表 --- end ----
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
// kkfilepreview 预览文件组件
|
|
48
|
+
kkfilepreviewContext: '/kkfilepreview',
|
|
49
|
+
// 错误文案
|
|
50
|
+
errorMessage: '系统开小差了,请稍后尝试',
|
|
51
|
+
// 用户即将过期提醒,用户距离过期天数小于等于leftLockDays提醒用户修改密码
|
|
52
|
+
leftLockDays: 7,
|
|
53
|
+
// 查询条件title所占宽度
|
|
54
|
+
labelStyle: {
|
|
55
|
+
labelWidthButton: 50 /* * ratio */,
|
|
56
|
+
labelWidth: 108 /* * ratio */,
|
|
57
|
+
labelWidthSmall: 100 + 40 /* * ratio */,
|
|
58
|
+
labelWidthMiddle: 120 + 40 /* * ratio */,
|
|
59
|
+
labelWidthMiddleLarge: 140 + 40 /* * ratio */,
|
|
60
|
+
labelWidthLarge: 160 + 40 /* * ratio */,
|
|
61
|
+
labelWidthSuperLarge: 180 + 40 /* * ratio */,
|
|
62
|
+
},
|
|
63
|
+
/** 点击跳转的文字颜色 */
|
|
64
|
+
linkColor: '#488AFF',
|
|
65
|
+
};
|
package/config/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as config } from './config'
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import directive from './directives'
|
|
2
|
+
|
|
3
|
+
const importDirective = (Vue) => {
|
|
4
|
+
/**
|
|
5
|
+
* 拖拽指令 v-draggable="options"
|
|
6
|
+
* options = {
|
|
7
|
+
* trigger: /这里传入作为拖拽触发器的CSS选择器/,
|
|
8
|
+
* body: /这里传入需要移动容器的CSS选择器/,
|
|
9
|
+
* recover: /拖动结束之后是否恢复到原来的位置/
|
|
10
|
+
* }
|
|
11
|
+
*/
|
|
12
|
+
Vue.directive('draggable', directive.draggable)
|
|
13
|
+
// /**
|
|
14
|
+
// * clipboard指令 v-draggable="options"
|
|
15
|
+
// * options = {
|
|
16
|
+
// * value: /在输入框中使用v-model绑定的值/,
|
|
17
|
+
// * success: /复制成功后的回调/,
|
|
18
|
+
// * error: /复制失败后的回调/
|
|
19
|
+
// * }
|
|
20
|
+
// */
|
|
21
|
+
// Vue.directive('clipboard', directive.clipboard)
|
|
22
|
+
|
|
23
|
+
Vue.directive('permission', directive.permission)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export default importDirective
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { on } from "@lambo-design/shared/utils/dom"
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
inserted: (el, binding, vnode) => {
|
|
5
|
+
console.log(el, vnode)
|
|
6
|
+
let triggerDom = document.querySelector(binding.value.trigger)
|
|
7
|
+
triggerDom.style.cursor = 'move'
|
|
8
|
+
let bodyDom = document.querySelector(binding.value.body)
|
|
9
|
+
let pageX = 0
|
|
10
|
+
let pageY = 0
|
|
11
|
+
let transformX = 0
|
|
12
|
+
let transformY = 0
|
|
13
|
+
let canMove = false
|
|
14
|
+
const handleMousedown = (e) => {
|
|
15
|
+
let transform = /\(.*\)/.exec(bodyDom.style.transform)
|
|
16
|
+
if (transform) {
|
|
17
|
+
transform = transform[0].slice(1, transform[0].length - 1)
|
|
18
|
+
let splitxy = transform.split('px, ')
|
|
19
|
+
transformX = parseFloat(splitxy[0])
|
|
20
|
+
transformY = parseFloat(splitxy[1].split('px')[0])
|
|
21
|
+
}
|
|
22
|
+
pageX = e.pageX
|
|
23
|
+
pageY = e.pageY
|
|
24
|
+
canMove = true
|
|
25
|
+
}
|
|
26
|
+
const handleMousemove = (e) => {
|
|
27
|
+
let xOffset = e.pageX - pageX + transformX
|
|
28
|
+
let yOffset = e.pageY - pageY + transformY
|
|
29
|
+
if (canMove) bodyDom.style.transform = `translate(${xOffset}px, ${yOffset}px)`
|
|
30
|
+
}
|
|
31
|
+
const handleMouseup = () => {
|
|
32
|
+
canMove = false
|
|
33
|
+
}
|
|
34
|
+
on(triggerDom, 'mousedown', handleMousedown)
|
|
35
|
+
on(document, 'mousemove', handleMousemove)
|
|
36
|
+
on(document, 'mouseup', handleMouseup)
|
|
37
|
+
},
|
|
38
|
+
update: (el, binding) => {
|
|
39
|
+
this.el = el
|
|
40
|
+
if (!binding.value.recover) return
|
|
41
|
+
let bodyDom = document.querySelector(binding.value.body)
|
|
42
|
+
bodyDom.style.transform = ''
|
|
43
|
+
},
|
|
44
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const checkPermission = function (el, binding, vnode) {
|
|
2
|
+
el.style.display = 'none'
|
|
3
|
+
const value = binding.value
|
|
4
|
+
let store = vnode.componentInstance.$store
|
|
5
|
+
const permission = store.state.app.permission
|
|
6
|
+
const have = permission[value]
|
|
7
|
+
if (have || value === 'all') {
|
|
8
|
+
el.style.display = ''
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export default {
|
|
13
|
+
bind: checkPermission,
|
|
14
|
+
update: checkPermission,
|
|
15
|
+
}
|
package/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@yy-common/shared",
|
|
3
|
+
"version": "1.0.0-beta.6",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"author": "lambo",
|
|
7
|
+
"license": "ISC",
|
|
8
|
+
"publishConfig": {
|
|
9
|
+
"access": "public",
|
|
10
|
+
"registry": "https://registry.npmjs.org/",
|
|
11
|
+
"files": [
|
|
12
|
+
"!**/.*",
|
|
13
|
+
"!**/CHANGELOG.md",
|
|
14
|
+
"**/*"
|
|
15
|
+
]
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"release-shared": "pnpm release-beta && git push --follow-tags && pnpm re-publish",
|
|
20
|
+
"release-major": "standard-version --release-as major",
|
|
21
|
+
"release-minor": "standard-version --release-as minor",
|
|
22
|
+
"release-patch": "standard-version --release-as patch",
|
|
23
|
+
"release-beta": "standard-version --prerelease beta",
|
|
24
|
+
"re-publish": "pnpm publish --access public --no-git-checks"
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { EmptyLayout, NotFound } from '../../components'
|
|
2
|
+
import config from '@yy-common/shared/config/config'
|
|
3
|
+
import _ from 'lodash'
|
|
4
|
+
|
|
5
|
+
const rootRoute = {
|
|
6
|
+
name: config.rootRouteName,
|
|
7
|
+
path: '/',
|
|
8
|
+
component: EmptyLayout,
|
|
9
|
+
meta: {},
|
|
10
|
+
children: [],
|
|
11
|
+
}
|
|
12
|
+
const notFoundRoute = {
|
|
13
|
+
path: '/404',
|
|
14
|
+
meta: {
|
|
15
|
+
hideInMenu: true,
|
|
16
|
+
},
|
|
17
|
+
component: NotFound,
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// 组织主应用的基础路由
|
|
21
|
+
export function createMacroBasicRoutes({ rootChildren } = {}) {
|
|
22
|
+
const rootRouteTemp = _.cloneDeep(rootRoute)
|
|
23
|
+
if (rootChildren && rootChildren.length) {
|
|
24
|
+
rootRouteTemp.children.push(...rootChildren)
|
|
25
|
+
}
|
|
26
|
+
let routesTmp = [rootRouteTemp, notFoundRoute]
|
|
27
|
+
return routesTmp
|
|
28
|
+
}
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import { EmptyLayout, NotFound } from '../../components'
|
|
2
|
+
import config from '@lambo-design/shared/config/config'
|
|
3
|
+
|
|
4
|
+
// 包装路由组件的类型枚举
|
|
5
|
+
export const constantRouterComponents = {
|
|
6
|
+
EmptyLayout: { component: EmptyLayout },
|
|
7
|
+
EmptyLayoutNotCache: { component: { ...EmptyLayout, name: 'IndEmptyLayoutNotCache' } },
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// 权限类型枚举
|
|
11
|
+
const PERMISSION_TYPE = {
|
|
12
|
+
DIRECTORY: 1,
|
|
13
|
+
MENU: 2,
|
|
14
|
+
BUTTON: 3,
|
|
15
|
+
PAGE: 4,
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// 是否是菜单要展示的类型
|
|
19
|
+
function isMenuPermissionType(type) {
|
|
20
|
+
return [PERMISSION_TYPE.DIRECTORY, PERMISSION_TYPE.MENU].includes(type)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function getPermissionType(type) {
|
|
24
|
+
return Object.keys(PERMISSION_TYPE).find((key) => PERMISSION_TYPE[key] === type)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function permission2Router(list, microType) {
|
|
28
|
+
if (!list) {
|
|
29
|
+
return []
|
|
30
|
+
}
|
|
31
|
+
let tempList = []
|
|
32
|
+
let routeNameKey = location.href.includes('imarket-analysis') ? 'name' : 'permissionValue'
|
|
33
|
+
for (const item of list) {
|
|
34
|
+
tempList.push({
|
|
35
|
+
path: dealRoutePath(item.uri, microType),
|
|
36
|
+
name: item[routeNameKey],
|
|
37
|
+
meta: {
|
|
38
|
+
appId: item.appId,
|
|
39
|
+
permissionId: item.permissionId,
|
|
40
|
+
title: item.label,
|
|
41
|
+
uri: item.uri,
|
|
42
|
+
icon: item.icon,
|
|
43
|
+
crumbs: [
|
|
44
|
+
{ icon: item.icon, name: item[routeNameKey], title: item.label, type: item.type },
|
|
45
|
+
],
|
|
46
|
+
activeName: item[routeNameKey],
|
|
47
|
+
data: item,
|
|
48
|
+
},
|
|
49
|
+
component: item[routeNameKey],
|
|
50
|
+
})
|
|
51
|
+
}
|
|
52
|
+
return tempList
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* 权限列表数据转树形结构
|
|
56
|
+
*
|
|
57
|
+
* @param {PermissionList2TreeOptions} params
|
|
58
|
+
* @param {Array} params.list 权限数据
|
|
59
|
+
* @param {Array} params.menuTree 菜单类权限树形结构
|
|
60
|
+
* @param {Array} params.pageNode 页面类权限,children里添加页面节点
|
|
61
|
+
* @param {string} params.parentId 父节点Id
|
|
62
|
+
* @param {Array} params.crumbs 从根节点到本节点的路径
|
|
63
|
+
* @param {boolean} params.root 是否是根节点
|
|
64
|
+
*/
|
|
65
|
+
function listToMenuTree({ list, menuTree, pageNode, parentId, crumbs, root }) {
|
|
66
|
+
if (!list) return
|
|
67
|
+
|
|
68
|
+
list.forEach((item) => {
|
|
69
|
+
const { permissionId, label: title, appId, pid, icon, type, uri, permissionValue, name } = item
|
|
70
|
+
// ! user-manage-server permissionValue 才是编码
|
|
71
|
+
// const name = permissionValue
|
|
72
|
+
// 判断是否为该父级节点的子节点
|
|
73
|
+
if (pid === parentId) {
|
|
74
|
+
if (isMenuPermissionType(type)) {
|
|
75
|
+
let node = {
|
|
76
|
+
type,
|
|
77
|
+
name,
|
|
78
|
+
pid,
|
|
79
|
+
path: dealRoutePath(uri),
|
|
80
|
+
uri,
|
|
81
|
+
component: name,
|
|
82
|
+
meta: {
|
|
83
|
+
appId,
|
|
84
|
+
permissionId,
|
|
85
|
+
title,
|
|
86
|
+
icon,
|
|
87
|
+
crumbs: [...crumbs],
|
|
88
|
+
activeName: name,
|
|
89
|
+
data: item,
|
|
90
|
+
},
|
|
91
|
+
children: [],
|
|
92
|
+
}
|
|
93
|
+
node.meta.crumbs.push({ icon, name, title, type })
|
|
94
|
+
|
|
95
|
+
if (PERMISSION_TYPE.DIRECTORY === type) {
|
|
96
|
+
node.component = 'EmptyLayout'
|
|
97
|
+
}
|
|
98
|
+
// 迭代 list, 找到当前菜单相符合的所有子菜单
|
|
99
|
+
listToMenuTree({
|
|
100
|
+
list,
|
|
101
|
+
menuTree: node.children,
|
|
102
|
+
pageNode,
|
|
103
|
+
parentId: permissionId,
|
|
104
|
+
crumbs: node.meta.crumbs,
|
|
105
|
+
root: false,
|
|
106
|
+
})
|
|
107
|
+
// 删掉不存在 children 值的属性
|
|
108
|
+
if (!node.children.length) {
|
|
109
|
+
delete node.children
|
|
110
|
+
}
|
|
111
|
+
// 加入到树中
|
|
112
|
+
menuTree.push(node)
|
|
113
|
+
}
|
|
114
|
+
if (PERMISSION_TYPE.PAGE === type) {
|
|
115
|
+
let child = {
|
|
116
|
+
type,
|
|
117
|
+
name,
|
|
118
|
+
pid,
|
|
119
|
+
path: dealRoutePath(uri),
|
|
120
|
+
uri,
|
|
121
|
+
component: name,
|
|
122
|
+
meta: {
|
|
123
|
+
appId,
|
|
124
|
+
permissionId,
|
|
125
|
+
title,
|
|
126
|
+
hideInMenu: true,
|
|
127
|
+
notCache: true,
|
|
128
|
+
crumbs: [...crumbs],
|
|
129
|
+
type,
|
|
130
|
+
data: item,
|
|
131
|
+
},
|
|
132
|
+
}
|
|
133
|
+
child.meta.crumbs.push({ icon, name, title, type })
|
|
134
|
+
pageNode.children.push(child)
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
})
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// 处理路由的path
|
|
141
|
+
function dealRoutePath(uri) {
|
|
142
|
+
if (!uri) return ''
|
|
143
|
+
if (!uri.startsWith('/')) {
|
|
144
|
+
uri = `/${uri}`
|
|
145
|
+
}
|
|
146
|
+
// 不要参数部分
|
|
147
|
+
if (uri.includes('?')) {
|
|
148
|
+
uri = uri.split('?')[0]
|
|
149
|
+
}
|
|
150
|
+
// 不要后缀部分
|
|
151
|
+
if (uri.includes('.')) {
|
|
152
|
+
uri = uri.split('.')[0]
|
|
153
|
+
}
|
|
154
|
+
if (uri.startsWith('/' + config.routerBase)) {
|
|
155
|
+
uri = uri.replace('/' + config.routerBase, '')
|
|
156
|
+
}
|
|
157
|
+
return uri
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* 根据所有的权限组织菜单
|
|
162
|
+
*
|
|
163
|
+
* @param {Array} permissionList 权限数据
|
|
164
|
+
* @returns 菜单
|
|
165
|
+
*/
|
|
166
|
+
export function generatorMenuTree(permissionList = []) {
|
|
167
|
+
permissionList = permissionList.filter((item) => isMenuPermissionType(item.type))
|
|
168
|
+
const menuTree = []
|
|
169
|
+
|
|
170
|
+
listToMenuTree({
|
|
171
|
+
list: permissionList,
|
|
172
|
+
menuTree,
|
|
173
|
+
pageNode: { children: [] },
|
|
174
|
+
parentId: '0',
|
|
175
|
+
crumbs: [],
|
|
176
|
+
root: true,
|
|
177
|
+
})
|
|
178
|
+
|
|
179
|
+
return menuTree
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* 根据权限数据生成动态的树形路由表
|
|
184
|
+
*
|
|
185
|
+
* @param {Array} permissionList 权限数据
|
|
186
|
+
* @returns 路由表
|
|
187
|
+
*/
|
|
188
|
+
export function generatorDynamicRouter(permissionList = []) {
|
|
189
|
+
// 菜单的树形结构
|
|
190
|
+
const menuTree = []
|
|
191
|
+
// 所有的页面都包装在同一个组件里
|
|
192
|
+
const pageNode = {
|
|
193
|
+
path: '/page',
|
|
194
|
+
name: 'page',
|
|
195
|
+
meta: { hideInMenu: true, notCache: true },
|
|
196
|
+
component: 'EmptyLayoutNotCache',
|
|
197
|
+
children: [],
|
|
198
|
+
}
|
|
199
|
+
// 转树形结构
|
|
200
|
+
listToMenuTree({
|
|
201
|
+
list: permissionList,
|
|
202
|
+
menuTree,
|
|
203
|
+
pageNode,
|
|
204
|
+
parentId: '0', // 根节点Id固定为0
|
|
205
|
+
crumbs: [],
|
|
206
|
+
root: true,
|
|
207
|
+
})
|
|
208
|
+
|
|
209
|
+
if (pageNode.children.length) {
|
|
210
|
+
menuTree.push(pageNode)
|
|
211
|
+
}
|
|
212
|
+
return generator(menuTree)
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* 生成 vue-router 层级路由表
|
|
217
|
+
*
|
|
218
|
+
* @param {Array} menuData 权限的树形结构数据
|
|
219
|
+
* @returns 路由表
|
|
220
|
+
*/
|
|
221
|
+
export function generator(menuData = []) {
|
|
222
|
+
for (let item of menuData) {
|
|
223
|
+
if (item.component) {
|
|
224
|
+
const target = constantRouterComponents[item.component]
|
|
225
|
+
if (target) {
|
|
226
|
+
item.component = target.component
|
|
227
|
+
} else if (item.path) {
|
|
228
|
+
if (window.loadComponentHandler) {
|
|
229
|
+
item.component = window.loadComponentHandler(item.path, item.name) || NotFound
|
|
230
|
+
}
|
|
231
|
+
} else {
|
|
232
|
+
// 打这个日志其实没啥意义,找不到就找不到了
|
|
233
|
+
// console.error(`找不到组件定义:${item.component},请排查资源路径配置是否正确`)
|
|
234
|
+
item.component = NotFound
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
if (item.children && item.children.length > 0) {
|
|
238
|
+
generator(item.children)
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
return menuData
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* 生成 vue-router 层级路由表
|
|
247
|
+
*
|
|
248
|
+
* @param {Array} menuData 权限的树形结构数据
|
|
249
|
+
* @returns 路由表
|
|
250
|
+
*/
|
|
251
|
+
export function generatorRouteByPermission(item) {
|
|
252
|
+
if (window.loadComponentHandler) {
|
|
253
|
+
item.component = window.loadComponentHandler(item.path, item.name) || NotFound
|
|
254
|
+
} else {
|
|
255
|
+
console.error(`找不到组件定义:${item.component},请排查资源路径配置是否正确`)
|
|
256
|
+
item.component = NotFound
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
return item
|
|
260
|
+
}
|