You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
132 lines
4.0 KiB
132 lines
4.0 KiB
<script>
|
|
const jwx = require('jweixin-module')
|
|
|
|
export default {
|
|
onLaunch: async function() {
|
|
try {
|
|
await new Promise(resolve => {
|
|
this.$nextTick(() => {
|
|
resolve();
|
|
});
|
|
});
|
|
let link = window.location.href;
|
|
if (/code=/.test(link) || link.indexOf("code") > -1) {
|
|
let temp = decodeURIComponent((new RegExp('[?|&]' + 'code' + '=' + '([^&;]+?)(&|#|;|$)').exec(
|
|
link) || [, ''])[1].replace(/\+/g, '%20')) || null;
|
|
let kpsz_lifeData = uni.getStorageSync('kpsz_lifeData');
|
|
if (!kpsz_lifeData.vuex_token) {
|
|
const loginRes = await this.$u.api.login({
|
|
code: temp
|
|
});
|
|
this.$u.vuex('vuex_token', loginRes.token);
|
|
|
|
const userRes = await this.$u.api.user();
|
|
this.$u.vuex('vuex_user', userRes);
|
|
|
|
let url = location.href.split('#')[0];
|
|
let shareLink = "https://vr.langye.net/h5kpsz/";
|
|
const shareRes = await this.$u.api.share({
|
|
url
|
|
});
|
|
|
|
jwx.config({
|
|
debug: false,
|
|
appId: shareRes.appId,
|
|
jsApiList: shareRes.jsApiList,
|
|
nonceStr: shareRes.nonceStr,
|
|
signature: shareRes.signature,
|
|
timestamp: shareRes.timestamp,
|
|
});
|
|
|
|
await new Promise((resolve) => {
|
|
jwx.ready(() => {
|
|
jwx.updateAppMessageShareData({
|
|
title: '科学就在身边',
|
|
link: shareLink,
|
|
desc: '你学科技知识·我送科普图书',
|
|
imgUrl: 'https://vr.langye.net/h5kpsz/static/share.jpg',
|
|
success: () => {
|
|
console.log('updateAppMessageShareData-success');
|
|
},
|
|
});
|
|
jwx.updateTimelineShareData({
|
|
title: '科学就在身边',
|
|
desc: '你学科技知识·我送科普图书',
|
|
link: shareLink,
|
|
imgUrl: 'https://vr.langye.net/h5kpsz/static/share.jpg',
|
|
success: () => {
|
|
console.log('updateTimelineShareData-success');
|
|
}
|
|
});
|
|
resolve();
|
|
});
|
|
});
|
|
} else {
|
|
const userRes = await this.$u.api.user();
|
|
this.$u.vuex('vuex_user', userRes);
|
|
|
|
let url = location.href.split('#')[0];
|
|
let shareLink = "https://vr.langye.net/h5kpsz/";
|
|
const shareRes = await this.$u.api.share({
|
|
url
|
|
});
|
|
|
|
jwx.config({
|
|
debug: false,
|
|
appId: shareRes.appId,
|
|
jsApiList: shareRes.jsApiList,
|
|
nonceStr: shareRes.nonceStr,
|
|
signature: shareRes.signature,
|
|
timestamp: shareRes.timestamp,
|
|
});
|
|
|
|
await new Promise((resolve) => {
|
|
jwx.ready(() => {
|
|
jwx.updateAppMessageShareData({
|
|
title: '科学就在身边',
|
|
link: shareLink,
|
|
desc: '你学科技知识·我送科普图书',
|
|
imgUrl: 'https://vr.langye.net/h5kpsz/static/share.jpg',
|
|
success: () => {
|
|
console.log('updateAppMessageShareData-success');
|
|
},
|
|
});
|
|
jwx.updateTimelineShareData({
|
|
title: '科学就在身边',
|
|
desc: '你学科技知识·我送科普图书',
|
|
link: shareLink,
|
|
imgUrl: 'https://vr.langye.net/h5kpsz/static/share.jpg',
|
|
success: () => {
|
|
console.log('updateTimelineShareData-success');
|
|
}
|
|
});
|
|
resolve();
|
|
});
|
|
});
|
|
}
|
|
} else {
|
|
const appIdRes = await this.$u.api.getAppId();
|
|
let redirect = encodeURIComponent(link.replace(/#\//, ""));
|
|
console.log(redirect);
|
|
window.location.href =
|
|
`https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appIdRes.appid}&redirect_uri=${redirect}&response_type=code&scope=snsapi_base#wechat_redirect`;
|
|
// this.$u.vuex('vuex_token', 'mobile-9614');
|
|
}
|
|
} catch (error) {
|
|
console.error('onLaunch 中出现错误:', error);
|
|
}
|
|
},
|
|
onShow: function() {
|
|
|
|
},
|
|
onHide: function() {
|
|
console.log('App Hide')
|
|
}
|
|
|
|
}
|
|
</script>
|
|
|
|
<style lang="scss">
|
|
/*每个页面公共css */
|
|
@import "uview-ui/index.scss";
|
|
</style> |