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