Commit bc844632 by liimin

优化

1 parent 5757ab1d
...@@ -6657,9 +6657,9 @@ ...@@ -6657,9 +6657,9 @@
} }
}, },
"glsx-common": { "glsx-common": {
"version": "2.0.4", "version": "2.0.5",
"resolved": "https://registry.npmjs.org/glsx-common/-/glsx-common-2.0.4.tgz", "resolved": "https://registry.npmjs.org/glsx-common/-/glsx-common-2.0.5.tgz",
"integrity": "sha512-EgWFYUmDk6axzEi6uq5FmYd8nPD7DDg2Vi5kepNMX7YS/cg4bLNBdGCp4iZe2SYFIx3U5O7yKf9fI/aWewCVxw==", "integrity": "sha512-4P5VobJFonr9avr21QVMFrY5yx1rfueyu8eVGCEGUL6B1Sp6yuv3q7F1HfsH6TyCNVThkGUlauNZnz7FiqRcIA==",
"requires": { "requires": {
"axios": "^0.21.3", "axios": "^0.21.3",
"md5": "^2.3.0", "md5": "^2.3.0",
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
"@sentry/vue": "^7.7.0", "@sentry/vue": "^7.7.0",
"core-js": "^3.6.5", "core-js": "^3.6.5",
"element-ui": "^2.15.6", "element-ui": "^2.15.6",
"glsx-common": "^2.0.4", "glsx-common": "^2.0.5",
"gltracker": "^0.1.3", "gltracker": "^0.1.3",
"md5": "^2.3.0", "md5": "^2.3.0",
"nprogress": "^0.2.0", "nprogress": "^0.2.0",
......
...@@ -4,8 +4,8 @@ ...@@ -4,8 +4,8 @@
* @Author: limin * @Author: limin
* @Date: 2022-03-25 09:54:08 * @Date: 2022-03-25 09:54:08
* @LastEditors: limin * @LastEditors: limin
* @LastEditTime: 2022-07-21 10:02:42 * @LastEditTime: 2022-12-19 09:36:48
* @FilePath: \scrm\scrm-base\src\common\helper.js * @FilePath: \scrm-base\src\common\helper.js
*/ */
import constants from './constants' import constants from './constants'
export function customized(cdn, { assets, title }) { export function customized(cdn, { assets, title }) {
...@@ -20,3 +20,11 @@ export function getIcon(iconName) { ...@@ -20,3 +20,11 @@ export function getIcon(iconName) {
const { ICONS, DEFAULT_ICON_NAME } = constants const { ICONS, DEFAULT_ICON_NAME } = constants
return ICONS.includes(iconName) && ICONS.includes(iconName + '-active') ? iconName : DEFAULT_ICON_NAME 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('='))
)
}
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* @Author: limin * @Author: limin
* @Date: 2021-06-07 14:12:32 * @Date: 2021-06-07 14:12:32
* @LastEditors: limin * @LastEditors: limin
* @LastEditTime: 2022-01-13 14:05:08 * @LastEditTime: 2022-12-15 15:41:46
*/ */
// 本地环境配置 // 本地环境配置
module.exports = { module.exports = {
...@@ -17,8 +17,8 @@ module.exports = { ...@@ -17,8 +17,8 @@ module.exports = {
code_message_map: {} code_message_map: {}
}, },
request: { request: {
baseURL: 'http://192.168.2.59:8315/rop-scrm-sso/router', // baseURL: 'http://192.168.2.59:8315/rop-scrm-sso/router',
// baseURL: 'https://oss-config.test.glsx.com.cn/mock/6136bea6ceeb5a5c2bec6950/base', baseURL: 'https://oss-config.dev.glsx.com.cn/mock/6136bea6ceeb5a5c2bec6950/base',
// 设置超时时间 // 设置超时时间
timeout: 180000, timeout: 180000,
// 携带凭证 // 携带凭证
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* @Author: limin * @Author: limin
* @Date: 2021-06-07 14:12:32 * @Date: 2021-06-07 14:12:32
* @LastEditors: limin * @LastEditors: limin
* @LastEditTime: 2022-11-15 17:17:35 * @LastEditTime: 2022-12-28 10:03:28
*/ */
// 根据环境引入不同配置 process.env.VUE_APP_ENV // 根据环境引入不同配置 process.env.VUE_APP_ENV
let cfg = require('./conf.js') let cfg = require('./conf.js')
......
import { Http, utils } from 'glsx-common' import { Http, utils } from 'glsx-common'
import { messenger, history } from '@/global' import { messenger, history } from '@/global'
import { configSwitch } from '@/config' import { configSwitch } from '@/config'
import { This } from '@/main'
import store from '@/store' import store from '@/store'
import router from '@/router'
import NProgress from 'nprogress' import NProgress from 'nprogress'
import 'nprogress/nprogress.css' import 'nprogress/nprogress.css'
NProgress.configure({ ease: 'ease', speed: 300, showSpinner: false }) NProgress.configure({ ease: 'ease', speed: 300, showSpinner: false })
...@@ -18,7 +20,7 @@ export const filterApps = microApps => { ...@@ -18,7 +20,7 @@ export const filterApps = microApps => {
activeRule, activeRule,
props: { props: {
routerBase: activeRule, // 下发基础路由 routerBase: activeRule, // 下发基础路由
globalState: { routers: filter(activeRule), session, configSwitch }, // 下发全局数据方法 globalState: { routers: filter(activeRule), session, configSwitch, parent: This }, // 下发全局数据方法
common: { Http, utils, tracker }, common: { Http, utils, tracker },
messenger, messenger,
history history
...@@ -31,15 +33,13 @@ export const filterApps = microApps => { ...@@ -31,15 +33,13 @@ export const filterApps = microApps => {
return apps return apps
} }
function filter(routerBase) { function filter(routerBase) {
const routers = store.getters.app.routers.reduce((collect, route) => { const routers = router
if (route.path.startsWith(routerBase + '/')) { .getRoutes()
route.path = route.path.slice(routerBase.length) .filter(route => route.path.startsWith(`${routerBase}/`))
route.compath = route.path .reduce((collect, { path, compath, name, meta }) => {
if (route.compath.includes('/:')) { path = path.slice(routerBase.length)
route.compath = route.compath.split('/:')[0] compath = path.split('/:')[0]
} collect.push({ path, compath, name, meta })
collect.push(route)
}
return collect return collect
}, []) }, [])
return routers return routers
......
...@@ -78,29 +78,32 @@ VueRouter.prototype.reset = function () { ...@@ -78,29 +78,32 @@ VueRouter.prototype.reset = function () {
const newRouter = createRouter() const newRouter = createRouter()
this.matcher = newRouter.matcher this.matcher = newRouter.matcher
} }
VueRouter.prototype.ERR404 = { path: '*', redirect: Path.E404 }
const router = createRouter() const router = createRouter()
router.onError(err => { router.onError(err => {
console.log(err) console.log(err)
}) })
router.beforeEach(async (to, from, next) => { router.beforeEach(async (to, from, next) => {
if (Object.values(Path).includes(to.path)) return next()
const session = store.getters.auth.session const session = store.getters.auth.session
const storeSession = utils.storage.getSession(constants.SCRM_BASE_SESSION) const storeSession = utils.storage.getSession(constants.SCRM_BASE_SESSION)
if (Object.values(Path).includes(to.path)) return next()
if (storeSession) { if (storeSession) {
if (from === VueRouter.START_LOCATION && session === null) { if (from === VueRouter.START_LOCATION && session === null) {
await store.dispatch('init/init') await store.dispatch('init/init')
return next({ ...to, replace: true }) return next({ ...to, replace: true })
} }
if (router.hasRoute(to.path)) { // if (router.hasRoute(to.path)) {
const { $title } = to.query const { $title } = to.query
$title && (to.meta.title = $title) $title && (to.meta.title = $title)
store.dispatch('app/setCurrentPage', to.meta) store.dispatch('app/setCurrentPage', to.meta)
return next() return next()
// }
// return next({ path: Path.E404, replace: true })
} }
return next({ path: Path.E404, replace: true }) if (!session) {
}
next({ path: Path.LOGIN }) next({ path: Path.LOGIN })
}
// next({ path: Path.LOGIN })
}) })
export default router export default router
...@@ -18,7 +18,7 @@ const app = { ...@@ -18,7 +18,7 @@ const app = {
}, },
SET_MENU_LIST(state, list) { SET_MENU_LIST(state, list) {
state.menuList = 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) { SET_ROUTES(state, payload) {
state.routers = payload state.routers = payload
...@@ -62,17 +62,9 @@ const app = { ...@@ -62,17 +62,9 @@ const app = {
commit('SET_LOADING', isLoading) commit('SET_LOADING', isLoading)
}, },
persisted({ commit }, data) { persisted({ commit }, data) {
const routes = data.reduce((routes, { name, children }) => { data.forEach(({ name, children }) => children?.length && getMenuItem(name, children))
if (children && children.length) { router.addRoute(router.ERR404)
const route = getMenuItem(name, children)
routes = routes.concat(route)
}
return routes
}, [])
router.addRoutes(routes)
commit('SET_MENU_LIST', data) commit('SET_MENU_LIST', data)
// routeMap(routes)
commit('SET_ROUTES', routes)
} }
} }
} }
...@@ -127,16 +119,12 @@ function formatData(menus, parentMenu) { ...@@ -127,16 +119,12 @@ function formatData(menus, parentMenu) {
// 组装路由数据 // 组装路由数据
function getMenuItem(moduleName, menus) { function getMenuItem(moduleName, menus) {
let routers = []
const flattenMenus = utils.array.flattenDeep(menus) const flattenMenus = utils.array.flattenDeep(menus)
for (let i = 0, j = flattenMenus.length; i < j; i++) { for (let i = 0, j = flattenMenus.length; i < j; i++) {
const menu = flattenMenus[i] const menu = flattenMenus[i]
const route = __gen(moduleName, menu) const route = __gen(moduleName, menu)
if (router.hasRoute(route.path)) continue router.addRoute(route)
// router.addRoute(route)
routers.push(route)
} }
return routers
} }
/** /**
...@@ -152,20 +140,7 @@ function __gen(moduleName, menu) { ...@@ -152,20 +140,7 @@ function __gen(moduleName, menu) {
if (path.includes('^')) { if (path.includes('^')) {
// const [originPath] = path.split('^') // const [originPath] = path.split('^')
_path = _gen_path_() + id _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) redirect = _gen_path_(children.noHidden()[0].path)
// } else {
// redirect = targetPath
// meta.targetPath = targetPath
// }
} else { } else {
_path = _gen_path_() _path = _gen_path_()
} }
...@@ -189,17 +164,6 @@ function __gen(moduleName, menu) { ...@@ -189,17 +164,6 @@ function __gen(moduleName, menu) {
return route 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 * @param {*} menu
......
...@@ -82,7 +82,7 @@ import { utils } from 'glsx-common' ...@@ -82,7 +82,7 @@ import { utils } from 'glsx-common'
import api from '@/api' import api from '@/api'
import md5 from 'md5' import md5 from 'md5'
import { Message } from '@/plugins/element' import { Message } from '@/plugins/element'
import { constants } from '@/common' import { constants, helper } from '@/common'
import LoginSMSCodeCheck from './components/LoginSMSCodeCheck.vue' import LoginSMSCodeCheck from './components/LoginSMSCodeCheck.vue'
const genRules = field => [{ required: true, message: `请输入${field}`, trigger: 'blur' }] const genRules = field => [{ required: true, message: `请输入${field}`, trigger: 'blur' }]
const RULES = Object.freeze({ const RULES = Object.freeze({
...@@ -152,7 +152,9 @@ export default { ...@@ -152,7 +152,9 @@ export default {
if (window.qiankunStarted) { if (window.qiankunStarted) {
const session = utils.storage.getSession(constants.SCRM_BASE_SESSION) const session = utils.storage.getSession(constants.SCRM_BASE_SESSION)
sessionStorage.clear() 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() next()
}, },
...@@ -215,8 +217,11 @@ export default { ...@@ -215,8 +217,11 @@ export default {
sessionData.track = track sessionData.track = track
this.setSession(sessionData) this.setSession(sessionData)
this.setTracker(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.push(defaultPath)
this.$router.onReady(() => this.$router.push(defaultPath)) this.$router.onReady(() => this.$router.push(to))
} else { } else {
this.error(message) this.error(message)
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!