123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- import * as api from '@/api/index'
- import {getUserInfo, getUserRoleList} from "@/api/modules/ztpt";
- const state = {
- apiProxy: {
- ztptApi: 'api-ztpt', // 总体平台基本接口
- },
- userInfo: <any>{},
- userRoleList: [],
- zby: false,
- timestamp: new Date().getTime()
- }
- const getters = {
- isZBY: (state) => {
- return state.zby
- }
- }
- const mutations = {
- SET_USER_INFO(state: any, data: object) {
- state.userInfo = data
- },
- SET_USER_ROLE(state: any, data: object) {
- state.userRoleList = data
- },
- SET_TIMESTAMP(state: any, data: any) {
- state.timestamp = new Date(data).getTime()
- setInterval(() => {
- state.timestamp += 1000
- }, 1000)
- },
- }
- const actions = {
- LOAD_USER_INFO({ commit }: any, refresh: boolean = false) {
- return new Promise((resolve, reject) => {
- if (refresh || !state.userInfo?.userId) {
- Promise.all([
- getUserInfo(),
- getUserRoleList()
- ]).then(([u, r]) => {
- if (u.code === 0 && r.code === 0) {
- commit('SET_USER_INFO', u.userInfo)
- commit('SET_USER_ROLE', r.userRoleList)
- resolve({u: u.userInfo, r: r.userRoleList})
- } else {
- reject(u.msg || r.msg)
- }
- })
- } else {
- resolve(state.userInfo)
- }
- })
- },
- LOAD_TIMESTAMP({ commit }: any) {
- const date = new Date('2022-09-18 10:20:32')
- commit('SET_TIMESTAMP', date)
- },
- }
- export default {
- namespaced: true,
- state,
- getters,
- mutations,
- actions
- }
|