Browse Source

修改存储store逻辑

fanghuisheng 11 months ago
parent
commit
b9d75601f4

+ 0 - 1
src/pages/business/common/fastMail/index.vue

@@ -70,7 +70,6 @@
 
 <script setup>
 import config from "@/config";
-import storage from "@/utils/storage";
 import { onLoad, onShow, onReady, onHide, onLaunch, onNavigationBarButtonTap, onPageScroll } from "@dcloudio/uni-app";
 import { ref, reactive, computed, getCurrentInstance, toRefs, inject } from "vue";
 import { useStores, commonStores } from "@/store/modules/index";

+ 0 - 1
src/pages/common/evaluate/index.vue

@@ -51,7 +51,6 @@
 
 <script setup>
 import config from "@/config";
-import storage from "@/utils/storage";
 import { onLoad, onShow, onReady, onHide, onLaunch, onNavigationBarButtonTap, onPageScroll } from "@dcloudio/uni-app";
 import { ref, reactive, computed, getCurrentInstance, toRefs, inject } from "vue";
 import { useStores, commonStores } from "@/store/modules/index";

+ 0 - 1
src/pages/common/nfc/index.vue

@@ -9,7 +9,6 @@
 
 <script setup>
 import config from "@/config";
-import storage from "@/utils/storage";
 import { onLoad, onShow, onReady, onHide, onLaunch, onUnload, onNavigationBarButtonTap, onPageScroll } from "@dcloudio/uni-app";
 import { ref, reactive, computed, getCurrentInstance, toRefs, inject, watch } from "vue";
 import { useStores, commonStores, xunJianStores } from "@/store/modules/index";

+ 0 - 1
src/pages/common/repairReport/index.vue

@@ -72,7 +72,6 @@
 
 <script setup>
 import config from "@/config";
-import storage from "@/utils/storage";
 import { onLoad, onShow, onReady, onHide, onLaunch, onNavigationBarButtonTap, onPageScroll } from "@dcloudio/uni-app";
 import { ref, reactive, computed, getCurrentInstance, toRefs, inject } from "vue";
 import { useStores, commonStores } from "@/store/modules/index";

+ 97 - 96
src/pages/index.vue

@@ -2,7 +2,6 @@
   <u-navbar :autoBack="false" :placeholder="true" :safeAreaInsetTop="true" :bgColor="proxy.$settingStore.themeColor.color">
     <template #left>
       <view class="u-navbar__content__left__item">
-        <!-- <u-icon name="arrow-left" size="19" color="#fff" style="display: none"></u-icon> -->
         <view class="u-navbar__content__left__item__title">应用中心</view>
       </view>
     </template>
@@ -39,32 +38,24 @@
                 <text class="transition-section-content-icon iconfont oaIcon-saoyisao"></text>
                 <view class="transition-section-content-text"> 扫一扫 </view>
               </view>
-              <!-- <div class="transition-section-divider"></div>
-              <view class="transition-section-content">
-                <text class="transition-section-content-icon iconfont oaIcon-saoyisao"></text>
-                <view class="transition-section-content-text">发起群聊 </view>
-              </view> -->
             </view>
           </view>
         </u-transition>
 
         <!-- 轮播图 -->
-        <u-swiper v-if="swiperBool" :list="swiperList" :interval="swiperTime" indicatorMode="line" radius="0" height="160" indicator circular keyName="url" @click="swiperClick" @change="swiperChange">
+        <u-swiper v-if="state.swiperBool" :list="state.swiperList" :interval="state.swiperTime" indicatorMode="line" radius="0" height="160" indicator circular keyName="url" @click="swiperClick">
         </u-swiper>
-        <image v-if="!swiperBool" style="width: 100%; height: 160px" src="@/static/images/index/banner1.png"></image>
+        <image v-if="!state.swiperBool" style="width: 100%; height: 160px" src="@/static/images/index/banner1.png"></image>
 
         <!-- 天气 -->
         <oa-weather ref="oaWeatherRef"></oa-weather>
 
         <!-- 最近使用宫格 -->
-        <view class="grid-area bg-white" v-if="recentlyUsed.length > 0">
+        <view class="grid-area bg-white" v-if="state.recentlyUsed.length > 0">
           <view class="grid-area_title">最近使用</view>
           <view class="grid-area_center cu-list grid col-5 no-border">
-            <view class="grid-area_center_item cu-item justify-center align-center" @tap="navItemClick(item)" v-for="(item, index) in recentlyUsed.slice(0, 5)" :key="index">
+            <view class="grid-area_center_item cu-item justify-center align-center" @tap="navItemClick(item)" v-for="(item, index) in state.recentlyUsed.slice(0, 5)" :key="index">
               <image class="grid-area_center_item_image" :src="item.meta.icon"></image>
-              <!-- <view class="cu-tag badge" v-if="item.badge != 0">
-                <block v-if="item.badge != 0">{{ item.badge > 99 ? "99+" : item.badge }}</block>
-              </view> -->
               <text class="grid-area_center_item_title">{{ item.meta.aliasTitle ? item.meta.aliasTitle : item.meta.title }}</text>
             </view>
           </view>
@@ -74,11 +65,8 @@
         <view class="grid-area bg-white">
           <view class="grid-area_title">常用功能</view>
           <view class="grid-area_center cu-list grid col-5 no-border">
-            <view class="grid-area_center_item cu-item justify-center align-center" @tap="navItemClick(item)" v-for="(item, index) in cuIconList" :key="index">
+            <view class="grid-area_center_item cu-item justify-center align-center" @tap="navItemClick(item)" v-for="(item, index) in state.cuIconList" :key="index">
               <image class="grid-area_center_item_image" :src="item.meta.icon"></image>
-              <!-- <view class="cu-tag badge" v-if="item.badge != 0">
-                <block v-if="item.badge != 0">{{ item.badge > 99 ? "99+" : item.badge }}</block>
-              </view> -->
               <text class="grid-area_center_item_title">{{ item.meta.aliasTitle ? item.meta.aliasTitle : item.meta.title }}</text>
             </view>
           </view>
@@ -91,18 +79,22 @@
 </template>
 
 <script setup>
+/*----------------------------------依赖引入-----------------------------------*/
 import { onReady, onLoad, onShow, onNavigationBarButtonTap, onPullDownRefresh, onReachBottom } from "@dcloudio/uni-app";
 import { ref, onMounted, inject, shallowRef, reactive, getCurrentInstance, toRefs, nextTick } from "vue";
-import { useStores, commonStores } from "@/store/modules/index";
-
+/*----------------------------------接口引入-----------------------------------*/
 import { scan_push, getHomePageData, getFunctionalModuleStatistics, getAppRouters, qrCodeSend, getMobileBanner } from "@/api/index";
+/*----------------------------------组件引入-----------------------------------*/
+/*----------------------------------store引入-----------------------------------*/
+import { useStores, stystemStores } from "@/store/modules/index";
+/*----------------------------------公共方法引入-----------------------------------*/
 import * as jwx from "@/utils/jssdk.js"; //引入js sdk的封装
-
-const useStore = useStores();
-const commonStore = commonStores(); //全局公共Store
+import { storage_stystem } from "@/utils/storage"; // 公共方法引用
+/*----------------------------------公共变量-----------------------------------*/
 const { proxy } = getCurrentInstance();
-
-const arrayList = reactive({
+const useStore = useStores();
+/*----------------------------------变量声明-----------------------------------*/
+const state = reactive({
   dialogFlag: false,
 
   swiperBool: false,
@@ -114,23 +106,32 @@ const arrayList = reactive({
   recentlyUsed: [],
 });
 
-const { dialogFlag, swiperBool, swiperIndex, swiperTime, swiperList, cuIconList, recentlyUsed } = toRefs(arrayList);
+const { dialogFlag } = toRefs(state);
 
 /**
- * @获取轮播图下标
- * @change事件
+ * @初始化
  */
-function swiperChange(e) {
-  swiperIndex.value = e.current;
+function init() {
+  //#ifdef H5
+  // if (proxy.$common.isWechatMp()) {
+  //   window.location.href = proxy.$BASE_URL + "/service-iot/weChat/getPageAuthorization";
+  // }
+  //#endif
+
+  nextTick(() => {
+    getAppRoutersData(); //调用路由信息接口
+    getMobileBannerApi(); //调用banner图接口
+    getLocation(); //调用获取地理位置方法
+  });
 }
 
 /**
  * @轮播图点击事件
  */
 function swiperClick(list) {
-  if (typeof swiperList.value[list] == "object") {
-    let linkType = swiperList.value[list].linkType;
-    let url = swiperList.value[list].link;
+  if (typeof state.swiperList[list] == "object") {
+    let linkType = state.swiperList[list].linkType;
+    let url = state.swiperList[list].link;
 
     if (url) {
       if (linkType == 1) {
@@ -146,6 +147,48 @@ function swiperClick(list) {
   }
 }
 
+/**
+ * @九宫格页面跳转
+ */
+function navItemClick(item) {
+  if (item.path) {
+    item.sort = 0;
+
+    state.recentlyUsed.push(item);
+    state.recentlyUsed = proxy.$common.uniq(state.recentlyUsed, "path");
+    state.recentlyUsed.filter((el) => {
+      if (el.path === item.path) {
+        el.meta.icon = item.meta.icon;
+        el.sort++;
+      }
+    });
+    state.recentlyUsed = proxy.$common.sortEvent(state.recentlyUsed, 1);
+
+    storage_stystem.set("homeList", state);
+
+    if (item.path.indexOf("http") != -1) {
+      uni.navigateTo({
+        url: "/pages/common/webview/index?url=" + item.path,
+      });
+    } else {
+      uni.navigateTo({
+        url: item.path,
+      });
+    }
+  } else {
+    uni.showModal({
+      title: "Tips",
+      content: "此模块开发中~",
+      showCancel: false,
+      success: function (res) {
+        if (res.confirm) {
+        } else if (res.cancel) {
+        }
+      },
+    });
+  }
+}
+
 // function connected() {
 //   refresh();
 //   uni.setNavigationBarColor({
@@ -163,9 +206,7 @@ function swiperClick(list) {
  * @scrollView刷新数据
  */
 function refresh() {
-  getAppRoutersData(); //调用路由信息接口
-  getMobileBannerApi(); //调用banner图接口
-  getLocation(); //调用获取地理位置方法
+  init();
 }
 
 /**
@@ -206,8 +247,8 @@ function scanCode() {
       });
       qrCodeSend({
         qrCode: list.uid,
-        tenantId: useStore.$state.tenantId,
-        userName: useStore.$state.name,
+        tenantId: useStore.tenantId,
+        userName: useStore.name,
       }).then((res) => {});
     },
     fail: (err) => {
@@ -252,48 +293,6 @@ function getLocation() {
   //#endif
 }
 
-/**
- * @九宫格页面跳转
- */
-function navItemClick(item) {
-  if (item.path) {
-    item.sort = 0;
-
-    recentlyUsed.value.push(item);
-    recentlyUsed.value = proxy.$common.uniq(recentlyUsed.value, "path");
-    recentlyUsed.value.filter((el) => {
-      if (el.path === item.path) {
-        el.meta.icon = item.meta.icon;
-        el.sort++;
-      }
-    });
-    recentlyUsed.value = commonStore.sortEvent(recentlyUsed.value, 1);
-
-    uni.setStorageSync(useStore.$state.nickName + useStore.$state.tenantId, recentlyUsed.value);
-
-    if (item.path.indexOf("http") != -1) {
-      uni.navigateTo({
-        url: "/pages/common/webview/index?url=" + item.path,
-      });
-    } else {
-      uni.navigateTo({
-        url: item.path,
-      });
-    }
-  } else {
-    uni.showModal({
-      title: "Tips",
-      content: "此模块开发中~",
-      showCancel: false,
-      success: function (res) {
-        if (res.confirm) {
-        } else if (res.cancel) {
-        }
-      },
-    });
-  }
-}
-
 /**
  * @右侧按钮点击事件
  */
@@ -307,16 +306,16 @@ function rightButtonClick() {
  */
 function getMobileBannerApi() {
   getMobileBanner({
-    tenantId: useStore.$state.tenantId,
+    tenantId: useStore.tenantId,
   }).then((res) => {
     if (res.data.length > 0) {
-      swiperList.value = [];
-      swiperBool.value = res.data[0].openNot == 1 ? true : false;
-      swiperTime.value = res.data[0].carouselTime * 1000;
+      state.swiperList = [];
+      state.swiperBool = res.data[0].openNot == 1 ? true : false;
+      state.swiperTime = res.data[0].carouselTime * 1000;
 
       for (let i = 1; i <= 5; i++) {
         if (res.data[0]["bannerPath" + i]) {
-          swiperList.value.push({
+          state.swiperList.push({
             url: res.data[0]["bannerPath" + i],
             link: res.data[0]["linkUrl" + i],
             linkType: res.data[0]["linkType" + i],
@@ -334,26 +333,28 @@ function getMobileBannerApi() {
  */
 function getAppRoutersData() {
   getAppRouters().then((res) => {
-    cuIconList.value = res.data;
+    state.cuIconList = res.data;
+    storage_stystem.set("homeList", state);
+
+    // plus.downloader
+    //   .createDownload("http://172.16.120.165:9300/statics/202312/20231201113810A027.jpg", {}, (d, status) => {
+    //     status != 200 && console.log("error");
+    //     console.log("Download success: " + d.filename);
+    //   })
+    //   .start();
   });
 }
 
 onLoad((option) => {
   uni.hideTabBar(); //隐藏自带tabbar
-
-  nextTick(() => {
-    getAppRoutersData(); //调用路由信息接口
-    getMobileBannerApi(); //调用banner图接口
-    getLocation(); //调用获取地理位置方法
-  });
+  init();
 });
 
 onShow(() => {
-  if (uni.getStorageSync(useStore.$state.nickName + useStore.$state.tenantId)) {
-    recentlyUsed.value = uni.getStorageSync(useStore.$state.nickName + useStore.$state.tenantId);
-  } else {
-    recentlyUsed.value = [];
-  }
+  var storages = storage_stystem.get("homeList");
+  Object.keys(storages).forEach((key) => {
+    state[key] = storages[key];
+  });
 });
 </script>
 

+ 9 - 5
src/pages/login.vue

@@ -17,7 +17,7 @@
         <!--#endif-->
       </view>
 
-      <view class="middle-input" v-if="switchText == '账号密码登录'">
+      <view class="middle-input" v-if="switchText == '验证码登录'">
         <u-input v-model="phone" prefixIcon="phone" placeholder="请输入手机号" :maxlength="11" />
 
         <u-input v-model="verify" prefixIcon="email" placeholder="请输入验证码" :maxlength="6">
@@ -27,7 +27,7 @@
         </u-input>
       </view>
 
-      <view class="middle-input" v-if="switchText == '验证码登录'">
+      <view class="middle-input" v-if="switchText == '账号密码登录'">
         <u-input type="text" v-model="username" prefixIcon="account" placeholder="请输入账号" />
 
         <u-input v-model="password" prefixIcon="lock" placeholder="请输入密码" :password="inputIconBool">
@@ -40,7 +40,7 @@
       <button class="middle-submit" @click="submitRes">登 录</button>
 
       <view class="middle-switch">
-        <text class="switch-loginMethod" @click="switchMode(1)">{{ switchText }}</text>
+        <text class="switch-loginMethod" @click="switchMode(1)">{{ switchText === "验证码登录" ? "账号密码登录" : "验证码登录" }}</text>
         <view style="margin: auto"></view>
         <text class="switch-register" @click="switchMode(2)">注册账号</text>
       </view>
@@ -104,7 +104,7 @@ function goSeverConfig() {
  */
 function switchMode(value) {
   if (value == 1) {
-    switchText.value == "验证码登录" ? (switchText.value = "账号密码登录") : (switchText.value = "验证码登录");
+    switchText.value = switchText.value == "验证码登录" ? "账号密码登录" : "验证码登录";
   } else if (value == 2) {
     proxy.$tab.navigateTo("/pages/register");
   }
@@ -137,6 +137,10 @@ function init() {
   useStore.SetInterval("codeTime"); //调用倒计时定时器
 
   //#ifdef H5
+  if (proxy.$common.isWechatMp()) {
+    window.location.href = proxy.$BASE_URL + "/service-iot/weChat/getFirst1";
+  }
+
   if (window.location.host) {
     linkUrl.value = window.location.host;
     // linkUrl.value = "172.16.120.165:13200";
@@ -175,7 +179,7 @@ function submitRes() {
   }
   //#endif
 
-  if (switchText.value == "账号密码登录") {
+  if (switchText.value == "验证码登录") {
     if (!phone.value) {
       proxy.$modal.msg("请输入手机号");
       return;

+ 1 - 2
src/pages/mine.vue

@@ -11,7 +11,7 @@
           <view class="login-tip" v-if="!data.nickName" @click="proxy.$settingStore.handleToLogin()"> 点击登录 </view>
           <view class="user-info" v-if="data.nickName">
             <view class="u_title"> {{ data.nickName }} </view>
-            <view class="u_title"> {{ data.phone }} </view>
+            <view class="u_title"> {{ data.phone ? data.phone.substr(0, 3) + "******" + data.phone.substr(9) : "" }} </view>
           </view>
         </view>
         <view class="flex align-center"> </view>
@@ -166,7 +166,6 @@
 
 <script setup>
 import config from "@/config";
-import storage from "@/utils/storage";
 import { onLoad, onShow, onReady, onHide, onLaunch, onNavigationBarButtonTap, onPageScroll } from "@dcloudio/uni-app";
 import { ref, reactive, computed, getCurrentInstance, toRefs, inject } from "vue";
 import { useStores, commonStores } from "@/store/modules/index";

+ 0 - 1
src/pages/mine/info/index.vue

@@ -125,7 +125,6 @@
 
 <script setup>
 import config from "@/config";
-import storage from "@/utils/storage";
 import { onLoad, onShow, onReady, onHide, onLaunch, onNavigationBarButtonTap, onPageScroll } from "@dcloudio/uni-app";
 import { ref, reactive, computed, getCurrentInstance, toRefs, inject } from "vue";
 import { useStores, commonStores } from "@/store/modules/index";

+ 0 - 1
src/pages/mine/secure/index.vue

@@ -114,7 +114,6 @@
 
 <script setup>
 import config from "@/config";
-import storage from "@/utils/storage";
 import { onLoad, onShow, onReady, onHide, onLaunch, onNavigationBarButtonTap, onPageScroll } from "@dcloudio/uni-app";
 import { ref, reactive, computed, getCurrentInstance, toRefs, inject } from "vue";
 import { useStores, commonStores } from "@/store/modules/index";

+ 1 - 1
src/store/modules/setting.js

@@ -1,7 +1,7 @@
 
 import { defineStore } from "pinia";
 import config from "@/config";
-import storage from "@/utils/storage";
+import { storage } from "@/utils/storage";
 import modal from "@/plugins/modal.plugins.js";
 import tab from "@/plugins/tab.plugins.js";
 import setting from "@/plugins/setting.plugins.js";

+ 4 - 2
src/store/modules/user.js

@@ -1,4 +1,4 @@
-import storage from "@/utils/storage";
+import { storage } from "@/utils/storage";
 import { getToken, setToken, removeToken } from "@/utils/auth";
 import { defineStore } from "pinia";
 // 接口引用
@@ -11,6 +11,7 @@ import modal from "@/plugins/modal.plugins.js";
 const useStores = defineStore("useStores", {
   state: () => ({
     token: getToken(),
+    userId: storage.get("userId"),//用户ID
     name: storage.get("name"),//用户名称
     nickName: storage.get("nickName"),//用户昵称
     phonenumber: storage.get("phonenumber"),//用户手机号
@@ -93,6 +94,7 @@ const useStores = defineStore("useStores", {
             }
 
             this.SET_STORAGE_OBJECT_KEYS({
+              userId: data.user.userId,//用户ID
               name: data.user.userName,//用户名称
               nickName: data.user.nickName,//用户昵称
               phonenumber: data.user.phonenumber ? data.user.phonenumber.substr(0, 3) + "******" + data.user.phonenumber.substr(9) : "",//手机号码
@@ -298,8 +300,8 @@ const useStores = defineStore("useStores", {
     },
     SET_STORAGE_OBJECT_KEYS(LIST) {
       Object.keys(LIST).forEach(function (key) {
-        useStores().$state[key] = LIST[key];
         storage.set(key, LIST[key]);
+        useStores().$state[key] = LIST[key];
       });
     },
   },

+ 2 - 2
src/store/modules/xunJian.js

@@ -3,9 +3,9 @@ import { defineStore } from "pinia";
 // 接口引用
 import { updatePlan } from "@/api/business/mhxf/xunJian/plan.js";
 // 公共方法引用
-import storage from "@/utils/storage";
+import { storage } from "@/utils/storage";
 
-const xunJianStore = defineStore(`${storage.get("nickName") + storage.get("tenantId")}_storage-xunJian`, {
+const xunJianStore = defineStore(`${storage.get("userId")}_storage-xunJian`, {
   state: () => ({
     planTabs: 0, //巡检计划页 tabs切换值
     siteId: null, //巡检计划页 站点id

+ 1 - 5
src/utils/request.js

@@ -18,11 +18,7 @@ function verification(res, resolve, reject) {
 
   if (code === 401) {
     //#ifdef H5
-    if (common.isWechatMp()) {
-      uni.reLaunch({ url: "/pages/register" });
-    } else {
-      uni.reLaunch({ url: "/pages/login" });
-    }
+    uni.reLaunch({ url: "/pages/login" });
     //#endif
 
     //#ifdef APP-PLUS || MP-WEIXIN

+ 24 - 7
src/utils/storage.js

@@ -1,9 +1,7 @@
+import { useStores, stystemStores } from "@/store/modules/index";
 // 存储变量名
 let storageKey = 'storage_data'
 
-// 存储的数据
-let storageData = uni.getStorageSync(storageKey) || {}
-
 const storage = {
   set: function (key, value) {
     let tmp = uni.getStorageSync(storageKey)
@@ -12,15 +10,34 @@ const storage = {
     uni.setStorageSync(storageKey, tmp)
   },
   get: function (key) {
-    return storageData[key] || ""
+    return uni.getStorageSync(storageKey)[key] || ""
   },
   remove: function (key) {
-    delete storageData[key]
-    uni.setStorageSync(storageKey, storageData)
+    delete uni.getStorageSync(storageKey)[key]
+    uni.setStorageSync(storageKey, uni.getStorageSync(storageKey))
   },
   clean: function () {
     uni.removeStorageSync(storageKey)
   }
 }
 
-export default storage
+const storage_stystem = {
+  set: function (key, value) {
+    let tmp = uni.getStorageSync(useStores().userId + "_storage_common")
+    tmp = tmp ? tmp : {}
+    tmp[key] = value
+    uni.setStorageSync(useStores().userId + "_storage_common", tmp)
+  },
+  get: function (key) {
+    return uni.getStorageSync(useStores().userId + "_storage_common")[key] || ""
+  },
+  remove: function (key) {
+    delete uni.getStorageSync(useStores().userId + "_storage_common")[key]
+    uni.setStorageSync(useStores().userId + "_storage_common", uni.getStorageSync(useStores().userId + "_storage_common"))
+  },
+  clean: function () {
+    uni.removeStorageSync(useStores().userId + "_storage_common")
+  }
+}
+
+export { storage, storage_stystem }