From bbc9b39c57fb2fa2aef5e0dbe82149354a37443b Mon Sep 17 00:00:00 2001 From: aihe <961836564@qq.com> Date: Fri, 10 May 2024 17:20:35 +0800 Subject: [PATCH] uu --- common/untool.js | 46 ++++++++++++++++++++++++++++++++-- pages/user/exclusiveQrcode.vue | 4 +-- 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/common/untool.js b/common/untool.js index 1770878..0644560 100644 --- a/common/untool.js +++ b/common/untool.js @@ -92,15 +92,55 @@ const downloadFile = (url)=> { success: (res) => { if (res.statusCode === 200) { console.log('下载成功'); - resolve(true) + resolve(res) } }, fail: (err)=>{ + console.log("downloadFile:err", err) reject(err) } }); }) } + +const saveNetFile = (url) => { + return new Promise(async (resolve, reject)=> { + showLoading('正在保存文件') + try{ + let { tempFilePath } = await downloadFile(url) + console.log("save:orgin:tempFilePath", tempFilePath) + let res = await saveFile({ tempFilePath }) + hideLoading() + showToast('保存成功') + resolve(res) + }catch(e){ + hideLoading() + showToast('保存失败') + reject(e) + } + }) + +} + +const saveFile = ({ tempFilePath })=> { + return new Promise(async (resolve, reject)=> { + //保存到本地 + uni.saveFile({ + tempFilePath,//文件的临时路径 + success: function(res) { + console.log("saveFile:success", res) + resolve(res) + }, + fail: function(err) { + console.log("saveFile:err", err) + reject(err) + }, + complete(res){ + console.log("saveFile:complete", res) + } + }); + }) +} export { @@ -114,5 +154,7 @@ export { showToast, scanCode, makePhoneCall, - downloadFile + downloadFile, + saveNetFile, + saveFile, } diff --git a/pages/user/exclusiveQrcode.vue b/pages/user/exclusiveQrcode.vue index 47cdcb4..68d0d89 100644 --- a/pages/user/exclusiveQrcode.vue +++ b/pages/user/exclusiveQrcode.vue @@ -65,8 +65,8 @@ let res = await apiService.getStaffQRCodePng({ _loading: true }) this.qrCodeImgUrl = res.data }, - handleSave(){ - + async handleSave(){ + this.saveNetFile(this.qrCodeImgUrl) }, } }