|
@@ -1,6 +1,8 @@
|
|
<template>
|
|
<template>
|
|
<div id="share">
|
|
<div id="share">
|
|
<van-button type="info" @click="toShare">分享</van-button>
|
|
<van-button type="info" @click="toShare">分享</van-button>
|
|
|
|
+ <van-button type="info" @click="toImg">图片</van-button>
|
|
|
|
+ <van-image :src="simg"></van-image>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
</template>
|
|
|
|
|
|
@@ -18,12 +20,16 @@ export default {
|
|
},
|
|
},
|
|
components: {},
|
|
components: {},
|
|
data: function() {
|
|
data: function() {
|
|
- return {};
|
|
|
|
|
|
+ return {
|
|
|
|
+ simg: '',
|
|
|
|
+ };
|
|
|
|
+ },
|
|
|
|
+ created() {
|
|
|
|
+ this.init();
|
|
},
|
|
},
|
|
- created() {},
|
|
|
|
methods: {
|
|
methods: {
|
|
...weixin(['jsAuth']),
|
|
...weixin(['jsAuth']),
|
|
- async toShare() {
|
|
|
|
|
|
+ async init() {
|
|
// 处理参数
|
|
// 处理参数
|
|
const { path, query } = this.$route;
|
|
const { path, query } = this.$route;
|
|
const { openid, ...others } = query;
|
|
const { openid, ...others } = query;
|
|
@@ -40,38 +46,58 @@ export default {
|
|
// 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;
|
|
const shareUrl = 'http://broadcast.waityou24.cn/articlemobile';
|
|
const shareUrl = 'http://broadcast.waityou24.cn/articlemobile';
|
|
this.$wx.config({
|
|
this.$wx.config({
|
|
- debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
|
|
|
|
- appId: data.appid, // 必填,公众号的唯一标识
|
|
|
|
- timestamp: data.timestamp, // 必填,生成签名的时间戳
|
|
|
|
- nonceStr: data.noncestr, // 必填,生成签名的随机串
|
|
|
|
- signature: data.sign, // 必填,签名
|
|
|
|
|
|
+ debug: false,
|
|
|
|
+ appId: data.appid,
|
|
|
|
+ timestamp: data.timestamp,
|
|
|
|
+ nonceStr: data.noncestr,
|
|
|
|
+ signature: data.sign,
|
|
jsApiList: [
|
|
jsApiList: [
|
|
'updateAppMessageShareData', //朋友及QQ
|
|
'updateAppMessageShareData', //朋友及QQ
|
|
'updateTimelineShareData', // 朋友圈及QQ空间
|
|
'updateTimelineShareData', // 朋友圈及QQ空间
|
|
|
|
+ 'chooseImage',
|
|
],
|
|
],
|
|
});
|
|
});
|
|
- this.$wx.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('share is fail');
|
|
|
|
- alert(JSON.stringify(err));
|
|
|
|
- },
|
|
|
|
- });
|
|
|
|
- });
|
|
|
|
- wx.error(res => {
|
|
|
|
|
|
+ this.$wx.ready(() => {});
|
|
|
|
+ this.$wx.error(res => {
|
|
console.log(res);
|
|
console.log(res);
|
|
});
|
|
});
|
|
}
|
|
}
|
|
},
|
|
},
|
|
|
|
+ async toShare() {
|
|
|
|
+ this.$wx.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('share is fail');
|
|
|
|
+ alert(JSON.stringify(err));
|
|
|
|
+ },
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+ 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('错误');
|
|
|
|
+ });
|
|
|
|
+ },
|
|
},
|
|
},
|
|
computed: {
|
|
computed: {
|
|
...mapState(['user', 'menuParams']),
|
|
...mapState(['user', 'menuParams']),
|