vite-uni-dev-tool
Version:
vite-uni-dev-tool, debug, uni-app, 一处编写,到处调试
86 lines (85 loc) • 2.45 kB
JavaScript
function c() {
return new Promise((n, t) => {
plus ? plus.io.resolveLocalFileSystemURL("_downloads", function(o) {
n(o.fullPath);
}) : t();
});
}
function a(n, t) {
plus.io.requestFileSystem(
plus.io.PUBLIC_DOCUMENTS,
function(o) {
var i;
(i = o.root) == null || i.getFile(
n,
{ create: !0 },
function(e) {
e.createWriter(function(l) {
l.onwriteend = function() {
console.log("[DevTool] 写入文件成功" + n), uni.showToast({
icon: "none",
title: "写入文件成功" + n,
duration: 10 * 1e3
});
}, l.onerror = function(s) {
console.log("[DevTool] 写入文件失败" + JSON.stringify(s)), uni.showToast({
icon: "none",
title: "写入文件失败"
});
}, l.write(t);
});
},
function(e) {
uni.showToast({
icon: "none",
title: "获取文件失败"
}), console.log("[DevTool] 获取文件失败" + JSON.stringify(e));
}
);
},
function(o) {
uni.showToast({
icon: "none",
title: "获取文件系统失败"
}), console.log("[DevTool] 获取文件系统失败" + JSON.stringify(o));
}
);
}
async function u(n, t) {
try {
const o = await c() + `${Date.now()}_${t}.txt`;
a(o, n);
} catch (o) {
console.log("[DevTool] " + JSON.stringify(o));
}
}
async function r(n, t) {
const o = new Blob([n], { type: "text/plain" }), i = URL.createObjectURL(o), e = document.createElement("a");
e.href = i, e.download = t, e.click();
}
async function f(n, t) {
var l;
const o = uni.getFileSystemManager(), i = `${t}_${Date.now()}.txt`, e = `${((l = uni == null ? void 0 : uni.env) == null ? void 0 : l.USER_DATA_PATH) ?? "Download"}/${i}`;
o.writeFile({
data: n,
filePath: e,
success: (s) => {
console.log("[DevTool] 写入文件成功" + e), uni.showToast({
title: "写入文件成功" + e,
icon: "none"
});
},
fail: (s) => {
console.log("[DevTool] 写入文件失败" + JSON.stringify(s)), uni.showToast({
title: "写入文件失败" + JSON.stringify(s),
icon: "none"
});
}
});
}
export {
c as getFilePath,
r as saveTextFileH5,
f as saveTextFileMicro,
u as saveTxtFileApp
};