Browse Source

调用点赞接口

Limengbo 6 years atrás
parent
commit
51fdd1e327
5 changed files with 58 additions and 20 deletions
  1. 1 2
      README.md
  2. 1 0
      compontents/chat/chat.js
  3. 50 17
      pages/transmit/transmit.js
  4. 1 1
      pages/transmit/transmit.wxml
  5. 5 0
      utils/APIClient.js

+ 1 - 2
README.md

@@ -13,8 +13,7 @@ appId: wx7b5ea6422847ea64;
 
 目录结构如下
 
-```├── README.md
-.
+```
 ├── README.md
 ├── app.js      // 小程序逻辑
 ├── app.json    // 小程序公共设置

+ 1 - 0
compontents/chat/chat.js

@@ -77,5 +77,6 @@ Component({
     }
   },
   ready: function(){
+    this.share = this.selectComponent("#share");
   }
 })

+ 50 - 17
pages/transmit/transmit.js

@@ -11,26 +11,59 @@ Page({
   data: {
     productionData: {}
   },
-
-  methods: {
-    listenerButtonPreviewImage: function(e) {
-      let imgUrl = [];
-      imgUrl.push(e.target.dataset.img);
-      wx.previewImage({
-          current: '', // 当前显示图片的http链接
-          urls: imgUrl, // 需要预览的图片http链接列表
-          //这根本就不走
-          success: function(res) {
-              //console.log(res);
-          },
-          //也根本不走
-          fail: function() {
-              //console.log('fail')
+  /*预览图片*/
+  listenerButtonPreviewImage: function(e) {
+    let imgUrl = [];
+    imgUrl.push(e.target.dataset.img);
+    wx.previewImage({
+        current: '', // 当前显示图片的http链接
+        urls: imgUrl, // 需要预览的图片http链接列表
+        //这根本就不走
+        success: function(res) {
+            //console.log(res);
+        },
+        //也根本不走
+        fail: function() {
+            //console.log('fail')
+        }
+    })
+  },
+  /*点赞接口*/
+  like: function () {
+    const postsId = util.getUrl().postsId;
+    //判断分享过来的参数是否有postId查询单挑显示
+    if(postsId) {
+      login.getOpenidSessionKey(res => {
+        APIClient.getLikeSchedule({
+          uid: res.data.data.uid
+        }, {
+          postsId, 
+        }).success(res => {
+          console.log(res.data)
+          if(res.data.success) {
+            this.setData({
+              productionData: res.data.data,
+            })
           }
-      })
-    }
+        })
+      }, function() {
+        wx.showModal({
+          title: '提示',
+          content: '需要获取您的公开信息(昵称、头像等),请从小程序列表删除小学王者班后再次扫码进入,允许授权后可正常使用',
+          showCancel: false,
+          success: function (res) {
+            if (res.confirm) {
+              console.log('用户点击确定')
+            } else if (res.cancel) {
+              console.log('用户点击取消')
+            }
+          }
+        })
+      });      
+    };
   },
 
+
   /**
    * 生命周期函数--监听页面加载
    */

+ 1 - 1
pages/transmit/transmit.wxml

@@ -29,7 +29,7 @@
                         </block>
                     </view>
                     <view class="icon">
-                        <view>
+                        <view bindtap="like">
                             <image src="../../pages/image/zan.png" class="zan"></image>
                             <text>{{productionData.postsAttributeInfo ? productionData.postsAttributeInfo.favors : '0'}}</text>
                         </view>

+ 5 - 0
utils/APIClient.js

@@ -52,5 +52,10 @@ module.exports = {
 	getSetNameSchedule(header, data) {
 		let url = genAPIUrl('wx/ucenter/user/update');
 		return request.getInstance().url(url).header(header).data(data).method('GET').send();
+	},
+	//分享后点赞
+	getLikeSchedule(header, data) {
+		let url = genAPIUrl('wx/posts/attribute');
+		return request.getInstance().url(url).header(header).data(data).method('GET').send();
 	}
 }