Browse Source

feat: bug

tangning 2 years ago
parent
commit
bfa7d77afc
1 changed files with 39 additions and 30 deletions
  1. 39 30
      src/App.vue

+ 39 - 30
src/App.vue

@@ -2,35 +2,43 @@
   <router-view />
 </template>
 <script setup lang="ts">
-import 'vant/lib/index.css'
-import { onMounted, computed } from 'vue'
-import { useUserStore } from '/@/store/modules/user';
-const userStore = useUserStore();
-console.log('userStore',userStore)
-const wxOpenId = computed(() => {
-  return userStore.getWxOpenId();
-});
-onMounted(async ()=>{
-  
-  let code=getUrlKey("code");//获取url参数code
-  if(wxOpenId.value){//
-    console.log('已登录',wxOpenId.value)
-  }else if(code){//存在code
-    userStore.setWxOpenId(code)
-  }else{//进行微信登录
-    getCodeApi(123)
+  import 'vant/lib/index.css';
+  import { onMounted, computed } from 'vue';
+  import { useUserStore } from '/@/store/modules/user';
+  const userStore = useUserStore();
+  console.log('userStore', userStore);
+  const wxOpenId = computed(() => {
+    return userStore.getWxOpenId;
+  });
+  onMounted(async () => {
+    let code = getUrlKey('code'); //获取url参数code
+    if (wxOpenId.value) {
+      //
+      console.log('已登录', wxOpenId.value);
+    } else if (code) {
+      //存在code
+      userStore.setWxOpenId(code);
+    } else {
+      //进行微信登录
+      getCodeApi(123);
+    }
+  });
+  function getUrlKey(name) {
+    //获取url 参数
+    return (
+      decodeURIComponent(
+        (new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.href) || [, ''])[1].replace(/\+/g, '%20'),
+      ) || null
+    );
+  }
+  function getCodeApi(state) {
+    //获取code
+    let urlNow = encodeURIComponent(window.location.href);
+    let scope = 'snsapi_base'; //snsapi_userinfo   //静默授权 用户无感知
+    let appid = 'wxac3d59ea82d9b82a';
+    let url = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${urlNow}&response_type=code&scope=${scope}&state=${state}#wechat_redirect`;
+    window.location.replace(url);
   }
-})
-function getUrlKey(name){//获取url 参数
-   return decodeURIComponent((new RegExp('[?|&]'+name+'='+'([^&;]+?)(&|#|;|$)').exec(location.href)||[,""])[1].replace(/\+/g,'%20'))||null;
- }
-function getCodeApi(state){//获取code   
-     let urlNow=encodeURIComponent(window.location.href);
-     let scope='snsapi_base';    //snsapi_userinfo   //静默授权 用户无感知
-     let appid='wxac3d59ea82d9b82a';
-     let url=`https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${urlNow}&response_type=code&scope=${scope}&state=${state}#wechat_redirect`;
-     window.location.replace(url);
-}
 </script>
 <style>
   #app {
@@ -40,7 +48,8 @@ function getCodeApi(state){//获取code
     color: #2c3e50;
     background-color: var(--color-bg-1);
   }
-  .van-toast{
-    background:rgba(0, 0, 0, 0.7) !important
+
+  .van-toast {
+    background: rgba(0, 0, 0, 0.7) !important;
   }
 </style>