Quellcode durchsuchen

2024-2-24 文件预览下载,放大

dzl vor 9 Monaten
Ursprung
Commit
b7f7be507c
3 geänderte Dateien mit 78 neuen und 10 gelöschten Zeilen
  1. 2 2
      manifest.json
  2. 13 2
      pages.json
  3. 63 6
      pages/office/office.vue

+ 2 - 2
manifest.json

@@ -2,8 +2,8 @@
     "name" : "协同办公",
     "appid" : "__UNI__EEB5AF5",
     "description" : "",
-    "versionName" : "1.7.5",
-    "versionCode" : 175,
+    "versionName" : "1.7.6",
+    "versionCode" : 176,
     "transformPx" : false,
     "app-plus" : {
         /* 5+App特有相关 */

+ 13 - 2
pages.json

@@ -187,8 +187,19 @@
 		"path" : "pages/office/office",
 		"style" : 
 		{
-			"navigationBarTitleText" : "",
-			"enablePullDownRefresh" : false
+			"navigationBarTitleText" : "文件预览",
+			"enablePullDownRefresh" : false,
+			"app-plus": {
+				"bounce": "none",
+				"titleNView": {
+					"buttons": [
+						{
+							"fontSize": "16px",
+							"text": "下载"
+						}
+					]
+				}
+			}
 		}
 	}],
 	"globalStyle": {

+ 63 - 6
pages/office/office.vue

@@ -1,28 +1,85 @@
 <template>
 	<div class="wrap">
-		 <web-view :src="filePath"></web-view>
+		 <web-view :src="filePath" :update-title="false"></web-view>
 	</div>
 </template>
 
 <script>
 	import Base64 from 'base-64'
+	var wv
+	var currentWebview 
 	//引入相关样式
 	export default {
 		data() {
 			return {
 				filePath: "", // 预览地址
-				fileType: "", // 文件类型
+				path: "", // 文件类型
+				list1:[],
+				list2:[]
 			};
 		},
 		onLoad(options) {
-			console.log(options)
+			uni.showLoading({
+				title:"加载中..."
+			})
+			currentWebview = this.$scope.$getAppWebview() //获取当前页面的webview对象
+			currentWebview.onLoad = this.loadSuccess()
 			this.filePath =`http://121.28.24.104:13898/app/kkfile/onlinePreview?url=${encodeURIComponent(Base64.encode(options.url))}` 
-			// this.fileType = options.type
-			// encodeURIComponent(Base64.encode(options.url))
+			this.path = options.url
+		},
+		onNavigationBarButtonTap(e) {
+			let that = this
+		    uni.showLoading({
+		    	title:"打开中...",
+		    })
+		    if(that.list1.indexOf(that.path) == -1){
+		    	uni.downloadFile({
+		    	  url:that.path,
+		    	  success: function(res) {
+		    	    if (res.statusCode === 200) {
+		    			that.list1.push(that.path)
+		    			that.list2.push(res.tempFilePath)
+		    	      uni.openDocument({
+		    	        filePath: res.tempFilePath,
+		    			success: function (res) {
+		    				uni.hideLoading();
+		    			}
+		    	      });
+		    	    }else{
+		    			uni.hideLoading()
+		    			uni.showToast({
+		    				title:"下载失败",
+		    				icon:'none'
+		    			})
+		    		}
+		    	  },fail:function(){
+		    		  uni.hideLoading()
+		    		  uni.showToast({
+		    		  	title:"下载失败",
+		    			icon:'none'
+		    		  })
+		    	  }
+		    	});
+		    }else{
+		    	uni.openDocument({
+		    	  filePath: that.list2[that.list1.indexOf(that.path)],
+		    	  success: function (res) {
+		    	  	uni.hideLoading();
+		    	  }
+		    	});
+		    }
 		},
 		methods: {
-			 
+			loadSuccess(){
+				uni.hideLoading()
+			}
 		},
+		onReady() {
+			setTimeout(function() {
+				wv = currentWebview.children()[0]
+				wv.setStyle({scalable:true})
+			}, 1000); //如果是页面初始化调用时,需要延时一下
+		}
 	};
 </script>