chending1994 4 лет назад
Родитель
Сommit
e675c8810c
3 измененных файлов с 79 добавлено и 38 удалено
  1. 2 2
      src/App.vue
  2. 2 2
      src/main.js
  3. 75 34
      src/utils/utils.js

+ 2 - 2
src/App.vue

@@ -1,5 +1,5 @@
 <script>
-	import { isWechat, wxConfigH5, weixinLogin, getQueryString } from '@/utils/utils';
+	import { isWechat, wxConfigH5, weixinLogin, getQueryString, wxShare } from '@/utils/utils';
 
 	export default {
 		async onLaunch(options) {
@@ -14,7 +14,7 @@
 				// #ifdef H5
 				if (isWechat()) {
 					const url = window.location.href.split('#')[0];
-					await wxConfigH5(url);
+					// await wxConfigH5(url);
 					wxShare();
 				}
 				// #endif

+ 2 - 2
src/main.js

@@ -12,8 +12,8 @@ import $mSettingConfig from '@/config/setting.config.js';
 import $mFormRule from '@/config/formRule.config.js';
 import $mGraceChecker from '@/utils/graceChecker';
 
-// import Vconsole from 'vconsole'
-// new Vconsole()
+import Vconsole from 'vconsole'
+new Vconsole()
 
 Vue.prototype.$http = http;
 Vue.prototype.$mStore = store;

+ 75 - 34
src/utils/utils.js

@@ -28,6 +28,8 @@ export async function wxConfigH5(url) {
     'chooseWXPay',
     'chooseImage',
     'scanQRCode',
+    'onMenuShareAppMessage',
+    'onMenuShareTimeline',
     'updateAppMessageShareData',
     'updateTimelineShareData',
     'getLocalImgData',
@@ -58,44 +60,83 @@ export async function wxConfigH5(url) {
 
 export function wxShare(title, imgUrl, desc, link) {
   const url = window.location.href.split('#')[0];
-  const shareTitle = title || '中德智慧教育';
-  const shareDesc = desc || '全球思维儿童教育专家 全球优质教育内容输出平台';
-  const shareLink = link || url;
-  const shareImgUrl = imgUrl || 'http://res.training.luojigou.vip/FiLdD-zXCwM6A6JkVzAp8nKM7WLx';
-  wx.ready(() => {
-    wx.onMenuShareTimeline({
-      title: shareTitle, // 分享时的标题
-      link: shareLink, // 分享时的链接
-      imgUrl: shareImgUrl, // 分享时的图标
-      success() {
-        // Toast('分享成功');
-        console.log('分享成功');
-      },
-      cancel() {
-        // Toast('取消分享');
-        console.log('取消分享');
-      },
+  if (!isWechat()) {
+    return;
+  }
+  const jsApiList = [
+    'chooseWXPay',
+    'chooseImage',
+    'scanQRCode',
+    'onMenuShareAppMessage',
+    'onMenuShareTimeline',
+    'updateAppMessageShareData',
+    'updateTimelineShareData',
+    'getLocalImgData',
+    'uploadImage'
+  ];
+  http.get(`${wechatConfig}`, {
+    // url: url,
+    url: url,
+    // baseUrl: 'https://app.zaojiao.net/'
+  })
+  .then(r=> {
+    wx.config({
+      debug: false,
+      appId: r.data.appId,
+      timestamp: r.data.timestamp,
+      nonceStr: r.data.nonceStr,
+      signature: r.data.signature,
+      jsApiList: jsApiList,
+      openTagList: ["wx-open-launch-weapp"]
     });
-    // 分享给朋友
-    wx.onMenuShareAppMessage({
-      title: shareTitle,
-      desc: shareDesc,
-      link: shareLink,
-      imgUrl: shareImgUrl,
-      type: '',
-      dataUrl: '',
-      success() {
-        // Toast('分享成功');
-        console.log('分享成功');
-      },
-      cancel() {
-        // Toast('取消分享');
-        console.log('取消分享');
-      },
+
+    wx.error((err) => {
+      console.log('err', err);
+    });
+
+    const shareTitle = title || '中德智慧教育';
+    const shareDesc = desc || '全球思维儿童教育专家 全球优质教育内容输出平台';
+    const shareLink = link || url;
+    const shareImgUrl = imgUrl || 'http://res.training.luojigou.vip/FiLdD-zXCwM6A6JkVzAp8nKM7WLx';
+    
+    wx.ready(() => {
+      wx.onMenuShareTimeline({
+        title: shareTitle, // 分享时的标题
+        link: shareLink, // 分享时的链接
+        imgUrl: shareImgUrl, // 分享时的图标
+        success() {
+          // Toast('分享成功');
+          console.log('分享成功');
+        },
+        cancel() {
+          // Toast('取消分享');
+          console.log('取消分享');
+        },
+      });
+      // 分享给朋友
+      wx.onMenuShareAppMessage({
+        title: shareTitle,
+        desc: shareDesc,
+        link: shareLink,
+        imgUrl: shareImgUrl,
+        type: '',
+        dataUrl: '',
+        success() {
+          // Toast('分享成功');
+          console.log('分享成功');
+        },
+        cancel() {
+          // Toast('取消分享');
+          console.log('取消分享');
+        },
+      });
     });
-  });
+  }).catch(() => {
+    console.log('catch')
+  })
 }
 
+
 export function getQueryString(name) {
   let reg = new RegExp(`(^|&)${name}=([^&]*)(&|$)`, 'i');
   let r = window.location.search.substr(1).match(reg); // 获取url中"?"符后的字符串并正则匹配