下载账单示例文件
This commit is contained in:
@@ -178,6 +178,37 @@ const DownloadBill: React.FC = () => {
|
|||||||
});
|
});
|
||||||
setShowFilterPopup(false);
|
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 handleDownloadBill = async () => {
|
||||||
const { start, end } = dateRange;
|
const { start, end } = dateRange;
|
||||||
if (!start || !end) return;
|
if (!start || !end) return;
|
||||||
@@ -188,10 +219,10 @@ const DownloadBill: React.FC = () => {
|
|||||||
transaction_sub_type,
|
transaction_sub_type,
|
||||||
date_range,
|
date_range,
|
||||||
});
|
});
|
||||||
const { fileUrl, fileName } = res.data;
|
const { bill_example, fileName } = res.data;
|
||||||
// 调用下载文件接口
|
// 调用下载文件接口
|
||||||
wx.downloadFile({
|
wx.downloadFile({
|
||||||
url: fileUrl, // 文件路径
|
url: bill_example, // 文件路径
|
||||||
success: function (res) {
|
success: function (res) {
|
||||||
// 只有200状态码表示下载成功
|
// 只有200状态码表示下载成功
|
||||||
if (res.statusCode === 200) {
|
if (res.statusCode === 200) {
|
||||||
@@ -233,6 +264,9 @@ const DownloadBill: React.FC = () => {
|
|||||||
</View>
|
</View>
|
||||||
<View className="hint_content">
|
<View className="hint_content">
|
||||||
<Text>最长可导出三个月的账单 </Text>
|
<Text>最长可导出三个月的账单 </Text>
|
||||||
|
<Text className="button_text" onClick={downloadExample}>
|
||||||
|
示例文件
|
||||||
|
</Text>
|
||||||
{/* <Text className="button_text">示例文件</Text> */}
|
{/* <Text className="button_text">示例文件</Text> */}
|
||||||
</View>
|
</View>
|
||||||
<View className="form_container">
|
<View className="form_container">
|
||||||
|
|||||||
Reference in New Issue
Block a user