|
@@ -2,8 +2,6 @@ import {
|
|
wechatConfig,
|
|
wechatConfig,
|
|
share
|
|
share
|
|
} from '@/api/wx';
|
|
} from '@/api/wx';
|
|
-// 加载日志
|
|
|
|
-import * as log from './log.js'
|
|
|
|
import {
|
|
import {
|
|
isAndroid
|
|
isAndroid
|
|
} from './platform.js'
|
|
} from './platform.js'
|
|
@@ -21,12 +19,11 @@ let router = '';
|
|
* @param {string} 当前页面地址信息
|
|
* @param {string} 当前页面地址信息
|
|
*/
|
|
*/
|
|
export async function loginWinxin() {
|
|
export async function loginWinxin() {
|
|
- console.log('1');
|
|
|
|
let pages, page, path;
|
|
let pages, page, path;
|
|
- if (!router) {
|
|
|
|
- router = await setRouter();
|
|
|
|
- }
|
|
|
|
try {
|
|
try {
|
|
|
|
+ if (!router) {
|
|
|
|
+ router = await setRouter();
|
|
|
|
+ }
|
|
pages = getCurrentPages();
|
|
pages = getCurrentPages();
|
|
// 获取跳转前页面
|
|
// 获取跳转前页面
|
|
page = pages[pages.length - 1];
|
|
page = pages[pages.length - 1];
|
|
@@ -34,11 +31,9 @@ export async function loginWinxin() {
|
|
path = page.route;
|
|
path = page.route;
|
|
} catch (e) {
|
|
} catch (e) {
|
|
console.log(e);
|
|
console.log(e);
|
|
- //TODO handle the exception
|
|
|
|
}
|
|
}
|
|
// 判断是否在登录页
|
|
// 判断是否在登录页
|
|
if (path != 'pages/redirect/redirect') {
|
|
if (path != 'pages/redirect/redirect') {
|
|
- log.addLog('开始注册微信')
|
|
|
|
weixindata().then(() => {
|
|
weixindata().then(() => {
|
|
// 调用
|
|
// 调用
|
|
try {
|
|
try {
|
|
@@ -51,13 +46,13 @@ export async function loginWinxin() {
|
|
}
|
|
}
|
|
};
|
|
};
|
|
// 微信授权登录
|
|
// 微信授权登录
|
|
-function weixinSq() {
|
|
|
|
|
|
+function weixinSq(data, path) {
|
|
// 微信授权后跳转页面
|
|
// 微信授权后跳转页面
|
|
try {
|
|
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');
|
|
|
|
+ console.log(ul, "ul")
|
|
// 打开微信授权页面
|
|
// 打开微信授权页面
|
|
|
|
+
|
|
let url =
|
|
let url =
|
|
'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' +
|
|
'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' +
|
|
appId +
|
|
appId +
|
|
@@ -66,10 +61,10 @@ function weixinSq() {
|
|
'&response_type=code&scope=snsapi_userinfo&state=' +
|
|
'&response_type=code&scope=snsapi_userinfo&state=' +
|
|
new Date().getTime() +
|
|
new Date().getTime() +
|
|
'#wechat_redirect';
|
|
'#wechat_redirect';
|
|
|
|
+ console.log(url, "url")
|
|
window.location.href = url;
|
|
window.location.href = url;
|
|
} catch (e) {
|
|
} catch (e) {
|
|
console.log(e);
|
|
console.log(e);
|
|
- //TODO handle the exception
|
|
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
|
|
@@ -91,9 +86,7 @@ export async function weixindata(config) {
|
|
if (router.mode === "hash") {
|
|
if (router.mode === "hash") {
|
|
url = location.href.split('#')[0];
|
|
url = location.href.split('#')[0];
|
|
}
|
|
}
|
|
- log.addLog('注册开始', url)
|
|
|
|
console.log('开始注册', url);
|
|
console.log('开始注册', url);
|
|
-
|
|
|
|
} catch (e) {
|
|
} catch (e) {
|
|
console.log('错误', e);
|
|
console.log('错误', e);
|
|
}
|
|
}
|
|
@@ -119,9 +112,9 @@ export async function weixindata(config) {
|
|
jsApiList: data.jsApiList // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
|
|
jsApiList: data.jsApiList // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
|
|
});
|
|
});
|
|
weixinObj.ready((e) => {
|
|
weixinObj.ready((e) => {
|
|
- log.addLog("注册完毕", data)
|
|
|
|
console.log('注册完毕');
|
|
console.log('注册完毕');
|
|
- ok(data)
|
|
|
|
|
|
+ store.commit('setWeiChatObj', weixinObj)
|
|
|
|
+ ok(weixinObj)
|
|
})
|
|
})
|
|
} catch (e) {
|
|
} catch (e) {
|
|
console.log(e)
|
|
console.log(e)
|
|
@@ -137,106 +130,74 @@ export async function weixindata(config) {
|
|
}
|
|
}
|
|
})
|
|
})
|
|
}
|
|
}
|
|
-
|
|
|
|
-// 判断分享调用方法
|
|
|
|
-export function shareLoad(config) {
|
|
|
|
- console.log('开始调用分享')
|
|
|
|
- try {
|
|
|
|
- weixindata().then((e) => {
|
|
|
|
- // 判断有无自定义数据
|
|
|
|
- if (config) {
|
|
|
|
- shareFun(config)
|
|
|
|
- } else {
|
|
|
|
- // 判断是否已经缓存了默认数据
|
|
|
|
- if (shareData) {
|
|
|
|
- shareFun()
|
|
|
|
- } else {
|
|
|
|
- // 请求获取默认数据
|
|
|
|
- share({}).then(({
|
|
|
|
- data
|
|
|
|
- }) => {
|
|
|
|
- shareData = data.data
|
|
|
|
- shareFun()
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
- } catch (e) {
|
|
|
|
- console.log('报错', e)
|
|
|
|
- //TODO handle the exception
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-// 配置分享数据
|
|
|
|
-function shareFun(config) {
|
|
|
|
- try {
|
|
|
|
- console.log('再付分享内容', config);
|
|
|
|
- let mess;
|
|
|
|
- if (config) {
|
|
|
|
- mess = {
|
|
|
|
- link: config.link, // 分享链接
|
|
|
|
- imgUrl: config.imgUrl,
|
|
|
|
- desc: config.desc,
|
|
|
|
- title: config.title,
|
|
|
|
- success: config.success || function(e) {
|
|
|
|
- console.log(e);
|
|
|
|
- },
|
|
|
|
- fail: config.fail || function(e) {
|
|
|
|
- console.log(e);
|
|
|
|
- }
|
|
|
|
|
|
+// 加载分享数据
|
|
|
|
+function shareLoad(config) {
|
|
|
|
+ let mess;
|
|
|
|
+ if (config) {
|
|
|
|
+ mess = {
|
|
|
|
+ link: config.link, // 分享链接
|
|
|
|
+ imgUrl: config.imgUrl,
|
|
|
|
+ desc: config.desc,
|
|
|
|
+ title: config.title,
|
|
|
|
+ success: config.success,
|
|
|
|
+ fail: config.fail||function (e) {
|
|
|
|
+ console.log(e);
|
|
}
|
|
}
|
|
- } else {
|
|
|
|
- const userInfo = uni.getStorageSync('userInfo')
|
|
|
|
- console.log(userInfo);
|
|
|
|
- const url = window.location.href + '?spread=' + userInfo.uid;
|
|
|
|
- url = url.replace(/[\?,&]{0,1}from=singlemessage/g, '');
|
|
|
|
- mess = {
|
|
|
|
- title: shareData.title,
|
|
|
|
- link: url, // 分享链接
|
|
|
|
- imgUrl: shareData.img, // 分享图标
|
|
|
|
- desc: shareData.synopsis,
|
|
|
|
- success: function() {
|
|
|
|
- // uni.showModal({
|
|
|
|
- // title: '分享',
|
|
|
|
- // content: '分享成功',
|
|
|
|
- // showCancel: false,
|
|
|
|
- // success: res => {
|
|
|
|
- // console.log('分享成功回调接口');
|
|
|
|
- // },
|
|
|
|
- // fail: () => {},
|
|
|
|
- // complete: () => {}
|
|
|
|
- // });
|
|
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ // console.log(window.location.href, 55)
|
|
|
|
+ // let url = window.location.href + '?spread=' + store.state.userInfo.uid;
|
|
|
|
+ let url = window.location.href;
|
|
|
|
+ url = url.replace(/[\?,&]{0,1}from=singlemessage/g, '');
|
|
|
|
+ mess = {
|
|
|
|
+ title: shareData.title,
|
|
|
|
+ link: url, // 分享链接
|
|
|
|
+ imgUrl: shareData.img, // 分享图标
|
|
|
|
+ desc: shareData.synopsis,
|
|
|
|
+ success: function() {
|
|
|
|
+ },
|
|
|
|
+ fail:function (e) {
|
|
|
|
+ console.log(e);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- // 获取仓库数据
|
|
|
|
- // 分享好友
|
|
|
|
- weixinObj.updateAppMessageShareData(mess);
|
|
|
|
-
|
|
|
|
- // 分享朋友圈
|
|
|
|
- weixinObj.updateTimelineShareData(mess)
|
|
|
|
- } catch (e) {
|
|
|
|
- console.log(e);
|
|
|
|
- //TODO handle the exception
|
|
|
|
}
|
|
}
|
|
|
|
+ // 获取仓库数据
|
|
|
|
+ // 分享好友
|
|
|
|
+ // weixinObj.updateAppMessageShareData(mess);
|
|
|
|
+ weixinObj.onMenuShareAppMessage(mess);// 即将废弃
|
|
|
|
+ // 分享朋友圈
|
|
|
|
+ // weixinObj.updateTimelineShareData(mess)
|
|
|
|
+ weixinObj.onMenuShareTimeline(mess);// 即将废弃
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// 隐藏功能按钮
|
|
|
|
+export function weixinhideMenu(config) {
|
|
|
|
+ console.log(config)
|
|
|
|
+ weixinObj.ready((e) => {
|
|
|
|
+ weixinObj.hideMenuItems({
|
|
|
|
+ menuList: config, // 要隐藏的菜单项,只能隐藏“传播类”和“保护类”按钮,所有menu项见附录3
|
|
|
|
+ });
|
|
|
|
+ })
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
// 保存路由对象
|
|
// 保存路由对象
|
|
export function setRouter(route) {
|
|
export function setRouter(route) {
|
|
return new Promise((ok, err) => {
|
|
return new Promise((ok, err) => {
|
|
router = getApp().$router;
|
|
router = getApp().$router;
|
|
- // console.log(router,'开始数据');
|
|
|
|
|
|
+ console.log(router,'开始数据');
|
|
if (!router) {
|
|
if (!router) {
|
|
const set = setInterval(() => {
|
|
const set = setInterval(() => {
|
|
router = getApp().$router;
|
|
router = getApp().$router;
|
|
- // console.log(router,'返回数据');
|
|
|
|
|
|
+ console.log(router,'返回数据');
|
|
if (router) {
|
|
if (router) {
|
|
- // console.log(router,'结束');
|
|
|
|
|
|
+ console.log(router,'结束');
|
|
clearInterval(set)
|
|
clearInterval(set)
|
|
ok(router)
|
|
ok(router)
|
|
}
|
|
}
|
|
}, 100);
|
|
}, 100);
|
|
}else{
|
|
}else{
|
|
- // console.log(router,'成功');
|
|
|
|
|
|
+ console.log(router,'成功');
|
|
ok(router)
|
|
ok(router)
|
|
}
|
|
}
|
|
})
|
|
})
|
|
@@ -246,6 +207,5 @@ export default {
|
|
weixinObj,
|
|
weixinObj,
|
|
shareData,
|
|
shareData,
|
|
appId,
|
|
appId,
|
|
- setRouter,
|
|
|
|
- shareLoad
|
|
|
|
|
|
+ setRouter
|
|
}
|
|
}
|