Browse Source

添加收藏、分享接口

306132416@qq.com 4 years ago
parent
commit
3488239cc4
3 changed files with 95 additions and 10 deletions
  1. 5 1
      components/footer-share/footer-share.vue
  2. 90 9
      pages/policy/policy_deatil.vue
  3. BIN
      static/collected.png

+ 5 - 1
components/footer-share/footer-share.vue

@@ -20,7 +20,7 @@
     >
       <view style="margin-right: 15rpx; font-size: 26rpx">收藏</view>
       <image
-        src="../../static/collection.png"
+        :src="isCollectedIcon ? '../../static/collected.png' : '../../static/collection.png'"
         mode="aspectFill"
         style="width: 40rpx; height: 40rpx"
       ></image>
@@ -36,6 +36,10 @@ export default {
       type: Boolean,
       default: false,
     },
+	isCollectedIcon: {
+	  type: Boolean,
+	  default: false,
+	},
   },
   data() {
     return {};

+ 90 - 9
pages/policy/policy_deatil.vue

@@ -149,6 +149,7 @@
       <footer-share
         style="width: 100%"
         :isCollection="true"
+		:isCollectedIcon="infoObj.if_collect"
         @collectionPages="collectionPage"
         @sharePages="sharePage"
       ></footer-share>
@@ -224,6 +225,7 @@ export default {
         },
         data: {
           id: ids,
+		  openId:getApp().globalData.open_id
         },
         success: (res) => {
           if (res.data.code === 200) {
@@ -318,18 +320,97 @@ export default {
       });
     },
     collectionPage() {
-      console.log("已收藏");
-    },
-    sharePage() {
-      console.log("分享");
-      uni.showShareMenu({
-        title: "园区XXX",
-        path: "pages/park/park_detail",
-        success(res) {
-          console.log(res);
+      let md5Sign = md5(
+        "method=" +
+          "user" +
+          "&timestamp=" +
+          getApp().globalData.globalTimestamp +
+          "&secret=" +
+          getApp().globalData.secret
+      );
+      let url =
+        getApp().globalData.shareUrl +
+        "api/api.php" +
+        "?method=user&source=policy&action=collect_add&timestamp=" +
+        getApp().globalData.globalTimestamp +
+        "&sign=" +
+        md5Sign;
+      uni.request({
+        url: url,
+        method: "POST",
+        header: {
+          "content-type": "application/x-www-form-urlencoded",
+        },
+        data: {
+			 openId :getApp().globalData.open_id,
+			 source :'policy',
+			 source_name :'政策',
+			 source_id :this.infoObj.id,
+			 source_title :this.infoObj.title
+        },
+        success: (res) => {
+          if (res.data.code === 200) {
+			  res.data.data ? this.infoObj.if_collect = true : this.infoObj.if_collect = false;
+			  this.$forceUpdate();
+			  uni.showToast({
+			  	duration:3000,
+				title:res.data.msg,
+				icon:'none'
+			  })
+          }
+        },
+        fail: () => {
+          console.log("连接失败");
         },
       });
     },
+	shareRequest(){
+		let md5Sign = md5(
+		  "method=" +
+		    "user" +
+		    "&timestamp=" +
+		    getApp().globalData.globalTimestamp +
+		    "&secret=" +
+		    getApp().globalData.secret
+		);
+		let url =
+		  getApp().globalData.shareUrl +
+		  "api/api.php" +
+		  "?method=user&source=policy&action=repost&timestamp=" +
+		  getApp().globalData.globalTimestamp +
+		  "&sign=" +
+		  md5Sign;
+		uni.request({
+		  url: url,
+		  method: "POST",
+		  header: {
+		    "content-type": "application/x-www-form-urlencoded",
+		  },
+		  data: {
+				 openId :getApp().globalData.open_id,
+				 source_id :this.infoObj.id,
+				 source :'policy',
+		  },
+		  success: (res) => {
+		    if (res.data.code === 200) {
+				console.log(res)
+		    }
+		  },
+		  fail: () => {
+		    console.log("连接失败");
+		  },
+		});
+	},
+    sharePage() {
+		let that = this;
+		  uni.showShareMenu({
+			title: that.infoObj.title,
+			path: "pages/policy/policy_detail?id="+that.infoObj.id,
+			success(res) {
+			  that.shareRequest();
+			},
+		});
+    },
     changeScroll(height) {
       //点的时候触发这个函数 height 是之前的高度
       uni.pageScrollTo({

BIN
static/collected.png