Browse Source

文件下载优化

maotao 1 year 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
 			<button @click="goBack" type="default" class="cancelButton btn">返回</button>
16
 			<button @click="goBack" type="default" class="cancelButton btn">返回</button>
17
 			<button @click="importData" type="default" class="primaryButton btn ">引入</button>
17
 			<button @click="importData" type="default" class="primaryButton btn ">引入</button>
18
 		</view>
18
 		</view>
19
+		<uni-popup ref="popup" type="center" >
20
+			<img :src="fileUrl" alt="" class="view-img">
21
+		</uni-popup>
19
   </view>
22
   </view>
20
 </template>
23
 </template>
21
 
24
 
@@ -36,8 +39,6 @@
36
   // 故障类型
39
   // 故障类型
37
   const mutiCategory = ref(null)
40
   const mutiCategory = ref(null)
38
   
41
   
39
-	// 操作类型
40
-	// const operateType = ref(null)
41
 	
42
 	
42
 	// 关联故障分类的知识库数量
43
 	// 关联故障分类的知识库数量
43
 	const introduceCount = ref(0)
44
 	const introduceCount = ref(0)
@@ -45,6 +46,12 @@
45
 	// tab类型
46
 	// tab类型
46
 	const tabType = ref('null')
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
   const dataInfo = reactive({
56
   const dataInfo = reactive({
50
     data: [],//数据
57
     data: [],//数据
@@ -57,14 +64,18 @@
57
   function downloadFile(item){
64
   function downloadFile(item){
58
     console.log(666,item)
65
     console.log(666,item)
59
 		let url = location.origin + "/file" + item.relativeFilePath
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
   onLoad((option) => {
146
   onLoad((option) => {
136
     dataInfo.incidentId = option.incidentId;
147
     dataInfo.incidentId = option.incidentId;
137
 		dataInfo.solutionnumber = option.solutionnumber ;
148
 		dataInfo.solutionnumber = option.solutionnumber ;
138
-		// operateType.value = decodeURIComponent(option.operateType);
139
 		if(option.tabType){
149
 		if(option.tabType){
140
 			tabType.value = option.tabType;
150
 			tabType.value = option.tabType;
141
 		}
151
 		}
@@ -189,5 +199,9 @@
189
 		width: 93.5%; 
199
 		width: 93.5%; 
190
 		padding: 0;
200
 		padding: 0;
191
 	}
201
 	}
202
+	.view-img{
203
+		width: 100%;
204
+		height: 100%;
205
+	}
192
 }
206
 }
193
 </style>
207
 </style>