Browse Source

微信单点登录

fanghuisheng 11 months ago
parent
commit
1fe92e830d

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

@@ -3,7 +3,7 @@
     <view class="nfc-container-image">
       <image class="nfc-gif" src="@/static/images/common/nfc-flash.gif" mode="aspectFit" style="width: 230px"></image>
     </view>
-    <view class="nfc-container-text">{{ commonStore.nfcWaiting }}</view>
+    <view class="nfc-container-text">{{ proxy.$settingStore.nfcWaiting }}</view>
   </view>
 </template>
 
@@ -11,13 +11,8 @@
 import config from "@/config";
 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";
 
 const { proxy } = getCurrentInstance();
-const commonStore = commonStores();
-
-const data = reactive({});
-const {} = toRefs(data);
 
 onLoad((options) => {
   // 开启nfc监听

+ 7 - 8
src/pages/index.vue

@@ -86,7 +86,7 @@ import { ref, onMounted, inject, shallowRef, reactive, getCurrentInstance, toRef
 import { scan_push, getHomePageData, getFunctionalModuleStatistics, getAppRouters, qrCodeSend, getMobileBanner } from "@/api/index";
 /*----------------------------------组件引入-----------------------------------*/
 /*----------------------------------store引入-----------------------------------*/
-import { useStores, stystemStores } from "@/store/modules/index";
+import { useStores } from "@/store/modules/index";
 /*----------------------------------公共方法引入-----------------------------------*/
 import * as jwx from "@/utils/jssdk.js"; //引入js sdk的封装
 import { storageStystem } from "@/utils/storage"; // 公共方法引用
@@ -112,17 +112,15 @@ const { dialogFlag } = toRefs(state);
  * @初始化
  */
 function init() {
-  //#ifdef H5
-  if (proxy.$common.isWechatMp()) {
-    window.location.href = proxy.$BASE_URL + "/service-iot/weChat/getPageAuthorization";
-  }
-  //#endif
+  setTimeout(() => {
+    //#ifdef H5
+    useStore.GetWxOpenId(2); //调用获取微信公众号openId
+    //#endif
 
-  nextTick(() => {
     getAppRoutersData(); //调用路由信息接口
     getMobileBannerApi(); //调用banner图接口
     getLocation(); //调用获取地理位置方法
-  });
+  }, 50);
 }
 
 /**
@@ -190,6 +188,7 @@ function navItemClick(item) {
 }
 
 // function connected() {
+
 //   refresh();
 //   uni.setNavigationBarColor({
 //     frontColor: "#FFFFFF", //字体颜色

+ 24 - 19
src/pages/login.vue

@@ -10,7 +10,6 @@
 
       <view class="middle-content">
         <text class="title" :style="{ color: useStore.loginBg ? '#FFFFFF' : '#000000' }">请登录</text>
-
         <!-- #ifdef APP-PLUS || MP-WEIXIN -->
         <view class="prompt" v-if="!linkUrl">首次账号登录请先配置服务器</view>
         <view class="setting" @tap="goSeverConfig"> 配置服务器 </view>
@@ -19,7 +18,6 @@
 
       <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">
           <template #suffix>
             <button class="verify" @click="getVerifyCode">{{ !useStore.codeTime ? "获取验证码" : useStore.codeTime + "s" }}</button>
@@ -29,21 +27,22 @@
 
       <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">
+        <u-input v-model="password" prefixIcon="lock" placeholder="请输入密码" :password="isPassword">
           <template #suffix>
-            <text :class="!inputIconBool ? 'iconfont oaIcon-eye' : 'iconfont oaIcon-eye-close'" @click="inputIconBool = !inputIconBool"></text>
+            <text :class="!isPassword ? 'iconfont oaIcon-eye' : 'iconfont oaIcon-eye-close'" @click="isPassword = !isPassword"></text>
           </template>
         </u-input>
       </view>
 
       <button class="middle-submit" @click="submitRes">登 录</button>
 
-      <view class="middle-switch">
+      <!-- #ifdef APP-PLUS || MP-WEIXIN || H5 -->
+      <view class="middle-switch" v-if="proxy.$common.isVisible()">
         <text class="switch-loginMethod" @click="switchMode(1)">{{ switchText === "验证码登录" ? "账号密码登录" : "验证码登录" }}</text>
         <view style="margin: auto"></view>
         <text class="switch-register" @click="switchMode(2)">注册账号</text>
       </view>
+      <!--#endif-->
 
       <!-- #ifdef APP-PLUS || MP-WEIXIN -->
       <view class="middle-agreed text-center">
@@ -66,31 +65,35 @@
 </template>
 
 <script setup>
-import config from "@/config";
+/*----------------------------------依赖引入-----------------------------------*/
 import { onLoad, onShow, onHide, onLaunch, onReady } from "@dcloudio/uni-app";
 import { reactive, getCurrentInstance, toRefs, inject, nextTick } from "vue";
+/*----------------------------------接口引入-----------------------------------*/
+/*----------------------------------组件引入-----------------------------------*/
+/*----------------------------------store引入-----------------------------------*/
 import { useStores, commonStores } from "@/store/modules/index";
-
+/*----------------------------------公共方法引入-----------------------------------*/
+import config from "@/config";
+/*----------------------------------公共变量-----------------------------------*/
+const { proxy } = getCurrentInstance();
 const useStore = useStores();
 const commonStore = commonStores();
-
-const { proxy } = getCurrentInstance();
-
-const data = reactive({
+/*----------------------------------变量声明-----------------------------------*/
+const state = reactive({
   /** login数据 */
   phone: undefined,
   verify: undefined,
   switchText: "验证码登录",
   username: undefined,
   password: undefined,
-  inputIconBool: true,
+  isPassword: true,
   /** 服务器配置数据 */
   linkUrl: uni.getStorageSync("serveUrl"),
   /** 用户隐私协议数据 */
   userChecked: [true],
 });
 
-const { phone, verify, switchText, username, password, inputIconBool, linkUrl, userChecked } = toRefs(data);
+const { phone, verify, switchText, username, password, isPassword, linkUrl, userChecked } = toRefs(state);
 
 /**
  * @跳转服务器配置
@@ -137,15 +140,12 @@ function init() {
   useStore.SetInterval("codeTime"); //调用倒计时定时器
 
   //#ifdef H5
-  if (proxy.$common.isWechatMp()) {
-    window.location.href = proxy.$BASE_URL + "/service-iot/weChat/getFirst1";
-  }
+  useStore.GetWxOpenId(1); //调用获取微信公众号openId
 
   if (window.location.host) {
     linkUrl.value = window.location.host;
-    linkUrl.value = "172.16.120.165:13200";
+    // linkUrl.value = "172.16.120.165:13200";
     // linkUrl.value = "localhost:81";
-
     useStore.GetMobileTenantConfig({ url: linkUrl.value });
   }
   //#endif
@@ -192,11 +192,14 @@ function submitRes() {
       proxy.$modal.msg("请输入验证码");
       return;
     }
+
     login({
       phone: phone.value,
       verify: verify.value,
       tenantId: useStore.tenantId,
       cids: proxy.$settingStore.pushClientId,
+      type: proxy.$common.isWechatMp() ? "wx" : "app",
+      openId: useStore.wxOpenId || undefined,
     });
   } else {
     if (!username.value) {
@@ -213,6 +216,8 @@ function submitRes() {
       password: password.value,
       tenantId: useStore.tenantId,
       cids: proxy.$settingStore.pushClientId,
+      type: proxy.$common.isWechatMp() ? "wx" : "app",
+      openId: useStore.wxOpenId || undefined,
     });
   }
 }

+ 1 - 4
src/pages/mine.vue

@@ -187,12 +187,9 @@ const data = reactive({
 
   colorModal: false,
   themeList: proxy.$constData.themeList,
-
-  modalShow: false,
-  modalArray: {},
 });
 
-const { colorModal, themeList, modalShow, modalArray } = toRefs(data);
+const { colorModal, themeList } = toRefs(data);
 
 /**
  * @检查更新

+ 5 - 5
src/pages/mine/info/index.vue

@@ -167,7 +167,7 @@ function handleConfirm() {
 
     updateUserProfile(userArr.value).then((response) => {
       proxy.$tab.reLaunch("/pages/mine");
-      useStore.getUser();
+      useStore.GetUser();
     });
   }
 
@@ -183,7 +183,7 @@ function handleConfirm() {
         updateUserProfile(userArr.value).then((response) => {
           proxy.$modal.msgSuccess("修改成功");
           proxy.$tab.reLaunch("/pages/mine");
-          useStore.getUser();
+          useStore.GetUser();
         });
       },
       error: (res) => {
@@ -205,7 +205,7 @@ function handleConfirm() {
 
     updateUserProfile(userArr.value).then((response) => {
       proxy.$tab.reLaunch("/pages/mine");
-      useStore.getUser();
+      useStore.GetUser();
     });
   }
 
@@ -217,7 +217,7 @@ function handleConfirm() {
 
     updateUserProfile(userArr.value).then((response) => {
       proxy.$tab.reLaunch("/pages/mine");
-      useStore.getUser();
+      useStore.GetUser();
     });
   }
 }
@@ -243,7 +243,7 @@ function tabsClick(e) {
 }
 
 onLoad((options) => {
-  useStore.getUser();
+  useStore.GetUser();
 });
 
 onReady(() => {

+ 3 - 3
src/pages/mine/secure/index.vue

@@ -160,7 +160,7 @@ function handleConfirm() {
         updateUserProfile(userArr.value).then((response) => {
           proxy.$modal.msgSuccess("修改成功");
           handleCancel(); //调用取消按钮
-          useStore.getUser();
+          useStore.GetUser();
         });
       },
       error: (res) => {
@@ -198,7 +198,7 @@ function handleConfirm() {
     updateUserPwd(oldPassword.value, newPassword.value).then((response) => {
       proxy.$modal.msgSuccess("修改成功");
       handleCancel(); //调用取消按钮
-      useStore.getUser();
+      useStore.GetUser();
     });
   }
 
@@ -267,7 +267,7 @@ function getVerifyCode() {
 }
 
 onLoad((options) => {
-  useStore.getUser();
+  useStore.GetUser();
 });
 
 onReady(() => {});

+ 16 - 0
src/plugins/common.plugins.js

@@ -156,6 +156,22 @@ export default {
     }
     return fmt;
   },
+  /**
+   * @公共获取URL中的参数
+   */
+  getUrlList() {
+    // 截取url中的list
+    var url = window.location.href;
+    var theRequest = new Object();
+    if (url.indexOf("?") != -1) {
+      var str = url.split("?")[1];
+      var strs = str.split("&");
+      for (var i = 0; i < strs.length; i++) {
+        theRequest[strs[i].split("=")[0]] = strs[i].split("=")[1];
+      }
+    }
+    return theRequest;
+  },
   /**
    * @获取当前日期前一年的日期
    */

+ 0 - 3
src/plugins/constData.plugins.js

@@ -1,7 +1,4 @@
 export default {
-	// app应用名称
-	appName: '通用办公',
-
 	// 主题列表
 	themeList: [
 		{

+ 0 - 42
src/plugins/grid.plugins.js

@@ -100,47 +100,7 @@ let xunJianList = [
     },
 ];
 
-let xunJianRecord = [
-    {
-        id: "561",
-        title: "计划:巡检计划1",
-        des: "点位:巡检点位01",
-        time: "2021-01-20 15:23:43",
-        status: 0,
-    },
-    {
-        id: "561",
-        title: "计划:巡检计划1",
-        des: "点位:巡检点位01",
-        time: "2021-01-20 15:23:43",
-        status: 1,
-    },
-    {
-        id: "561",
-        title: "计划:巡检计划1",
-        des: "点位:巡检点位01",
-        time: "2021-01-20 15:23:43",
-        status: 1,
-    },
-];
 
-let xunJianPlan = [
-    {
-        id: "561",
-        title: "虹泾总部园巡检点位1",
-        status: 0,
-    },
-    {
-        id: "561",
-        title: "虹泾总部园巡检点位2",
-        status: 0,
-    },
-    {
-        id: "561",
-        title: "虹泾总部园巡检点位3",
-        status: 1,
-    },
-];
 // 巡检模块 结束
 
 // 定义数据出口
@@ -149,6 +109,4 @@ export default {
     cuIconList: cuIconList,
 
     xunJianList: xunJianList,
-    xunJianRecord: xunJianRecord,
-    xunJianPlan: xunJianPlan,
 };

+ 4 - 4
src/plugins/nfc.plugins.js

@@ -1,5 +1,5 @@
 import tab from "./tab.plugins";
-import { commonStores } from "@/store/modules/index";
+import { settingStores } from "@/store/modules/index";
 
 var NfcAdapter;
 var NdefRecord;
@@ -210,7 +210,7 @@ function __write(intent) {
  */
 function __read(intent) {
     try {
-        commonStores().nfcWaiting = '请勿移开标签\n正在读取数据...'
+        settingStores().nfcWaiting = '请勿移开标签\n正在读取数据...'
         // waiting.setTitle("请勿移开标签\n正在读取数据...");
         var tag = plus.android.importClass("android.nfc.Tag");
         tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
@@ -277,13 +277,13 @@ function writeData() {
         return;
     }
     readyWriteData = true;
-    commonStores().nfcWaiting = '请将手机靠近NFC标签'
+    settingStores().nfcWaiting = '请将手机靠近NFC标签'
     // waiting = plus.nativeUI.showWaiting("请将手机靠近NFC标签!");
 }
 
 function readData() {
     readyRead = true;
-    commonStores().nfcWaiting = '请将手机靠近NFC标签'
+    settingStores().nfcWaiting = '请将手机靠近NFC标签'
     // waiting = plus.nativeUI.showWaiting("请将手机靠近NFC标签!", {
     //     modal: false,
     // });

+ 0 - 2
src/store/modules/common.js

@@ -78,8 +78,6 @@ const commonStore = defineStore("common", {
       recordPictureList: [],
       typeGuise: "", //点线面类型
     }, //设施采集页面-数据存储
-
-    nfcWaiting: "请将手机靠近NFC标签", //nfc读取页面-提示文字-数据存储
   }),
   actions: {
     /**

+ 10 - 15
src/store/modules/setting.js

@@ -13,7 +13,7 @@ import { checkUpdates } from "@/api/system/setting";
 
 const settingStore = defineStore("storage-setting", {
     state: () => ({
-        pushClientId: "",//应用消息推送cid
+        pushClientId: undefined,//应用消息推送cid
         currentSize: "",//APP缓存
         barHeight: 0,//微信小程序顶部安全距离
         webViewHeight: "",//webView整体高度-铺满
@@ -23,6 +23,8 @@ const settingStore = defineStore("storage-setting", {
 
         themeColor: storage.get("themeColor"),//主题
         fingerprintUserList: storage.get("fingerprintUserList"),//指纹登录用户数据
+
+        nfcWaiting: "请将手机靠近NFC标签", //nfc读取页面-提示文字-数据存储
     }),
     actions: {
         /**
@@ -56,7 +58,6 @@ const settingStore = defineStore("storage-setting", {
                 }
             }, 0);
         },
-
         /**
          * @动态获取屏幕头部高度
          */
@@ -114,7 +115,6 @@ const settingStore = defineStore("storage-setting", {
                 },
             });
         },
-
         /**
          * @消息推送监听
          */
@@ -128,8 +128,14 @@ const settingStore = defineStore("storage-setting", {
                     console.log(err);
                 },
             });
-
             const platform = uni.getSystemInfoSync().platform;
+            // 接收推送信息  在线
+            plus.push.addEventListener("receive", (res) => {
+                uni.createPushMessage({
+                    title: res.title,
+                    content: res.content,
+                });
+            });
             // 点击推送信息
             plus.push.addEventListener("click", (res) => {
                 console.log(res);
@@ -140,17 +146,6 @@ const settingStore = defineStore("storage-setting", {
                     console.log(res.payload);
                 }
             });
-            // 接收推送信息  在线
-            plus.push.addEventListener("receive", (res) => {
-                console.log(res);
-                if (platform == "android") {
-                } else {
-                    uni.createPushMessage({
-                        title: res.title,
-                        content: res.content,
-                    });
-                }
-            });
         },
 
         /**

+ 28 - 11
src/store/modules/user.js

@@ -6,7 +6,9 @@ import { login, logout, getInfo, getMobileTenantConfig, getCodeImg } from "@/api
 import { getUserProfile, appAdd, appDel } from "@/api/system/user";
 import { phoneVerify } from "@/api/common/index.js";
 // 组件引用
+import config from "@/config";
 import modal from "@/plugins/modal.plugins.js";
+import common from "@/plugins/common.plugins.js";
 
 const useStores = defineStore("useStores", {
   state: () => ({
@@ -32,6 +34,8 @@ const useStores = defineStore("useStores", {
 
     codeTime: 0,//验证码倒计时
     codeTimeInterval: null,//验证码倒计时定时器
+
+    wxOpenId: storage.get("wxOpenId"),//微信openId
   }),
   actions: {
     // 登录
@@ -51,7 +55,6 @@ const useStores = defineStore("useStores", {
           });
       });
     },
-
     //获取登录页数据
     GetMobileTenantConfig(params) {
       getMobileTenantConfig(params).then((res) => {
@@ -67,9 +70,8 @@ const useStores = defineStore("useStores", {
         }
       });
     },
-
     // 获取用户信息
-    getUser() {
+    GetUser() {
       getUserProfile().then((response) => {
         this.user = JSON.parse(JSON.stringify(response.data.user));
         this.user.phonenumber = this.user.phonenumber ? this.user.phonenumber.substr(0, 3) + "******" + this.user.phonenumber.substr(9) : "";
@@ -78,7 +80,6 @@ const useStores = defineStore("useStores", {
         this.roleGroup = response.roleGroup;
       });
     },
-
     // 获取用户信息
     GetInfo() {
       return new Promise((resolve, reject) => {
@@ -109,7 +110,6 @@ const useStores = defineStore("useStores", {
           });
       });
     },
-
     /**
      * @获取手机验证码
      * @param { 手机号 } phone 
@@ -146,7 +146,6 @@ const useStores = defineStore("useStores", {
         this.SetInterval("codeTime");
       }
     },
-
     // 手机验证码倒计时定时器
     SetInterval(key) {
       if (this.codeTimeInterval) {
@@ -160,7 +159,6 @@ const useStores = defineStore("useStores", {
         }
       }, 1000);
     },
-
     /**
      * @手机验证码校验
      * @param { 数据 } data 
@@ -189,14 +187,12 @@ const useStores = defineStore("useStores", {
       }).then((res) => {
         if (res.status === "SUCCESS") {
           success(res)
-
         } else {
           error(res)
         }
         modal.closeLoading();
       });
     },
-
     /**
      * @注册
      * @param { 数据 } data 
@@ -244,7 +240,6 @@ const useStores = defineStore("useStores", {
         }
       })
     },
-
     /**
      * @用户注销
      * @param { 数据 } data
@@ -260,7 +255,6 @@ const useStores = defineStore("useStores", {
         }
       })
     },
-
     // 退出系统
     LogOut() {
       return new Promise((resolve, reject) => {
@@ -286,6 +280,29 @@ const useStores = defineStore("useStores", {
           });
       });
     },
+    /**
+     * @获取微信OpenId
+     * @param { 类型 } type 
+     */
+    GetWxOpenId(type) {
+      if (type == 1 && common.isWechatMp()) {
+        if (window.location.href.indexOf("openId=") == -1) {
+          window.location.href = config.baseUrl + "/service-iot/weChat/getFirst1";
+        } else {
+          this.SET_STORAGE_OBJECT_KEYS({
+            wxOpenId: common.getUrlList().openId
+          })
+        }
+      } else if (type == 2 && common.isWechatMp()) {
+        if (window.location.href.indexOf("openId=") == -1) {
+          window.location.href = config.baseUrl + "/service-iot/weChat/getPageAuthorization?openId=" + this.wxOpenId;
+        } else {
+          this.SET_STORAGE_OBJECT_KEYS({
+            wxOpenId: common.getUrlList().openId
+          })
+        }
+      }
+    },
 
     SET_TOKEN(token) {
       this.token = token;

+ 3 - 3
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, storageStystem } from "@/utils/storage";
 
-const xunJianStore = defineStore(`${storage.get("userId")}_storage-xunJian`, {
+const xunJianStores = defineStore(`storage-xunJian`, {
   state: () => ({
     planTabs: 0, //巡检计划页 tabs切换值
     siteId: null, //巡检计划页 站点id
@@ -45,4 +45,4 @@ const xunJianStore = defineStore(`${storage.get("userId")}_storage-xunJian`, {
   },
 });
 
-export default xunJianStore;
+export default xunJianStores;