| | |
| | | import Vue from 'vue'
|
| | | import Vuex from 'vuex' |
| | | import { pageCount } 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'); |
| | |
|
| | |
|
| | | // 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', |
| | | // 待办数量 |
| | | 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 |
| | | }
|
| | | },
|
| | | actions: {
|
| | | // 获取状态高度
|
| | | 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() { |
| | | let res = await pageCount({}) |
| | | if (res.code === 200) { |
| | | content.commit('SETNUM', { d: res.data.startNum, y: res.data.endNum }) |
| | | } |
| | | } |
| | | }
|
| | | })
|
| | |
|
| | | export default store |