123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- import frameworkApi from '@/api/framework'
- import storage from '@/framework/utils/storage'
- import axios from 'axios'
- import authutils from '../../utils/authutils'
- const KEY_MENU_SELECTED = 'menu_selected'
- const KEY_PROJECT_SELECTED = 'global_project_selected'
- const KEY_PAGE_BRANDCRUMB = 'page_brandcrumb'
- export default {
- namespaced: true,
- state: {
- sidebarClosed: false,
- sidebarSelected: '', // sidebar选中的选项
- userInfo: null, //{ username: 'admin' },
- permissions: { "system:role:delete": true, "system:role:create": true, "system:role:query": true, "system:role:setOpts": true },
- projectId: 'Pj4201050001',
- projects: [{ name: '风雅园', id: 'Pj1101010001' }, { name: '亚心医院', id: 'Pj4201050001' }],
- breadcrumb: [],
- secret: "saga123456", //密码
- userId: "test", //用户id
- },
- getters: {
- sidebarClosed: state => state.sidebarClosed,
- secret: state => state.secret,
- userId: state => state.userId,
- sidebarSelected: state => {
- // if (!state.pageSidebarSelected) {
- // let menu = storage.get(KEY_MENU_SELECTED)
- // if (menu) {
- // state.pageSidebarSelected = menu
- // }
- // }
- // return state.pageSidebarSelected
- return state.sidebarSelected
- },
- userInfo: state => state.userInfo,
- permissions: state => state.permissions,
- projects: state => state.projects,
- projectId: state => {
- if (!state.projectId) {
- let pid = storage.get(KEY_PROJECT_SELECTED)
- if (pid) {
- state.projectId = pid
- }
- }
- return state.projectId
- },
- breadcrumb: state => {
- if (!state.breadcrumb) {
- let arr = storage.get(KEY_PAGE_BRANDCRUMB)
- if (arr) {
- state.breadcrumb = arr
- }
- }
- return state.breadcrumb
- }
- },
- mutations: {
- setSidebarClosed: (state, val) => (state.sidebarClosed = val),
- setSidebarSelected: (state, val) => {
- state.sidebarSelected = val
- storage.set(KEY_MENU_SELECTED, val)
- },
- setprojectId: (state, val) => {
- state.projectId = val
- localStorage.setItem('projectId', val)
- storage.set(KEY_PROJECT_SELECTED, val)
- }
- },
- actions: {
- loadUserInfo({ state }) {
- console.log(state)
- return new Promise((resolve, reject) => {
- frameworkApi.loadUserInfo().then(resp => {
- console.log(resp)
- if (resp.result == 'success') {
- state.userInfo = { username: resp.username }
- state.permissions = {}
- if (resp.permissions) {
- resp.permissions.forEach(p => (state.permissions[p] = true))
- }
- state.projects = []
- if (resp.projects) {
- resp.projects.forEach(proj =>
- state.projects.push({
- id: proj.projId,
- name: proj.projLocalName
- })
- )
- }
- } else {
- state.userInfo = null
-
- }
- resolve(resp)
- })
- })
- },
- setBreadcrumb: {
- root: true,
- handler({ state }, val) {
- state.breadcrumb = []
- state.breadcrumb = val
- storage.set(KEY_PAGE_BRANDCRUMB, val)
- }
- }
- }
- }
|