From 64b432916af9c9218ab3f3eca614e26c542142ae Mon Sep 17 00:00:00 2001
From: jiangping <jp@doumee.com>
Date: 星期二, 07 十一月 2023 15:47:13 +0800
Subject: [PATCH] bug
---
minipro_standard/store/index.js | 123 +++++++++++++++++++++++++++++++++++++++++
1 files changed, 123 insertions(+), 0 deletions(-)
diff --git a/minipro_standard/store/index.js b/minipro_standard/store/index.js
new file mode 100644
index 0000000..c3e919e
--- /dev/null
+++ b/minipro_standard/store/index.js
@@ -0,0 +1,123 @@
+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涓殑閫犳垚娣锋穯锛宻tate涓殑鍙橀噺鍓嶉潰寤鸿鍔犱笂$绗﹀彿
+ 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
\ No newline at end of file
--
Gitblit v1.9.3