Merge 4329dce5587c00a2b6e5e3edd0cfc1954fee7b59 into 17e41ce1fc1537a90a48b0d0f408f49403faf31c

This commit is contained in:
Midaug 2023-04-11 14:31:58 +08:00 committed by GitHub
commit e0c1ba06ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 340 additions and 181 deletions

View File

@ -6,6 +6,7 @@
"scripts": { "scripts": {
"serve": "vue-cli-service serve", "serve": "vue-cli-service serve",
"build": "vue-cli-service build", "build": "vue-cli-service build",
"build:stage": "vue-cli-service build --mode staging",
"lint": "vue-cli-service lint", "lint": "vue-cli-service lint",
"predeploy": "yarn build", "predeploy": "yarn build",
"deploy": "gh-pages -d dist -b pages -r https://gitee.com/iczer/vue-antd-admin.git", "deploy": "gh-pages -d dist -b pages -r https://gitee.com/iczer/vue-antd-admin.git",

View File

@ -126,6 +126,7 @@ import {setting} from '@/config/default'
import sysConfig from '@/config/config' import sysConfig from '@/config/config'
import fastEqual from 'fast-deep-equal' import fastEqual from 'fast-deep-equal'
import deepMerge from 'deepmerge' import deepMerge from 'deepmerge'
import {getLocalStorage, setLocalStorage, removeLocalStorage} from '@/utils/cache'
const ColorCheckboxGroup = ColorCheckbox.Group const ColorCheckboxGroup = ColorCheckbox.Group
const ImgCheckboxGroup = ImgCheckbox.Group const ImgCheckboxGroup = ImgCheckbox.Group
@ -162,7 +163,7 @@ export default {
let clipboard = new Clipboard('#copyBtn') let clipboard = new Clipboard('#copyBtn')
clipboard.on('success', () => { clipboard.on('success', () => {
this.$message.success(`复制成功,覆盖文件 src/config/config.js 然后重启项目即可生效`).then(() => { this.$message.success(`复制成功,覆盖文件 src/config/config.js 然后重启项目即可生效`).then(() => {
const localConfig = localStorage.getItem(process.env.VUE_APP_SETTING_KEY) const localConfig = getLocalStorage(process.env.VUE_APP_SETTING_KEY)
if (localConfig) { if (localConfig) {
console.warn('检测到本地有历史保存的主题配置,想要要拷贝的配置代码生效,您可能需要先重置配置') console.warn('检测到本地有历史保存的主题配置,想要要拷贝的配置代码生效,您可能需要先重置配置')
this.$message.warn('检测到本地有历史保存的主题配置,想要要拷贝的配置代码生效,您可能需要先重置配置', 5) this.$message.warn('检测到本地有历史保存的主题配置,想要要拷贝的配置代码生效,您可能需要先重置配置', 5)
@ -174,14 +175,14 @@ export default {
saveSetting() { saveSetting() {
const closeMessage = this.$message.loading('正在保存到本地,请稍后...', 0) const closeMessage = this.$message.loading('正在保存到本地,请稍后...', 0)
const config = this.extractConfig(true) const config = this.extractConfig(true)
localStorage.setItem(process.env.VUE_APP_SETTING_KEY, JSON.stringify(config)) setLocalStorage(process.env.VUE_APP_SETTING_KEY, JSON.stringify(config))
setTimeout(closeMessage, 800) setTimeout(closeMessage, 800)
}, },
resetSetting() { resetSetting() {
this.$confirm({ this.$confirm({
title: '重置主题会刷新页面,当前页面内容不会保留,确认重置?', title: '重置主题会刷新页面,当前页面内容不会保留,确认重置?',
onOk() { onOk() {
localStorage.removeItem(process.env.VUE_APP_SETTING_KEY) removeLocalStorage(process.env.VUE_APP_SETTING_KEY)
window.location.reload() window.location.reload()
} }
}) })

View File

@ -5,6 +5,7 @@ module.exports = {
mode: 'dark', mode: 'dark',
}, },
multiPage: true, multiPage: true,
asyncRoutes: true,
animate: { animate: {
name: 'lightSpeed', name: 'lightSpeed',
direction: 'left' direction: 'left'

View File

@ -1,5 +1,5 @@
<template> <template>
<exception-page home-route="/dashboard/workplace" :style="`min-height: ${minHeight}`" type="403" /> <exception-page home-route="/" :style="`min-height: ${minHeight}`" type="403" />
</template> </template>
<script> <script>

View File

@ -1,5 +1,5 @@
<template> <template>
<exception-page home-route="/dashboard/workplace" :style="`min-height: ${minHeight}`" type="404" /> <exception-page home-route="/" :style="`min-height: ${minHeight}`" type="404" />
</template> </template>
<script> <script>

View File

@ -1,5 +1,5 @@
<template> <template>
<exception-page home-route="/dashboard/workplace" :style="`min-height: ${minHeight}`" type="500" /> <exception-page home-route="/" :style="`min-height: ${minHeight}`" type="500" />
</template> </template>
<script> <script>

View File

@ -75,9 +75,9 @@
<script> <script>
import CommonLayout from '@/layouts/CommonLayout' import CommonLayout from '@/layouts/CommonLayout'
import {login, getRoutesConfig} from '@/services/user' import {login, logout} from '@/services/user'
import {setAuthorization} from '@/utils/request' import {setAuthorization} from '@/utils/request'
import {loadRoutes} from '@/utils/routerUtil' import {initRoutes} from '@/utils/routerUtil'
import {mapMutations} from 'vuex' import {mapMutations} from 'vuex'
export default { export default {
@ -104,6 +104,7 @@ export default {
this.logging = true this.logging = true
const name = this.form.getFieldValue('name') const name = this.form.getFieldValue('name')
const password = this.form.getFieldValue('password') const password = this.form.getFieldValue('password')
logout()
login(name, password).then(this.afterLogin) login(name, password).then(this.afterLogin)
} }
}) })
@ -118,10 +119,8 @@ export default {
this.setRoles(roles) this.setRoles(roles)
setAuthorization({token: loginRes.data.token, expireAt: new Date(loginRes.data.expireAt)}) setAuthorization({token: loginRes.data.token, expireAt: new Date(loginRes.data.expireAt)})
// //
getRoutesConfig().then(result => { initRoutes(() => {
const routesConfig = result.data.data this.$router.push('/')
loadRoutes(routesConfig)
this.$router.push('/dashboard/workplace')
this.$message.success(loginRes.message, 3) this.$message.success(loginRes.message, 3)
}) })
} else { } else {

View File

@ -5,150 +5,155 @@ const view = {
page: () => import('@/layouts/PageView') page: () => import('@/layouts/PageView')
} }
// 路由组件注册 export const initRouterMap = () => {
const routerMap = { return {
login: { login: {
authority: '*', authority: '*',
path: '/login', path: '/login',
component: () => import('@/pages/login') component: () => import('@/pages/login')
}, },
root: { root: {
path: '/', path: '/',
name: '首页', name: '首页',
redirect: '/login', redirect: '/login',
component: view.tabs component: view.tabs
}, },
dashboard: { dashboard: {
name: 'Dashboard', name: 'Dashboard',
component: view.blank component: view.blank
}, },
workplace: { workplace: {
name: '工作台', name: '工作台',
component: () => import('@/pages/dashboard/workplace') component: () => import('@/pages/dashboard/workplace')
}, },
analysis: { analysis: {
name: '分析页', name: '分析页',
component: () => import('@/pages/dashboard/analysis') component: () => import('@/pages/dashboard/analysis')
}, },
form: { form: {
name: '表单页', name: '表单页',
icon: 'form', icon: 'form',
component: view.page component: view.page
}, },
basicForm: { basicForm: {
path: 'basic', path: 'basic',
name: '基础表单', name: '基础表单',
component: () => import('@/pages/form/basic') component: () => import('@/pages/form/basic')
}, },
stepForm: { stepForm: {
path: 'step', path: 'step',
name: '分步表单', name: '分步表单',
component: () => import('@/pages/form/step') component: () => import('@/pages/form/step')
}, },
advanceForm: { advanceForm: {
path: 'advance', path: 'advance',
name: '高级表单', name: '高级表单',
component: () => import('@/pages/form/advance') component: () => import('@/pages/form/advance')
}, },
list: { list: {
name: '列表页', name: '列表页',
icon: 'table', icon: 'table',
component: view.page component: view.page
}, },
queryList: { queryList: {
path: 'query', path: 'query',
name: '查询表格', name: '查询表格',
component: () => import('@/pages/list/QueryList') component: () => import('@/pages/list/QueryList')
}, },
primaryList: { primaryList: {
path: 'primary', path: 'primary',
name: '标准列表', name: '标准列表',
component: () => import('@/pages/list/StandardList') component: () => import('@/pages/list/StandardList')
}, },
cardList: { cardList: {
path: 'card', path: 'card',
name: '卡片列表', name: '卡片列表',
component: () => import('@/pages/list/CardList') component: () => import('@/pages/list/CardList')
}, },
searchList: { searchList: {
path: 'search', path: 'search',
name: '搜索列表', name: '搜索列表',
component: () => import('@/pages/list/search/SearchLayout') component: () => import('@/pages/list/search/SearchLayout')
}, },
article: { article: {
name: '文章', name: '文章',
component: () => import('@/pages/list/search/ArticleList') component: () => import('@/pages/list/search/ArticleList')
}, },
application: { application: {
name: '应用', name: '应用',
component: () => import('@/pages/list/search/ApplicationList') component: () => import('@/pages/list/search/ApplicationList')
}, },
project: { project: {
name: '项目', name: '项目',
component: () => import('@/pages/list/search/ProjectList') component: () => import('@/pages/list/search/ProjectList')
}, },
details: { details: {
name: '详情页', name: '详情页',
icon: 'profile', icon: 'profile',
component: view.blank component: view.blank
}, },
basicDetails: { basicDetails: {
path: 'basic', path: 'basic',
name: '基础详情页', name: '基础详情页',
component: () => import('@/pages/detail/BasicDetail') component: () => import('@/pages/detail/BasicDetail')
}, },
advanceDetails: { advanceDetails: {
path: 'advance', path: 'advance',
name: '高级详情页', name: '高级详情页',
component: () => import('@/pages/detail/AdvancedDetail') component: () => import('@/pages/detail/AdvancedDetail')
}, },
result: { result: {
name: '结果页', name: '结果页',
icon: 'check-circle-o', icon: 'check-circle-o',
component: view.page component: view.page
}, },
success: { success: {
name: '成功', name: '成功',
component: () => import('@/pages/result/Success') component: () => import('@/pages/result/Success')
}, },
error: { error: {
name: '失败', name: '失败',
component: () => import('@/pages/result/Error') component: () => import('@/pages/result/Error')
}, },
exception: { exception: {
name: '异常页', name: '异常页',
icon: 'warning', icon: 'warning',
component: view.blank component: view.blank
}, },
exp403: { exp403: {
authority: '*', authority: '*',
name: 'exp403', name: 'exp403',
path: '403', path: '403',
component: () => import('@/pages/exception/403') component: () => import('@/pages/exception/403')
}, },
exp404: { exp404: {
name: 'exp404', name: 'exp404',
path: '404', path: '404',
component: () => import('@/pages/exception/404') component: () => import('@/pages/exception/404')
}, },
exp500: { exp500: {
name: 'exp500', name: 'exp500',
path: '500', path: '500',
component: () => import('@/pages/exception/500') component: () => import('@/pages/exception/500')
}, },
components: { components: {
name: '小组件', name: '小组件',
icon: 'appstore-o', icon: 'appstore-o',
component: view.page component: view.page
}, },
taskCard: { taskCard: {
name: '任务卡片', name: '任务卡片',
component: () => import('@/pages/components/TaskCard') component: () => import('@/pages/components/TaskCard')
}, },
palette: { palette: {
name: '颜色复选框', name: '颜色复选框',
component: () => import('@/pages/components/Palette') component: () => import('@/pages/components/Palette')
}
} }
} }
// 路由组件注册
const routerMap = initRouterMap()
export default routerMap export default routerMap

View File

@ -1,6 +1,7 @@
import {hasAuthority} from '@/utils/authority-utils' import {hasAuthority} from '@/utils/authority-utils'
import {loginIgnore} from '@/router/index' import {loginIgnore} from '@/router/index'
import {checkAuthorization} from '@/utils/request' import {checkAuthorization} from '@/utils/request'
import {logout} from '@/services/user'
import NProgress from 'nprogress' import NProgress from 'nprogress'
NProgress.configure({ showSpinner: false }) NProgress.configure({ showSpinner: false })
@ -28,7 +29,8 @@ const progressStart = (to, from, next) => {
*/ */
const loginGuard = (to, from, next, options) => { const loginGuard = (to, from, next, options) => {
const {message} = options const {message} = options
if (!loginIgnore.includes(to) && !checkAuthorization()) { if (!checkAuthorization() && !loginIgnore.includes(to)) {
logout()
message.warning('登录已失效,请重新登录') message.warning('登录已失效,请重新登录')
next({path: '/login'}) next({path: '/login'})
} else { } else {

View File

@ -6,7 +6,8 @@ Vue.use(Router)
// 不需要登录拦截的路由配置 // 不需要登录拦截的路由配置
const loginIgnore = { const loginIgnore = {
names: ['404', '403'], //根据路由名称匹配 names: [],
//names: ['404', '403'], //根据路由名称匹配
paths: ['/login'], //根据路由fullPath匹配 paths: ['/login'], //根据路由fullPath匹配
/** /**
* 判断路由是否包含在该配置中 * 判断路由是否包含在该配置中

View File

@ -22,9 +22,6 @@ export async function getRoutesConfig() {
* 退出登录 * 退出登录
*/ */
export function logout() { export function logout() {
localStorage.removeItem(process.env.VUE_APP_ROUTES_KEY)
localStorage.removeItem(process.env.VUE_APP_PERMISSIONS_KEY)
localStorage.removeItem(process.env.VUE_APP_ROLES_KEY)
removeAuthorization() removeAuthorization()
} }
export default { export default {

View File

@ -1,3 +1,5 @@
import {getLocalStorage, setLocalStorage} from '@/utils/cache'
export default { export default {
namespaced: true, namespaced: true,
state: { state: {
@ -10,7 +12,7 @@ export default {
user: state => { user: state => {
if (!state.user) { if (!state.user) {
try { try {
const user = localStorage.getItem(process.env.VUE_APP_USER_KEY) const user = getLocalStorage(process.env.VUE_APP_USER_KEY)
state.user = JSON.parse(user) state.user = JSON.parse(user)
} catch (e) { } catch (e) {
console.error(e) console.error(e)
@ -21,7 +23,7 @@ export default {
permissions: state => { permissions: state => {
if (!state.permissions) { if (!state.permissions) {
try { try {
const permissions = localStorage.getItem(process.env.VUE_APP_PERMISSIONS_KEY) const permissions = getLocalStorage(process.env.VUE_APP_PERMISSIONS_KEY)
state.permissions = JSON.parse(permissions) state.permissions = JSON.parse(permissions)
state.permissions = state.permissions ? state.permissions : [] state.permissions = state.permissions ? state.permissions : []
} catch (e) { } catch (e) {
@ -33,7 +35,7 @@ export default {
roles: state => { roles: state => {
if (!state.roles) { if (!state.roles) {
try { try {
const roles = localStorage.getItem(process.env.VUE_APP_ROLES_KEY) const roles = getLocalStorage(process.env.VUE_APP_ROLES_KEY)
state.roles = JSON.parse(roles) state.roles = JSON.parse(roles)
state.roles = state.roles ? state.roles : [] state.roles = state.roles ? state.roles : []
} catch (e) { } catch (e) {
@ -45,7 +47,7 @@ export default {
routesConfig: state => { routesConfig: state => {
if (!state.routesConfig) { if (!state.routesConfig) {
try { try {
const routesConfig = localStorage.getItem(process.env.VUE_APP_ROUTES_KEY) const routesConfig = getLocalStorage(process.env.VUE_APP_ROUTES_KEY)
state.routesConfig = JSON.parse(routesConfig) state.routesConfig = JSON.parse(routesConfig)
state.routesConfig = state.routesConfig ? state.routesConfig : [] state.routesConfig = state.routesConfig ? state.routesConfig : []
} catch (e) { } catch (e) {
@ -58,19 +60,19 @@ export default {
mutations: { mutations: {
setUser (state, user) { setUser (state, user) {
state.user = user state.user = user
localStorage.setItem(process.env.VUE_APP_USER_KEY, JSON.stringify(user)) setLocalStorage(process.env.VUE_APP_USER_KEY, JSON.stringify(user))
}, },
setPermissions(state, permissions) { setPermissions(state, permissions) {
state.permissions = permissions state.permissions = permissions
localStorage.setItem(process.env.VUE_APP_PERMISSIONS_KEY, JSON.stringify(permissions)) setLocalStorage(process.env.VUE_APP_PERMISSIONS_KEY, JSON.stringify(permissions))
}, },
setRoles(state, roles) { setRoles(state, roles) {
state.roles = roles state.roles = roles
localStorage.setItem(process.env.VUE_APP_ROLES_KEY, JSON.stringify(roles)) setLocalStorage(process.env.VUE_APP_ROLES_KEY, JSON.stringify(roles))
}, },
setRoutesConfig(state, routesConfig) { setRoutesConfig(state, routesConfig) {
state.routesConfig = routesConfig state.routesConfig = routesConfig
localStorage.setItem(process.env.VUE_APP_ROUTES_KEY, JSON.stringify(routesConfig)) setLocalStorage(process.env.VUE_APP_ROUTES_KEY, JSON.stringify(routesConfig))
} }
} }
} }

View File

@ -1,4 +1,4 @@
import Cookie from 'js-cookie' import {getCookie} from '@/utils/cache'
// 401拦截 // 401拦截
const resp401 = { const resp401 = {
/** /**
@ -58,7 +58,7 @@ const reqCommon = {
onFulfilled(config, options) { onFulfilled(config, options) {
const {message} = options const {message} = options
const {url, xsrfCookieName} = config const {url, xsrfCookieName} = config
if (url.indexOf('login') === -1 && xsrfCookieName && !Cookie.get(xsrfCookieName)) { if (url.indexOf('login') === -1 && xsrfCookieName && !getCookie(xsrfCookieName)) {
message.warning('认证 token 已过期,请重新登录') message.warning('认证 token 已过期,请重新登录')
} }
return config return config

105
src/utils/cache.js Normal file
View File

@ -0,0 +1,105 @@
const Cookies = require('js-cookie')
const prefix = process.env.VUE_APP_NAME || 'vue-antd-admin'
// 动态获取cookie参数
const getCookieAttr = () => {
return {
path: process.env.BASE_URL || '/'
}
}
const ck = (key) => {
return prefix + "." + key;
}
// 设置cookie值
const setCookie = (key, value, options) => {
if (!key) {
return;
}
const cookieAttr = getCookieAttr()
if (options && typeof options === 'object') {
for (const key in options) {
cookieAttr[key] = options[key]
}
}
Cookies.set(ck(key), value, cookieAttr);
}
// 获取cookie值
const getCookie = (key) => {
if (!key) {
return;
}
return Cookies.get(ck(key));
}
// 删除cookie值
const removeCookie = (key) => {
if (!key) {
return;
}
return Cookies.remove(ck(key));
}
// 设置sessionStorage值
const setSessionStore = (key, value) => {
if (!key) {
return;
}
sessionStorage.setItem(ck(key), value);
}
// 获取sessionStorage值
const getSessionStore = (key) => {
if (!key) {
return;
}
return sessionStorage.getItem(ck(key));
}
// 删除sessionStorage值
const removeSessionStore = (key) => {
if (!key) {
return;
}
return sessionStorage.removeItem(ck(key));
}
// 设置localStorage值
const setLocalStorage = (key, value) => {
if (!key) {
return;
}
localStorage.setItem(ck(key), value);
}
// 获取localStorage值
const getLocalStorage = (key) => {
if (!key) {
return;
}
return localStorage.getItem(ck(key));
}
// 删除localStorage值
const removeLocalStorage = (key) => {
if (!key) {
return;
}
return localStorage.removeItem(ck(key));
}
module.exports = {
setCookie,
getCookie,
removeCookie,
setSessionStore,
getSessionStore,
removeSessionStore,
setLocalStorage,
getLocalStorage,
removeLocalStorage
}

View File

@ -1,5 +1,6 @@
import axios from 'axios' import axios from 'axios'
import Cookie from 'js-cookie' // import Cookie from 'js-cookie'
import {setCookie, getCookie, removeCookie, removeLocalStorage} from '@/utils/cache'
// 跨域认证信息 header 名 // 跨域认证信息 header 名
const xsrfHeaderName = 'Authorization' const xsrfHeaderName = 'Authorization'
@ -49,7 +50,7 @@ async function request(url, method, params, config) {
function setAuthorization(auth, authType = AUTH_TYPE.BEARER) { function setAuthorization(auth, authType = AUTH_TYPE.BEARER) {
switch (authType) { switch (authType) {
case AUTH_TYPE.BEARER: case AUTH_TYPE.BEARER:
Cookie.set(xsrfHeaderName, 'Bearer ' + auth.token, {expires: auth.expireAt}) setCookie(xsrfHeaderName, 'Bearer ' + auth.token, {expires: auth.expireAt})
break break
case AUTH_TYPE.BASIC: case AUTH_TYPE.BASIC:
case AUTH_TYPE.AUTH1: case AUTH_TYPE.AUTH1:
@ -66,7 +67,7 @@ function setAuthorization(auth, authType = AUTH_TYPE.BEARER) {
function removeAuthorization(authType = AUTH_TYPE.BEARER) { function removeAuthorization(authType = AUTH_TYPE.BEARER) {
switch (authType) { switch (authType) {
case AUTH_TYPE.BEARER: case AUTH_TYPE.BEARER:
Cookie.remove(xsrfHeaderName) removeCookie(xsrfHeaderName)
break break
case AUTH_TYPE.BASIC: case AUTH_TYPE.BASIC:
case AUTH_TYPE.AUTH1: case AUTH_TYPE.AUTH1:
@ -74,6 +75,10 @@ function removeAuthorization(authType = AUTH_TYPE.BEARER) {
default: default:
break break
} }
removeLocalStorage(process.env.VUE_APP_ROUTES_KEY)
removeLocalStorage(process.env.VUE_APP_PERMISSIONS_KEY)
removeLocalStorage(process.env.VUE_APP_ROLES_KEY)
removeLocalStorage(process.env.VUE_APP_USER_KEY)
} }
/** /**
@ -84,7 +89,7 @@ function removeAuthorization(authType = AUTH_TYPE.BEARER) {
function checkAuthorization(authType = AUTH_TYPE.BEARER) { function checkAuthorization(authType = AUTH_TYPE.BEARER) {
switch (authType) { switch (authType) {
case AUTH_TYPE.BEARER: case AUTH_TYPE.BEARER:
if (Cookie.get(xsrfHeaderName)) { if (getCookie(xsrfHeaderName)) {
return true return true
} }
break break

View File

@ -1,8 +1,10 @@
import routerMap from '@/router/async/router.map' import {initRouterMap} from '@/router/async/router.map'
import {mergeI18nFromRoutes} from '@/utils/i18n' import {mergeI18nFromRoutes} from '@/utils/i18n'
import Router from 'vue-router' import Router from 'vue-router'
import deepMerge from 'deepmerge' import deepMerge from 'deepmerge'
import basicOptions from '@/router/async/config.async' import basicOptions from '@/router/async/config.async'
import {getRoutesConfig} from '@/services/user'
import {checkAuthorization} from '@/utils/request'
//应用配置 //应用配置
let appOptions = { let appOptions = {
@ -89,6 +91,24 @@ function parseRoutes(routesConfig, routerMap) {
return routes return routes
} }
/**
* 初始化路由
* @param func function 回调方法
*/
function initRoutes(func) {
if (!checkAuthorization()) {
return
}
getRoutesConfig().then(result => {
if (result.data.data && result.data.data.length > 0) {
loadRoutes(result.data.data)
if (func){
func(result)
}
}
})
}
/** /**
* 加载路由 * 加载路由
* @param routesConfig {RouteConfig[]} 路由配置 * @param routesConfig {RouteConfig[]} 路由配置
@ -109,17 +129,35 @@ function loadRoutes(routesConfig) {
// 应用配置 // 应用配置
const {router, store, i18n} = appOptions const {router, store, i18n} = appOptions
// 如果 routesConfig 有值,则更新到本地,否则从本地获取 // 如果 routesConfig 不存在则重新加载
if (!routesConfig || routesConfig.length <= 0) {
routesConfig = store.getters['account/routesConfig']
if (!routesConfig || routesConfig.length <= 0){
initRoutes()
}
}
// 如果 routesConfig 有值,则更新到本地
if (routesConfig) { if (routesConfig) {
store.commit('account/setRoutesConfig', routesConfig) store.commit('account/setRoutesConfig', routesConfig)
} else {
routesConfig = store.getters['account/routesConfig']
} }
// 如果开启了异步路由,则加载异步路由配置 // 如果开启了异步路由,则加载异步路由配置
const asyncRoutes = store.state.setting.asyncRoutes const asyncRoutes = store.state.setting.asyncRoutes
if (asyncRoutes) { if (asyncRoutes) {
if (routesConfig && routesConfig.length > 0) { if (routesConfig && routesConfig.length > 0) {
const routes = parseRoutes(routesConfig, routerMap) const routes = parseRoutes(routesConfig, initRouterMap())
// 解决动态路由初始化时找不到首页
if (routes && routes.length > 0) {
const getFirstChild = (routes) => {
const route = routes[0]
let path = route.path
if (!route.children || route.children.length === 0) {
return path
}
return !(path) || path === '/' ? '/' + getFirstChild(route.children) : path + '/'+ getFirstChild(route.children)
}
const redirect = getFirstChild(routes)
routes[0].redirect = redirect
}
const finalRoutes = mergeRoutes(basicOptions.routes, routes) const finalRoutes = mergeRoutes(basicOptions.routes, routes)
formatRoutes(finalRoutes) formatRoutes(finalRoutes)
router.options = {...router.options, routes: finalRoutes} router.options = {...router.options, routes: finalRoutes}
@ -270,4 +308,4 @@ function loadGuards(guards, options) {
}) })
} }
export {parseRoutes, loadRoutes, formatAuthority, getI18nKey, loadGuards, deepMergeRoutes, formatRoutes, setAppOptions} export {parseRoutes, loadRoutes, initRoutes, formatAuthority, getI18nKey, loadGuards, deepMergeRoutes, formatRoutes, setAppOptions}

View File

@ -2,6 +2,7 @@ const client = require('webpack-theme-color-replacer/client')
const {theme} = require('../config') const {theme} = require('../config')
const {getMenuColors, getAntdColors, getThemeToggleColors, getFunctionalColors} = require('../utils/colors') const {getMenuColors, getAntdColors, getThemeToggleColors, getFunctionalColors} = require('../utils/colors')
const {ANTD} = require('../config/default') const {ANTD} = require('../config/default')
const {getLocalStorage} = require('./cache')
function getThemeColors(color, $theme) { function getThemeColors(color, $theme) {
const _color = color || theme.color const _color = color || theme.color
@ -82,7 +83,7 @@ function loadLocalTheme(localSetting) {
function getLocalSetting(loadTheme) { function getLocalSetting(loadTheme) {
let localSetting = {} let localSetting = {}
try { try {
const localSettingStr = localStorage.getItem(process.env.VUE_APP_SETTING_KEY) const localSettingStr = getLocalStorage(process.env.VUE_APP_SETTING_KEY)
localSetting = JSON.parse(localSettingStr) localSetting = JSON.parse(localSettingStr)
} catch (e) { } catch (e) {
console.error(e) console.error(e)

View File

@ -35,6 +35,7 @@ const assetsCDN = {
} }
module.exports = { module.exports = {
lintOnSave: isProd,
devServer: { devServer: {
// proxy: { // proxy: {
// '/api': { //此处要与 /services/api.js 中的 API_PROXY_PREFIX 值保持一致 // '/api': { //此处要与 /services/api.js 中的 API_PROXY_PREFIX 值保持一致