diff --git a/config.py b/config.py index 21c6776..ddfc794 100644 --- a/config.py +++ b/config.py @@ -24,7 +24,7 @@ DB = { "host": "192.168.1.80", "user": "root", "password": "Khq#P9hZ4L@EwCZw", - "database": "health_ai_b", + "database": "health_ai", "port": 3728 } diff --git a/config.yml b/config.yml index 9b4be57..7646991 100644 --- a/config.yml +++ b/config.yml @@ -87,10 +87,12 @@ application: # =============================== # vue 应用级配置 +# editFields 不编辑,不展示 # =============================== frontend: root: F:/zxmgee/codegen/vue-vben-admin api: apps/web-antd/src/api views: apps/web-antd/src/views router: apps/web-antd/src/router/routes/modules - mock: apps/web-antd/mock \ No newline at end of file + mock: apps/web-antd/mock + editFields: "user_id,created_at,created_by,updated_at,updated_by,deleted_flag" \ No newline at end of file diff --git a/frontend_vue.py b/frontend_vue.py index 065a664..2c12943 100644 --- a/frontend_vue.py +++ b/frontend_vue.py @@ -1,6 +1,6 @@ import os from jinja2 import Environment, FileSystemLoader -from db import get_columns +from db import get_table, get_columns from utils import * import yaml @@ -21,21 +21,17 @@ def build_fields(table): cols = get_columns(table) fields = [] - for c in cols: - field = {} - field["name"] = to_camel(c["column_name"]) field["comment"] = c["column_comment"] field["type"] = c["data_type"] - # ⭐ 在这里调用组件解析 field["component"] = parse_component(c) - fields.append(field) return fields + def generate(table): with open("./config.yml", "r", encoding="utf-8") as f: @@ -46,18 +42,20 @@ def generate(table): VIEW_DIR = cfg["frontend"]["root"]+"/"+cfg["frontend"]["views"] ROUTER_DIR = cfg["frontend"]["root"]+"/"+cfg["frontend"]["router"] MOCK_DIR = cfg["frontend"]["root"]+"/"+cfg["frontend"]["mock"] + EDIT_FIELDS = cfg["frontend"]["editFields"] - - fields = get_columns(table) + table_info = get_table(table) entity = table.replace("health_","") - ctx = { "table":table, + "table_comment":table_info["table_comment"], "old_table": to_kebab(table), "entity":entity, + "editFields": to_class_join(EDIT_FIELDS), "fields":build_fields(table) } + print(ctx) render( "api.ts.j2", f"{API_DIR}/{entity}.ts", @@ -96,6 +94,21 @@ def generate(table): ) -if __name__ == "__main__": +# ... existing code ... - generate("health_user") \ No newline at end of file +if __name__ == "__main__": + import sys + + # 从命令行参数获取表名 + if len(sys.argv) > 1: + table_name = sys.argv[1] + print(f"=== 生成前端代码1:{table_name} ===") + generate(table_name) + else: + # 如果没有提供参数,提示用户输入 + table_name = input("请输入表名 (例如 health_user): ").strip() + if table_name: + print(f"=== 生成前端代码2:{table_name} ===") + generate(table_name) + else: + print("❌ 未输入表名,退出程序") \ No newline at end of file diff --git a/templates/vue/api.ts.j2 b/templates/vue/api.ts.j2 index c5ebe3a..288be03 100644 --- a/templates/vue/api.ts.j2 +++ b/templates/vue/api.ts.j2 @@ -15,7 +15,8 @@ export namespace {{entity}}Api { * 分页查询 */ export function page(params: any) { - return requestClient.post(applicationConfig.javaURL+'/{{old_table}}/page', params,{ headers: {'Content-Type': 'application/json', Token: 'ded93460-0cf5-45db-81ae-7608dbd3f51e', version: '1.0.1'}}); + return requestClient.post(applicationConfig.javaURL+'/{{old_table}}/page', params, + { headers: {'Content-Type': 'application/json', Token: 'ded93460-0cf5-45db-81ae-7608dbd3f51e', version: '1.0.1', familyId: 0}}); } /** @@ -26,10 +27,19 @@ export namespace {{entity}}Api { } /** - * 新增 / 修改 + * 新增 + */ + export function add(data: any) { + return requestClient.post(applicationConfig.javaURL+'/{{old_table}}/add', data, + { headers: {'Content-Type': 'application/json', Token: 'ded93460-0cf5-45db-81ae-7608dbd3f51e', version: '1.0.1', familyId: 0}}); + } + + /** + * 修改 */ export function save(data: any) { - return requestClient.post(applicationConfig.javaURL+'/{{old_table}}', data); + return requestClient.post(applicationConfig.javaURL+'/{{old_table}}/modify', data, + { headers: {'Content-Type': 'application/json', Token: 'ded93460-0cf5-45db-81ae-7608dbd3f51e', version: '1.0.1', familyId: 0}}); } /** diff --git a/templates/vue/index.vue.j2 b/templates/vue/index.vue.j2 index 8de90b1..925795e 100644 --- a/templates/vue/index.vue.j2 +++ b/templates/vue/index.vue.j2 @@ -1,6 +1,6 @@ - - - - - - 查询条件 - - - - 🔍 查询 - - - 🔄 重置 - - - - - - - - ➕ 新增 - gridApi.reload()">🔄 刷新 - - - - - handleEdit(row)" class="text-blue-500 hover:text-blue-700">✏️ 编辑 - - handleDelete(row)" class="text-red-500 hover:text-red-700">🗑️ 删除 - - - - - - - - - -