function download(items){
try {
const urlObject = window.URL || window.webkitURL || window;
const export_blob = new Blob(
[
items
.map(
(item) =>
item.nickname +
"(" +
item.total +
")" +
"\n" +
item.rewards
.map(
(r) =>
r.name + " 已兑奖:" + r.done + " 待兑奖:" + r.amount
)
.join("\n")
)
.join("\n\n"),
],
{
type: "text/plain",
}
);
const blobUrl = urlObject.createObjectURL(export_blob);
const a = document.createElement("a");
a.style.display = "none";
const date = new Date();
a.download =
date.getMonth() +
"月" +
date.getDay() +
"日" +
parseInt(Math.random() * 99) +
".txt";
a.href = blobUrl;
a.click();
a.remove();
// a.removeChild(a)
} catch (err) {
console.log(err);
Tip.show("保存失败");
}
}
js通过createObjectURL将JSON数据保存到本地
最新推荐文章于 2024-04-22 11:48:16 发布