MrShi
2025-08-21 a223d5e29e9384f720ae98c44cbe10f8fa4f73e7
small-program/store/index.js
@@ -5,12 +5,21 @@
const navHeight = uni.getStorageSync('navHeight');
const statusbarHeight = uni.getStorageSync('statusbarHeight');
const userInfo = uni.getStorageSync('userInfo');
const token = uni.getStorageSync('token');
const openid = uni.getStorageSync('openid');
const store = new Vuex.Store({
   
   state: {
      navHeight: navHeight || '',
      statusbarHeight: statusbarHeight || ''
      statusbarHeight: statusbarHeight || '',
      userInfo: userInfo || {},
      token: token || '',
      openid: token || '',
      latitude: '',
      longitude: ''
   },
   mutations: {
      // 设置导航栏高度
@@ -19,6 +28,34 @@
         state.statusbarHeight = val.statusbarHeight
         uni.setStorageSync('navHeight', val.navHeight);
         uni.setStorageSync('statusbarHeight', val.statusbarHeight);
      },
      // 设置token
      setToken(state, val) {
         state.token = val
         uni.setStorageSync('token', val);
      },
      // 设置token
      setOpenid(state, val) {
         state.openid = val
         uni.setStorageSync('openid', val);
      },
      // 设置用户信息
      setUserInfo(state, val) {
         state.userInfo = val
         uni.setStorageSync('userInfo', val);
      },
      // 设置经纬度
      setPosition(state, obj) {
         console.log(obj)
         state.latitude = obj.latitude
         state.longitude = obj.longitude
      },
      // 清除缓存数据
      empty(state) {
         state.userInfo = ''
         state.token = ''
         uni.removeStorageSync('token');
         uni.removeStorageSync('userInfo');
      }
   },