Browse Source

文件下载优化

maotao 11 months ago
parent
commit
956129d519
1 changed files with 25 additions and 11 deletions
  1. 25 11
      pages/repositoryDetails/repositoryDetails.vue

+ 25 - 11
pages/repositoryDetails/repositoryDetails.vue

@@ -16,6 +16,9 @@
16 16
 			<button @click="goBack" type="default" class="cancelButton btn">返回</button>
17 17
 			<button @click="importData" type="default" class="primaryButton btn ">引入</button>
18 18
 		</view>
19
+		<uni-popup ref="popup" type="center" >
20
+			<img :src="fileUrl" alt="" class="view-img">
21
+		</uni-popup>
19 22
   </view>
20 23
 </template>
21 24
 
@@ -36,8 +39,6 @@
36 39
   // 故障类型
37 40
   const mutiCategory = ref(null)
38 41
   
39
-	// 操作类型
40
-	// const operateType = ref(null)
41 42
 	
42 43
 	// 关联故障分类的知识库数量
43 44
 	const introduceCount = ref(0)
@@ -45,6 +46,12 @@
45 46
 	// tab类型
46 47
 	const tabType = ref('null')
47 48
 	
49
+	// 附件图片预览
50
+	const fileUrl = ref('null')
51
+	
52
+	// Popup状态
53
+	const popup = ref(null)
54
+	
48 55
   // 数据
49 56
   const dataInfo = reactive({
50 57
     data: [],//数据
@@ -57,14 +64,18 @@
57 64
   function downloadFile(item){
58 65
     console.log(666,item)
59 66
 		let url = location.origin + "/file" + item.relativeFilePath
60
-		uni.downloadFile({
61
-			url: url, //仅为示例,并非真实的资源
62
-			success: (res) => {
63
-				if (res.statusCode === 200) {
64
-					console.log('下载成功');
65
-				}
66
-			}
67
-		});
67
+		fileUrl.value = url
68
+		let name = item.name  //文件下载后的名称(带后缀)
69
+		if(item.suffix=='png' || item.suffix=='jpg' || item.suffix=='gif'){
70
+			popup.value.open()
71
+		}else{
72
+			var oA = document.createElement("a");
73
+			oA.download = name; 
74
+			oA.href = url
75
+			document.body.appendChild(oA);
76
+			oA.click();
77
+			oA.remove(); 
78
+		}
68 79
   }
69 80
   
70 81
 	// 引入
@@ -135,7 +146,6 @@
135 146
   onLoad((option) => {
136 147
     dataInfo.incidentId = option.incidentId;
137 148
 		dataInfo.solutionnumber = option.solutionnumber ;
138
-		// operateType.value = decodeURIComponent(option.operateType);
139 149
 		if(option.tabType){
140 150
 			tabType.value = option.tabType;
141 151
 		}
@@ -189,5 +199,9 @@
189 199
 		width: 93.5%; 
190 200
 		padding: 0;
191 201
 	}
202
+	.view-img{
203
+		width: 100%;
204
+		height: 100%;
205
+	}
192 206
 }
193 207
 </style>