fix(api): 修改评论图片上传接口为支持FormData格式

refactor(Item.vue): 调整样式和布局,优化图片高度和文本显示

feat(details/[id].vue): 实现图片上传配置获取和FormData上传功能
This commit is contained in:
DESKTOP-RQ919RC\Pc
2025-09-08 17:16:40 +08:00
parent 0d111436af
commit 62aafa10ac
66 changed files with 475 additions and 433 deletions

View File

@@ -1378,8 +1378,6 @@ const replaceState = (uni) => {
// 替换当前URL但不刷新页面
window.history.pushState({}, "", `${window.location.origin}/details/${uni}`);
console.log("uni", uni, "location", location);
if (location.pathname.indexOf(uni) == -1) XSTAT.trackNewPage();
};
@@ -2032,7 +2030,7 @@ const handleInputPaste = (event, index, ii) => {
reader.onload = (e) => {
const base64 = e.target.result;
uploadImg(base64).then((res) => {
uploadImg(file).then((res) => {
const obj = {
base64,
...res,
@@ -2069,7 +2067,7 @@ const handleFileUpload = (event, index, i) => {
const reader = new FileReader();
reader.onload = (e) => {
const base64 = e.target.result;
uploadImg(base64).then((res) => {
uploadImg(file).then((res) => {
const obj = {
base64,
...res,
@@ -2099,27 +2097,37 @@ const closeFileUpload = (index, i) => {
};
// 上传图片 获取图片url
const uploadImg = (base64) => {
const uploadImg = (file) => {
return new Promise((resolve, reject) => {
// detailLoading.value = true
commonUploadHttp({
data: base64,
})
.then((res) => {
const upload = () => {
let config = uploadConfig;
const formData = new FormData();
formData.append(config.requestName, file); // 文件数据
formData.append("type", "image"); // 文件名
formData.append("data", config.params.data); // 文件名
commonUploadHttp(config.url, formData).then((res) => {
if (res.code != 200) {
ElMessage({
message: res.message || "上传失败",
type: "error",
});
ElMessage.error(res.message || "上传失败");
return;
}
let data = res.data;
resolve(data);
})
.catch((err) => {
console.log("err", err);
});
// .finally(() => (detailLoading.value = false))
};
if (uploadConfig) upload();
else getUploadConfig().then(() => upload());
});
};
let uploadConfig = null;
const getUploadConfig = () => {
return new Promise((resolve, reject) => {
commonUploadConfigHttp().then((res) => {
let data = res.data;
uploadConfig = data;
resolve();
});
});
};