From b783cb87afd35e8e8024cdefd7efb59dae754be0 Mon Sep 17 00:00:00 2001 From: xusd Date: Tue, 9 Jul 2024 11:29:43 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E5=A4=87=E5=9B=BE=E7=BA=B8=E6=9F=A5?= =?UTF-8?q?=E7=9C=8B=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/work/drawing/listDrawing.vue | 125 ++++++----------------------- 1 file changed, 24 insertions(+), 101 deletions(-) diff --git a/pages/work/drawing/listDrawing.vue b/pages/work/drawing/listDrawing.vue index f2be979..dbb7a25 100644 --- a/pages/work/drawing/listDrawing.vue +++ b/pages/work/drawing/listDrawing.vue @@ -10,11 +10,8 @@ - 下载 - 打开 + 查看 @@ -132,60 +129,27 @@ } }, methods: { - //打开文件 - openDrawing(fileName) { - // 判断当前环境是否为App环境 - if (this.$scope.$mp && this.$scope.$mp.runtime && this.$scope.$mp.runtime === 'app-plus') { - // 在App环境中调用plus.io.getRoot()获取根目录 - plus.io.getRoot((root) => { - console.log('App根目录:' + root); - }); - } else { - console.log('当前不是App环境,无法获取根目录'); - } - console.log(fileName) + lookDrawing(fileName,url,index){ + uni.showLoading({ + title: '正在加载……' + }); let fileType = fileName.substring(fileName.lastIndexOf(".") + 1); console.log(fileType) - uni.openDocument({ - showMenu: true, - fileType: fileType, - filePath: 'file://storage/emulated/0/Android/data/com.inspur.ipcApp/apps/__UNI__B298C37/downloads/storage/ipcApp/' + - fileName, - success: function(res) { - console.log(res, "打开文件成功"); - }, - fail: function(res) { - console.log(res) - uni.showToast({ - title: "打开文件失败请重试", - icon: "none", - }); - }, - }); - }, - //本地无文件--下载并打开文件 - downloadDrawing(name, url, index) { - let progressVal = 0; - let that = this - uni.showLoading({ - title: '正在下载……' - }); - let dtask = plus.downloader.createDownload(url, { - // filename: 'file://storage/ipcApp/' + name - filename: 'file://storage/ipcApp/' + name - }, function(d, status) { + uni.downloadFile({ + url: url, + success: function (res) { uni.hideLoading(); - if (status == 200) { - uni.$u.toast('下载成功') - let fileSaveUrl = plus.io.convertLocalFileSystemURL(d.filename); - console.log(fileSaveUrl) - that.itemDrawingList[index].localHave = true; - } else { - uni.$u.toast('下载失败') - plus.downloader.clear(); - } + var filePath = res.tempFilePath; + uni.openDocument({ + filePath: filePath, + fileType: fileType, + showMenu: true, + success: function (res) { + console.log('打开文档成功'); + } + }); + } }); - dtask.start(); }, clickDownload(paths) { this.itemDrawingList = []; @@ -193,52 +157,11 @@ let list = paths.split(","); list.forEach((item, index) => { let fileName = item.substring(item.lastIndexOf("/") + 1) - const self = this; - // // 假设你想检查的文件路径是_local://hello.txt_ - // let filePath = 'file://storage/ipcApp/' + fileName; - // // 使用plus.io的resolveLocalFileSystemURL方法 - // plus.io.resolveLocalFileSystemURL(filePath, - // function(entry) { - // // 文件存在的回调 - // console.log("文件存在: " + entry.fullPath); - // let drawing = { - // url: baseUrl + item, - // fileName: fileName, - // localHave: true - // } - // self.itemDrawingList.push(drawing) - // }, - // function(error) { - // // 文件不存在的回调 - // console.log("文件不存在: " + filePath); - // let drawing = { - // url: baseUrl + item, - // fileName: fileName, - // localHave: false - // } - // self.itemDrawingList.push(drawing) - // } - // ); - uni.getFileInfo({ - filePath: 'file://storage/emulated/0/Android/data/com.inspur.ipcApp/apps/__UNI__B298C37/downloads/storage/ipcApp/' + - fileName, - success(res) { - let drawing = { - url: baseUrl + item, - fileName: fileName, - localHave: true - } - self.itemDrawingList.push(drawing) - }, - fail(err) { - let drawing = { - url: baseUrl + item, - fileName: fileName, - localHave: false - } - self.itemDrawingList.push(drawing) - } - }) + let drawing = { + url: baseUrl + item, + fileName: fileName + } + this.itemDrawingList.push(drawing) }) } this.showDrawing = true;