源文件
This commit is contained in:
26
src/store/modules/api.js
Normal file
26
src/store/modules/api.js
Normal file
@@ -0,0 +1,26 @@
|
||||
// 适配 Nginx 反向代理
|
||||
const baseUrl = process.env.VUE_APP_BASE_API === '/' ? '' : process.env.VUE_APP_BASE_API
|
||||
const api = {
|
||||
state: {
|
||||
// 部署包上传
|
||||
deployUploadApi: baseUrl + '/api/deploy/upload',
|
||||
// SQL脚本上传
|
||||
databaseUploadApi: baseUrl + '/api/database/upload',
|
||||
// 图片上传
|
||||
imagesUploadApi: baseUrl + '/api/localStorage/pictures',
|
||||
// 修改头像
|
||||
updateAvatarApi: baseUrl + '/api/users/updateAvatar',
|
||||
// 上传文件到七牛云
|
||||
qiNiuUploadApi: baseUrl + '/api/qiNiuContent',
|
||||
// Sql 监控
|
||||
sqlApi: baseUrl + '/druid/index.html',
|
||||
// swagger
|
||||
swaggerApi: baseUrl + '/doc.html',
|
||||
// 文件上传
|
||||
fileUploadApi: baseUrl + '/api/localStorage',
|
||||
// baseUrl,
|
||||
baseApi: baseUrl
|
||||
}
|
||||
}
|
||||
|
||||
export default api
|
||||
56
src/store/modules/app.js
Normal file
56
src/store/modules/app.js
Normal file
@@ -0,0 +1,56 @@
|
||||
import Cookies from 'js-cookie'
|
||||
|
||||
const state = {
|
||||
sidebar: {
|
||||
opened: Cookies.get('sidebarStatus') ? !!+Cookies.get('sidebarStatus') : true,
|
||||
withoutAnimation: false
|
||||
},
|
||||
device: 'desktop',
|
||||
size: Cookies.get('size') || 'default'
|
||||
}
|
||||
|
||||
const mutations = {
|
||||
TOGGLE_SIDEBAR: state => {
|
||||
state.sidebar.opened = !state.sidebar.opened
|
||||
state.sidebar.withoutAnimation = false
|
||||
if (state.sidebar.opened) {
|
||||
Cookies.set('sidebarStatus', 1)
|
||||
} else {
|
||||
Cookies.set('sidebarStatus', 0)
|
||||
}
|
||||
},
|
||||
CLOSE_SIDEBAR: (state, withoutAnimation) => {
|
||||
Cookies.set('sidebarStatus', 0)
|
||||
state.sidebar.opened = false
|
||||
state.sidebar.withoutAnimation = withoutAnimation
|
||||
},
|
||||
TOGGLE_DEVICE: (state, device) => {
|
||||
state.device = device
|
||||
},
|
||||
SET_SIZE: (state, size) => {
|
||||
state.size = size
|
||||
Cookies.set('size', size)
|
||||
}
|
||||
}
|
||||
|
||||
const actions = {
|
||||
toggleSideBar({ commit }) {
|
||||
commit('TOGGLE_SIDEBAR')
|
||||
},
|
||||
closeSideBar({ commit }, { withoutAnimation }) {
|
||||
commit('CLOSE_SIDEBAR', withoutAnimation)
|
||||
},
|
||||
toggleDevice({ commit }, device) {
|
||||
commit('TOGGLE_DEVICE', device)
|
||||
},
|
||||
setSize({ commit }, size) {
|
||||
commit('SET_SIZE', size)
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
namespaced: true,
|
||||
state,
|
||||
mutations,
|
||||
actions
|
||||
}
|
||||
83
src/store/modules/permission.js
Normal file
83
src/store/modules/permission.js
Normal file
@@ -0,0 +1,83 @@
|
||||
import { constantRouterMap } from '@/router/routers'
|
||||
import Layout from '@/layout/index'
|
||||
import ParentView from '@/components/ParentView'
|
||||
|
||||
const permission = {
|
||||
state: {
|
||||
routers: constantRouterMap,
|
||||
addRouters: [],
|
||||
sidebarRouters: []
|
||||
},
|
||||
mutations: {
|
||||
SET_ROUTERS: (state, routers) => {
|
||||
state.addRouters = routers
|
||||
state.routers = constantRouterMap.concat(routers)
|
||||
},
|
||||
SET_SIDEBAR_ROUTERS: (state, routers) => {
|
||||
state.sidebarRouters = constantRouterMap.concat(routers)
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
GenerateRoutes({ commit }, asyncRouter) {
|
||||
commit('SET_ROUTERS', asyncRouter)
|
||||
},
|
||||
SetSidebarRouters({ commit }, sidebarRouter) {
|
||||
commit('SET_SIDEBAR_ROUTERS', sidebarRouter)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const filterAsyncRouter = (routers, lastRouter = false, type = false) => { // 遍历后台传来的路由字符串,转换为组件对象
|
||||
return routers.filter(router => {
|
||||
if (type && router.children) {
|
||||
router.children = filterChildren(router.children)
|
||||
}
|
||||
if (router.component) {
|
||||
if (router.component === 'Layout') { // Layout组件特殊处理
|
||||
router.component = Layout
|
||||
} else if (router.component === 'ParentView') {
|
||||
router.component = ParentView
|
||||
} else {
|
||||
const component = router.component
|
||||
router.component = loadView(component)
|
||||
}
|
||||
}
|
||||
if (router.children != null && router.children && router.children.length) {
|
||||
router.children = filterAsyncRouter(router.children, router, type)
|
||||
} else {
|
||||
delete router['children']
|
||||
delete router['redirect']
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
function filterChildren(childrenMap, lastRouter = false) {
|
||||
var children = []
|
||||
childrenMap.forEach((el, index) => {
|
||||
if (el.children && el.children.length) {
|
||||
if (el.component === 'ParentView') {
|
||||
el.children.forEach(c => {
|
||||
c.path = el.path + '/' + c.path
|
||||
if (c.children && c.children.length) {
|
||||
children = children.concat(filterChildren(c.children, c))
|
||||
return
|
||||
}
|
||||
children.push(c)
|
||||
})
|
||||
return
|
||||
}
|
||||
}
|
||||
if (lastRouter) {
|
||||
el.path = lastRouter.path + '/' + el.path
|
||||
}
|
||||
children = children.concat(el)
|
||||
})
|
||||
return children
|
||||
}
|
||||
|
||||
export const loadView = (view) => {
|
||||
return (resolve) => require([`@/views/${view}`], resolve)
|
||||
}
|
||||
|
||||
export default permission
|
||||
36
src/store/modules/settings.js
Normal file
36
src/store/modules/settings.js
Normal file
@@ -0,0 +1,36 @@
|
||||
import variables from '@/assets/styles/element-variables.scss'
|
||||
import defaultSettings from '@/settings'
|
||||
const { tagsView, fixedHeader, sidebarLogo, showFooter, footerTxt, caseNumber } = defaultSettings
|
||||
|
||||
const state = {
|
||||
theme: variables.theme,
|
||||
showSettings: false,
|
||||
tagsView: tagsView,
|
||||
fixedHeader: fixedHeader,
|
||||
sidebarLogo: sidebarLogo,
|
||||
showFooter: showFooter,
|
||||
footerTxt: footerTxt,
|
||||
caseNumber: caseNumber
|
||||
}
|
||||
|
||||
const mutations = {
|
||||
CHANGE_SETTING: (state, { key, value }) => {
|
||||
if (state.hasOwnProperty(key)) {
|
||||
state[key] = value
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const actions = {
|
||||
changeSetting({ commit }, data) {
|
||||
commit('CHANGE_SETTING', data)
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
namespaced: true,
|
||||
state,
|
||||
mutations,
|
||||
actions
|
||||
}
|
||||
|
||||
165
src/store/modules/tagsView.js
Normal file
165
src/store/modules/tagsView.js
Normal file
@@ -0,0 +1,165 @@
|
||||
const state = {
|
||||
visitedViews: [],
|
||||
cachedViews: []
|
||||
}
|
||||
|
||||
const mutations = {
|
||||
ADD_VISITED_VIEW: (state, view) => {
|
||||
if (state.visitedViews.some(v => v.path === view.path)) return
|
||||
state.visitedViews.push(
|
||||
Object.assign({}, view, {
|
||||
title: view.meta.title || 'no-name'
|
||||
})
|
||||
)
|
||||
},
|
||||
ADD_CACHED_VIEW: (state, view) => {
|
||||
if (state.cachedViews.includes(view.name)) return
|
||||
if (!view.meta.noCache) {
|
||||
state.cachedViews.push(view.name)
|
||||
}
|
||||
},
|
||||
|
||||
DEL_VISITED_VIEW: (state, view) => {
|
||||
for (const [i, v] of state.visitedViews.entries()) {
|
||||
if (v.path === view.path) {
|
||||
state.visitedViews.splice(i, 1)
|
||||
break
|
||||
}
|
||||
}
|
||||
},
|
||||
DEL_CACHED_VIEW: (state, view) => {
|
||||
for (const i of state.cachedViews) {
|
||||
if (i === view.name) {
|
||||
const index = state.cachedViews.indexOf(i)
|
||||
state.cachedViews.splice(index, 1)
|
||||
break
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
DEL_OTHERS_VISITED_VIEWS: (state, view) => {
|
||||
state.visitedViews = state.visitedViews.filter(v => {
|
||||
return v.meta.affix || v.path === view.path
|
||||
})
|
||||
},
|
||||
DEL_OTHERS_CACHED_VIEWS: (state, view) => {
|
||||
for (const i of state.cachedViews) {
|
||||
if (i === view.name) {
|
||||
const index = state.cachedViews.indexOf(i)
|
||||
state.cachedViews = state.cachedViews.slice(index, index + 1)
|
||||
break
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
DEL_ALL_VISITED_VIEWS: state => {
|
||||
// keep affix tags
|
||||
const affixTags = state.visitedViews.filter(tag => tag.meta.affix)
|
||||
state.visitedViews = affixTags
|
||||
},
|
||||
DEL_ALL_CACHED_VIEWS: state => {
|
||||
state.cachedViews = []
|
||||
},
|
||||
|
||||
UPDATE_VISITED_VIEW: (state, view) => {
|
||||
for (let v of state.visitedViews) {
|
||||
if (v.path === view.path) {
|
||||
v = Object.assign(v, view)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const actions = {
|
||||
addView({ dispatch }, view) {
|
||||
dispatch('addVisitedView', view)
|
||||
dispatch('addCachedView', view)
|
||||
},
|
||||
addVisitedView({ commit }, view) {
|
||||
commit('ADD_VISITED_VIEW', view)
|
||||
},
|
||||
addCachedView({ commit }, view) {
|
||||
commit('ADD_CACHED_VIEW', view)
|
||||
},
|
||||
|
||||
delView({ dispatch, state }, view) {
|
||||
return new Promise(resolve => {
|
||||
dispatch('delVisitedView', view)
|
||||
dispatch('delCachedView', view)
|
||||
resolve({
|
||||
visitedViews: [...state.visitedViews],
|
||||
cachedViews: [...state.cachedViews]
|
||||
})
|
||||
})
|
||||
},
|
||||
delVisitedView({ commit, state }, view) {
|
||||
return new Promise(resolve => {
|
||||
commit('DEL_VISITED_VIEW', view)
|
||||
resolve([...state.visitedViews])
|
||||
})
|
||||
},
|
||||
delCachedView({ commit, state }, view) {
|
||||
return new Promise(resolve => {
|
||||
commit('DEL_CACHED_VIEW', view)
|
||||
resolve([...state.cachedViews])
|
||||
})
|
||||
},
|
||||
|
||||
delOthersViews({ dispatch, state }, view) {
|
||||
return new Promise(resolve => {
|
||||
dispatch('delOthersVisitedViews', view)
|
||||
dispatch('delOthersCachedViews', view)
|
||||
resolve({
|
||||
visitedViews: [...state.visitedViews],
|
||||
cachedViews: [...state.cachedViews]
|
||||
})
|
||||
})
|
||||
},
|
||||
delOthersVisitedViews({ commit, state }, view) {
|
||||
return new Promise(resolve => {
|
||||
commit('DEL_OTHERS_VISITED_VIEWS', view)
|
||||
resolve([...state.visitedViews])
|
||||
})
|
||||
},
|
||||
delOthersCachedViews({ commit, state }, view) {
|
||||
return new Promise(resolve => {
|
||||
commit('DEL_OTHERS_CACHED_VIEWS', view)
|
||||
resolve([...state.cachedViews])
|
||||
})
|
||||
},
|
||||
|
||||
delAllViews({ dispatch, state }, view) {
|
||||
return new Promise(resolve => {
|
||||
dispatch('delAllVisitedViews', view)
|
||||
dispatch('delAllCachedViews', view)
|
||||
resolve({
|
||||
visitedViews: [...state.visitedViews],
|
||||
cachedViews: [...state.cachedViews]
|
||||
})
|
||||
})
|
||||
},
|
||||
delAllVisitedViews({ commit, state }) {
|
||||
return new Promise(resolve => {
|
||||
commit('DEL_ALL_VISITED_VIEWS')
|
||||
resolve([...state.visitedViews])
|
||||
})
|
||||
},
|
||||
delAllCachedViews({ commit, state }) {
|
||||
return new Promise(resolve => {
|
||||
commit('DEL_ALL_CACHED_VIEWS')
|
||||
resolve([...state.cachedViews])
|
||||
})
|
||||
},
|
||||
|
||||
updateVisitedView({ commit }, view) {
|
||||
commit('UPDATE_VISITED_VIEW', view)
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
namespaced: true,
|
||||
state,
|
||||
mutations,
|
||||
actions
|
||||
}
|
||||
103
src/store/modules/user.js
Normal file
103
src/store/modules/user.js
Normal file
@@ -0,0 +1,103 @@
|
||||
import { login, getInfo, logout } from '@/api/login'
|
||||
import { getToken, setToken, removeToken } from '@/utils/auth'
|
||||
|
||||
const user = {
|
||||
state: {
|
||||
token: getToken(),
|
||||
user: {},
|
||||
roles: [],
|
||||
// 第一次加载菜单时用到
|
||||
loadMenus: false
|
||||
},
|
||||
|
||||
mutations: {
|
||||
// 是否为手动退出登录
|
||||
SD_LOGOUT: (state, f) => {
|
||||
state.sdLogout = f
|
||||
},
|
||||
SET_TOKEN: (state, token) => {
|
||||
state.token = token
|
||||
},
|
||||
SET_USER: (state, user) => {
|
||||
state.user = user
|
||||
},
|
||||
SET_ROLES: (state, roles) => {
|
||||
state.roles = roles
|
||||
},
|
||||
SET_LOAD_MENUS: (state, loadMenus) => {
|
||||
state.loadMenus = loadMenus
|
||||
}
|
||||
},
|
||||
|
||||
actions: {
|
||||
// 登录
|
||||
Login({ commit }, userInfo) {
|
||||
const rememberMe = userInfo.rememberMe
|
||||
return new Promise((resolve, reject) => {
|
||||
login(userInfo.username, userInfo.password, userInfo.code, userInfo.uuid).then(res => {
|
||||
// console.log('登录成功后返回===', res)
|
||||
localStorage.setItem('logoutHandle', false)
|
||||
localStorage.setItem('shopId', res.shopId)
|
||||
localStorage.setItem('shopName', res.shopName)
|
||||
localStorage.setItem('logo', res.logo)
|
||||
setToken(res.token, rememberMe)
|
||||
commit('SET_TOKEN', res.token)
|
||||
setUserInfo(res.user, commit)
|
||||
// 第一次加载菜单时用到, 具体见 src 目录下的 permission.js
|
||||
commit('SET_LOAD_MENUS', true)
|
||||
resolve()
|
||||
}).catch(error => {
|
||||
reject(error)
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
// 获取用户信息
|
||||
GetInfo({ commit }) {
|
||||
return new Promise((resolve, reject) => {
|
||||
getInfo().then(res => {
|
||||
setUserInfo(res, commit)
|
||||
resolve(res)
|
||||
}).catch(error => {
|
||||
reject(error)
|
||||
})
|
||||
})
|
||||
},
|
||||
// 登出
|
||||
LogOut({ commit }) {
|
||||
return new Promise((resolve, reject) => {
|
||||
logout().then(res => {
|
||||
logOut(commit)
|
||||
resolve()
|
||||
}).catch(error => {
|
||||
logOut(commit)
|
||||
reject(error)
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
updateLoadMenus({ commit }) {
|
||||
return new Promise((resolve, reject) => {
|
||||
commit('SET_LOAD_MENUS', false)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const logOut = (commit) => {
|
||||
commit('SET_TOKEN', '')
|
||||
commit('SET_ROLES', [])
|
||||
removeToken()
|
||||
}
|
||||
|
||||
export const setUserInfo = (res, commit) => {
|
||||
// 如果没有任何权限,则赋予一个默认的权限,避免请求死循环
|
||||
if (res.roles.length === 0) {
|
||||
commit('SET_ROLES', ['ROLE_SYSTEM_DEFAULT'])
|
||||
} else {
|
||||
commit('SET_ROLES', res.roles)
|
||||
}
|
||||
commit('SET_USER', res.user)
|
||||
}
|
||||
|
||||
export default user
|
||||
Reference in New Issue
Block a user