init
This commit is contained in:
+2
-1
@@ -1,4 +1,5 @@
|
||||
/**
|
||||
* @author chuzhixin 1204505056@qq.com (不想保留author可删除)
|
||||
* @description 导入所有 vuex 模块,自动加入namespaced:true,用于解决vuex命名冲突,请勿修改。
|
||||
*/
|
||||
|
||||
@@ -16,6 +17,6 @@ Object.keys(modules).forEach((key) => {
|
||||
modules[key]['namespaced'] = true
|
||||
})
|
||||
const store = new Vuex.Store({
|
||||
modules
|
||||
modules,
|
||||
})
|
||||
export default store
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* @author chuzhixin 1204505056@qq.com (不想保留author可删除)
|
||||
* @description 异常捕获的状态拦截,请勿修改
|
||||
*/
|
||||
|
||||
const state = () => ({
|
||||
errorLogs: [],
|
||||
})
|
||||
const getters = {
|
||||
errorLogs: (state) => state.errorLogs,
|
||||
}
|
||||
const mutations = {
|
||||
addErrorLog(state, errorLog) {
|
||||
state.errorLogs.push(errorLog)
|
||||
},
|
||||
clearErrorLog: (state) => {
|
||||
state.errorLogs.splice(0)
|
||||
},
|
||||
}
|
||||
const actions = {
|
||||
addErrorLog({ commit }, errorLog) {
|
||||
commit('addErrorLog', errorLog)
|
||||
},
|
||||
clearErrorLog({ commit }) {
|
||||
commit('clearErrorLog')
|
||||
},
|
||||
}
|
||||
export default { state, getters, mutations, actions }
|
||||
@@ -0,0 +1,52 @@
|
||||
/**
|
||||
* @author chuzhixin 1204505056@qq.com (不想保留author可删除)
|
||||
* @description 路由拦截状态管理,目前两种模式:all模式与intelligence模式,其中partialRoutes是菜单暂未使用
|
||||
*/
|
||||
import { asyncRoutes, constantRoutes } from '@/router'
|
||||
import { getRouterList } from '@/api/router'
|
||||
import { convertRouter, filterAsyncRoutes } from '@/utils/handleRoutes'
|
||||
import { routes } from '@/config'
|
||||
|
||||
const state = () => ({
|
||||
routes: [],
|
||||
partialRoutes: [],
|
||||
})
|
||||
const getters = {
|
||||
routes: (state) => state.routes,
|
||||
partialRoutes: (state) => state.partialRoutes,
|
||||
}
|
||||
const mutations = {
|
||||
setRoutes(state, routes) {
|
||||
state.routes = constantRoutes.concat(routes)
|
||||
},
|
||||
setAllRoutes(state, routes) {
|
||||
state.routes = constantRoutes.concat(routes)
|
||||
},
|
||||
setPartialRoutes(state, routes) {
|
||||
state.partialRoutes = constantRoutes.concat(routes)
|
||||
},
|
||||
}
|
||||
const actions = {
|
||||
async setRoutes({ commit }, permissions) {
|
||||
//开源版只过滤动态路由permissions,admin不再默认拥有全部权限
|
||||
const finallyAsyncRoutes = await filterAsyncRoutes(
|
||||
[...asyncRoutes],
|
||||
permissions
|
||||
)
|
||||
commit('setRoutes', finallyAsyncRoutes)
|
||||
return finallyAsyncRoutes
|
||||
},
|
||||
async setAllRoutes({ commit }) {
|
||||
// let { data } = await getRouterList()
|
||||
let data = routes
|
||||
data.push({ path: '*', redirect: '/404', hidden: true })
|
||||
let accessRoutes = convertRouter(data)
|
||||
commit('setAllRoutes', accessRoutes)
|
||||
return accessRoutes
|
||||
},
|
||||
setPartialRoutes({ commit }, accessRoutes) {
|
||||
commit('setPartialRoutes', accessRoutes)
|
||||
return accessRoutes
|
||||
},
|
||||
}
|
||||
export default { state, getters, mutations, actions }
|
||||
@@ -0,0 +1,75 @@
|
||||
/**
|
||||
* @author chuzhixin 1204505056@qq.com (不想保留author可删除)
|
||||
* @description 所有全局配置的状态管理,如无必要请勿修改
|
||||
*/
|
||||
|
||||
import defaultSettings from '@/config'
|
||||
|
||||
const { tabsBar, logo, layout, header, themeBar } = defaultSettings
|
||||
const theme =
|
||||
JSON.parse(localStorage.getItem('vue-admin-beautiful-theme')) || ''
|
||||
const state = () => ({
|
||||
tabsBar: theme.tabsBar || tabsBar,
|
||||
logo,
|
||||
collapse: false,
|
||||
layout: theme.layout || layout,
|
||||
header: theme.header || header,
|
||||
device: 'desktop',
|
||||
themeBar,
|
||||
})
|
||||
const getters = {
|
||||
collapse: (state) => state.collapse,
|
||||
device: (state) => state.device,
|
||||
header: (state) => state.header,
|
||||
layout: (state) => state.layout,
|
||||
logo: (state) => state.logo,
|
||||
tabsBar: (state) => state.tabsBar,
|
||||
themeBar: (state) => state.themeBar,
|
||||
}
|
||||
const mutations = {
|
||||
changeLayout: (state, layout) => {
|
||||
if (layout) state.layout = layout
|
||||
},
|
||||
changeHeader: (state, header) => {
|
||||
if (header) state.header = header
|
||||
},
|
||||
changeTabsBar: (state, tabsBar) => {
|
||||
if (tabsBar) state.tabsBar = tabsBar
|
||||
},
|
||||
changeCollapse: (state) => {
|
||||
state.collapse = !state.collapse
|
||||
},
|
||||
foldSideBar: (state) => {
|
||||
state.collapse = true
|
||||
},
|
||||
openSideBar: (state) => {
|
||||
state.collapse = false
|
||||
},
|
||||
toggleDevice: (state, device) => {
|
||||
state.device = device
|
||||
},
|
||||
}
|
||||
const actions = {
|
||||
changeLayout({ commit }, layout) {
|
||||
commit('changeLayout', layout)
|
||||
},
|
||||
changeHeader({ commit }, header) {
|
||||
commit('changeHeader', header)
|
||||
},
|
||||
changeTabsBar({ commit }, tabsBar) {
|
||||
commit('changeTabsBar', tabsBar)
|
||||
},
|
||||
changeCollapse({ commit }) {
|
||||
commit('changeCollapse')
|
||||
},
|
||||
foldSideBar({ commit }) {
|
||||
commit('foldSideBar')
|
||||
},
|
||||
openSideBar({ commit }) {
|
||||
commit('openSideBar')
|
||||
},
|
||||
toggleDevice({ commit }, device) {
|
||||
commit('toggleDevice', device)
|
||||
},
|
||||
}
|
||||
export default { state, getters, mutations, actions }
|
||||
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* @author chuzhixin 1204505056@qq.com (不想保留author可删除)
|
||||
* @description 代码生成机状态管理
|
||||
*/
|
||||
|
||||
const state = () => ({
|
||||
srcCode: '',
|
||||
})
|
||||
const getters = {
|
||||
srcTableCode: (state) => state.srcCode,
|
||||
}
|
||||
|
||||
const mutations = {
|
||||
setTableCode(state, srcCode) {
|
||||
state.srcCode = srcCode
|
||||
},
|
||||
}
|
||||
const actions = {
|
||||
setTableCode({ commit }, srcCode) {
|
||||
commit('setTableCode', srcCode)
|
||||
},
|
||||
}
|
||||
export default { state, getters, mutations, actions }
|
||||
@@ -0,0 +1,112 @@
|
||||
/**
|
||||
* @author chuzhixin 1204505056@qq.com (不想保留author可删除)
|
||||
* @description tabsBar多标签页逻辑,前期借鉴了很多开源项目发现都有个共同的特点很繁琐并不符合框架设计的初衷,后来在github用户hipi的启发下完成了重构,请勿修改
|
||||
*/
|
||||
|
||||
const state = () => ({
|
||||
visitedRoutes: [],
|
||||
})
|
||||
const getters = {
|
||||
visitedRoutes: (state) => state.visitedRoutes,
|
||||
}
|
||||
const mutations = {
|
||||
addVisitedRoute(state, route) {
|
||||
let target = state.visitedRoutes.find((item) => item.path === route.path)
|
||||
if (target) {
|
||||
if (route.fullPath !== target.fullPath) Object.assign(target, route)
|
||||
return
|
||||
}
|
||||
state.visitedRoutes.push(Object.assign({}, route))
|
||||
},
|
||||
delVisitedRoute(state, route) {
|
||||
state.visitedRoutes.forEach((item, index) => {
|
||||
if (item.path === route.path) state.visitedRoutes.splice(index, 1)
|
||||
})
|
||||
},
|
||||
delOthersVisitedRoute(state, route) {
|
||||
state.visitedRoutes = state.visitedRoutes.filter(
|
||||
(item) => item.meta.affix || item.path === route.path
|
||||
)
|
||||
},
|
||||
delLeftVisitedRoute(state, route) {
|
||||
let index = state.visitedRoutes.length
|
||||
state.visitedRoutes = state.visitedRoutes.filter((item) => {
|
||||
if (item.name === route.name) index = state.visitedRoutes.indexOf(item)
|
||||
return item.meta.affix || index <= state.visitedRoutes.indexOf(item)
|
||||
})
|
||||
},
|
||||
delRightVisitedRoute(state, route) {
|
||||
let index = state.visitedRoutes.length
|
||||
state.visitedRoutes = state.visitedRoutes.filter((item) => {
|
||||
if (item.name === route.name) index = state.visitedRoutes.indexOf(item)
|
||||
return item.meta.affix || index >= state.visitedRoutes.indexOf(item)
|
||||
})
|
||||
},
|
||||
delAllVisitedRoutes(state) {
|
||||
state.visitedRoutes = state.visitedRoutes.filter((item) => item.meta.affix)
|
||||
},
|
||||
updateVisitedRoute(state, route) {
|
||||
state.visitedRoutes.forEach((item) => {
|
||||
if (item.path === route.path) item = Object.assign(item, route)
|
||||
})
|
||||
},
|
||||
}
|
||||
const actions = {
|
||||
addVisitedRoute({ commit }, route) {
|
||||
commit('addVisitedRoute', route)
|
||||
},
|
||||
async delRoute({ dispatch, state }, route) {
|
||||
await dispatch('delVisitedRoute', route)
|
||||
return {
|
||||
visitedRoutes: [...state.visitedRoutes],
|
||||
}
|
||||
},
|
||||
delVisitedRoute({ commit, state }, route) {
|
||||
commit('delVisitedRoute', route)
|
||||
return [...state.visitedRoutes]
|
||||
},
|
||||
async delOthersRoutes({ dispatch, state }, route) {
|
||||
await dispatch('delOthersVisitedRoute', route)
|
||||
return {
|
||||
visitedRoutes: [...state.visitedRoutes],
|
||||
}
|
||||
},
|
||||
async delLeftRoutes({ dispatch, state }, route) {
|
||||
await dispatch('delLeftVisitedRoute', route)
|
||||
return {
|
||||
visitedRoutes: [...state.visitedRoutes],
|
||||
}
|
||||
},
|
||||
async delRightRoutes({ dispatch, state }, route) {
|
||||
await dispatch('delRightVisitedRoute', route)
|
||||
return {
|
||||
visitedRoutes: [...state.visitedRoutes],
|
||||
}
|
||||
},
|
||||
delOthersVisitedRoute({ commit, state }, route) {
|
||||
commit('delOthersVisitedRoute', route)
|
||||
return [...state.visitedRoutes]
|
||||
},
|
||||
delLeftVisitedRoute({ commit, state }, route) {
|
||||
commit('delLeftVisitedRoute', route)
|
||||
return [...state.visitedRoutes]
|
||||
},
|
||||
delRightVisitedRoute({ commit, state }, route) {
|
||||
commit('delRightVisitedRoute', route)
|
||||
return [...state.visitedRoutes]
|
||||
},
|
||||
async delAllRoutes({ dispatch, state }, route) {
|
||||
await dispatch('delAllVisitedRoutes', route)
|
||||
return {
|
||||
visitedRoutes: [...state.visitedRoutes],
|
||||
}
|
||||
},
|
||||
delAllVisitedRoutes({ commit, state }) {
|
||||
commit('delAllVisitedRoutes')
|
||||
return [...state.visitedRoutes]
|
||||
},
|
||||
updateVisitedRoute({ commit }, route) {
|
||||
commit('updateVisitedRoute', route)
|
||||
},
|
||||
}
|
||||
export default { state, getters, mutations, actions }
|
||||
+101
-5
@@ -1,12 +1,108 @@
|
||||
/**
|
||||
* @author chuzhixin 1204505056@qq.com (不想保留author可删除)
|
||||
* @description 登录、获取用户信息、退出登录、清除accessToken逻辑,不建议修改
|
||||
*/
|
||||
|
||||
import Vue from 'vue'
|
||||
import { getUserInfo, login, logout } from '@/api/user'
|
||||
import {
|
||||
getAccessToken,
|
||||
removeAccessToken,
|
||||
setAccessToken,
|
||||
} from '@/utils/accessToken'
|
||||
import { resetRouter } from '@/router'
|
||||
import { title, tokenName, routes } from '@/config'
|
||||
|
||||
const state = () => ({})
|
||||
const getters = {}
|
||||
const mutations = {}
|
||||
const actions = {}
|
||||
|
||||
const state = () => ({
|
||||
accessToken: getAccessToken(),
|
||||
username: '',
|
||||
avatar: '',
|
||||
permissions: [],
|
||||
})
|
||||
const getters = {
|
||||
accessToken: (state) => state.accessToken,
|
||||
username: (state) => state.username,
|
||||
avatar: (state) => state.avatar,
|
||||
permissions: (state) => state.permissions,
|
||||
}
|
||||
const mutations = {
|
||||
setAccessToken(state, accessToken) {
|
||||
state.accessToken = accessToken
|
||||
setAccessToken(accessToken)
|
||||
},
|
||||
setUsername(state, username) {
|
||||
state.username = username
|
||||
},
|
||||
setAvatar(state, avatar) {
|
||||
state.avatar = avatar
|
||||
},
|
||||
setPermissions(state, permissions) {
|
||||
state.permissions = permissions
|
||||
},
|
||||
}
|
||||
const actions = {
|
||||
setPermissions({ commit }, permissions) {
|
||||
commit('setPermissions', permissions)
|
||||
},
|
||||
async login({ commit }, userInfo) {
|
||||
// const { data } = await login(userInfo)
|
||||
// const accessToken = data[tokenName]
|
||||
const accessToken = 'test_20210420'
|
||||
if (accessToken) {
|
||||
commit('setAccessToken', accessToken)
|
||||
const hour = new Date().getHours()
|
||||
const thisTime =
|
||||
hour < 8
|
||||
? '早上好'
|
||||
: hour <= 11
|
||||
? '上午好'
|
||||
: hour <= 13
|
||||
? '中午好'
|
||||
: hour < 18
|
||||
? '下午好'
|
||||
: '晚上好'
|
||||
Vue.prototype.$baseNotify(`欢迎登录${title}`, `${thisTime}!`)
|
||||
} else {
|
||||
Vue.prototype.$baseMessage(
|
||||
`登录接口异常,未正确返回${tokenName}...`,
|
||||
'error'
|
||||
)
|
||||
}
|
||||
},
|
||||
async getUserInfo({ commit, state }) {
|
||||
// const { data } = await getUserInfo(state.accessToken)
|
||||
const data = {
|
||||
permissions: ['admin'],
|
||||
username: 'admin',
|
||||
'avatar|1': [
|
||||
'https://i.gtimg.cn/club/item/face/img/2/15922_100.gif',
|
||||
'https://i.gtimg.cn/club/item/face/img/8/15918_100.gif',
|
||||
],
|
||||
}
|
||||
if (!data) {
|
||||
Vue.prototype.$baseMessage('验证失败,请重新登录...', 'error')
|
||||
return false
|
||||
}
|
||||
let { permissions, username, avatar } = data
|
||||
if (permissions && username && Array.isArray(permissions)) {
|
||||
commit('setPermissions', permissions)
|
||||
commit('setUsername', username)
|
||||
commit('setAvatar', avatar)
|
||||
return permissions
|
||||
} else {
|
||||
Vue.prototype.$baseMessage('用户信息接口异常', 'error')
|
||||
return false
|
||||
}
|
||||
},
|
||||
async logout({ dispatch }) {
|
||||
await logout(state.accessToken)
|
||||
await dispatch('resetAccessToken')
|
||||
await resetRouter()
|
||||
},
|
||||
resetAccessToken({ commit }) {
|
||||
commit('setPermissions', [])
|
||||
commit('setAccessToken', '')
|
||||
removeAccessToken()
|
||||
},
|
||||
}
|
||||
export default { state, getters, mutations, actions }
|
||||
|
||||
Reference in New Issue
Block a user