|
@@ -1,8 +1,6 @@
|
|
|
<template>
|
|
|
<div id="share">
|
|
|
- <van-button type="info" @click="toShare">分享</van-button>
|
|
|
- <van-button type="info" @click="toImg">图片</van-button>
|
|
|
- <van-image :src="simg"></van-image>
|
|
|
+ <van-button @click="test">分享</van-button>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
@@ -21,12 +19,18 @@ export default {
|
|
|
components: {},
|
|
|
data: function() {
|
|
|
return {
|
|
|
- simg: '',
|
|
|
+ config: {
|
|
|
+ shareList: ['weixin'],
|
|
|
+ common: {
|
|
|
+ bdText: '分享测试',
|
|
|
+ bdDesc: '分享测试摘要',
|
|
|
+ bdUrl: 'http://broadcast.waityou24.cn/api/article/auth?redirect_uri=http://broadcast.waityou24.cn/articlemobile',
|
|
|
+ },
|
|
|
+ },
|
|
|
};
|
|
|
},
|
|
|
- mounted() {
|
|
|
- console.log('in function:');
|
|
|
- this.init();
|
|
|
+ created() {
|
|
|
+ // this.init();
|
|
|
},
|
|
|
methods: {
|
|
|
...weixin(['jsAuth']),
|
|
@@ -44,10 +48,10 @@ export default {
|
|
|
const res = await this.jsAuth({ url });
|
|
|
if (this.$checkRes(res)) {
|
|
|
const { data } = res;
|
|
|
- // const shareUrl = 'http://broadcast.waityou24.cn/api/article/auth?redirect_uri=http://broadcast.waityou24.cn/articlemobile' + this.route;
|
|
|
+ const shareUrl = 'http://broadcast.waityou24.cn/api/article/auth?redirect_uri=http://broadcast.waityou24.cn/articlemobile' + this.route;
|
|
|
// 'updateTimelineShareData', // 朋友圈及QQ空间
|
|
|
this.$wx.config({
|
|
|
- debug: true,
|
|
|
+ debug: false,
|
|
|
appId: data.appid,
|
|
|
timestamp: data.timestamp,
|
|
|
nonceStr: data.noncestr,
|
|
@@ -55,7 +59,20 @@ export default {
|
|
|
jsApiList: ['updateAppMessageShareData', 'chooseImage', 'onMenuShareAppMessage'],
|
|
|
});
|
|
|
this.$wx.ready(() => {
|
|
|
- console.log('in ready');
|
|
|
+ this.$wx.updateAppMessageShareData({
|
|
|
+ title: this.title,
|
|
|
+ desc: this.desc,
|
|
|
+ // imgUrl: this.img,
|
|
|
+ link: shareUrl,
|
|
|
+ success: res => {
|
|
|
+ console.log(res);
|
|
|
+ console.log(shareUrl);
|
|
|
+ console.log('in function:share success');
|
|
|
+ },
|
|
|
+ error: err => {
|
|
|
+ alert(JSON.stringify(err));
|
|
|
+ },
|
|
|
+ });
|
|
|
});
|
|
|
this.$wx.error(res => {
|
|
|
console.log('config 有问题');
|
|
@@ -63,45 +80,23 @@ export default {
|
|
|
});
|
|
|
}
|
|
|
},
|
|
|
- async toShare() {
|
|
|
- this.$wx.ready(() => {
|
|
|
- const shareUrl = 'http://broadcast.waityou24.cn/articlemobile';
|
|
|
- this.$wx.onMenuShareAppMessage({
|
|
|
- title: this.title,
|
|
|
- desc: this.desc,
|
|
|
- // imgUrl: this.img,
|
|
|
- link: shareUrl,
|
|
|
- success: res => {
|
|
|
- console.log(res);
|
|
|
- console.log(shareUrl);
|
|
|
- console.log('in function:share success');
|
|
|
- },
|
|
|
- error: err => {
|
|
|
- alert('share is fail');
|
|
|
- alert(JSON.stringify(err));
|
|
|
- },
|
|
|
- });
|
|
|
- });
|
|
|
- this.$wx.error(res => {
|
|
|
- console.log('share 有问题');
|
|
|
- console.log(res);
|
|
|
- });
|
|
|
- },
|
|
|
- async toImg() {
|
|
|
- this.$wx.ready(() => {
|
|
|
- this.$wx.chooseImage({
|
|
|
- count: 1, // 默认9
|
|
|
- sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
|
|
|
- sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
|
|
|
- success: res => {
|
|
|
- var localIds = res.localIds; // 返回选定照片的本地ID列表,localId可以作为img标签的src属性显示图片
|
|
|
- this.simg = res.localIds[0];
|
|
|
- },
|
|
|
- });
|
|
|
- });
|
|
|
- this.$wx.error(err => {
|
|
|
- console.log('错误');
|
|
|
- });
|
|
|
+ async test() {
|
|
|
+ console.log(WeixinJSBridge);
|
|
|
+ WeixinJSBridge.invoke(
|
|
|
+ 'sendAppMessage',
|
|
|
+ {
|
|
|
+ appid: 'wxdf3ed83c095be97a', //appid 设置空就好了。
|
|
|
+ // img_url: '',
|
|
|
+ // img_width: '120', //图片宽度
|
|
|
+ // img_height: '120', //图片高度
|
|
|
+ link: 'http://broadcast.waityou24.cn/api/article/auth?redirect_uri=http://broadcast.waityou24.cn/articlemobile', //分享附带链接地址
|
|
|
+ desc: '我是一个介绍', //分享内容介绍
|
|
|
+ title: '标题,再简单不过了。',
|
|
|
+ },
|
|
|
+ function(res) {
|
|
|
+ /*** 回调函数,最好设置为空 ***/
|
|
|
+ }
|
|
|
+ );
|
|
|
},
|
|
|
},
|
|
|
computed: {
|