Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
saas
/
scrm-base
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit bc844632
authored
Dec 28, 2022
by
liimin
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
优化
1 parent
5757ab1d
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
55 additions
and
75 deletions
package-lock.json
package.json
src/common/helper.js
src/config/env.development.js
src/config/index.js
src/qiankun/registerApp.js
src/router/index.js
src/store/modules/app.js
src/views/Login.vue
package-lock.json
View file @
bc84463
...
...
@@ -6657,9 +6657,9 @@
}
},
"glsx-common"
:
{
"version"
:
"2.0.
4
"
,
"resolved"
:
"https://registry.npmjs.org/glsx-common/-/glsx-common-2.0.
4
.tgz"
,
"integrity"
:
"sha512-
EgWFYUmDk6axzEi6uq5FmYd8nPD7DDg2Vi5kepNMX7YS/cg4bLNBdGCp4iZe2SYFIx3U5O7yKf9fI/aWewCVxw
=="
,
"version"
:
"2.0.
5
"
,
"resolved"
:
"https://registry.npmjs.org/glsx-common/-/glsx-common-2.0.
5
.tgz"
,
"integrity"
:
"sha512-
4P5VobJFonr9avr21QVMFrY5yx1rfueyu8eVGCEGUL6B1Sp6yuv3q7F1HfsH6TyCNVThkGUlauNZnz7FiqRcIA
=="
,
"requires"
:
{
"axios"
:
"^0.21.3"
,
"md5"
:
"^2.3.0"
,
...
...
package.json
View file @
bc84463
...
...
@@ -13,7 +13,7 @@
"@sentry/vue"
:
"^7.7.0"
,
"core-js"
:
"^3.6.5"
,
"element-ui"
:
"^2.15.6"
,
"glsx-common"
:
"^2.0.
4
"
,
"glsx-common"
:
"^2.0.
5
"
,
"gltracker"
:
"^0.1.3"
,
"md5"
:
"^2.3.0"
,
"nprogress"
:
"^0.2.0"
,
...
...
src/common/helper.js
View file @
bc84463
...
...
@@ -4,8 +4,8 @@
* @Author: limin
* @Date: 2022-03-25 09:54:08
* @LastEditors: limin
* @LastEditTime: 2022-
07-21 10:02:42
* @FilePath: \scrm
\scrm
-base\src\common\helper.js
* @LastEditTime: 2022-
12-19 09:36:48
* @FilePath: \scrm-base\src\common\helper.js
*/
import
constants
from
'./constants'
export
function
customized
(
cdn
,
{
assets
,
title
})
{
...
...
@@ -20,3 +20,11 @@ export function getIcon(iconName) {
const
{
ICONS
,
DEFAULT_ICON_NAME
}
=
constants
return
ICONS
.
includes
(
iconName
)
&&
ICONS
.
includes
(
iconName
+
'-active'
)
?
iconName
:
DEFAULT_ICON_NAME
}
export
function
locationPath
()
{
return
new
Map
(
location
.
search
.
slice
(
1
)
.
split
(
'&'
)
.
map
(
kv
=>
kv
.
split
(
'='
))
)
}
src/config/env.development.js
View file @
bc84463
...
...
@@ -4,7 +4,7 @@
* @Author: limin
* @Date: 2021-06-07 14:12:32
* @LastEditors: limin
* @LastEditTime: 2022-
01-13 14:05:08
* @LastEditTime: 2022-
12-15 15:41:46
*/
// 本地环境配置
module
.
exports
=
{
...
...
@@ -17,8 +17,8 @@ module.exports = {
code_message_map
:
{}
},
request
:
{
baseURL
:
'http://192.168.2.59:8315/rop-scrm-sso/router'
,
// baseURL: 'https://oss-config.test
.glsx.com.cn/mock/6136bea6ceeb5a5c2bec6950/base',
//
baseURL: 'http://192.168.2.59:8315/rop-scrm-sso/router',
baseURL
:
'https://oss-config.dev
.glsx.com.cn/mock/6136bea6ceeb5a5c2bec6950/base'
,
// 设置超时时间
timeout
:
180000
,
// 携带凭证
...
...
src/config/index.js
View file @
bc84463
...
...
@@ -4,7 +4,7 @@
* @Author: limin
* @Date: 2021-06-07 14:12:32
* @LastEditors: limin
* @LastEditTime: 2022-1
1-15 17:17:35
* @LastEditTime: 2022-1
2-28 10:03:28
*/
// 根据环境引入不同配置 process.env.VUE_APP_ENV
let
cfg
=
require
(
'./conf.js'
)
...
...
src/qiankun/registerApp.js
View file @
bc84463
import
{
Http
,
utils
}
from
'glsx-common'
import
{
messenger
,
history
}
from
'@/global'
import
{
configSwitch
}
from
'@/config'
import
{
This
}
from
'@/main'
import
store
from
'@/store'
import
router
from
'@/router'
import
NProgress
from
'nprogress'
import
'nprogress/nprogress.css'
NProgress
.
configure
({
ease
:
'ease'
,
speed
:
300
,
showSpinner
:
false
})
...
...
@@ -18,7 +20,7 @@ export const filterApps = microApps => {
activeRule
,
props
:
{
routerBase
:
activeRule
,
// 下发基础路由
globalState
:
{
routers
:
filter
(
activeRule
),
session
,
configSwitch
},
// 下发全局数据方法
globalState
:
{
routers
:
filter
(
activeRule
),
session
,
configSwitch
,
parent
:
This
},
// 下发全局数据方法
common
:
{
Http
,
utils
,
tracker
},
messenger
,
history
...
...
@@ -31,17 +33,15 @@ export const filterApps = microApps => {
return
apps
}
function
filter
(
routerBase
)
{
const
routers
=
store
.
getters
.
app
.
routers
.
reduce
((
collect
,
route
)
=>
{
if
(
route
.
path
.
startsWith
(
routerBase
+
'/'
))
{
route
.
path
=
route
.
path
.
slice
(
routerBase
.
length
)
route
.
compath
=
route
.
path
if
(
route
.
compath
.
includes
(
'/:'
))
{
route
.
compath
=
route
.
compath
.
split
(
'/:'
)[
0
]
}
collect
.
push
(
route
)
}
return
collect
},
[])
const
routers
=
router
.
getRoutes
()
.
filter
(
route
=>
route
.
path
.
startsWith
(
`
${
routerBase
}
/`
))
.
reduce
((
collect
,
{
path
,
compath
,
name
,
meta
})
=>
{
path
=
path
.
slice
(
routerBase
.
length
)
compath
=
path
.
split
(
'/:'
)[
0
]
collect
.
push
({
path
,
compath
,
name
,
meta
})
return
collect
},
[])
return
routers
}
...
...
src/router/index.js
View file @
bc84463
...
...
@@ -78,29 +78,32 @@ VueRouter.prototype.reset = function () {
const
newRouter
=
createRouter
()
this
.
matcher
=
newRouter
.
matcher
}
VueRouter
.
prototype
.
ERR404
=
{
path
:
'*'
,
redirect
:
Path
.
E404
}
const
router
=
createRouter
()
router
.
onError
(
err
=>
{
console
.
log
(
err
)
})
router
.
beforeEach
(
async
(
to
,
from
,
next
)
=>
{
if
(
Object
.
values
(
Path
).
includes
(
to
.
path
))
return
next
()
const
session
=
store
.
getters
.
auth
.
session
const
storeSession
=
utils
.
storage
.
getSession
(
constants
.
SCRM_BASE_SESSION
)
if
(
Object
.
values
(
Path
).
includes
(
to
.
path
))
return
next
()
if
(
storeSession
)
{
if
(
from
===
VueRouter
.
START_LOCATION
&&
session
===
null
)
{
await
store
.
dispatch
(
'init/init'
)
return
next
({
...
to
,
replace
:
true
})
}
if
(
router
.
hasRoute
(
to
.
path
))
{
const
{
$title
}
=
to
.
query
$title
&&
(
to
.
meta
.
title
=
$title
)
store
.
dispatch
(
'app/setCurrentPage'
,
to
.
meta
)
return
next
()
}
return
next
({
path
:
Path
.
E404
,
replace
:
true
})
// if (router.hasRoute(to.path)) {
const
{
$title
}
=
to
.
query
$title
&&
(
to
.
meta
.
title
=
$title
)
store
.
dispatch
(
'app/setCurrentPage'
,
to
.
meta
)
return
next
()
// }
// return next({ path: Path.E404, replace: true })
}
if
(
!
session
)
{
next
({
path
:
Path
.
LOGIN
})
}
next
({
path
:
Path
.
LOGIN
})
//
next({ path: Path.LOGIN })
})
export
default
router
src/store/modules/app.js
View file @
bc84463
...
...
@@ -18,7 +18,7 @@ const app = {
},
SET_MENU_LIST
(
state
,
list
)
{
state
.
menuList
=
list
state
.
flatten
=
utils
.
array
.
flattenDeep
(
list
)
state
.
flatten
=
utils
.
array
.
flattenDeep
(
list
)
.
map
(({
path
,
id
})
=>
({
path
,
id
}))
},
SET_ROUTES
(
state
,
payload
)
{
state
.
routers
=
payload
...
...
@@ -62,17 +62,9 @@ const app = {
commit
(
'SET_LOADING'
,
isLoading
)
},
persisted
({
commit
},
data
)
{
const
routes
=
data
.
reduce
((
routes
,
{
name
,
children
})
=>
{
if
(
children
&&
children
.
length
)
{
const
route
=
getMenuItem
(
name
,
children
)
routes
=
routes
.
concat
(
route
)
}
return
routes
},
[])
router
.
addRoutes
(
routes
)
data
.
forEach
(({
name
,
children
})
=>
children
?.
length
&&
getMenuItem
(
name
,
children
))
router
.
addRoute
(
router
.
ERR404
)
commit
(
'SET_MENU_LIST'
,
data
)
// routeMap(routes)
commit
(
'SET_ROUTES'
,
routes
)
}
}
}
...
...
@@ -127,16 +119,12 @@ function formatData(menus, parentMenu) {
// 组装路由数据
function
getMenuItem
(
moduleName
,
menus
)
{
let
routers
=
[]
const
flattenMenus
=
utils
.
array
.
flattenDeep
(
menus
)
for
(
let
i
=
0
,
j
=
flattenMenus
.
length
;
i
<
j
;
i
++
)
{
const
menu
=
flattenMenus
[
i
]
const
route
=
__gen
(
moduleName
,
menu
)
if
(
router
.
hasRoute
(
route
.
path
))
continue
// router.addRoute(route)
routers
.
push
(
route
)
router
.
addRoute
(
route
)
}
return
routers
}
/**
...
...
@@ -152,20 +140,7 @@ function __gen(moduleName, menu) {
if
(
path
.
includes
(
'^'
))
{
// const [originPath] = path.split('^')
_path
=
_gen_path_
()
+
id
// if (!targetPath) {
// if (!children || children.length == 0) {
// throw new Error(constants.SCRM_BASE_ERRORS.ILLEGAL_ROUTER_NO_THIRD_ROUTE.MESSAGE)
// }
// const childs = children.noHidden()
// if (childs.length == 0) {
// throw new Error(constants.SCRM_BASE_ERRORS.ILLEGAL_ROUTER_NO_THIRD_ROUTE.MESSAGE)
// }
// if (!originPath) _path += id
redirect
=
_gen_path_
(
children
.
noHidden
()[
0
].
path
)
// } else {
// redirect = targetPath
// meta.targetPath = targetPath
// }
}
else
{
_path
=
_gen_path_
()
}
...
...
@@ -189,17 +164,6 @@ function __gen(moduleName, menu) {
return
route
}
// function routeMap(routes) {
// const redirects = routes.filter(route => route.meta.targetPath)
// redirects.forEach(item => {
// const target = routes.find(route => route.path == item.meta.targetPath)
// if (target) {
// target.meta.origin = item.meta
// }
// })
// return routes
// }
/**
* 获取默认加载路由
* @param {*} menu
...
...
src/views/Login.vue
View file @
bc84463
...
...
@@ -82,7 +82,7 @@ import { utils } from 'glsx-common'
import
api
from
'@/api'
import
md5
from
'md5'
import
{
Message
}
from
'@/plugins/element'
import
{
constants
}
from
'@/common'
import
{
constants
,
helper
}
from
'@/common'
import
LoginSMSCodeCheck
from
'./components/LoginSMSCodeCheck.vue'
const
genRules
=
field
=>
[{
required
:
true
,
message
:
`请输入
${
field
}
`
,
trigger
:
'blur'
}]
const
RULES
=
Object
.
freeze
({
...
...
@@ -152,7 +152,9 @@ export default {
if
(
window
.
qiankunStarted
)
{
const
session
=
utils
.
storage
.
getSession
(
constants
.
SCRM_BASE_SESSION
)
sessionStorage
.
clear
()
return
location
.
replace
(
session
?.
loginpath
||
'/login'
)
const
redirect
=
window
.
history
.
state
?.
page
?.
split
(
'/'
).
slice
(
3
).
join
(
'/'
)
const
path
=
`
${
session
?.
loginpath
||
'/login'
}
$
{
redirect
?
`?redirect=
${
redirect
}
`
:
''
}
`
return location.replace(path)
}
next()
},
...
...
@@ -215,8 +217,11 @@ export default {
sessionData.track = track
this.setSession(sessionData)
this.setTracker(sessionData)
const path = helper.locationPath()
const redirect = path?.get('redirect')
const to = redirect ? `
/
$
{
decodeURIComponent
(
redirect
)}
` : defaultPath
// this.$router.push(defaultPath)
this
.
$router
.
onReady
(()
=>
this
.
$router
.
push
(
defaultPath
))
this.$router.onReady(() => this.$router.push(
to
))
} else {
this.error(message)
}
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment