diff --git a/src/main.js b/src/main.js index ddde5c3..499b369 100644 --- a/src/main.js +++ b/src/main.js @@ -2,83 +2,68 @@ * @Author: ch * @Date: 2022-07-08 11:46:30 * @LastEditors: ch - * @LastEditTime: 2022-07-12 10:47:34 + * @LastEditTime: 2022-07-12 10:55:29 * @Description: file content */ -import {FormatSearchJson} from '@/common/utils'; -import {ApiGetOpenId, ApiGetAuthUrl} from '@/common/api/auth'; +import { FormatSearchJson } from '@/common/utils'; +import { ApiGetOpenId, ApiGetAuthUrl } from '@/common/api/auth'; import { ApiGetOrderInfo } from '@/common/api/pay'; import Vue from 'vue'; import App from './App'; import '@/common/utils/uniUtilsIndex' // 微信打开需要授权 -const ua = navigator ? navigator.userAgent.toLowerCase() : ''; +const ua = navigator ? navigator.userAgent.toLowerCase() : ''; if (ua.includes('micromessenger')) { - const openId = localStorage.getItem('openId'); - if(!openId){ - let query = FormatSearchJson(window.location.search); - if(query.code){ - ApiGetOpenId({ - code : query.code - }).then(({error, result}) => { - if(error){ - // uni.$u.toast(error.message); - return false; - } - store.commit('SET_OPEN_ID', result.openId); - }) - } else { - ApiGetOrderInfo({ payOrderNo: query.payOrderNo }).then(({result}) => { + const openId = localStorage.getItem('openId'); + if (!openId) { + let query = FormatSearchJson(window.location.search); + + ApiGetOrderInfo({ payOrderNo: query.payOrderNo }).then(({ result }) => { + const appid = result.prepayWxApp.prepayAppId; + if (query.code) { + ApiGetOpenId({ + code: query.code, + appid + }).then(({ error, result }) => { + if (error) { + // uni.$u.toast(error.message); + return false; + } + store.commit('SET_OPEN_ID', result.openId); + }) + } else { + + ApiGetAuthUrl({ + appid, + redirectUrl: window.location.href, + scope: 'snsapi_base' + }).then(({ result, error }) => { + if (error) { + // uni.$u.toast(error.message); + uni.showToast({ + title: error.message, + icon: 'none', + duration: 2000 + }) + return false; + } + window.location.replace(result); + }); + + } + }) + + } - ApiGetAuthUrl({ - appid: result.prepayWxApp.prepayAppId, - redirectUrl : window.location.href, - scope : 'snsapi_base' - }).then(({result, error}) => { - if(error){ - // uni.$u.toast(error.message); - uni.showToast({ - title: error.message, - icon: 'none', - duration : 2000 - }) - return false; - } - window.location.replace(result); - }); - }) - - - // ApiGetOpenId({ payOrderNo: query.payOrderNo }).then(res => { - // ApiGetAuthUrl({ - // redirectUrl : window.location.href, - // scope : 'snsapi_base' - // }).then(({result, error}) => { - // if(error){ - // // uni.$u.toast(error.message); - // uni.showToast({ - // title: error.message, - // icon: 'none', - // duration : 2000 - // }) - // return false; - // } - // window.location.replace(result); - // }) - // }); - - } - } - } Vue.config.productionTip = false App.mpType = 'app' const app = new Vue({ - ...App + ...App }) app.$mount()