feat: release

This commit is contained in:
zzc
2026-05-20 23:32:59 +08:00
parent c03a699ab9
commit 1107d296ce
2 changed files with 64 additions and 65 deletions

View File

@@ -47,6 +47,54 @@ export const uploadImage = (filePath) => {
});
};
/**
* 统一的选择并上传图片的方法
* @param {Object} options 配置项
* @param {number} options.count 最多可选择的图片数量,默认为 1
* @param {string} options.loadingTitle 上传中提示文案,默认为 '上传中...'
* @returns {Promise<string[]>} 返回一个包含所有上传成功图片 URL 的数组 Promise
*/
export const chooseAndUploadImage = (options = {}) => {
const { count = 1, loadingTitle = '上传中...' } = options;
return new Promise((resolve, reject) => {
uni.chooseImage({
count,
success: async (res) => {
const filePaths = res.tempFilePaths;
if (!filePaths || filePaths.length === 0) {
return resolve([]);
}
uni.showLoading({ title: loadingTitle });
try {
// 并发上传所有选中的图片
const uploadPromises = filePaths.map(path => uploadImage(path));
const urls = await Promise.all(uploadPromises);
uni.hideLoading();
resolve(urls);
} catch (error) {
uni.hideLoading();
uni.showToast({
title: "上传失败",
icon: "none",
});
console.error("图片上传异常:", error);
reject(error);
}
},
fail: (err) => {
// 用户取消选择不作为异常抛出,返回空数组
if (err.errMsg && err.errMsg.indexOf('cancel') !== -1) {
resolve([]);
} else {
reject(err);
}
}
});
});
};
export const saveRecordRequest = async (path, targetId, scene, imageUrl) => {
if (!imageUrl) {
imageUrl = await uploadImage(path);