lrf402788946 4 年之前
父節點
當前提交
9537aff682
共有 3 個文件被更改,包括 47 次插入2 次删除
  1. 1 1
      src/layout/common/share.vue
  2. 1 1
      src/main.js
  3. 45 0
      src/router/index.js

+ 1 - 1
src/layout/common/share.vue

@@ -18,7 +18,7 @@ export default {
     return {};
   },
   created() {
-    this.init();
+    // this.init();
   },
   methods: {
     ...weixin(['jsAuth']),

+ 1 - 1
src/main.js

@@ -1,5 +1,6 @@
 import Vue from 'vue';
 import App from './App.vue';
+import '@/plugins/weixin';
 import router from './router';
 import store from './store';
 import '@/plugins/element.js';
@@ -12,7 +13,6 @@ import '@/plugins/loading';
 import '@/plugins/var';
 import '@/plugins/methods';
 import '@/plugins/setting';
-import '@/plugins/weixin';
 import InitStomp from '@/plugins/stomp';
 Vue.config.productionTip = false;
 

+ 45 - 0
src/router/index.js

@@ -113,6 +113,51 @@ router.beforeEach(async (to, form, next) => {
   }
   next();
 });
+
+router.afterEach(async (to, form) => {
+  const url = encodeURIComponent(location.href.split('#')[0]);
+  const wx = Vue.prototype.$wx;
+  const res = await store.dispatch('weixin/jsAuth', { url });
+  if (res.errcode == '0') {
+    const { data } = res;
+    const shareUrl = 'http://broadcast.waityou24.cn/api/article/auth?redirect_uri=' + url;
+    wx.config({
+      debug: true,
+      appId: data.appid,
+      timestamp: data.timestamp,
+      nonceStr: data.noncestr,
+      signature: data.sign,
+      jsApiList: ['updateAppMessageShareData', 'updateTimelineShareData'],
+    });
+    wx.ready(() => {
+      wx.updateAppMessageShareData({
+        title: '测试',
+        desc: '测试内容',
+        // imgUrl: this.img,
+        link: shareUrl,
+        success: res => {
+          console.log('friend share');
+        },
+        error: err => {
+          alert(JSON.stringify(err));
+        },
+      });
+      wx.updateTimelineShareData({
+        title: '测试',
+        // desc: '测试内容',
+        // imgUrl: this.img,
+        link: shareUrl,
+        success: res => {
+          console.log('friends share');
+        },
+        error: err => {
+          alert(JSON.stringify(err));
+        },
+      });
+    });
+  }
+});
+
 const originalPush = VueRouter.prototype.push;
 VueRouter.prototype.push = function push(location, onResolve, onReject) {
   if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject);