imatrix-ui 0.2.3-up → 0.2.5-up

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/src/permission.js CHANGED
@@ -1,160 +1,160 @@
1
- import NProgress from 'nprogress' // Progress 进度条
2
- import 'nprogress/nprogress.css' // Progress 进度条样式
3
- import { getToken, setToken } from './utils/auth' // 验权
4
- import store from './store'
5
- import router, { errorRouterMap } from './router'
6
- NProgress.configure({ showSpinner: false }) // NProgress Configuration
7
- import { ElMessage as Message } from 'element-plus'
8
- import * as Vue from 'vue'
9
-
10
- const whiteList = [
11
- '/login',
12
- '/update-password',
13
- '/forget-password',
14
- '/reset-password',
15
- '/redirect',
16
- ] // 不重定向白名单
17
- router.beforeEach((to, from, next) => {
18
- NProgress.start()
19
- console.log('router.beforeEach-to=', to)
20
- console.log('router.beforeEach-from=', from)
21
- // console.log('router.beforeEach-to.path=', to.path)
22
- let token = getToken()
23
- // console.log('router.beforeEach-to.query.JWT=', to.query.JWT)
24
- if (!token && to.query && to.query.JWT) {
25
- token = to.query.JWT
26
- if (token) {
27
- // 微信小程序web-view直接访问路径时使用?将JWT传过来
28
- setToken(token)
29
- }
30
- }
31
- if (!token && to.query && to.query.jwt) {
32
- token = to.query.jwt
33
- if (token) {
34
- // 微信小程序web-view直接访问路径时使用?将JWT传过来
35
- setToken(token)
36
- }
37
- }
38
- if (to.query && to.query._systemName_) {
39
- // 表示需要设置浏览器页签名
40
- window.top.document.title = to.query._systemName_
41
- }
42
- // console.log('router.beforeEach-getToken()=', token)
43
- if (
44
- ([
45
- '/update-password',
46
- '/forget-password',
47
- '/reset-password',
48
- '/redirect',
49
- ].indexOf(to.path) === -1 ||
50
- store.getters.whiteList.indexOf(to.path) !== -1) &&
51
- token
52
- ) {
53
- if (to.path === '/login') {
54
- next({ path: '/', query: to.query })
55
- NProgress.done() // if current page is dashboard will not trigger afterEach hook, so manually handle it
56
- } else {
57
- console.log('router.beforeEach-to.path!=login')
58
- if (store.getters.name === '') {
59
- // 表示刷新了页面(例如点击了一级菜单)后,会重新走该方法
60
- console.log('router.beforeEach-store.getters.name === ""')
61
- store
62
- .dispatch('isLoginTimeOut')
63
- .then((result) => {
64
- if (result === true) {
65
- store.dispatch('clearToken').then(() => {
66
- next({ path: '/', replace: true })
67
- NProgress.done()
68
- })
69
- } else {
70
- store
71
- .dispatch('getCurrentUser')
72
- .then((user) => {
73
- console.log('router.beforeEach-getCurrentUser')
74
- return store.dispatch(
75
- 'getCurrentUserPermissions',
76
- user.loginName
77
- )
78
- })
79
- .then((permissions) => {
80
- console.log(
81
- 'router.beforeEach-getCurrentUserPermissions-result=='
82
- )
83
- return store.dispatch('generateRoutes', permissions)
84
- })
85
- .then(() => {
86
- console.log('iMatrix-router.beforeEach2-getPermissionMenus')
87
- return store.dispatch(
88
- 'getPermissionMenus',
89
- window.$vueApp.config.globalProperties.currentSystem
90
- )
91
- })
92
- .then(() => {
93
- // 根据roles权限生成可访问的路由表
94
- console.log(
95
- 'router.beforeEach-generateRoutes==to=',
96
- to,
97
- ',from=',
98
- from
99
- )
100
- store.getters.protectedRouters.forEach(item =>{
101
- router.addRoute(item)
102
- })
103
- console.log('%c描述-170412','color:#2E3435;background:#F8BB07;padding:3px;border-radius:2px',router.options.routes);
104
- // 404等错误路由一定要放到受权限保护的路由之后
105
- // router.addRoutes(errorRouterMap)
106
- window.sessionStorage.setItem(
107
- new Date().getTime() + '-name=null-from~~toPath',
108
- from.path + '~~' + to.path
109
- )
110
- console.log(
111
- 'router.beforeEach-generateRoutes==to.path=',
112
- to.path
113
- )
114
- next({ ...to, replace: true })
115
- })
116
- .catch((err) => {
117
- store.dispatch('clearToken').then(() => {
118
- Message.error(
119
- err || 'Verification failed, please login again'
120
- )
121
- next({ path: '/' })
122
- })
123
- })
124
- }
125
- })
126
- .catch((err) => {
127
- store.dispatch('clearToken').then(() => {
128
- Message.error(err || 'Verification failed, please login again')
129
- next({ path: '/' })
130
- })
131
- })
132
- } else {
133
- window.sessionStorage.setItem(
134
- new Date().getTime() + '-name!==null-from~~toPath',
135
- from.path + '~~' + to.path
136
- )
137
- console.log(
138
- 'router.beforeEach-store.getters.name ==',
139
- store.getters.name
140
- )
141
- next()
142
- }
143
- }
144
- } else {
145
- if (
146
- whiteList.indexOf(to.path) !== -1 ||
147
- store.getters.whiteList.indexOf(to.path) !== -1
148
- ) {
149
- next()
150
- } else {
151
- // 必须使用to.fullPath,fullPath是带有参数的,to.path没有参数,会导致跳转到的页面参数丢失
152
- next(`/login?redirect=${to.fullPath}`) // 否则全部重定向到登录页
153
- NProgress.done()
154
- }
155
- }
156
- })
157
-
158
- router.afterEach(() => {
159
- NProgress.done() // 结束Progress
160
- })
1
+ import NProgress from 'nprogress' // Progress 进度条
2
+ import 'nprogress/nprogress.css' // Progress 进度条样式
3
+ import { getToken, setToken } from './utils/auth' // 验权
4
+ import store from './store'
5
+ import router, { errorRouterMap } from './router'
6
+ NProgress.configure({ showSpinner: false }) // NProgress Configuration
7
+ import { ElMessage as Message } from 'element-plus'
8
+ import * as Vue from 'vue'
9
+
10
+ const whiteList = [
11
+ '/login',
12
+ '/update-password',
13
+ '/forget-password',
14
+ '/reset-password',
15
+ '/redirect',
16
+ ] // 不重定向白名单
17
+ router.beforeEach((to, from, next) => {
18
+ NProgress.start()
19
+ console.log('router.beforeEach-to=', to)
20
+ console.log('router.beforeEach-from=', from)
21
+ // console.log('router.beforeEach-to.path=', to.path)
22
+ let token = getToken()
23
+ // console.log('router.beforeEach-to.query.JWT=', to.query.JWT)
24
+ if (!token && to.query && to.query.JWT) {
25
+ token = to.query.JWT
26
+ if (token) {
27
+ // 微信小程序web-view直接访问路径时使用?将JWT传过来
28
+ setToken(token)
29
+ }
30
+ }
31
+ if (!token && to.query && to.query.jwt) {
32
+ token = to.query.jwt
33
+ if (token) {
34
+ // 微信小程序web-view直接访问路径时使用?将JWT传过来
35
+ setToken(token)
36
+ }
37
+ }
38
+ if (to.query && to.query._systemName_) {
39
+ // 表示需要设置浏览器页签名
40
+ window.top.document.title = to.query._systemName_
41
+ }
42
+ // console.log('router.beforeEach-getToken()=', token)
43
+ if (
44
+ ([
45
+ '/update-password',
46
+ '/forget-password',
47
+ '/reset-password',
48
+ '/redirect',
49
+ ].indexOf(to.path) === -1 ||
50
+ store.getters.whiteList.indexOf(to.path) !== -1) &&
51
+ token
52
+ ) {
53
+ if (to.path === '/login') {
54
+ next({ path: '/', query: to.query })
55
+ NProgress.done() // if current page is dashboard will not trigger afterEach hook, so manually handle it
56
+ } else {
57
+ console.log('router.beforeEach-to.path!=login')
58
+ if (store.getters.name === '') {
59
+ // 表示刷新了页面(例如点击了一级菜单)后,会重新走该方法
60
+ console.log('router.beforeEach-store.getters.name === ""')
61
+ store
62
+ .dispatch('isLoginTimeOut')
63
+ .then((result) => {
64
+ if (result === true) {
65
+ store.dispatch('clearToken').then(() => {
66
+ next({ path: '/', replace: true })
67
+ NProgress.done()
68
+ })
69
+ } else {
70
+ store
71
+ .dispatch('getCurrentUser')
72
+ .then((user) => {
73
+ console.log('router.beforeEach-getCurrentUser')
74
+ return store.dispatch(
75
+ 'getCurrentUserPermissions',
76
+ user.loginName
77
+ )
78
+ })
79
+ .then((permissions) => {
80
+ console.log(
81
+ 'router.beforeEach-getCurrentUserPermissions-result=='
82
+ )
83
+ return store.dispatch('generateRoutes', permissions)
84
+ })
85
+ .then(() => {
86
+ console.log('iMatrix-router.beforeEach2-getPermissionMenus')
87
+ return store.dispatch(
88
+ 'getPermissionMenus',
89
+ window.$vueApp.config.globalProperties.currentSystem
90
+ )
91
+ })
92
+ .then(() => {
93
+ // 根据roles权限生成可访问的路由表
94
+ console.log(
95
+ 'router.beforeEach-generateRoutes==to=',
96
+ to,
97
+ ',from=',
98
+ from
99
+ )
100
+ store.getters.protectedRouters.forEach(item =>{
101
+ router.addRoute(item)
102
+ })
103
+ console.log('%c描述-170412','color:#2E3435;background:#F8BB07;padding:3px;border-radius:2px',router.options.routes);
104
+ // 404等错误路由一定要放到受权限保护的路由之后
105
+ // router.addRoutes(errorRouterMap)
106
+ window.sessionStorage.setItem(
107
+ new Date().getTime() + '-name=null-from~~toPath',
108
+ from.path + '~~' + to.path
109
+ )
110
+ console.log(
111
+ 'router.beforeEach-generateRoutes==to.path=',
112
+ to.path
113
+ )
114
+ next({ ...to, replace: true })
115
+ })
116
+ .catch((err) => {
117
+ store.dispatch('clearToken').then(() => {
118
+ Message.error(
119
+ err || 'Verification failed, please login again'
120
+ )
121
+ next({ path: '/' })
122
+ })
123
+ })
124
+ }
125
+ })
126
+ .catch((err) => {
127
+ store.dispatch('clearToken').then(() => {
128
+ Message.error(err || 'Verification failed, please login again')
129
+ next({ path: '/' })
130
+ })
131
+ })
132
+ } else {
133
+ window.sessionStorage.setItem(
134
+ new Date().getTime() + '-name!==null-from~~toPath',
135
+ from.path + '~~' + to.path
136
+ )
137
+ console.log(
138
+ 'router.beforeEach-store.getters.name ==',
139
+ store.getters.name
140
+ )
141
+ next()
142
+ }
143
+ }
144
+ } else {
145
+ if (
146
+ whiteList.indexOf(to.path) !== -1 ||
147
+ store.getters.whiteList.indexOf(to.path) !== -1
148
+ ) {
149
+ next()
150
+ } else {
151
+ // 必须使用to.fullPath,fullPath是带有参数的,to.path没有参数,会导致跳转到的页面参数丢失
152
+ next(`/login?redirect=${to.fullPath}`) // 否则全部重定向到登录页
153
+ NProgress.done()
154
+ }
155
+ }
156
+ })
157
+
158
+ router.afterEach(() => {
159
+ NProgress.done() // 结束Progress
160
+ })
@@ -1,110 +1,110 @@
1
- import * as Vue from 'vue'
2
- import * as VueRouter from 'vue-router'
3
-
4
- /* Layout */
5
- import Layout from '../views/layout/NewLayout.vue'
6
-
7
- /**
8
- * hidden: true if `hidden:true` will not show in the sidebar(default is false)
9
- * alwaysShow: true if set true, will always show the root menu, whatever its child routes length
10
- * if not set alwaysShow, only more than one route under the children
11
- * it will becomes nested mode, otherwise not show the root menu
12
- * redirect: noredirect if `redirect:noredirect` will no redirect in the breadcrumb
13
- * name:'router-name' the name is used by <keep-alive> (must set!!!)
14
- * meta : {
15
- title: 'title' the name show in submenu and breadcrumb (recommend set)
16
- icon: 'svg-name' the icon show in the sidebar,
17
- }
18
- **/
19
- export const publicRouterMap = [
20
- {
21
- path: '/redirect',
22
- component: Layout,
23
- hidden: true,
24
- children: [
25
- {
26
- path: '/redirect/:path*',
27
- component: Vue.defineAsyncComponent(
28
- () => import('../views/redirect/index.vue')
29
- ),
30
- },
31
- ],
32
- },
33
- {
34
- path: '/iframe-page',
35
- component: Layout,
36
- hidden: true,
37
- children: [
38
- {
39
- path: 'page',
40
- component: Vue.defineAsyncComponent(
41
- () => import('../views/layout/components/iframe-page.vue')
42
- ),
43
- hidden: true,
44
- },
45
- ],
46
- },
47
- // {
48
- // path: '/login',
49
- // component: () => import('../views/login/index'),
50
- // hidden: true
51
- // },
52
- {
53
- path: '/auth-redirect',
54
- component: Vue.defineAsyncComponent(
55
- () => import('../views/login/authredirect.vue')
56
- ),
57
- hidden: true,
58
- },
59
- {
60
- path: '/404',
61
- component: Vue.defineAsyncComponent(
62
- () => import('../views/error-page/404.vue')
63
- ),
64
- hidden: true,
65
- },
66
- {
67
- path: '/401',
68
- component: Vue.defineAsyncComponent(
69
- () => import('../views/error-page/401.vue')
70
- ),
71
- hidden: true,
72
- },
73
- {
74
- path: '/show-sub-wf-history',
75
- component: Vue.defineAsyncComponent(
76
- () => import('../views/wf-history/tache-subprocess-history.vue')
77
- ),
78
- hidden: true,
79
- },
80
- {
81
- path: '/tab-content-index',
82
- component: Vue.defineAsyncComponent(
83
- () => import('../views/layout/tab-content-index.vue')
84
- ),
85
- hidden: true,
86
- },
87
- {
88
- path: '/tab-content-iframe-index',
89
- component: Vue.defineAsyncComponent(
90
- Vue.defineAsyncComponent(
91
- () => import('../views/layout/tab-content-iframe-index.vue')
92
- )
93
- ),
94
- hidden: true,
95
- },
96
- ]
97
- export const protectedRouterMap = []
98
- export const errorRouterMap = [
99
- // 404的映射必须是最后一个
100
- { path: '*', redirect: '/404', hidden: true },
101
- ]
102
-
103
-
104
- export default VueRouter.createRouter({
105
- history: VueRouter.createWebHashHistory(),
106
- routes: publicRouterMap,
107
- scrollBehavior: () => ({
108
- top: 0,
109
- }),
110
- })
1
+ import * as Vue from 'vue'
2
+ import * as VueRouter from 'vue-router'
3
+
4
+ /* Layout */
5
+ import Layout from '../views/layout/NewLayout.vue'
6
+
7
+ /**
8
+ * hidden: true if `hidden:true` will not show in the sidebar(default is false)
9
+ * alwaysShow: true if set true, will always show the root menu, whatever its child routes length
10
+ * if not set alwaysShow, only more than one route under the children
11
+ * it will becomes nested mode, otherwise not show the root menu
12
+ * redirect: noredirect if `redirect:noredirect` will no redirect in the breadcrumb
13
+ * name:'router-name' the name is used by <keep-alive> (must set!!!)
14
+ * meta : {
15
+ title: 'title' the name show in submenu and breadcrumb (recommend set)
16
+ icon: 'svg-name' the icon show in the sidebar,
17
+ }
18
+ **/
19
+ export const publicRouterMap = [
20
+ {
21
+ path: '/redirect',
22
+ component: Layout,
23
+ hidden: true,
24
+ children: [
25
+ {
26
+ path: '/redirect/:path*',
27
+ component: Vue.defineAsyncComponent(
28
+ () => import('../views/redirect/index.vue')
29
+ ),
30
+ },
31
+ ],
32
+ },
33
+ {
34
+ path: '/iframe-page',
35
+ component: Layout,
36
+ hidden: true,
37
+ children: [
38
+ {
39
+ path: 'page',
40
+ component: Vue.defineAsyncComponent(
41
+ () => import('../views/layout/components/iframe-page.vue')
42
+ ),
43
+ hidden: true,
44
+ },
45
+ ],
46
+ },
47
+ // {
48
+ // path: '/login',
49
+ // component: () => import('../views/login/index'),
50
+ // hidden: true
51
+ // },
52
+ {
53
+ path: '/auth-redirect',
54
+ component: Vue.defineAsyncComponent(
55
+ () => import('../views/login/authredirect.vue')
56
+ ),
57
+ hidden: true,
58
+ },
59
+ {
60
+ path: '/404',
61
+ component: Vue.defineAsyncComponent(
62
+ () => import('../views/error-page/404.vue')
63
+ ),
64
+ hidden: true,
65
+ },
66
+ {
67
+ path: '/401',
68
+ component: Vue.defineAsyncComponent(
69
+ () => import('../views/error-page/401.vue')
70
+ ),
71
+ hidden: true,
72
+ },
73
+ {
74
+ path: '/show-sub-wf-history',
75
+ component: Vue.defineAsyncComponent(
76
+ () => import('../views/wf-history/tache-subprocess-history.vue')
77
+ ),
78
+ hidden: true,
79
+ },
80
+ {
81
+ path: '/tab-content-index',
82
+ component: Vue.defineAsyncComponent(
83
+ () => import('../views/layout/tab-content-index.vue')
84
+ ),
85
+ hidden: true,
86
+ },
87
+ {
88
+ path: '/tab-content-iframe-index',
89
+ component: Vue.defineAsyncComponent(
90
+ Vue.defineAsyncComponent(
91
+ () => import('../views/layout/tab-content-iframe-index.vue')
92
+ )
93
+ ),
94
+ hidden: true,
95
+ },
96
+ ]
97
+ export const protectedRouterMap = []
98
+ export const errorRouterMap = [
99
+ // 404的映射必须是最后一个
100
+ { path: '*', redirect: '/404', hidden: true },
101
+ ]
102
+
103
+
104
+ export default VueRouter.createRouter({
105
+ history: VueRouter.createWebHashHistory(),
106
+ routes: publicRouterMap,
107
+ scrollBehavior: () => ({
108
+ top: 0,
109
+ }),
110
+ })