修改系统
This commit is contained in:
		
							
								
								
									
										56
									
								
								stdiet-ui/src/store/modules/app.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										56
									
								
								stdiet-ui/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') || 'medium' | ||||
| } | ||||
|  | ||||
| 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 | ||||
| } | ||||
							
								
								
									
										54
									
								
								stdiet-ui/src/store/modules/permission.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										54
									
								
								stdiet-ui/src/store/modules/permission.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,54 @@ | ||||
| import { constantRoutes } from '@/router' | ||||
| import { getRouters } from '@/api/menu' | ||||
| import Layout from '@/layout/index' | ||||
|  | ||||
| const permission = { | ||||
|   state: { | ||||
|     routes: [], | ||||
|     addRoutes: [] | ||||
|   }, | ||||
|   mutations: { | ||||
|     SET_ROUTES: (state, routes) => { | ||||
|       state.addRoutes = routes | ||||
|       state.routes = constantRoutes.concat(routes) | ||||
|     } | ||||
|   }, | ||||
|   actions: { | ||||
|     // 生成路由 | ||||
|     GenerateRoutes({ commit }) { | ||||
|       return new Promise(resolve => { | ||||
|         // 向后端请求路由数据 | ||||
|         getRouters().then(res => { | ||||
|           const accessedRoutes = filterAsyncRouter(res.data) | ||||
|           accessedRoutes.push({ path: '*', redirect: '/404', hidden: true }) | ||||
|           commit('SET_ROUTES', accessedRoutes) | ||||
|           resolve(accessedRoutes) | ||||
|         }) | ||||
|       }) | ||||
|     } | ||||
|   } | ||||
| } | ||||
|  | ||||
| // 遍历后台传来的路由字符串,转换为组件对象 | ||||
| function filterAsyncRouter(asyncRouterMap) { | ||||
|   return asyncRouterMap.filter(route => { | ||||
|     if (route.component) { | ||||
|       // Layout组件特殊处理 | ||||
|       if (route.component === 'Layout') { | ||||
|         route.component = Layout | ||||
|       } else { | ||||
|         route.component = loadView(route.component) | ||||
|       } | ||||
|     } | ||||
|     if (route.children != null && route.children && route.children.length) { | ||||
|       route.children = filterAsyncRouter(route.children) | ||||
|     } | ||||
|     return true | ||||
|   }) | ||||
| } | ||||
|  | ||||
| export const loadView = (view) => { // 路由懒加载 | ||||
|   return (resolve) =>  require([`@/views/${view}`], resolve) | ||||
| } | ||||
|  | ||||
| export default permission | ||||
							
								
								
									
										34
									
								
								stdiet-ui/src/store/modules/settings.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								stdiet-ui/src/store/modules/settings.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,34 @@ | ||||
| import variables from '@/assets/styles/element-variables.scss' | ||||
| import defaultSettings from '@/settings' | ||||
|  | ||||
| const { showSettings, tagsView, fixedHeader, sidebarLogo } = defaultSettings | ||||
|  | ||||
| const state = { | ||||
|   theme: variables.theme, | ||||
|   showSettings: showSettings, | ||||
|   tagsView: tagsView, | ||||
|   fixedHeader: fixedHeader, | ||||
|   sidebarLogo: sidebarLogo | ||||
| } | ||||
|  | ||||
| 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 | ||||
| } | ||||
|  | ||||
							
								
								
									
										159
									
								
								stdiet-ui/src/store/modules/tagsView.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										159
									
								
								stdiet-ui/src/store/modules/tagsView.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,159 @@ | ||||
| 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) => { | ||||
|     const index = state.cachedViews.indexOf(view.name) | ||||
|     index > -1 && state.cachedViews.splice(index, 1) | ||||
|   }, | ||||
|  | ||||
|   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) => { | ||||
|     const index = state.cachedViews.indexOf(view.name) | ||||
|     if (index > -1) { | ||||
|       state.cachedViews = state.cachedViews.slice(index, index + 1) | ||||
|     } else { | ||||
|       state.cachedViews = [] | ||||
|     } | ||||
|   }, | ||||
|  | ||||
|   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 | ||||
| } | ||||
							
								
								
									
										96
									
								
								stdiet-ui/src/store/modules/user.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										96
									
								
								stdiet-ui/src/store/modules/user.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,96 @@ | ||||
| import { login, logout, getInfo } from '@/api/login' | ||||
| import { getToken, setToken, removeToken } from '@/utils/auth' | ||||
|  | ||||
| const user = { | ||||
|   state: { | ||||
|     token: getToken(), | ||||
|     name: '', | ||||
|     avatar: '', | ||||
|     roles: [], | ||||
|     permissions: [] | ||||
|   }, | ||||
|  | ||||
|   mutations: { | ||||
|     SET_TOKEN: (state, token) => { | ||||
|       state.token = token | ||||
|     }, | ||||
|     SET_NAME: (state, name) => { | ||||
|       state.name = name | ||||
|     }, | ||||
|     SET_AVATAR: (state, avatar) => { | ||||
|       state.avatar = avatar | ||||
|     }, | ||||
|     SET_ROLES: (state, roles) => { | ||||
|       state.roles = roles | ||||
|     }, | ||||
|     SET_PERMISSIONS: (state, permissions) => { | ||||
|       state.permissions = permissions | ||||
|     } | ||||
|   }, | ||||
|  | ||||
|   actions: { | ||||
|     // 登录 | ||||
|     Login({ commit }, userInfo) { | ||||
|       const username = userInfo.username.trim() | ||||
|       const password = userInfo.password | ||||
|       const code = userInfo.code | ||||
|       const uuid = userInfo.uuid | ||||
|       return new Promise((resolve, reject) => { | ||||
|         login(username, password, code, uuid).then(res => { | ||||
|           setToken(res.token) | ||||
|           commit('SET_TOKEN', res.token) | ||||
|           resolve() | ||||
|         }).catch(error => { | ||||
|           reject(error) | ||||
|         }) | ||||
|       }) | ||||
|     }, | ||||
|  | ||||
|     // 获取用户信息 | ||||
|     GetInfo({ commit, state }) { | ||||
|       return new Promise((resolve, reject) => { | ||||
|         getInfo(state.token).then(res => { | ||||
|           const user = res.user | ||||
|           const avatar = user.avatar == "" ? require("@/assets/image/profile.jpg") : process.env.VUE_APP_BASE_API + user.avatar; | ||||
|           if (res.roles && res.roles.length > 0) { // 验证返回的roles是否是一个非空数组 | ||||
|             commit('SET_ROLES', res.roles) | ||||
|             commit('SET_PERMISSIONS', res.permissions) | ||||
|           } else { | ||||
|             commit('SET_ROLES', ['ROLE_DEFAULT']) | ||||
|           } | ||||
|           commit('SET_NAME', user.userName) | ||||
|           commit('SET_AVATAR', avatar) | ||||
|           resolve(res) | ||||
|         }).catch(error => { | ||||
|           reject(error) | ||||
|         }) | ||||
|       }) | ||||
|     }, | ||||
|      | ||||
|     // 退出系统 | ||||
|     LogOut({ commit, state }) { | ||||
|       return new Promise((resolve, reject) => { | ||||
|         logout(state.token).then(() => { | ||||
|           commit('SET_TOKEN', '') | ||||
|           commit('SET_ROLES', []) | ||||
|           commit('SET_PERMISSIONS', []) | ||||
|           removeToken() | ||||
|           resolve() | ||||
|         }).catch(error => { | ||||
|           reject(error) | ||||
|         }) | ||||
|       }) | ||||
|     }, | ||||
|  | ||||
|     // 前端 登出 | ||||
|     FedLogOut({ commit }) { | ||||
|       return new Promise(resolve => { | ||||
|         commit('SET_TOKEN', '') | ||||
|         removeToken() | ||||
|         resolve() | ||||
|       }) | ||||
|     } | ||||
|   } | ||||
| } | ||||
|  | ||||
| export default user | ||||
		Reference in New Issue
	
	Block a user