Procházet zdrojové kódy

手机号绑定提醒功能微信绑定提醒功能

dengshaobo před 6 měsíci
rodič
revize
e9a443641d

+ 0 - 242
src/http/request.js

@@ -1,242 +0,0 @@
-import axios from "axios";
-// import config from '@/rsaConfig.js';
-// import tokenUtil from '../utils/tokenUtil.js';
-import { Loading } from "element-ui";
-const qs = require("qs");
-
-let refreshTokenState = 0;
-import store from "../store/index.js";
-// import {errorTip} from '../utils/index.js'
-
-//token过期跳转登录页
-const gotoLogin = () => {
-  let url = window.location.href.split("#")[0];
-
-  console.log("打印当前登录方式", store.state.LoginSource);
-  if (store.state.LoginSource == "mobile") {
-    // 开发环境使用
-    if (url == "http://localhost:8883/") {
-      window.location.href = `${url}#/logins`;
-    } else {
-      //正式环境
-      window.location.replace(location.origin + "/shanghu/#/logins");
-    }
-  } else {
-    //非手机号登录
-    window.location.href = `${url}#/login`;
-  }
-};
-
-/**
- * 封装的axios和ajax 一般用axios足够。如果有jsonp需求可以使用zport的ajax;
- */
-export default async ({
-  apiUrl,
-  params = {},
-  type = "GET",
-  // apiCode = "",   //license的值
-  // isSendRsa = false,   //请求参数是否加密
-  // isUCode = false,  //是否需要登录
-  // release = false,
-  responseType = "",
-  contentType = "application/json;charset=utf-8", //请求头
-}) => {
-  type = type.toUpperCase();
-  return new Promise((resolve, reject) => {
-    const timestamp = new Date().getTime() + "";
-
-    let rsaParams;
-    let rsaObj = {};
-
-    //加载动画
-
-    // let loadingInstance = Loading.service(
-    //     {
-    //         fullscreen: true,
-    //         lock: true,
-    //         text: 'loading',
-    //         spinner: 'el-icon-loading',
-    //         background: 'rgba(0, 0, 0, 0)'
-    //     }
-    // );
-    axios({
-      method: type,
-      url: apiUrl,
-      headers: {
-        Authorization: getToken(),
-        "Content-Type": contentType,
-      },
-      data: type === "POST" ? rsaParams || params : "",
-      params: type === "GET" ? rsaParams || params : "",
-      timeout: 60000000,
-      responseType,
-      /* 开启跨域cookie携带 */
-      // credentials : true,
-      // emulateHTTP: true,
-      // emulateJSON:true
-    })
-      .then((res) => {
-        res = res.data;
-
-        //刷新token
-        if (
-          (res.code === 10035 ||
-            res.code === 10038 ||
-            res.code === 10039 ||
-            res.code === 10023 ||
-            res.code === 10026 ||
-            res.code === 10028) &&
-          !release
-        ) {
-          //refreshToken 存在的情况下
-          if (tokenUtil.getRefreshToken() !== undefined) {
-            if (refreshTokenState === 0) {
-              refreshTokenState++;
-              tokenUtil.refreshToken();
-            }
-          } else {
-            //不存在返回登录
-            tokenUtil.clearToken();
-
-            gotoLogin();
-          }
-          return;
-        }
-        //账号异常登录情况
-        if (res.code === 10037 || res.code === 10036) {
-          tokenUtil.clearToken();
-          gotoLogin(); //跳转到登录页
-
-          return;
-        }
-        //刷新token过期
-        if (res.code === 10041) {
-          tokenUtil.clearToken();
-          gotoLogin(); //跳转到登录页
-          // let url = window.location.href.split("#")[0];
-          // window.location.href = `${url}#/login`;
-          return;
-        }
-        //无权访问
-        if (
-          res.code === 10032 ||
-          res.code === 10024 ||
-          res.code === 10030 ||
-          res.code === 10029 ||
-          res.code === 10031 ||
-          res.code === 10040
-        ) {
-          return;
-        }
-
-        if (res.de) {
-          // 需要解密
-          if (!res.data) {
-            resolve(res);
-            return false;
-          }
-          let decryptData = rsa.decryptLong(res.data);
-          res.data = JSON.parse(Base64.decode(decryptData));
-
-          // if (res.vsg) { // 需要验签
-          //     let sign = res.sign;
-          //     let signature = rsa.getServiceSignature(res.data, res.noncestr, res.timestamp);
-          //     if (sign === signature) {
-          //         resolve(res);
-          //     } else {
-          //         console.log("验签失败,数据可能存在错误...");
-          //         reject(res)
-          //     }
-          // } else { // 不验签
-          //     resolve(res);
-          // }
-          resolve(res);
-        } else {
-          // 不需要解密
-          if (res.vsg) {
-            // 需要验签
-            let sign = res.sign;
-            let signature = rsa.getServiceSignature(
-              res.data,
-              res.noncestr,
-              res.timestamp
-            );
-            if (sign === signature) {
-              resolve(res);
-            } else {
-              console.log("验签失败,数据可能存在错误...");
-            }
-          } else {
-            // 不验签
-            resolve(res);
-          }
-        }
-      })
-      .catch((err) => {
-        console.log("err.response", err.response);
-        let errCode = err.response.data.code;
-
-        if (err.response.status == 504) {
-          //不存在返回登录
-          tokenUtil.clearToken();
-          gotoLogin(); //跳转到登录页
-          // let url = window.location.href.split("#")[0];
-          // window.location.href = `${url}#/login`;
-          return;
-        }
-        //刷新token
-        if (
-          errCode === 10035 ||
-          errCode === 10038 ||
-          errCode === 10039 ||
-          errCode === 10023 ||
-          errCode === 10026 ||
-          errCode === 10028
-        ) {
-          //refreshToken 存在的情况下
-          if (tokenUtil.getRefreshToken() !== undefined) {
-            if (refreshTokenState === 0) {
-              refreshTokenState++;
-              tokenUtil.refreshToken();
-            }
-          } else {
-            //不存在返回登录
-            tokenUtil.clearToken();
-            gotoLogin(); //跳转到登录页
-            // let url = window.location.href.split("#")[0];
-            // window.location.href = `${url}#/login`;
-          }
-          return;
-        }
-        //账号异常登录情况
-        if (errCode === 10037 || errCode === 10036) {
-          tokenUtil.clearToken();
-          gotoLogin(); //跳转到登录页
-          // let url = window.location.href.split("#")[0];
-          // window.location.href = `${url}#/login`;
-          return;
-        }
-        //刷新token过期
-        if (errCode === 10041) {
-          tokenUtil.clearToken();
-          gotoLogin(); //跳转到登录页
-          // let url = window.location.href.split("#")[0];
-          // window.location.href = `${url}#/login`;
-          return;
-        }
-        //无权访问
-        if (
-          errCode === 10032 ||
-          errCode === 10024 ||
-          errCode === 10030 ||
-          errCode === 10029 ||
-          errCode === 10031 ||
-          errCode === 10040
-        ) {
-          return;
-        }
-        reject(err);
-      });
-  });
-
-};

+ 1 - 1
src/styles/common.scss

@@ -3284,7 +3284,7 @@ body {
   .bingding_center
   {
     width: calc(100% - 40px);
-    margin:20px auto;
+    // margin:20px auto;
 
      //绑定手机号 输入框
     .bingding_input

+ 34 - 5
src/views/login/login.vue

@@ -82,12 +82,41 @@ export default {
           this.$store.dispatch("user/SET_TOKEN", userInfo.tokenValue);
           this.$store.dispatch("user/SET_SCHOOL_LOGO",userInfo.schoolLogoUrl);//设置学校logo
           this.$store.dispatch("user/SET_SCHOOL_WEB_SITE_ID",userInfo.cloudMonitorSiteId || '');//设置学校网站id
-          this.$store.dispatch("user/getUserInfoByToken");//获取用户登录信息
+       
+          this.$store.dispatch("user/getUserInfoByToken").then((user)=>{
+               console.log("获取用户信息成功",this.$store.state.user.userInfo);
+               let userInfos = this.$store.state.user.userInfo;
+               // 移除事件监听器,避免重复处理
+               window.removeEventListener('message', messageHandler);
+               if(userInfos.phone)
+               {
+                const directUrl = "/studentAnalysisReport/list";
+               
+                this.$router.push({ path: directUrl });
+               }
+               else
+               {
 
-          const directUrl = "/studentAnalysisReport/list";
-          // 移除事件监听器,避免重复处理
-          window.removeEventListener('message', messageHandler);
-          this.$router.push({ path: directUrl });
+                this.$router.push({ path: '/userInfo/personInfo' });
+                // // 使用 this.$confirm 替代
+                // this.$confirm('为了方便找回密码,我们建议您绑定手机号!', '', {
+                //   confirmButtonText: '确定',
+                //   cancelButtonText: '取消',
+                //   customClass:"page_dialog",
+                //   type: 'warning'
+                // }).then(() => {
+                //   // 用户点击立即绑定,跳转到个人资料页面
+                  
+                // }).catch(() => {
+                //   // 用户点击稍后绑定,直接进入首页
+                //   const directUrl = "/studentAnalysisReport/list";
+                //   this.$router.push({ path: directUrl });
+                // });
+              }
+               
+
+          });//获取用户登录信息
+          
         }
 
       };

+ 74 - 14
src/views/userInfo/personInfo.vue

@@ -57,11 +57,11 @@
     </div>
     <div class="page_jg_20"></div>
     <div class="page_dialog">
-      <el-dialog title="绑定手机号" center :visible.sync="bindingPhoneData.showDialog" width="400px">
+      <el-dialog title="绑定手机号(用于找回密码)" center :visible.sync="bindingPhoneData.showDialog" width="400px">
         <div class="dialog_center padding_20">
           <div class="bingding_center">
             <div class="bingding_input">
-              <el-input v-model="bindingPhoneData.phone" placeholder="请输入手机号"  prefix-icon="iconfont icon_shoujihao" />
+              <el-input v-model="bindingPhoneData.phone" placeholder="请输入手机号" maxlength="11"  prefix-icon="iconfont icon_shoujihao" />
             </div>
             <div class="bingding_input">
               <el-input v-model="bindingPhoneData.code" placeholder="请输入验证码" prefix-icon="iconfont icon_yanzhengma">
@@ -75,15 +75,14 @@
         </div>
        
       </el-dialog>
-      <el-dialog title="绑定微信" center :visible.sync="showWeChartDialog" width="400px" @close="CloseWeChartDialog">
+      <el-dialog title="绑定微信(快捷登录)" center :visible.sync="showWeChartDialog" width="400px" @close="CloseWeChartDialog">
         <div class="dialog_center padding_20">
-          <div class="bingding_center wechar_qr" id="wechat-qr-container" style="width: 250px; height: 250px; transform: scale(0.8); transform-origin: 0 0;" v-loading="qrLoading"></div>
+          <div class="bingding_center wechar_qr" id="wechat-qr-container" v-loading="qrLoading"></div>
           <div class="wechart_img">
             <img src="@/assets/login/login_wechat.webp" alt="" />
+            <p class="wechar_text">微信扫描</p>
           </div>
-          <p class="wechar_text">
-            
-            微信扫描</p>
+          
         </div>
       </el-dialog>
     </div>
@@ -140,6 +139,16 @@ export default {
     {
       this.roleNames=this.userInfo.roleNames.join("、");
     }
+
+    //判断是否绑定了手机号
+    if(this.userInfo.phone)
+    {
+
+    }
+    else
+    {
+      this.OpenPhoneDialog();
+    }
    
    
     this.LoadSdk() //加载微信sdk
@@ -190,7 +199,15 @@ export default {
             this.bindingPhoneData.code = ''
             this.codeText = '获取验证码'
             this.isCount = false
-            this.count = 60
+            this.count = 60;
+            if(this.userInfo.wxName)
+            {
+
+            }
+            else
+            {
+              this.OpenWeChartDialog();
+            }
           } 
           else 
           {
@@ -209,6 +226,13 @@ export default {
         this.$message.warning('请输入手机号码');
         return
       }
+
+      // 验证手机号格式和位数
+      const phoneRegex = /^1[3-9]\d{9}$/;
+      if (!phoneRegex.test(this.bindingPhoneData.phone)) {
+        this.$message.warning('请输入正确的手机号码');
+        return;
+      }
       if(this.isCount) return
       this.$api.user.getBindPhoneValidCode({
         phoneNumber: this.bindingPhoneData.phone
@@ -262,6 +286,7 @@ export default {
         console.log(container)
         if (!container || container.children.length > 0) return; // 防止重复渲染
 
+       
         const queryString = this.wechatUrl.split('?')[1]?.split('#')[0];
         const urlParams = new URLSearchParams(queryString)
         const appid = urlParams.get('appid')
@@ -274,8 +299,24 @@ export default {
           redirect_uri: encodeURIComponent(process.env.VUE_APP_BASE+"/#/wechatLogin"), // 回调 URL
           state: "STATE",               // 可选状态值
           style: "black",               // 样式风格
-          stylelite: 1                 // 新版二维码样式
+          stylelite: 1 ,               // 新版二维码样式
         });
+
+        // 定时调整 iframe 大小
+        const resizeInterval = setInterval(() => {
+          const iframe = container.querySelector('iframe');
+          if (iframe) {
+            iframe.style.width = '250px';
+            iframe.style.height = '160px';
+            iframe.style.border = 'none';
+            clearInterval(resizeInterval);
+          }
+        }, 100);
+        
+        // 设置超时防止无限循环
+        setTimeout(() => {
+          clearInterval(resizeInterval);
+        }, 3000);
     },
     // 扫码绑定微信
     WechatBind(event) {
@@ -324,17 +365,36 @@ export default {
 .wechart_img
 {
   margin: auto;
-  text-align: center;
-
+  display: flex;
+  justify-content: center;
+  align-items: center;
+  height: 40px;
   img
   {
     width: 32px;
     height: 32px;
+    
+  }
+  .wechar_text
+  {
+    text-align: center;
+    margin-left: 5px;
   }
   
 }
-.wechar_text
-{
-  text-align: center;
+
+#wechat-qr-container {
+  display: flex;
+  justify-content: center;
+  align-items: center;
+  width: 100%;
+  min-height: 160px;
+  
+  iframe {
+    width: 250px !important;
+    height: 250px !important;
+    border: none;
+  }
 }
+
 </style>