xjc 3 vuotta sitten
vanhempi
commit
7faf71fba1
4 muutettua tiedostoa jossa 53 lisäystä ja 15 poistoa
  1. 23 12
      pages/message/message.js
  2. 4 1
      pages/message/message.wxml
  3. 25 0
      pages/message/message.wxss
  4. 1 2
      utils/api.js

+ 23 - 12
pages/message/message.js

@@ -10,7 +10,9 @@ Page({
      */
     data: {
         focus:false,
-        scrollTop:0
+        scrollTop:0,
+        template_id:"RIsv-Kj_Aws7OnbOxv_v1iQDDESXo0ePPLJQpjkHuus",
+        subscribe:false
     },
 
     /**
@@ -18,12 +20,13 @@ Page({
      */
     onLoad: function (options) {
       this.getData()
-      wx.getSetting({
-        withSubscriptions:true,
-        success (res) {
-          console.log(res)
-          console.log(res.subscriptionsSetting)
-        }
+      wx.getStorage({
+        key: this.data.template_id,
+        success: res=> {
+          this.setData({
+            subscribe: true
+          })
+        },
       })
     },
     getData(){
@@ -44,10 +47,20 @@ Page({
         })
     },
     subscribe(){
+      const template_id = this.data.template_id
+      const that = this;
       wx.requestSubscribeMessage({
-        tmplIds: ['RIsv-Kj_Aws7OnbOxv_v1iQDDESXo0ePPLJQpjkHuus'],
+        tmplIds: [template_id],
         success (res) { 
-          console.log(res)
+          if(res[template_id]=='accept'){
+            wx.setStorage({
+              key: template_id,
+              data: "accept",
+            })
+            that.setData({
+              subscribe:true
+            })
+          }
         }
       })
     },
@@ -79,13 +92,11 @@ Page({
     onShow: function () {
       let that = this;
       wx.createSelectorQuery().select("#messageScroll").boundingClientRect(function(rect){
+        console.log(rect)
         wx.pageScrollTo({
           scrollTop:rect.height,
           duration:100
         })
-        that.setData({
-          scrollTop:rect.height - that.data.scrollTop
-        })
       }).exec()
     },
 

+ 4 - 1
pages/message/message.wxml

@@ -1,4 +1,8 @@
 <view id="messageScroll">
+    <view class="subscribe" wx:if="{{!subscribe}}">
+      <image src="../../images/lb.png" mode="widthFix" class="notice"></image>
+      <text class="noticeMsg" bindtap="subscribe">点我开通即时消息提醒!</text>
+    </view>
     <view class="list" wx:for="{{list}}" >
         <view class="me" wx:if='{{item.user_id}}'>
             <image src="{{item.user_avatar}}" ></image>
@@ -15,7 +19,6 @@
     <view class="post">
         <input confirm-type='send' bindconfirm='post' value="{{comment}}" placeholder-style="color:#999" maxlength="500" bindinput="inputchange" type="text" placeholder="我要咨询"/>
         <button bindtap="post">提交</button>
-        <button bindtap="subscribe">订阅</button>
     </view>
     <view style="clear: both;"></view>
 </view>

+ 25 - 0
pages/message/message.wxss

@@ -89,4 +89,29 @@ page{
     font-size: 28rpx;
     margin-left: 20rpx;
     margin-bottom: 20rpx;
+}
+
+.subscribe{
+  position: fixed;
+  padding: 24rpx 30rpx 80rpx;
+  bottom: 180rpx;
+  left: 0;
+  background: #fff;
+  z-index: 9;
+  border-top: 1px solid rgba(245, 245, 245, 1);
+  display: flex;
+  justify-content: space-between;
+  width: 100%;
+  height: 34rpx;
+}
+.subscribe .notice{
+  width: 34rpx;
+  height: 34rpx;
+  position: absolute;
+  left: 10px;
+  top: 35rpx;
+}
+.subscribe .noticeMsg{
+  padding-left:60rpx;
+  color: red;
 }

+ 1 - 2
utils/api.js

@@ -35,7 +35,6 @@ function request(method, url, data) {
           success(res) {
             //请求成功
             //判断状态码---errCode状态根据后端定义来判断
-            wx.hideNavigationBarLoading()
             if (res.data.code == 0||res.data.pass==1) {
               resolve(res);
             } else if (res.data.code == 403) {
@@ -47,7 +46,7 @@ function request(method, url, data) {
                 })
               }
             }else{
-              
+              wx.hideNavigationBarLoading()
               wx.hideLoading()
               wx.showToast({
                 title: res.data.message,