修复上传本地文件返回值问题
@ -49,12 +49,13 @@ const { setValues, setValue } = methods
|
||||
|
||||
// 上传成功的钩子函数
|
||||
const handleICOUploadSuccess: UploadProps['onSuccess'] = (response) => {
|
||||
setValue('web_ico', response.data)
|
||||
setValue('web_ico', response.data.remote_path)
|
||||
setValue('web_ico_local_path', response.data.local_path)
|
||||
}
|
||||
|
||||
// 上传成功的钩子函数
|
||||
const handleLogoUploadSuccess: UploadProps['onSuccess'] = (response) => {
|
||||
setValue('web_logo', response.data)
|
||||
setValue('web_logo', response.data.remote_path)
|
||||
}
|
||||
|
||||
let formData = ref({} as Recordable)
|
||||
|
@ -44,6 +44,16 @@ export const schema = reactive<FormSchema[]>([
|
||||
span: 24
|
||||
}
|
||||
},
|
||||
{
|
||||
field: 'web_ico_local_path',
|
||||
label: 'ICO 图标服务器文件地址',
|
||||
colProps: {
|
||||
span: 24
|
||||
},
|
||||
ifshow: () => {
|
||||
return false
|
||||
}
|
||||
},
|
||||
{
|
||||
field: 'web_icp_number',
|
||||
label: '备案号',
|
||||
|
@ -11,13 +11,13 @@ from fastapi.security import OAuth2PasswordBearer
|
||||
"""
|
||||
系统版本
|
||||
"""
|
||||
VERSION = "1.4.0"
|
||||
VERSION = "1.4.2"
|
||||
|
||||
"""安全警告: 不要在生产中打开调试运行!"""
|
||||
DEBUG = False
|
||||
DEBUG = True
|
||||
|
||||
"""是否开启演示功能:取消所有POST,DELETE,PUT操作权限"""
|
||||
DEMO = True
|
||||
DEMO = False
|
||||
"""演示功能白名单"""
|
||||
DEMO_WHITE_LIST_PATH = [
|
||||
"/auth/login/",
|
||||
@ -71,7 +71,8 @@ STATIC_ROOT:静态文件目录绝对路径
|
||||
"""
|
||||
STATIC_ENABLE = True
|
||||
STATIC_URL = "/media"
|
||||
STATIC_ROOT = os.path.join(BASE_DIR, "static")
|
||||
STATIC_DIR = "static"
|
||||
STATIC_ROOT = os.path.join(BASE_DIR, STATIC_DIR)
|
||||
|
||||
|
||||
"""
|
||||
|
@ -9,9 +9,12 @@
|
||||
# sqlalchemy 查询操作:https://segmentfault.com/a/1190000016767008
|
||||
# sqlalchemy 关联查询:https://www.jianshu.com/p/dfad7c08c57a
|
||||
# sqlalchemy 关联查询详细:https://blog.csdn.net/u012324798/article/details/103940527
|
||||
import os
|
||||
from typing import List, Union
|
||||
from sqlalchemy import select, update
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from application.settings import STATIC_ROOT
|
||||
from utils.file_manage import FileManage
|
||||
from . import models, schemas
|
||||
from core.crud import DalBase
|
||||
@ -75,14 +78,21 @@ class SettingsDal(DalBase):
|
||||
"""
|
||||
for key, value in datas.items():
|
||||
if key == "web_ico":
|
||||
continue
|
||||
elif key == "web_ico_local_path":
|
||||
if not value:
|
||||
continue
|
||||
ico = await self.get_data(config_key="web_ico", tab_id=1)
|
||||
if ico.config_value == value:
|
||||
web_ico = datas.get("web_ico")
|
||||
if ico.config_value == web_ico:
|
||||
continue
|
||||
# 将上传的ico路径替换到static/system/favicon.ico文件
|
||||
FileManage.copy(value, "static/system/favicon.ico")
|
||||
await self.db.execute(update(self.model).where(self.model.config_key == key).values(config_value=value))
|
||||
FileManage.copy(value, os.path.join(STATIC_ROOT, "system/favicon.ico"))
|
||||
sql = update(self.model).where(self.model.config_key == "web_ico").values(config_value=web_ico)
|
||||
await self.db.execute(sql)
|
||||
else:
|
||||
sql = update(self.model).where(self.model.config_key == key).values(config_value=value)
|
||||
await self.db.execute(sql)
|
||||
|
||||
|
||||
class SettingsTabDal(DalBase):
|
||||
|
Before Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 20 KiB |
Before Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 8.3 KiB |
Before Width: | Height: | Size: 8.3 KiB |
Before Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 8.3 KiB |
Before Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 8.3 KiB |
Before Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 20 KiB |
Before Width: | Height: | Size: 0 B After Width: | Height: | Size: 20 KiB |
@ -8,7 +8,7 @@
|
||||
import datetime
|
||||
import os
|
||||
import shutil
|
||||
from application.settings import TEMP_DIR, STATIC_ROOT, BASE_DIR
|
||||
from application.settings import TEMP_DIR, STATIC_ROOT, BASE_DIR, STATIC_DIR, STATIC_URL
|
||||
from fastapi import UploadFile
|
||||
import sys
|
||||
from core.exception import CustomException
|
||||
@ -33,7 +33,7 @@ class FileManage:
|
||||
self.path = f"{path}/{full_date}/{filename}{os.path.splitext(file.filename)[-1]}"
|
||||
self.file = file
|
||||
|
||||
async def save_image_local(self, accept: list = None):
|
||||
async def save_image_local(self, accept: list = None) -> dict:
|
||||
"""
|
||||
保存图片文件到本地
|
||||
"""
|
||||
@ -43,22 +43,25 @@ class FileManage:
|
||||
raise CustomException(f"上传图片必须是 {'/'.join(accept)} 格式!", status.HTTP_ERROR)
|
||||
return await self.save_local()
|
||||
|
||||
async def save_local(self):
|
||||
async def save_local(self) -> dict:
|
||||
"""
|
||||
保存文件到本地
|
||||
"""
|
||||
path = self.path
|
||||
if sys.platform == "win32":
|
||||
path = self.path.replace("/", "\\")
|
||||
filename = os.path.join(STATIC_ROOT, path)
|
||||
if not os.path.exists(os.path.dirname(filename)):
|
||||
os.mkdir(os.path.dirname(filename))
|
||||
with open(filename, "wb") as f:
|
||||
save_path = os.path.join(STATIC_ROOT, path)
|
||||
if not os.path.exists(os.path.dirname(save_path)):
|
||||
os.mkdir(os.path.dirname(save_path))
|
||||
with open(save_path, "wb") as f:
|
||||
f.write(await self.file.read())
|
||||
return f"/static/{self.path}"
|
||||
return {
|
||||
"local_path": f"{STATIC_DIR}/{self.path}",
|
||||
"remote_path": f"{STATIC_URL}/{self.path}"
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
async def save_tmp_file(file: UploadFile):
|
||||
async def save_tmp_file(file: UploadFile) -> str:
|
||||
"""
|
||||
保存临时文件
|
||||
"""
|
||||
@ -72,13 +75,13 @@ class FileManage:
|
||||
return filename
|
||||
|
||||
@staticmethod
|
||||
def copy(src: str, dst: str):
|
||||
def copy(src: str, dst: str) -> None:
|
||||
"""
|
||||
复制文件
|
||||
根目录为项目根目录,传过来的文件路径均为相对路径
|
||||
|
||||
@param src: 原始文件
|
||||
@param dst: 目标路径
|
||||
@param dst: 目标路径。绝对路径
|
||||
"""
|
||||
if src[0] == "/":
|
||||
src = src.lstrip("/")
|
||||
@ -86,7 +89,6 @@ class FileManage:
|
||||
src = src.replace("/", "\\")
|
||||
dst = dst.replace("/", "\\")
|
||||
src = os.path.join(BASE_DIR, src)
|
||||
dst = os.path.join(BASE_DIR, dst)
|
||||
if not os.path.exists(os.path.dirname(dst)):
|
||||
os.mkdir(os.path.dirname(dst))
|
||||
shutil.copyfile(src, dst)
|
||||
|