lrf402788946 4 rokov pred
rodič
commit
d042b07c55
1 zmenil súbory, kde vykonal 52 pridanie a 26 odobranie
  1. 52 26
      src/layout/common/share.vue

+ 52 - 26
src/layout/common/share.vue

@@ -1,6 +1,8 @@
 <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>
   </div>
 </template>
 
@@ -18,12 +20,16 @@ export default {
   },
   components: {},
   data: function() {
-    return {};
+    return {
+      simg: '',
+    };
+  },
+  created() {
+    this.init();
   },
-  created() {},
   methods: {
     ...weixin(['jsAuth']),
-    async toShare() {
+    async init() {
       // 处理参数
       const { path, query } = this.$route;
       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/articlemobile';
         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: [
             'updateAppMessageShareData', //朋友及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);
         });
       }
     },
+    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: {
     ...mapState(['user', 'menuParams']),