fix(commentList): 修改图片上传逻辑,使用文件对象代替base64
refactor(uploadImg): 重构图片上传方法,支持FormData方式上传 feat(upload): 添加获取上传配置的逻辑 chore: 更新构建文件和依赖版本
This commit is contained in:
@@ -13085,8 +13085,8 @@ const _sfc_main$2 = {
|
||||
const file = item.getAsFile();
|
||||
const reader = new FileReader();
|
||||
reader.onload = (e) => {
|
||||
const base64 = e.target.result;
|
||||
uploadImg(base64).then((res) => {
|
||||
e.target.result;
|
||||
uploadImg(file).then((res) => {
|
||||
let questionTextarea = null;
|
||||
if (type2 == "you") questionTextarea = (void 0).querySelector(".your-answer-textarea");
|
||||
else questionTextarea = (void 0).querySelector(".question-textarea");
|
||||
@@ -13103,22 +13103,39 @@ const _sfc_main$2 = {
|
||||
}
|
||||
}
|
||||
};
|
||||
const uploadImg = (base64) => {
|
||||
const uploadImg = (file) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
detailLoading.value = true;
|
||||
$ajax("/api/common/upload", {
|
||||
data: base64
|
||||
}).then((res) => {
|
||||
if (res.code != 200) {
|
||||
handleMsg("error", res.message || "上传失败");
|
||||
return;
|
||||
}
|
||||
let data = res.data;
|
||||
resolve(data);
|
||||
}).finally(() => detailLoading.value = false);
|
||||
const upload = () => {
|
||||
let config = uploadConfig;
|
||||
const formData = new FormData();
|
||||
formData.append(config.requestName, file);
|
||||
formData.append("type", "image");
|
||||
formData.append("data", config.params.data);
|
||||
$ajax(config.url, formData).then((res) => {
|
||||
if (res.code != 200) {
|
||||
handleMsg("error", res.message || "上传失败");
|
||||
return;
|
||||
}
|
||||
let data = res.data;
|
||||
resolve(data);
|
||||
}).finally(() => detailLoading.value = false);
|
||||
};
|
||||
if (uploadConfig) upload();
|
||||
else getUploadConfig().then(() => upload());
|
||||
});
|
||||
};
|
||||
provide("uploadImg", uploadImg);
|
||||
let uploadConfig = null;
|
||||
const getUploadConfig = () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
$ajax("https://api.gter.net/v1/config/upload?type=comment").then((res) => {
|
||||
let data = res.data;
|
||||
uploadConfig = data;
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
};
|
||||
let questionPlaceholderState = ref(false);
|
||||
let yourAnswerPlaceholderState = ref(true);
|
||||
const handleInput = () => {
|
||||
|
||||
Reference in New Issue
Block a user