Parcourir la source

开发联调发送通知

bayi il y a 1 an
Parent
commit
d67d5009bd
6 fichiers modifiés avec 53 ajouts et 9 suppressions
  1. 2 0
      api/global.js
  2. 31 6
      pages/index/index.js
  3. 8 0
      pages/index/index.less
  4. 1 0
      pages/index/index.wxml
  5. 8 0
      pages/index/index.wxss
  6. 3 3
      utils/request.js

+ 2 - 0
api/global.js

@@ -27,6 +27,8 @@ module.exports = {
     // 获取邀新总榜
     getInviteRanking: data => request('/v3/activity/inviteNewRank',
         'get', data),
+    // 获取授权推送消息接口
+    setSubscribe: (data, method = 'get') => request('/v3/subscribe', method, data),
     //  生成用户分享二维码
     createWxCode: data => request('/qrCode', 'get', data),
     // 用户行为统计

+ 31 - 6
pages/index/index.js

@@ -4,7 +4,8 @@ import {
     getResourceList
 } from "~/api/works"
 import {
-    getBannerList
+    getBannerList,
+    setSubscribe
 } from '~/api/global'
 import event from '~/mixins/event'
 import share from '~/mixins/share'
@@ -22,6 +23,8 @@ Page({
         bannerList: [],
         categoryList: [],
         listOptions: {},
+        subscribeShow: false,
+        tmplIds: []
     },
     onLoad(options) {
         this.getLocUserInfo()
@@ -47,7 +50,6 @@ Page({
                 })
             }, 6000)
         }
-        this.requestMessage()
     },
     onShow() {
         if (typeof this.getTabBar === 'function') {
@@ -60,6 +62,7 @@ Page({
         this.getBannerList()
         this.getResource()
         this.getCategoryList()
+        this.getSubscribe()
     },
     async getLocUserInfo() {
         this.storeBindings = createStoreBindings(this, {
@@ -126,11 +129,33 @@ Page({
             url: '/pages/childClassify/index?type=search',
         })
     },
+    async getSubscribe() {
+        let tmplIds = await setSubscribe()
+        console.log(tmplIds);
+        this.setData({
+            tmplIds: tmplIds ? tmplIds : [],
+            subscribeShow: tmplIds ? true : false,
+        })
+    },
     requestMessage() {
-       /*  wx.requestSubscribeMessage({
-            tmplIds: [''],
-            success(res) {}
-        }) */
+        wx.requestSubscribeMessage({
+            tmplIds: this.data.tmplIds,
+            success: async (res) => {
+                console.log(res);
+                let accept = []
+                this.data.tmplIds.forEach(item => {
+                    console.log(res[item]);
+                    if (res[item] == 'accept') {
+                        accept.push(item)
+                    }
+                })
+                let subscribeRes = await setSubscribe({
+                    ids: accept
+                }, 'post')
+                console.log(subscribeRes);
+                this.getSubscribe()
+            }
+        })
     },
     onUnload() {
         this.storeBindings.destroyStoreBindings()

+ 8 - 0
pages/index/index.less

@@ -67,4 +67,12 @@
             height: 176rpx;
         }
     }
+}
+.subscribe{
+    position: fixed;
+    top: 0;
+    left: 0;
+    z-index: 99;
+    width: 100vw;
+    height: 100vh;
 }

+ 1 - 0
pages/index/index.wxml

@@ -28,4 +28,5 @@
         <image src="http://reader-wx.ai160.com/images/reader/v3/desktop-android.png" class="tipsImg" />
     </view>
 </view>
+<view class="subscribe" wx:if="{{subscribeShow}}" bindtap="requestMessage"></view>
 <canvas id='share' type="2d"> </canvas>

+ 8 - 0
pages/index/index.wxss

@@ -60,3 +60,11 @@
   width: 530rpx;
   height: 176rpx;
 }
+.subscribe {
+  position: fixed;
+  top: 0;
+  left: 0;
+  z-index: 99;
+  width: 100vw;
+  height: 100vh;
+}

+ 3 - 3
utils/request.js

@@ -6,13 +6,13 @@ const {
         envVersion
     }
 } = wx.getAccountInfoSync();
-/* if (envVersion == 'develop') {
+if (envVersion == 'develop') {
     baseUrl = 'https://reader-api.efunbox.cn/wx'
     oldUrl = 'https://reader-api.efunbox.cn'
-} else { */
+} else {
     baseUrl = 'https://reader-api.ai160.com/wx'
     oldUrl = 'https://reader-api.ai160.com'
-// }
+}
 
 function request(url, method, data, oldBaseUrl = false, intercept = true) {