diff --git a/ruoyi-fastapi-backend/config/constant.py b/ruoyi-fastapi-backend/config/constant.py index 1b124a0..eb77464 100644 --- a/ruoyi-fastapi-backend/config/constant.py +++ b/ruoyi-fastapi-backend/config/constant.py @@ -252,6 +252,8 @@ class GenConstant: 'double', 'decimal', ] + COLUMNNAME_NOT_ADD_SHOW = ['create_by', 'create_time'] + COLUMNNAME_NOT_EDIT_SHOW = ['update_by', 'update_time'] COLUMNNAME_NOT_EDIT = ['id', 'create_by', 'create_time', 'del_flag'] COLUMNNAME_NOT_LIST = ['id', 'create_by', 'create_time', 'del_flag', 'update_by', 'update_time'] COLUMNNAME_NOT_QUERY = ['id', 'create_by', 'create_time', 'del_flag', 'update_by', 'update_time', 'remark'] diff --git a/ruoyi-fastapi-backend/module_generator/templates/python/dao.py.jinja2 b/ruoyi-fastapi-backend/module_generator/templates/python/dao.py.jinja2 index 6cf19a1..ecf3040 100644 --- a/ruoyi-fastapi-backend/module_generator/templates/python/dao.py.jinja2 +++ b/ruoyi-fastapi-backend/module_generator/templates/python/dao.py.jinja2 @@ -145,7 +145,7 @@ class {{ BusinessName }}Dao: :param {{ businessName }}: {{ functionName }}对象 :return: """ - db_{{ businessName }} = {{ ClassName }}(**{{ businessName }}.model_dump(exclude={% raw %}{{% endraw %}{% if table.sub %}'{{ subclassName }}_list', {% endif %}{% for column in columns %}{% if not column.insert %}'{{ column.python_field | camel_to_snake }}'{% if not loop.last %}, {% endif %}{% endif %}{% endfor %}{% raw %}}{% endraw %})) + db_{{ businessName }} = {{ ClassName }}(**{{ businessName }}.model_dump(exclude={% raw %}{{% endraw %}{% if table.sub %}'{{ subclassName }}_list', {% endif %}{% for column in columns %}{% if not column.insert and column.column_name not in column_not_add_show + column_not_edit_show %}'{{ column.python_field | camel_to_snake }}'{% if not loop.last %}, {% endif %}{% endif %}{% endfor %}{% raw %}}{% endraw %})) db.add(db_{{ businessName }}) await db.flush() diff --git a/ruoyi-fastapi-backend/module_generator/templates/python/service.py.jinja2 b/ruoyi-fastapi-backend/module_generator/templates/python/service.py.jinja2 index 27d6979..5726c5d 100644 --- a/ruoyi-fastapi-backend/module_generator/templates/python/service.py.jinja2 +++ b/ruoyi-fastapi-backend/module_generator/templates/python/service.py.jinja2 @@ -103,7 +103,7 @@ class {{ BusinessName }}Service: :param page_object: 编辑{{ functionName }}对象 :return: 编辑{{ functionName }}校验结果 """ - edit_{{ businessName }} = page_object.model_dump(exclude_unset=True, exclude={% raw %}{{% endraw %}{% if table.sub %}'{{ subclassName }}_list', {% endif %}{% for column in columns %}{% if not column.edit and not column.pk %}'{{ column.python_field | camel_to_snake }}'{% if not loop.last %}, {% endif %}{% endif %}{% endfor %}{% raw %}}{% endraw %}) + edit_{{ businessName }} = page_object.model_dump(exclude_unset=True, exclude={% raw %}{{% endraw %}{% if table.sub %}'{{ subclassName }}_list', {% endif %}{% for column in columns %}{% if not column.edit and not column.pk and column.column_name not in column_not_edit_show %}'{{ column.python_field | camel_to_snake }}'{% if not loop.last %}, {% endif %}{% endif %}{% endfor %}{% raw %}}{% endraw %}) {{ businessName }}_info = await cls.{{ businessName }}_detail_services(query_db, page_object.{{ pk_field }}) if {{ businessName }}_info.{{ pk_field }}: {% for column in columns %} diff --git a/ruoyi-fastapi-backend/module_generator/templates/vue/index-tree.vue.jinja2 b/ruoyi-fastapi-backend/module_generator/templates/vue/index-tree.vue.jinja2 index 741f132..f71e378 100644 --- a/ruoyi-fastapi-backend/module_generator/templates/vue/index-tree.vue.jinja2 +++ b/ruoyi-fastapi-backend/module_generator/templates/vue/index-tree.vue.jinja2 @@ -161,33 +161,33 @@ {% for column in columns %} {% set field = column.python_field %} - {% if column.insert and not column.pk %} + {% if (column.insert or column.edit) and not column.pk and column.column_name not in column_not_add_show + column_not_edit_show %} {% if column.usable_column or not column.super_column %} {% set parentheseIndex = column.column_comment.find("(") %} {% set comment = column.column_comment[:parentheseIndex] if parentheseIndex != -1 else column.column_comment %} {% set dictType = column.dict_type %} {% if treeParentCode and column.python_field == treeParentCode %} - + {% elif column.html_type == "input" %} - + {% elif column.html_type == "imageUpload" %} - + {% elif column.html_type == "fileUpload" %} - + {% elif column.html_type == "editor" %} - + {% elif column.html_type == "select" and dictType %} - + {% elif column.html_type == "select" and not dictType %} - + {% elif column.html_type == "checkbox" and dictType %} - + {% elif column.html_type == "checkbox" and not dictType %} - + 请选择字典生成 {% elif column.html_type == "radio" and dictType %} - + {% elif column.html_type == "radio" and not dictType %} - + {% elif column.html_type == "datetime" %} - + {% elif column.html_type == "textarea" %} - + {% endif %} @@ -485,6 +485,10 @@ export default { this.getList(); this.$modal.msgSuccess("删除成功"); }).catch(() => {}); + }, + /** 是否渲染字段 */ + renderField(insert, edit) { + return this.form.{{ pkColumn.python_field }} == null ? insert : edit; } }, }; diff --git a/ruoyi-fastapi-backend/module_generator/templates/vue/index.vue.jinja2 b/ruoyi-fastapi-backend/module_generator/templates/vue/index.vue.jinja2 index a1b7f4b..7f2fc47 100644 --- a/ruoyi-fastapi-backend/module_generator/templates/vue/index.vue.jinja2 +++ b/ruoyi-fastapi-backend/module_generator/templates/vue/index.vue.jinja2 @@ -173,29 +173,29 @@ {% for column in columns %} {% set field = column.python_field %} - {% if column.insert and not column.pk %} + {% if (column.insert or column.edit) and not column.pk and column.column_name not in column_not_add_show + column_not_edit_show %} {% if column.usable_column or not column.super_column %} {% set parentheseIndex = column.column_comment.find("(") %} {% set comment = column.column_comment[:parentheseIndex] if parentheseIndex != -1 else column.column_comment %} {% set dictType = column.dict_type %} {% if column.html_type == "input" %} - + {% elif column.html_type == "imageUpload" %} - + {% elif column.html_type == "fileUpload" %} - + {% elif column.html_type == "editor" %} - + {% elif column.html_type == "select" and dictType %} - + {% elif column.html_type == "select" and not dictType %} - + {% elif column.html_type == "checkbox" and dictType %} - + {% elif column.html_type == "checkbox" and not dictType %} - + 请选择字典生成 {% elif column.html_type == "radio" and dictType %} - + {% elif column.html_type == "radio" and not dictType %} - + {% elif column.html_type == "datetime" %} - + {% elif column.html_type == "textarea" %} - + {% endif %} @@ -580,6 +580,10 @@ export default { this.download('{{ moduleName }}/{{ businessName }}/export', { ...this.queryParams }, `{{ businessName }}_${new Date().getTime()}.xlsx`); + }, + /** 是否渲染字段 */ + renderField(insert, edit) { + return this.form.{{ pkColumn.python_field }} == null ? insert : edit; } }, }; diff --git a/ruoyi-fastapi-backend/module_generator/templates/vue/v3/index-tree.vue.jinja2 b/ruoyi-fastapi-backend/module_generator/templates/vue/v3/index-tree.vue.jinja2 index 433c162..a7c1382 100644 --- a/ruoyi-fastapi-backend/module_generator/templates/vue/v3/index-tree.vue.jinja2 +++ b/ruoyi-fastapi-backend/module_generator/templates/vue/v3/index-tree.vue.jinja2 @@ -136,13 +136,13 @@ {% for column in columns %} {% set field = column.python_field %} - {% if column.insert and not column.pk %} + {% if (column.insert or column.edit) and not column.pk and column.column_name not in column_not_add_show + column_not_edit_show %} {% if column.usable_column or not column.super_column %} {% set parentheseIndex = column.column_comment.find("(") %} {% set comment = column.column_comment[:parentheseIndex] if parentheseIndex != -1 else column.column_comment %} {% set dictType = column.dict_type %} {% if treeParentCode and column.python_field == treeParentCode %} - + {% elif column.html_type == "input" %} - + {% elif column.html_type == "imageUpload" %} - + {% elif column.html_type == "fileUpload" %} - + {% elif column.html_type == "editor" %} - + {% elif column.html_type == "select" and dictType %} - + {% elif column.html_type == "select" and not dictType %} - + {% elif column.html_type == "checkbox" and dictType %} - + {% elif column.html_type == "checkbox" and not dictType %} - + 请选择字典生成 {% elif column.html_type == "radio" and dictType %} - + {% elif column.html_type == "radio" and not dictType %} - + {% elif column.html_type == "datetime" %} - + {% elif column.html_type == "textarea" %} - + {% endif %} @@ -450,5 +450,10 @@ function handleDelete(row) { }).catch(() => {}); } +/** 是否渲染字段 */ +function renderField(insert, edit) { + return form.value.{{ pkColumn.python_field }} == null ? insert : edit; +} + getList(); \ No newline at end of file diff --git a/ruoyi-fastapi-backend/module_generator/templates/vue/v3/index.vue.jinja2 b/ruoyi-fastapi-backend/module_generator/templates/vue/v3/index.vue.jinja2 index 981124f..ad79130 100644 --- a/ruoyi-fastapi-backend/module_generator/templates/vue/v3/index.vue.jinja2 +++ b/ruoyi-fastapi-backend/module_generator/templates/vue/v3/index.vue.jinja2 @@ -159,29 +159,29 @@ {% for column in columns %} {% set field = column.python_field %} - {% if column.insert and not column.pk %} + {% if (column.insert or column.edit) and not column.pk and column.column_name not in column_not_add_show + column_not_edit_show %} {% if column.usable_column or not column.super_column %} {% set parentheseIndex = column.column_comment.find("(") %} {% set comment = column.column_comment[:parentheseIndex] if parentheseIndex != -1 else column.column_comment %} {% set dictType = column.dict_type %} {% if column.html_type == "input" %} - + {% elif column.html_type == "imageUpload" %} - + {% elif column.html_type == "fileUpload" %} - + {% elif column.html_type == "editor" %} - + {% elif column.html_type == "select" and dictType %} - + {% elif column.html_type == "select" and not dictType %} - + {% elif column.html_type == "checkbox" and dictType %} - + {% elif column.html_type == "checkbox" and not dictType %} - + 请选择字典生成 {% elif column.html_type == "radio" and dictType %} - + {% elif column.html_type == "radio" and not dictType %} - + {% elif column.html_type == "datetime" %} - + {% elif column.html_type == "textarea" %} - + {% endif %} @@ -567,5 +567,10 @@ function handleExport() { }, `{{ businessName }}_${new Date().getTime()}.xlsx`); } +/** 是否渲染字段 */ +function renderField(insert, edit) { + return form.value.{{ pkColumn.python_field }} == null ? insert : edit; +} + getList(); \ No newline at end of file diff --git a/ruoyi-fastapi-backend/utils/template_util.py b/ruoyi-fastapi-backend/utils/template_util.py index 55a8f87..6765bd0 100644 --- a/ruoyi-fastapi-backend/utils/template_util.py +++ b/ruoyi-fastapi-backend/utils/template_util.py @@ -91,6 +91,8 @@ class TemplateUtils: 'table': gen_table, 'dicts': cls.get_dicts(gen_table), 'dbType': DataBaseConfig.db_type, + 'column_not_add_show': GenConstant.COLUMNNAME_NOT_ADD_SHOW, + 'column_not_edit_show': GenConstant.COLUMNNAME_NOT_EDIT_SHOW, } # 设置菜单、树形结构、子表的上下文