| ¶Ô±ÈÐÂÎļþ |
| | |
| | | import Vue from 'vue' |
| | | import Vuex from 'vuex' |
| | | import { |
| | | pageCount, |
| | | getTreeList, |
| | | getUserInfo |
| | | } from '@/util/api/index.js' |
| | | |
| | | Vue.use(Vuex) // vueçæä»¶æºå¶ |
| | | |
| | | const navHeight = uni.getStorageSync('navHeight'); |
| | | const statusbarHeight = uni.getStorageSync('statusbarHeight'); |
| | | const menuButtonWidth = uni.getStorageSync('menuButtonWidth'); |
| | | const token = uni.getStorageSync('token'); |
| | | const userInfo = uni.getStorageSync('userInfo'); |
| | | const Menu = uni.getStorageSync('MenuList'); |
| | | const session = uni.getStorageSync('session'); |
| | | |
| | | |
| | | // Vuex.Store æé å¨é项 |
| | | const store = new Vuex.Store({ |
| | | // 为äºä¸å页颿ç»ä»¶çdataä¸çé ææ··æ·ï¼stateä¸çåéåé¢å»ºè®®å ä¸$ç¬¦å· |
| | | state: { |
| | | // ç¨æ·ä¿¡æ¯ |
| | | userInfo: userInfo || null, |
| | | token: token || null, |
| | | menuButtonWidth: menuButtonWidth || '0', |
| | | statusbarHeight: statusbarHeight || '0', |
| | | navHeight: navHeight || '0', |
| | | session: session ? session : '', |
| | | // èåæé |
| | | Menu: Menu ? JSON.parse(Menu) : [], |
| | | // å¾
åæ°é |
| | | upcomingNum: { |
| | | d: 0, |
| | | y: 0 |
| | | }, |
| | | }, |
| | | mutations: { |
| | | setHeight(state, val) { |
| | | state.navHeight = val.navHeight |
| | | state.statusbarHeight = val.statusbarHeight |
| | | state.menuButtonWidth = val.menuButtonWidth |
| | | uni.setStorageSync('navHeight', val.navHeight); |
| | | uni.setStorageSync('statusbarHeight', val.statusbarHeight); |
| | | uni.setStorageSync('menuButtonWidth', val.menuButtonWidth); |
| | | }, |
| | | SETTOKEN(state, val) { |
| | | state.token = val |
| | | uni.setStorageSync('token', val); |
| | | }, |
| | | SETUSERINFO(state, val) { |
| | | state.userInfo = val |
| | | uni.setStorageSync('userInfo', val); |
| | | }, |
| | | SETNUM(state, val) { |
| | | state.upcomingNum.d = val.d |
| | | state.upcomingNum.y = val.y |
| | | }, |
| | | SETMENU(state, data) { |
| | | state.Menu = data |
| | | uni.setStorageSync('MenuList', JSON.stringify(data)); |
| | | }, |
| | | SETSESSION(state, data) { |
| | | state.session = data; |
| | | uni.setStorageSync('session', data); |
| | | }, |
| | | clearCache(state) { |
| | | state.userInfo = '' |
| | | state.token = '' |
| | | state.session = '' |
| | | state.Menu = [] |
| | | state.upcomingNum.d = 0 |
| | | state.upcomingNum.y = 0 |
| | | uni.clearStorageSync() |
| | | } |
| | | }, |
| | | actions: { |
| | | // åå端è·åèåæ æé |
| | | async getMenuList(content, type) { |
| | | let res = await getTreeList({ |
| | | type: type |
| | | }) |
| | | if (res.code === 200) { |
| | | content.commit('SETMENU', res.data) |
| | | } |
| | | }, |
| | | // è·åç¶æé«åº¦ |
| | | getHeight(context) { |
| | | let res = uni.getMenuButtonBoundingClientRect() |
| | | let status = uni.getSystemInfoSync() |
| | | let menuButtonWidth = res.width |
| | | let height = res.height |
| | | let statusbarHeight = status.statusBarHeight |
| | | let navHeight = res.height + (res.top - statusbarHeight) * 2; |
| | | context.commit('setHeight', { |
| | | statusbarHeight, |
| | | navHeight, |
| | | height, |
| | | menuButtonWidth |
| | | }) |
| | | }, |
| | | async getUpcomingNum(context) { |
| | | let res = await pageCount({}) |
| | | if (res.code === 200) { |
| | | context.commit('SETNUM', { |
| | | d: res.data.startNum, |
| | | y: res.data.endNum |
| | | }) |
| | | } |
| | | }, |
| | | // åå端è·åä¸ªäººä¿¡æ¯ |
| | | async getUserInfos(content) { |
| | | let res = await getUserInfo() |
| | | if (res.code === 200) { |
| | | content.commit('SETUSERINFO', res.data) |
| | | return true; |
| | | } |
| | | } |
| | | } |
| | | }) |
| | | |
| | | export default store |