zizhong.wang 3 years ago
parent
commit
30f985a674
1 changed files with 73 additions and 0 deletions
  1. 73 0
      pages/notice/notice_deatil.vue

+ 73 - 0
pages/notice/notice_deatil.vue

@@ -1,6 +1,12 @@
 <template>
   <view>
     <artical-deatil :model="model"></artical-deatil>
+	<view class="closure-font" v-if="enClosureList.length">
+		附件:
+	</view>
+	<view class="enClosure-box" v-for="(item,index) in enClosureList" :key="item.id">
+		<view @click="showEnclosure(item.url)">{{index + 1}}.{{item.name}}</view>
+	</view>
   </view>
 </template>
 
@@ -17,6 +23,8 @@ export default {
         artical: "",
         id: "",
       },
+	  enClosureList:[],
+	  shareUrl:getApp().globalData.shareUrl
     };
   },
   components: {
@@ -65,6 +73,9 @@ export default {
             );
             this.model.time = time + " " + timeSecond;
             this.getRich();
+			if(data.attach_ids){
+				this.getEnclosure(data.attach_ids)
+			}
           }
         },
         fail: () => {
@@ -72,6 +83,53 @@ export default {
         },
       });
     },
+	showEnclosure(url){
+		uni.showLoading({
+			title:'加载中...'
+		})
+		let urls = this.shareUrl + url;
+		uni.downloadFile({
+		  url: urls,
+		  success: function (res) {
+			var filePath = res.tempFilePath;
+			uni.openDocument({
+			  filePath: filePath,
+			  showMenu: true,
+			  success: function (res) {
+				uni.hideLoading();
+			  }
+			});
+		  }
+		});
+	},
+	getEnclosure(athId){
+		let md5Sign = md5(
+		  "method=" +"common" +"&timestamp=" + getApp().globalData.globalTimestamp +"&secret=" +getApp().globalData.secret
+		);
+		let url =
+		  getApp().globalData.shareUrl + "api/api.php" +"?method=common&action=attach_ids&timestamp=" +
+		  getApp().globalData.globalTimestamp + "&sign=" + md5Sign;
+		let postData = {
+		  attach_ids: athId,
+		};
+		//获取文章
+		uni.request({
+		  url: url,
+		  method: "POST",
+		  header: {
+		    "content-type": "application/x-www-form-urlencoded",
+		  },
+		  data: postData,
+		  success: (res) => {
+		    if (res.data.code === 200) {
+				this.enClosureList = res.data.data;
+		    }
+		  },
+		  fail: () => {
+		    console.log("连接失败");
+		  },
+		});
+	},
     replaceImg(html) {
       let result = html.replace(
         /<img [^>]*src=['"]([^'"]+)[^>]*>/gi,
@@ -116,4 +174,19 @@ export default {
 </script>
 
 <style lang="scss" scoped>
+	.closure-font {
+		font-size: 28rpx;
+		padding-left: 40rpx;
+		margin-bottom: 20rpx;
+	}
+	.enClosure-box {
+		width: 100%;
+		display: flex;
+		flex-direction: column;
+		font-size: 26rpx;
+		padding-left: 40rpx;
+		color: cornflowerblue;
+		cursor: pointer;
+		margin-bottom: 20rpx;
+	}
 </style>