From 246628d2cf00a9e0ac747a6ff93d1f736b094337 Mon Sep 17 00:00:00 2001 From: zhangtao <9480807882@qq.com> Date: Sun, 23 Nov 2025 19:02:38 +0800 Subject: [PATCH 1/4] =?UTF-8?q?refactor(base=5Fmodel):=20=E7=A7=BB?= =?UTF-8?q?=E9=99=A4=E6=9C=AA=E4=BD=BF=E7=94=A8=E7=9A=84uuid=E5=AD=97?= =?UTF-8?q?=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/core/base_model.py | 1 - 1 file changed, 1 deletion(-) diff --git a/backend/app/core/base_model.py b/backend/app/core/base_model.py index 99fff072..ce252083 100644 --- a/backend/app/core/base_model.py +++ b/backend/app/core/base_model.py @@ -94,7 +94,6 @@ class ModelMixin(DateTimeMixin): __abstract__ = True id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True, comment='主键ID') - uuid: Mapped[str] = mapped_column(String(64), unique=True) description: Mapped[Optional[str]] = mapped_column(Text, nullable=True, default=None, comment="备注/描述") From 8e25a2549be3fb9d5c66b049ae7f6255a005dbd1 Mon Sep 17 00:00:00 2001 From: zhangtao <9480807882@qq.com> Date: Mon, 24 Nov 2025 20:56:11 +0800 Subject: [PATCH 2/4] =?UTF-8?q?refactor(cli):=20=E5=B0=86=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E5=A3=B0=E6=98=8E=E4=BB=8EArgument=E6=94=B9=E4=B8=BAO?= =?UTF-8?q?ption=E4=BB=A5=E4=BF=9D=E6=8C=81=E4=B8=80=E8=87=B4=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修改revision和upgrade命令的环境参数声明方式,从typer.Argument改为typer.Option,与run命令保持一致 --- backend/main.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/backend/main.py b/backend/main.py index 601107b9..0d280ad4 100755 --- a/backend/main.py +++ b/backend/main.py @@ -47,8 +47,9 @@ def create_app() -> FastAPI: return app +# typer.Option是非必填;typer.Argument是必填 @fastapiadmin_cli.command(name="run", help="启动 FastapiAdmin 服务, 运行 python main.py run --env=dev 不加参数默认 dev 环境") -def run(env: Annotated[EnvironmentEnum, typer.Option(EnvironmentEnum.DEV, "--env", help="运行环境 (dev, prod)")] = EnvironmentEnum.DEV) -> None: +def run(env: Annotated[EnvironmentEnum, typer.Option("--env", help="运行环境 (dev, prod)")] = EnvironmentEnum.DEV) -> None: """启动FastAPI服务""" try: @@ -84,14 +85,14 @@ def run(env: Annotated[EnvironmentEnum, typer.Option(EnvironmentEnum.DEV, "--env raise @fastapiadmin_cli.command(name="revision", help="生成新的 Alembic 迁移脚本, 运行 python main.py revision --env=dev") -def revision(env: Annotated[EnvironmentEnum, typer.Argument(help="运行环境 (dev, prod)")] = EnvironmentEnum.DEV) -> None: +def revision(env: Annotated[EnvironmentEnum, typer.Option("--env", help="运行环境 (dev, prod)")] = EnvironmentEnum.DEV) -> None: """生成新的 Alembic 迁移脚本""" os.environ["ENVIRONMENT"] = env.value command.revision(alembic_cfg, autogenerate=True, message="迁移脚本") typer.echo(f"迁移脚本已生成") @fastapiadmin_cli.command(name="upgrade", help="应用最新的 Alembic 迁移, 运行 python main.py upgrade --env=dev") -def upgrade(env: Annotated[EnvironmentEnum, typer.Argument(help="运行环境 (dev, prod)")] = EnvironmentEnum.DEV) -> None: +def upgrade(env: Annotated[EnvironmentEnum, typer.Option("--env", help="运行环境 (dev, prod)")] = EnvironmentEnum.DEV) -> None: """应用最新的 Alembic 迁移""" os.environ["ENVIRONMENT"] = env.value command.upgrade(alembic_cfg, "head") From 334b59a8ab033c5bdd5fb2110572f2ba9b7127ac Mon Sep 17 00:00:00 2001 From: zhangtao <9480807882@qq.com> Date: Thu, 27 Nov 2025 00:00:23 +0800 Subject: [PATCH 3/4] =?UTF-8?q?refactor(base=5Fcrud):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E5=88=86=E9=A1=B5=E6=9F=A5=E8=AF=A2=E8=BF=94=E5=9B=9E=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将PageResultSchema的实例化改为直接返回字典结构,简化代码并提高性能 ``` ```msg fix(module_generator): 修正模板字段命名问题 将模板中的python_field统一改为column_name,保持字段命名一致性 --- .../gencode/templates/ts/api.ts.j2 | 12 ++++++------ backend/app/core/base_crud.py | 16 +++++++--------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/backend/app/api/v1/module_generator/gencode/templates/ts/api.ts.j2 b/backend/app/api/v1/module_generator/gencode/templates/ts/api.ts.j2 index 54f3cffa..06ce9411 100644 --- a/backend/app/api/v1/module_generator/gencode/templates/ts/api.ts.j2 +++ b/backend/app/api/v1/module_generator/gencode/templates/ts/api.ts.j2 @@ -107,12 +107,12 @@ export interface {{ class_name }}PageQuery extends PageQuery { end_time?: string; } -// 列表查询结果 +// 列表展示项 export interface {{ class_name }}Table { index?: number; {% for column in columns %} - {{ column.python_field }}?: {{ - 'boolean' if ('status' in (column.python_field|lower)) or (column.html_type == 'radio') + {{ column.column_name }}?: {{ + 'boolean' if ('status' in (column.column_name|lower)) or (column.html_type == 'radio') else 'number' if column.is_pk == 1 else 'string' }}; @@ -123,9 +123,9 @@ export interface {{ class_name }}Table { // 新增/修改/详情表单参数 export interface {{ class_name }}Form { {% for column in columns %} - {% if (column.is_insert == 1 or column.is_edit == 1) and column.python_field not in ['creatorId', 'createdAt', 'updatedAt'] %} - {{ column.python_field }}?: {{ - 'boolean' if ('status' in (column.python_field|lower)) or (column.html_type == 'radio') + {% if (column.is_insert == 1 or column.is_edit == 1) and column.column_name not in ['creator_id', 'created_at', 'updated_at'] %} + {{ column.column_name }}?: {{ + 'boolean' if ('status' in (column.column_name|lower)) or (column.html_type == 'radio') else 'number' if column.is_pk == 1 else 'string' }}; diff --git a/backend/app/core/base_crud.py b/backend/app/core/base_crud.py index 9969ca01..313474f7 100644 --- a/backend/app/core/base_crud.py +++ b/backend/app/core/base_crud.py @@ -179,15 +179,13 @@ class CRUDBase(Generic[ModelType, CreateSchemaType, UpdateSchemaType]): result: Result = await self.db.execute(sql.offset(offset).limit(limit)) objs = result.scalars().all() - data = PageResultSchema( - items=[out_schema.model_validate(obj).model_dump() for obj in objs], - total=total, - page_no=offset // limit + 1 if limit else 1, - page_size=limit, - has_next=offset + limit < total, - ).model_dump() - - return data + return { + "page_no": offset // limit + 1 if limit else 1, + "page_size": limit if limit else 10, + "total": total, + "has_next": offset + limit < total, + "items": [out_schema.model_validate(obj).model_dump() for obj in objs] + } except Exception as e: raise CustomException(msg=f"分页查询失败: {str(e)}") From 007076986488fc165c2d0bb67bde3e05dee15d06 Mon Sep 17 00:00:00 2001 From: zhangtao <9480807882@qq.com> Date: Thu, 27 Nov 2025 00:10:18 +0800 Subject: [PATCH 4/4] =?UTF-8?q?refactor(vue=E6=A8=A1=E6=9D=BF):=20?= =?UTF-8?q?=E7=BB=9F=E4=B8=80=E4=BD=BF=E7=94=A8column=5Fname=E6=9B=BF?= =?UTF-8?q?=E4=BB=A3python=5Ffield=E4=BD=9C=E4=B8=BA=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修改vue模板文件,将所有使用python_field的地方替换为column_name,保持字段命名一致性 --- .../gencode/templates/vue/index.vue.j2 | 68 +++++++++---------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/backend/app/api/v1/module_generator/gencode/templates/vue/index.vue.j2 b/backend/app/api/v1/module_generator/gencode/templates/vue/index.vue.j2 index eeb43bf5..16e233b8 100644 --- a/backend/app/api/v1/module_generator/gencode/templates/vue/index.vue.j2 +++ b/backend/app/api/v1/module_generator/gencode/templates/vue/index.vue.j2 @@ -10,24 +10,24 @@ {% set parentheseIndex = column_comment.find("(") %} {% set comment = column_comment[:parentheseIndex] if parentheseIndex != -1 else column_comment %} {% if column.html_type == "input" %} - - + + {% elif (column.html_type == "select" or column.html_type == "radio") and dict_type != "" %} - - + + {% elif (column.html_type == "select" or column.html_type == "radio") and dict_type %} - - + + {% elif column.html_type == "datetime" and column.query_type != "BETWEEN" %} - - + + {% endif %} {% endif %} @@ -155,7 +155,7 @@ {% for column in columns %} - {% set python_field = column.python_field %} + {% set python_field = column.column_name %} {% set column_comment = column.column_comment if column.column_comment else '' %} {% set parentheseIndex = column_comment.find("(") %} {% set comment = column_comment[:parentheseIndex] if parentheseIndex != -1 else column_comment %} @@ -194,7 +194,7 @@