vue3版本初版上线 自测已可用

This commit is contained in:
piexlmax
2021-08-26 12:45:41 +08:00
parent adc7f567f9
commit 265e42f513
81 changed files with 4478 additions and 18639 deletions
+3 -4
View File
@@ -1,17 +1,16 @@
import Vue from 'vue'
import Vuex from 'vuex'
import { createStore } from 'vuex'
import VuexPersistence from 'vuex-persist'
import { user } from '@/store/module/user'
import { router } from '@/store/module/router'
import { dictionary } from '@/store/module/dictionary'
Vue.use(Vuex)
const vuexLocal = new VuexPersistence({
storage: window.localStorage,
modules: ['user']
})
export const store = new Vuex.Store({
export const store = createStore({
modules: {
user,
router,
+3 -3
View File
@@ -3,18 +3,18 @@ import { findSysDictionary } from '@/api/sysDictionary'
export const dictionary = {
namespaced: true,
state: {
dictionaryMap: {}
dictionaryMap: {},
},
mutations: {
setDictionaryMap(state, dictionaryMap) {
state.dictionaryMap = { ...state.dictionaryMap, ...dictionaryMap }
}
},
},
actions: {
// 从后台获取动态路由
async getDictionary({ commit, state }, type) {
if (state.dictionaryMap[type]) {
if (state.dictionaryMap[type] && state.dictionaryMap[type].length) {
return state.dictionaryMap[type]
} else {
const res = await findSysDictionary({ type })
+8 -11
View File
@@ -3,11 +3,13 @@ import { asyncRouterHandle } from '@/utils/asyncRouter'
import { asyncMenu } from '@/api/menu'
const routerList = []
const formatRouter = (routes) => {
routes && routes.map(item => {
if ((!item.children || item.children.every(ch => ch.hidden)) && item.name !== '404') {
if ((!item.children || item.children.every(ch => ch.hidden)) && item.name !== '404' && !item.hidden) {
routerList.push({ label: item.meta.title, value: item.name })
}
item.meta.hidden = item.hidden
if (item.children && item.children.length > 0) {
formatRouter(item.children)
}
@@ -18,7 +20,7 @@ export const router = {
namespaced: true,
state: {
asyncRouters: [],
routerList: routerList
routerList: routerList,
},
mutations: {
setRouterList(state, routerList) {
@@ -42,24 +44,22 @@ export const router = {
children: []
}]
const asyncRouterRes = await asyncMenu()
if (asyncRouterRes.code !== 0) {
return
}
const asyncRouter = asyncRouterRes.data && asyncRouterRes.data.menus
const asyncRouter = asyncRouterRes.data.menus
asyncRouter.push({
path: '404',
name: '404',
hidden: true,
meta: {
title: '迷路了*。*'
title: '迷路了*。*',
},
component: 'view/error/index.vue'
})
formatRouter(asyncRouter)
baseRouter[0].children = asyncRouter
baseRouter.push({
path: '*',
path: '/:catchAll(.*)',
redirect: '/layout/404'
})
asyncRouterHandle(baseRouter)
commit('setAsyncRouter', baseRouter)
@@ -74,9 +74,6 @@ export const router = {
},
routerList(state) {
return state.routerList
},
defaultRouter(state) {
return state.defaultRouter
}
}
}
+8 -7
View File
@@ -2,7 +2,7 @@ import { login, getUserInfo } from '@/api/user'
import { jsonInBlacklist } from '@/api/jwt'
import router from '@/router/index'
import { setUserInfo } from '@/api/user'
import { Message } from 'element-ui'
import { ElMessage } from 'element-plus'
export const user = {
namespaced: true,
@@ -16,7 +16,7 @@ export const user = {
activeColor: '#1890ff',
baseColor: '#fff'
},
token: ''
token: '',
},
mutations: {
setUserInfo(state, userInfo) {
@@ -70,7 +70,9 @@ export const user = {
commit('setToken', res.data.token)
await dispatch('router/SetAsyncRouter', {}, { root: true })
const asyncRouters = rootGetters['router/asyncRouters']
router.addRoutes(asyncRouters)
asyncRouters.map(asyncRouter => {
router.addRoute(asyncRouter)
})
// const redirect = router.history.current.query.redirect
// console.log(redirect)
// if (redirect) {
@@ -91,7 +93,7 @@ export const user = {
const res = await setUserInfo({ activeColor: data, ID: state.userInfo.ID })
if (res.code === 0) {
commit('ChangeActiveColor', data)
Message({
ElMessage({
type: 'success',
message: '设置成功'
})
@@ -101,7 +103,7 @@ export const user = {
const res = await setUserInfo({ sideMode: data, ID: state.userInfo.ID })
if (res.code === 0) {
commit('ChangeSideMode', data)
Message({
ElMessage({
type: 'success',
message: '设置成功'
})
@@ -111,7 +113,7 @@ export const user = {
const res = await setUserInfo({ baseColor: data, ID: state.userInfo.ID })
if (res.code === 0) {
commit('ChangeBaseColor', data)
Message({
ElMessage({
type: 'success',
message: '设置成功'
})
@@ -152,6 +154,5 @@ export const user = {
}
return state.userInfo.activeColor
}
}
}