下载账单示例文件

This commit is contained in:
2025-10-27 11:20:48 +08:00
parent c9f2fc80b6
commit 80a4cc35fa

View File

@@ -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 = () => {
</View>
<View className="hint_content">
<Text> </Text>
<Text className="button_text" onClick={downloadExample}>
</Text>
{/* <Text className="button_text">示例文件</Text> */}
</View>
<View className="form_container">