zc 3 months ago
parent f30e00fc51
commit 91c18d91f0
  1. 38
      app/api/v1/upload/upload.py
  2. 24
      web/src/views/system/question/index.vue

@ -2,8 +2,8 @@
import os
import uuid
from fastapi import APIRouter, File, UploadFile
from fastapi.responses import JSONResponse
from app.settings.config import settings
from app.schemas.base import Success, Fail # 导入项目标准响应模型
router = APIRouter()
@ -28,19 +28,14 @@ async def upload_image(file: UploadFile = File(...)):
# 构建访问URL
file_url = f'/resource/images/{filename}'
return JSONResponse({
'errno': 0,
'data': [{
'url': file_url,
'alt': '',
'href': ''
}]
})
# 使用标准响应模型
return Success(data={
'url': file_url,
'alt': '',
'href': ''
}, msg='上传成功')
except Exception as e:
return JSONResponse({
'errno': 1,
'message': str(e)
})
return Fail(code=500, msg=f'上传失败: {str(e)}')
@router.post('/video', summary='上传视频')
@ -60,15 +55,10 @@ async def upload_video(file: UploadFile = File(...)):
# 构建访问URL
file_url = f'/resource/videos/{filename}'
return JSONResponse({
'errno': 0,
'data': {
'url': file_url,
'duration': 0 # 实际应用中可以计算视频时长
}
})
# 使用标准响应模型
return Success(data={
'url': file_url,
'duration': 0 # 实际应用中可以计算视频时长
}, msg='上传成功')
except Exception as e:
return JSONResponse({
'errno': 1,
'message': str(e)
})
return Fail(code=500, msg=f'上传失败: {str(e)}')

@ -111,7 +111,7 @@ defineOptions({ name: '快捷问题管理' })
//
const editorRef = ref(null)
const toolbarConfig = ref({})
//
//
const editorConfig = ref({
placeholder: '请输入问题内容...',
MENU_CONF: {
@ -122,12 +122,13 @@ const editorConfig = ref({
headers: {
'token': getToken()
},
onFailed: (file, err, res) => {
console.error('上传回调失败', file, err, res)
},
// Add upload progress callback for debugging
onProgress: (progress) => {
console.log('Upload progress:', progress)
//
customInsert(res, insertFn) {
if (res.code === 200 && res.data && res.data.url) {
insertFn(res.data.url);
} else {
ElMessage.error(`上传失败: ${res.msg || '未知错误'}`);
}
}
},
uploadVideo: {
@ -137,8 +138,13 @@ const editorConfig = ref({
headers: {
'token': getToken()
},
onProgress: (progress) => {
console.log('Upload progress:', progress)
//
customInsert(res, insertFn) {
if (res.code === 200 && res.data && res.data.url) {
insertFn(res.data.url);
} else {
ElMessage.error(`上传失败: ${res.msg || '未知错误'}`);
}
}
}
}

Loading…
Cancel
Save