diff --git a/src/user_pages/downloadBill/index.tsx b/src/user_pages/downloadBill/index.tsx index bc9027c..d92b863 100644 --- a/src/user_pages/downloadBill/index.tsx +++ b/src/user_pages/downloadBill/index.tsx @@ -178,6 +178,37 @@ const DownloadBill: React.FC = () => { }); setShowFilterPopup(false); }; + const downloadExample = async () => { + const { start, end } = dateRange; + if (!start || !end) return; + try { + const res = await httpService.post("/parameter/many_key", { + keys: "bill_example", + }); + const { bill_example, fileName } = res.data; + // 调用下载文件接口 + wx.downloadFile({ + url: bill_example, // 文件路径 + success: function (res) { + // 只有200状态码表示下载成功 + if (res.statusCode === 200) { + // 下载成功后可以使用res.tempFilePath访问临时文件路径 + console.log("文件下载成功,临时路径为:", res.tempFilePath); + // 保存文件到本地 + wx.openDocument({ + filePath: res.tempFilePath, + showMenu: true, // 显示保存菜单 + }); + } + }, + fail: function (err) { + console.error("文件下载失败:", err); + }, + }); + } catch (error) { + console.error(error); + } + }; const handleDownloadBill = async () => { const { start, end } = dateRange; if (!start || !end) return; @@ -188,10 +219,10 @@ const DownloadBill: React.FC = () => { transaction_sub_type, date_range, }); - const { fileUrl, fileName } = res.data; + const { bill_example, fileName } = res.data; // 调用下载文件接口 wx.downloadFile({ - url: fileUrl, // 文件路径 + url: bill_example, // 文件路径 success: function (res) { // 只有200状态码表示下载成功 if (res.statusCode === 200) { @@ -233,6 +264,9 @@ const DownloadBill: React.FC = () => { 最长可导出三个月的账单 + + 示例文件 + {/* 示例文件 */}