Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #55 crud.ts 列配置未使用小驼峰命名规则导致后端参数接受不到 #56

Merged
merged 1 commit into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dfs_generate/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
VUE_INDEX_VUE,
VUE_CRUD_TS,
)
from dfs_generate.tools import to_pascal, tran, to_snake
from dfs_generate.tools import to_pascal, tran, to_snake, to_camel


def _pydantic_field(column, imports):
Expand All @@ -33,7 +33,7 @@ def _pydantic_field(column, imports):


def _fast_crud_column(column):
name = column["COLUMN_NAME"]
name = to_camel(column["COLUMN_NAME"])
title = column["COLUMN_COMMENT"] or name
fmt = f"{name}: {{ title: '{title}', type: 'text', search: {{ show: true }}}}"
return fmt
Expand Down
13 changes: 13 additions & 0 deletions dfs_generate/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@ def to_snake(camel: str) -> str:
return snake.lower()


def to_camel(snake: str) -> str:
"""Convert a snake_case string to camelCase.

Args:
snake: The string to convert.

Returns:
The converted camelCase string.
"""
camel = to_pascal(snake)
return re.sub("(^_*[A-Z])", lambda m: m.group(1).lower(), camel)


@dataclass
class MySQLConf:
host: str
Expand Down
Loading