Complete core mini program flows
ci-cd / verify (push) Successful in 5s
ci-cd / deploy (push) Skipped

This commit is contained in:
2026-10-04 09:26:58 +08:00
parent 5688db4d63
commit c72cf24f56
28 changed files with 490 additions and 65 deletions
+18 -2
View File
@@ -38,7 +38,7 @@ async function secure(path, method, data) {
function toast(error) {
wx.showToast({ title: error.message || "操作失败", icon: "none" });
}
function upload(path) {
function uploadOnce(path) {
return new Promise((resolve, reject) => {
const token = getApp().globalData.token;
wx.uploadFile({
@@ -50,7 +50,11 @@ function upload(path) {
try {
const body = JSON.parse(res.data);
if (body.code === 0) resolve(body.data);
else reject(new Error(body.message));
else {
const error = new Error(body.message || "上传失败");
error.status = res.statusCode;
reject(error);
}
} catch (e) {
reject(e);
}
@@ -59,4 +63,16 @@ function upload(path) {
});
});
}
async function upload(path) {
await getApp().login();
try {
return await uploadOnce(path);
} catch (error) {
if (error.status !== 401) throw error;
wx.removeStorageSync("pet_token");
getApp().globalData.token = "";
await getApp().login();
return uploadOnce(path);
}
}
module.exports = { request, secure, toast, upload };