mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-10-14 13:06:51 +00:00
chore: 清理冗余代码与配置,优化项目结构
1. 删除无用文件与废弃代码:移除locale枚举、element-plus插件、sse路由、api token模块等 2. 简化类型导入与依赖:移除大量未使用的类型导入,统一echarts导入方式 3. 优化配置与样式:调整gitignore、样式引入顺序,新增列表动画样式 4. 修复接口与模型:修正接口返回类型、查询参数配置,更新部门模型字段 5. 优化性能与体验:添加图片懒加载,优化加载逻辑与表格渲染 6. 调整环境配置:新增并更新开发/生产环境配置文件
This commit is contained in:
@@ -1,9 +1,7 @@
|
||||
from typing import Annotated
|
||||
|
||||
from fastapi import APIRouter, Body, Depends, Path, Query, Security, status
|
||||
from fastapi import APIRouter, Body, Depends, Path, Security, status
|
||||
from fastapi.responses import JSONResponse, StreamingResponse
|
||||
from fastapi_cache import FastAPICache
|
||||
from fastapi_cache.decorator import cache
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.common.response import ResponseSchema, StreamResponse, SuccessResponse
|
||||
@@ -17,16 +15,13 @@ from .service import PositionService
|
||||
|
||||
PositionRouter = APIRouter(route_class=OperationLogRoute, prefix="/position", tags=["岗位管理"])
|
||||
|
||||
_POS_NS = "position"
|
||||
|
||||
|
||||
@PositionRouter.get("/list", summary="查询岗位", response_model=ResponseSchema[PageResultSchema[PositionOutSchema]])
|
||||
@cache(expire=300, namespace=_POS_NS)
|
||||
async def get_obj_list_controller(
|
||||
auth: Annotated[AuthSchema, Security(AuthPermission(["module_system:position:query"]))],
|
||||
db: Annotated[AsyncSession, Depends(db_getter)],
|
||||
page: Annotated[PaginationQueryParam, Depends()],
|
||||
search: Annotated[PositionQueryParam, Query()],
|
||||
search: Annotated[PositionQueryParam, Depends()],
|
||||
) -> JSONResponse:
|
||||
result_dict = await PositionService(auth, db).page(
|
||||
page_no=page.page_no,
|
||||
@@ -54,7 +49,6 @@ async def create_obj_controller(
|
||||
data: Annotated[PositionCreateSchema, Body(description="岗位创建参数")],
|
||||
) -> JSONResponse:
|
||||
result_dict = await PositionService(auth, db).create(data=data)
|
||||
await FastAPICache.clear(namespace=_POS_NS)
|
||||
return SuccessResponse(data=result_dict, msg="创建岗位成功")
|
||||
|
||||
|
||||
@@ -66,7 +60,6 @@ async def update_obj_controller(
|
||||
data: Annotated[PositionUpdateSchema, Body(description="岗位修改参数")],
|
||||
) -> JSONResponse:
|
||||
result_dict = await PositionService(auth, db).update(id=id, data=data)
|
||||
await FastAPICache.clear(namespace=_POS_NS)
|
||||
return SuccessResponse(data=result_dict, msg="修改岗位成功")
|
||||
|
||||
|
||||
@@ -77,7 +70,6 @@ async def delete_obj_controller(
|
||||
ids: Annotated[list[int], Body(description="ID列表")],
|
||||
) -> JSONResponse:
|
||||
await PositionService(auth, db).delete(ids=ids)
|
||||
await FastAPICache.clear(namespace=_POS_NS)
|
||||
return SuccessResponse(msg="删除岗位成功")
|
||||
|
||||
|
||||
@@ -88,7 +80,6 @@ async def batch_set_available_obj_controller(
|
||||
data: Annotated[BatchSetAvailable, Body(description="状态设置")],
|
||||
) -> JSONResponse:
|
||||
await PositionService(auth, db).set_available(data=data)
|
||||
await FastAPICache.clear(namespace=_POS_NS)
|
||||
return SuccessResponse(msg="批量修改岗位状态成功")
|
||||
|
||||
|
||||
|
||||
@@ -14,17 +14,12 @@ class PositionModel(ModelMixin, UserMixin):
|
||||
|
||||
__tablename__: str = "sys_position"
|
||||
__table_args__: dict[str, str] = {"comment": "岗位表"}
|
||||
__loader_options__: list[str] = ["users", "created_by", "updated_by", "deleted_by"]
|
||||
|
||||
name: Mapped[str] = mapped_column(String(64), nullable=False, comment="岗位名称")
|
||||
name: Mapped[str] = mapped_column(String(64), nullable=False, index=True, comment="岗位名称")
|
||||
code: Mapped[str] = mapped_column(String(64), unique=True, nullable=False, comment="岗位编码")
|
||||
order: Mapped[int] = mapped_column(Integer, nullable=False, default=1, comment="显示排序")
|
||||
status: Mapped[int] = mapped_column(Integer, default=0, nullable=False, comment="状态(0:启动 1:停用)", index=True)
|
||||
status: Mapped[int] = mapped_column(Integer, default=0, nullable=False, comment="状态(0:启动 1:停用)")
|
||||
description: Mapped[str | None] = mapped_column(Text, default=None, nullable=True, comment="备注")
|
||||
|
||||
# 关联关系
|
||||
users: Mapped[list["UserModel"]] = relationship(
|
||||
secondary="sys_user_positions",
|
||||
back_populates="positions",
|
||||
lazy="selectin",
|
||||
)
|
||||
users: Mapped[list["UserModel"]] = relationship(secondary="sys_user_positions", back_populates="positions")
|
||||
|
||||
@@ -49,5 +49,5 @@ class PositionOutSchema(PositionCreateSchema, BaseSchema, UserBySchema):
|
||||
class PositionQueryParam(BaseQueryParam, UserByQueryParam):
|
||||
"""岗位管理查询参数"""
|
||||
|
||||
name: str | None = Field(None, description="岗位名称")
|
||||
status: int | None = Field(None, ge=0, le=1, description="状态(0:启动 1:停用)")
|
||||
name: str | None = Field(None, description="岗位名称", json_schema_extra={"q": "like"})
|
||||
status: int | None = Field(None, ge=0, le=1, description="状态(0:启动 1:停用)", json_schema_extra={"q": "eq"})
|
||||
|
||||
@@ -63,15 +63,15 @@ class PositionService:
|
||||
if position:
|
||||
raise CustomException(msg="创建失败,该数据已存在")
|
||||
new_position = await PositionCRUD(self.auth, self.db).create(data=data)
|
||||
return PositionOutSchema.model_validate(new_position)
|
||||
return await self.detail(id=new_position.id)
|
||||
|
||||
async def update(self, id: int, data: PositionUpdateSchema) -> PositionOutSchema:
|
||||
_ = await PositionCRUD(self.auth, self.db).get_or_404(id=id, msg="更新失败,该数据不存在")
|
||||
exist_position = await PositionCRUD(self.auth, self.db).get(name=data.name)
|
||||
if exist_position and exist_position.id != id:
|
||||
raise CustomException(msg="更新失败,名称已存在")
|
||||
updated_position = await PositionCRUD(self.auth, self.db).update(id=id, data=data)
|
||||
return PositionOutSchema.model_validate(updated_position)
|
||||
await PositionCRUD(self.auth, self.db).update(id=id, data=data)
|
||||
return await self.detail(id=id)
|
||||
|
||||
async def delete(self, ids: list[int]) -> None:
|
||||
if not ids:
|
||||
|
||||
Reference in New Issue
Block a user