feat: release
This commit is contained in:
@@ -165,6 +165,7 @@ import { smartNavigateBack } from "@/utils/page";
|
|||||||
import {
|
import {
|
||||||
uploadImage,
|
uploadImage,
|
||||||
FILE_BASE_URL,
|
FILE_BASE_URL,
|
||||||
|
chooseAndUploadImage,
|
||||||
} from "@/utils/common.js";
|
} from "@/utils/common.js";
|
||||||
|
|
||||||
const statusBarHeight = ref(getStatusBarHeight() || 0);
|
const statusBarHeight = ref(getStatusBarHeight() || 0);
|
||||||
@@ -225,76 +226,26 @@ const handlePreview = () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const chooseCover = () => {
|
const chooseCover = async () => {
|
||||||
uni.chooseImage({
|
|
||||||
count: 1,
|
|
||||||
sizeType: ["original", "compressed"],
|
|
||||||
sourceType: ["album"],
|
|
||||||
success: (res) => {
|
|
||||||
const path = res.tempFilePaths[0];
|
|
||||||
|
|
||||||
// #ifdef MP-ALIPAY
|
|
||||||
// 支付宝小程序不支持 cropImage,直接使用原图
|
|
||||||
onAvatarSelect(path);
|
|
||||||
// #endif
|
|
||||||
|
|
||||||
// #ifndef MP-ALIPAY
|
|
||||||
// 调用系统裁剪,强制 1:1
|
|
||||||
uni.cropImage({
|
|
||||||
src: path,
|
|
||||||
aspectRatio: "1:1",
|
|
||||||
success: (cropRes) => {
|
|
||||||
onAvatarSelect(cropRes.tempFilePath);
|
|
||||||
},
|
|
||||||
fail: (err) => {
|
|
||||||
console.warn("Crop failed or cancelled", err);
|
|
||||||
onAvatarSelect(path);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
// #endif
|
|
||||||
},
|
|
||||||
fail: (err) => {
|
|
||||||
console.warn("Crop failed or cancelled", err);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const onAvatarSelect = async (url) => {
|
|
||||||
if (!url) return;
|
|
||||||
|
|
||||||
uni.showLoading({ title: "上传中...", mask: true });
|
|
||||||
try {
|
try {
|
||||||
const imageUrl = await uploadImage(url);
|
const urls = await chooseAndUploadImage({ count: 1 });
|
||||||
|
if (urls && urls.length > 0) {
|
||||||
formData.coverUrl = imageUrl;
|
formData.coverUrl = urls[0];
|
||||||
uni.hideLoading();
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
uni.hideLoading();
|
console.error("选择封面失败", e);
|
||||||
uni.showToast({ title: e || "上传失败", icon: "none" });
|
|
||||||
console.error("Upload avatar error", e);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const chooseParticipantAvatar = (index) => {
|
const chooseParticipantAvatar = async (index) => {
|
||||||
uni.chooseImage({
|
try {
|
||||||
count: 1,
|
const urls = await chooseAndUploadImage({ count: 1 });
|
||||||
success: async (res) => {
|
if (urls && urls.length > 0) {
|
||||||
const url = res.tempFilePaths[0];
|
participants.value[index].avatar = urls[0];
|
||||||
uni.showLoading({ title: '上传中...' });
|
}
|
||||||
try {
|
} catch (e) {
|
||||||
const imageUrl = await uploadImage(url);
|
console.error("选择评分对象头像失败", e);
|
||||||
participants.value[index].avatar = imageUrl;
|
}
|
||||||
uni.hideLoading();
|
|
||||||
} catch (e) {
|
|
||||||
uni.hideLoading();
|
|
||||||
uni.showToast({
|
|
||||||
title: "上传失败",
|
|
||||||
icon: "none",
|
|
||||||
});
|
|
||||||
console.error(e);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleAddTag = () => {
|
const handleAddTag = () => {
|
||||||
|
|||||||
@@ -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) => {
|
export const saveRecordRequest = async (path, targetId, scene, imageUrl) => {
|
||||||
if (!imageUrl) {
|
if (!imageUrl) {
|
||||||
imageUrl = await uploadImage(path);
|
imageUrl = await uploadImage(path);
|
||||||
|
|||||||
Reference in New Issue
Block a user