fix(commentList): 修改图片上传逻辑,使用文件对象代替base64

refactor(uploadImg): 重构图片上传方法,支持FormData方式上传
feat(upload): 添加获取上传配置的逻辑
chore: 更新构建文件和依赖版本
This commit is contained in:
DESKTOP-RQ919RC\Pc
2025-09-08 17:16:30 +08:00
parent d8f5b53e4a
commit 6c9221aa08
14 changed files with 121 additions and 82 deletions

View File

@@ -18,7 +18,7 @@ const client_manifest = {
"module": true,
"prefetch": true,
"preload": true,
"file": "6S51YVf7.js",
"file": "BLt8-I-t.js",
"name": "error-404",
"src": "node_modules/.store/nuxt@3.16.0/node_modules/nuxt/dist/app/components/error-404.vue",
"isDynamicEntry": true,
@@ -38,7 +38,7 @@ const client_manifest = {
"module": true,
"prefetch": true,
"preload": true,
"file": "RzIEFrlU.js",
"file": "7PxzC_cV.js",
"name": "error-500",
"src": "node_modules/.store/nuxt@3.16.0/node_modules/nuxt/dist/app/components/error-500.vue",
"isDynamicEntry": true,
@@ -58,7 +58,7 @@ const client_manifest = {
"module": true,
"prefetch": true,
"preload": true,
"file": "DEG17TeB.js",
"file": "mbMJmbi0.js",
"name": "entry",
"src": "node_modules/.store/nuxt@3.16.0/node_modules/nuxt/dist/app/entry.js",
"isEntry": true,

View File

@@ -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 = () => {

View File

@@ -4,9 +4,9 @@ const styles = {
"app.vue": () => import('./app-styles.C0pZGo-Z.mjs').then(interopDefault),
"node_modules/.store/nuxt@3.16.0/node_modules/nuxt/dist/app/components/error-404.vue": () => import('./error-404-styles.BshXrwM5.mjs').then(interopDefault),
"node_modules/.store/nuxt@3.16.0/node_modules/nuxt/dist/app/components/error-500.vue": () => import('./error-500-styles.DobFeJtS.mjs').then(interopDefault),
"node_modules/.store/nuxt@3.16.0/node_modules/nuxt/dist/app/components/error-500.vue?vue&type=style&index=0&scoped=84d937c0&lang.css": () => import('./error-500-styles.DIlGYe2L.mjs').then(interopDefault),
"node_modules/.store/nuxt@3.16.0/node_modules/nuxt/dist/app/components/error-404.vue?vue&type=style&index=0&scoped=075d74b5&lang.css": () => import('./error-404-styles.CuaO5MB7.mjs').then(interopDefault),
"components/Like.vue": () => import('./Like-styles.DQDennjP.mjs').then(interopDefault),
"node_modules/.store/nuxt@3.16.0/node_modules/nuxt/dist/app/components/error-500.vue?vue&type=style&index=0&scoped=84d937c0&lang.css": () => import('./error-500-styles.DIlGYe2L.mjs').then(interopDefault),
"components/Like.vue?vue&type=style&index=0&scoped=972d2ebd&lang.css": () => import('./Like-styles.BIsA7GNG.mjs').then(interopDefault),
"app.vue?vue&type=style&index=0&lang.css": () => import('./app-styles.C_uXCS2z.mjs').then(interopDefault)
};

View File

@@ -1 +1 @@
{"version":3,"file":"styles.mjs","sources":["../../../../.nuxt/dist/server/styles.mjs"],"sourcesContent":null,"names":[],"mappings":"AAAA,MAAM,cAAc,GAAG,CAAC,IAAI,CAAC,CAAC,OAAO,IAAI,CAAC,IAAI;AAC9C,eAAe;AACf,EAAE,qEAAqE,EAAE,MAAM,OAAO,6BAAoC,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC;AAChJ,EAAE,SAAS,EAAE,MAAM,OAAO,2BAAkC,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC;AAClF,EAAE,qFAAqF,EAAE,MAAM,OAAO,iCAAwC,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC;AACpK,EAAE,qFAAqF,EAAE,MAAM,OAAO,iCAAwC,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC;AACpK,EAAE,qIAAqI,EAAE,MAAM,OAAO,iCAAwC,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC;AACpN,EAAE,qBAAqB,EAAE,MAAM,OAAO,4BAAmC,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC;AAC/F,EAAE,qIAAqI,EAAE,MAAM,OAAO,iCAAwC,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC;AACpN,EAAE,qEAAqE,EAAE,MAAM,OAAO,4BAAmC,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC;AAC/I,EAAE,yCAAyC,EAAE,MAAM,OAAO,2BAAkC,CAAC,CAAC,IAAI,CAAC,cAAc;AACjH;;;;"}
{"version":3,"file":"styles.mjs","sources":["../../../../.nuxt/dist/server/styles.mjs"],"sourcesContent":null,"names":[],"mappings":"AAAA,MAAM,cAAc,GAAG,CAAC,IAAI,CAAC,CAAC,OAAO,IAAI,CAAC,IAAI;AAC9C,eAAe;AACf,EAAE,qEAAqE,EAAE,MAAM,OAAO,6BAAoC,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC;AAChJ,EAAE,SAAS,EAAE,MAAM,OAAO,2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