|
|
@@ -20,9 +20,12 @@ let router = '';
|
|
|
/**
|
|
|
* @param {string} 当前页面地址信息
|
|
|
*/
|
|
|
-export function loginWinxin() {
|
|
|
+export async function loginWinxin() {
|
|
|
console.log('1');
|
|
|
let pages, page, path;
|
|
|
+ if (!router) {
|
|
|
+ router = await setRouter();
|
|
|
+ }
|
|
|
try {
|
|
|
pages = getCurrentPages();
|
|
|
// 获取跳转前页面
|
|
|
@@ -37,7 +40,6 @@ export function loginWinxin() {
|
|
|
if (path != 'pages/redirect/redirect') {
|
|
|
log.addLog('开始注册微信')
|
|
|
weixindata().then(() => {
|
|
|
- console.log('2');
|
|
|
// 调用
|
|
|
try {
|
|
|
weixinSq();
|
|
|
@@ -53,8 +55,15 @@ function weixinSq() {
|
|
|
// 微信授权后跳转页面
|
|
|
try {
|
|
|
// 判断是否真实路由模式
|
|
|
+
|
|
|
+ // const type = router.mode === "history"?'':'/#'
|
|
|
+ // let ul = encodeURIComponent(store.state.baseURL + store.state.urlFile +type+ '/pages/redirect/redirect');
|
|
|
+ // let ul = encodeURIComponent(store.state.baseURL + store.state.urlFile + '/#/pages/redirect/redirect');
|
|
|
+
|
|
|
const type = router.mode === "history"?'':'/#'
|
|
|
+ console.log(type)
|
|
|
let ul = encodeURIComponent(store.state.baseURL + store.state.urlFile +type+ '/pages/redirect/redirect');
|
|
|
+
|
|
|
// 打开微信授权页面
|
|
|
let url =
|
|
|
'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' +
|
|
|
@@ -72,12 +81,16 @@ function weixinSq() {
|
|
|
};
|
|
|
|
|
|
// 微信注册
|
|
|
-export function weixindata(config) {
|
|
|
+export async function weixindata(config) {
|
|
|
let url;
|
|
|
try {
|
|
|
+ // 判断是否存在router
|
|
|
+ if (!router) {
|
|
|
+ router = await setRouter();
|
|
|
+ }
|
|
|
if (router.mode === "history") {
|
|
|
// 在ios中时候注册为微信刚进入时候的页面
|
|
|
- if (window.entryUrl === '') {
|
|
|
+ if (!window.entryUrl) {
|
|
|
window.entryUrl = location.href.split('#')[0]
|
|
|
}
|
|
|
url = isAndroid() ? location.href.split('#')[0] : window.entryUrl;
|
|
|
@@ -115,7 +128,9 @@ export function weixindata(config) {
|
|
|
weixinObj.ready((e) => {
|
|
|
log.addLog("注册完毕", data)
|
|
|
console.log('注册完毕');
|
|
|
- ok(data)
|
|
|
+ store.commit('setWeiChatObj', weixinObj)
|
|
|
+ ok(weixinObj)
|
|
|
+ // ok(data)
|
|
|
})
|
|
|
} catch (e) {
|
|
|
console.log(e)
|
|
|
@@ -216,7 +231,24 @@ function shareFun(config) {
|
|
|
|
|
|
// 保存路由对象
|
|
|
export function setRouter(route) {
|
|
|
- router = route
|
|
|
+ return new Promise((ok, err) => {
|
|
|
+ router = getApp().$router;
|
|
|
+ console.log(router,'开始数据');
|
|
|
+ if (!router) {
|
|
|
+ const set = setInterval(() => {
|
|
|
+ router = getApp().$router;
|
|
|
+ console.log(router,'返回数据');
|
|
|
+ if (router) {
|
|
|
+ console.log(router,'结束');
|
|
|
+ clearInterval(set)
|
|
|
+ ok(router)
|
|
|
+ }
|
|
|
+ }, 100);
|
|
|
+ }else{
|
|
|
+ console.log(router,'成功');
|
|
|
+ ok(router)
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
export default {
|