Pārlūkot izejas kodu

feat:分享方法

yangfeng 3 gadi atpakaļ
vecāks
revīzija
c3cb5a6c26

+ 82 - 0
src/web/staticres/common-module/yearEndReport/js/share.js

@@ -0,0 +1,82 @@
+var shareFn = {
+  isWeiXinBrowser: navigator.userAgent.toLowerCase().indexOf('micromessenger') !== -1,
+  wxSDKSign: {
+    debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印
+    appId: '', // 必填,公众号的唯一标识
+    timestamp: '', // 必填,生成签名的时间戳
+    nonceStr: '', // 必填,生成签名的随机串
+    signature: '',// 必填,签名
+    jsApiList: [
+        // 自定义“分享给朋友”及“分享到QQ”按钮的分享内容
+        'updateAppMessageShareData',
+        // 自定义“分享到朋友圈”及“分享到QQ空间”按钮的分享内容
+        'updateTimelineShareData',
+        // 获取“分享到腾讯微博”按钮点击状态及自定义分享内容接口
+        'onMenuShareWeibo',
+        // 关闭当前网页窗口接口
+        'closeWindow',
+        // 批量隐藏功能按钮接口
+        // 'hideMenuItems',
+        // 批量显示功能按钮接口
+        // 'showMenuItems',
+        // 隐藏所有非基础按钮接口
+        // 'hideAllNonBaseMenuItem',
+        // 显示所有功能按钮接口
+        // 'showAllNonBaseMenuItem',
+        // 调起微信扫一扫接口
+        // 'scanQRCode'
+    ],
+    openTagList: ['wx-open-launch-app']
+  },
+  shareInfo: {
+    title: '剑鱼标讯',
+    desc: '我的剑鱼标讯2021年度报告已经生成,请查收',
+    link: location.href.split('?')[0],
+    imgUrl: 'https://cdn-ali.jianyu360.com/images/appext/fixed-sm.jpg'
+  },
+  init: function () {
+    if (this.isWeiXinBrowser) {
+      this.getWxSdkSign()
+    }
+  },
+   // 取用户appid、签名等
+   getWxSdkSign: function() {
+    var _this = this
+    $.ajax({
+      url: '/jypay/wx/getwxSdkSign',
+      type: 'POST',
+      data: {
+        url: location.href.split('#')[0]
+      },
+      success: function (res) {
+        if (res && res.wxsdk && $.isArray(res.wxsdk)) {
+          _this.wxSDKSign.appId = res.wxsdk[0]
+          _this.wxSDKSign.timestamp = res.wxsdk[1]
+          _this.wxSDKSign.nonceStr = res.wxsdk[2]
+          _this.wxSDKSign.signature = res.wxsdk[3]
+          _this.registerWxSDK()
+        }
+      },
+      complete: function () {},
+      error: function () {}
+    })
+  },
+  // 注册微信sdk方法
+  registerWxSDK: function () {
+    var _this = this
+    // 微信sdk注册
+    wx.config(this.wxSDKSign)
+    wx.error(function(err){
+      console.log(err);
+    })
+    wx.ready(function (res) {
+      // 自定义“分享给朋友”及“分享到QQ”按钮的分享内容
+      wx.updateAppMessageShareData(_this.shareInfo)
+      // 自定义“分享到朋友圈”及“分享到QQ空间”按钮的分享内容
+      wx.updateTimelineShareData(_this.shareInfo)
+      // onMenuShareWeibo
+      wx.onMenuShareWeibo(_this.shareInfo)
+    })
+  }
+}
+shareFn.init()