wujingjing
2025-04-03 a05faa2676efb41c44738f27c2e736c465b931b3
src/layout/component/login/Login.vue
@@ -4,8 +4,8 @@
         <div class="login_box">
            <div class="sign_in">
               <i class="ywifont ywicon-guanbi closes" @click="handleClose"></i>
               <h1><span>登录 WI 水务智能</span></h1>
               <el-tabs v-model="state.activeLoginName" class="mt-[24px]" @tab-change="handleTabChange">
               <h1><span>登录 WI水务智能</span></h1>
               <el-tabs v-model="state.activeLoginName" class="w-full mt-[24px]" @tab-change="handleTabChange">
                  <el-tab-pane label="账户密码登录" name="accountUser">
                     <el-form
                        ref="loginFormRef"
@@ -45,7 +45,20 @@
                     </el-form>
                  </el-tab-pane>
                  <el-tab-pane label="微信登录" name="wechat">
                     <div id="wechat-login"></div>
                     <!-- <div id="wechat-login"></div> -->
                     <div id="wechat-login" class="flex justify-center items-center">
                        <div class="flex flex-col items-center justify-center">
                           <iframe
                              ref="wechatQrRef"
                              sandbox="allow-top-navigation allow-scripts"
                              style="width: 300px; height: 213px; overflow: hidden"
                              frameborder="0"
                           ></iframe>
                           <span class="relative top-[-10px]" :class="{ 'text-red-400': wechatTip.type === 'error' }">{{
                              wechatTip.value
                           }}</span>
                        </div>
                     </div>
                  </el-tab-pane>
               </el-tabs>
@@ -60,39 +73,105 @@
   </div>
</template>
<script setup lang="ts">
import { ElMessage, type FormInstance } from 'element-plus';
import type { FormInstance } from 'element-plus';
import { ElMessage } from 'element-plus';
import { computed, nextTick, reactive, ref, watch } from 'vue';
import { ACCOUNT_EXPIRE_DAY, handleAfterLogin, LOGIN_CLIENT, STORED_ACCOUNT_KEY } from './login';
import './wxLogin.js';
import { loginMessageUser, loginVerifyMessage, PostLogin } from '/@/api/ai/user';
import { SERVE_URL } from '/@/constants';
import { isShowLogin } from '/@/stores/chatRoom';
import { encrypt } from '/@/utils/cypto';
import { LocalPlus } from '/@/utils/storage';
import './wxLogin.js';
import { SERVE_URL } from '/@/constants';
import { Local, LocalPlus } from '/@/utils/storage';
const handleClose = () => {
   isShowLogin.value = false;
};
const getWechatTipInfo = () => {
   const wechatLoginMsgInfo = Local.get('wechatLoginMsgInfo');
   if (wechatLoginMsgInfo) {
      Local.remove('wechatLoginMsgInfo');
      return wechatLoginMsgInfo;
   }
   return { type: 'info', value: '使用微信扫一扫登陆' };
};
const wechatTip = ref(getWechatTipInfo());
const resetWechatTip = () => {
   wechatTip.value = {
      type: 'info',
      value: '使用微信扫一扫登陆',
   };
};
const getWechartQrCode = () => {
   const state = (new Date().getTime() / 1000).toString();
   // JJJHHH 表示#号
   const url = `${SERVE_URL}JJJHHH/home?isWxLogin=Y`;
   const base64 =
      'LmltcG93ZXJCb3ggLnRpdGxlIHtkaXNwbGF5Om5vbmU7fQoKLmltcG93ZXJCb3ggLnN0YXR1cy5zdGF0dXNfYnJvd3NlciAgcDpudGgtb2YtdHlwZSgyKXsKICAgIGRpc3BsYXk6IG5vbmU7Cn0=';
   const obj = new window.WxLogin({
      id: 'wechat-login',
      appid: 'wx4ea2dca37170074c',
      scope: 'snsapi_login',
      redirect_uri: encodeURIComponent(`http://apiv3.xpump.net/User/wxUserLoginCB.html?from=wi&url=${url}`),
      state: state,
      href: `data:text/css;base64,${base64}`,
   });
};
const wechatQrRef = ref<HTMLIFrameElement>();
const openWechatLogin = () => {
   if (!wechatQrRef.value) return;
   const url = `${SERVE_URL}JJJHHH/home?isWxLogin=Y`;
   const appid = 'wx4ea2dca37170074c';
   const state = (new Date().getTime() / 1000).toString();
   const base64 = btoa(`
   .impowerBox .title {display:none;}
   .impowerBox .status.status_browser  p:nth-of-type(2){
      display: none;
   }
   .impowerBox .qrcode {
   width: 170px;
   margin-top:0;
   }
   .impowerBox .status{
   }
      .info{
      display: none;
   }
   #tpl_for_iframe{
      height:100%;
      overflow: hidden;
          display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
   }
   `);
   const wechatAuthUrl = `https://open.weixin.qq.com/connect/qrconnect?appid=${appid}&redirect_uri=${encodeURIComponent(
      `http://apiv3.xpump.net/User/wxUserLoginCB.html?from=wi&url=${url}`
   )}&response_type=code&scope=snsapi_login&state=${state}&href=data:text/css;base64,${base64}#wechat_redirect`;
   wechatQrRef.value.src = wechatAuthUrl;
};
//切换用户登录页面
const handleTabChange = (item) => {
   state.activeLoginName = item;
   resetWechatTip();
   switch (item) {
      case 'wechat':
         getWechartQrCode();
         // getWechartQrCode();
         openWechatLogin();
         break;
      case 'accountUser':
         break;
@@ -106,14 +185,23 @@
   (val) => {
      if (val && state.activeLoginName === 'wechat') {
         nextTick(() => {
            getWechartQrCode();
            openWechatLogin();
         });
      }
   }
);
const getActiveLoginName = () => {
   const isWechatLogin = Local.get('isWechatLogin');
   if (isWechatLogin) {
      Local.remove('isWechatLogin');
      return 'wechat';
   }
   return 'accountUser';
};
const state = reactive({
   activeLoginName: 'accountUser',
   activeLoginName: getActiveLoginName(),
   loginForm: {
      account: '',
      pwd: '',