tangning 2 år sedan
förälder
incheckning
cce7b6786a
1 ändrade filer med 14 tillägg och 11 borttagningar
  1. 14 11
      src/views/mobile/index.vue

+ 14 - 11
src/views/mobile/index.vue

@@ -11,10 +11,11 @@ const orderDetal = ref({})
 const orderSn = ref(route.query.id || GetRequest('id'))
 const { getToken, openId, isEur, info, setUserData } = useUserStore()
 const is_weixn = computed(() => {
-  if (typeof WeixinJSBridge == 'undefined') {
-    return false
+  var wx = window.navigator.userAgent.toLowerCase()
+  if (wx.match(/MicroMessenger/i) == 'micromessenger') {
+    return true // 是微信端
   } else {
-    return true
+    return false
   }
 })
 // let PAYSID = {
@@ -24,7 +25,7 @@ const is_weixn = computed(() => {
 // }
 //判断是否微信
 onMounted(() => {
-  console.log('useUserStore',getToken, openId, isEur, info)
+  console.log('useUserStore', getToken, openId, isEur, info, is_weixn)
   getDetial()
 })
 async function handelPay() {
@@ -33,7 +34,7 @@ async function handelPay() {
     payType: is_weixn.value ? '1' : payType.value,
     openId: 'dolor exercitation velit'
   }
-  console.log('handelPay',apiData)
+  console.log('handelPay', apiData)
   const res = await openPay(apiData)
   // console.log('apiData', res)
   if (is_weixn.value) {
@@ -102,14 +103,16 @@ function getDetial() {
     handleWxlogin(res.wxAppId)
   })
 }
-async function handleWxlogin(wxAppId:string) {
+async function handleWxlogin(wxAppId: string) {
   const code = GetRequest('code')
-  if(!openId && !code){//微信登录
+  if (!openId && !code) {
+    //微信登录
     getWeChatCode(wxAppId)
-  }else if(code){//存在code 换取openid
-    const res = wxLogin({code,orderSn:orderSn.value})
-    if(!res.errmsg){
-      setUserData(res.openid,'openId')
+  } else if (code) {
+    //存在code 换取openid
+    const res = wxLogin({ code, orderSn: orderSn.value })
+    if (!res.errmsg) {
+      setUserData(res.openid, 'openId')
     }
   }
 }