<template>
<div id="app">
<keep-alive>
<router-view v-if="$route.meta.keepAlive" :key="$route.fullPath"></router-view>
</keep-alive>
<router-view v-if="!$route.meta.keepAlive" :key="$route.fullPath"></router-view>
</div>
</template>
<script>
// import wx from "weixin-js-sdk";
export default {
name: "App",
created() {
// document.body.removeChild(document.getElementById('loader-wrapper'));
},
mounted() {
// this.getWxShareConfig();
},
methods: {
// 获取分享配置
getWxShareConfig() {
var link = this.api_host + "/web/#/";
var title = "分享标题";
var desc = "分享desc";
var imgUrl =
"http://wangshijie.oss-cn-beijing.aliyuncs.com/20191213/165211_975274.1576227131.png";
let url = this.api_host + "/index.php/api/v1_0_0.share/do_share";
let p = {
user_id: localStorage.getItem("user_id"),
user_token: localStorage.getItem("user_token"),
url: window.location.href
};
console.log('share p:');
console.log(p);
console.log('');
this.post(url, p).then(r => {
var res = r.data;
console.log('share res:');
console.log(res);
console.log('');
var code = res.code;
var msg = res.msg;
var data = res.data;
if (code == 200) {
let appId = data.share.appId;
let nonceStr = data.share.nonceStr;
let timestamp = data.share.timestamp;
let signature = data.share.signature;
let that = this;
wx.config({
debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
appId: appId, // 必填,公众号的唯一标识
timestamp: timestamp, // 必填,生成签名的时间戳
nonceStr: nonceStr, // 必填,生成签名的随机串
signature: signature, // 必填,签名
jsApiList: ["updateAppMessageShareData", "updateTimelineShareData"] // 必填,需要使用的JS接口列表
});
wx.ready(function() {
//需在用户可能点击分享按钮前就先调用
wx.updateAppMessageShareData({
title: title, // 分享标题
desc: desc, // 分享描述
link: link, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
imgUrl: imgUrl, // 分享图标
success: function() {
// 设置成功
}
});
});
wx.ready(function() {
//需在用户可能点击分享按钮前就先调用
wx.updateTimelineShareData({
title: title, // 分享标题
link: link, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
imgUrl: imgUrl, // 分享图标
success: function() {
// 设置成功
}
});
});
} else if (code == 201) {
this.$toast(msg);
} else if (code == 202) {
this.$router.push({ path: "/index/login/wx" });
}
});
}
}
};
</script>
<style>
#app {
font-family: "Avenir", Helvetica, Arial, sans-serif;
/* -webkit-font-smoothing: antialiased; */
/* -moz-osx-font-smoothing: grayscale; */
color: #2c3e50;
/* margin-top: 60px; */
font-size: 32px;
}
body {
margin: 0;
padding: 0;
min-height: 100vh;
background: #fff;
}
</style>
网友评论