fix: 修复vue2模版异常问题

This commit is contained in:
insistence
2025-02-19 00:16:23 +08:00
parent f42a0b530b
commit 6bae2d2d0c
3 changed files with 213 additions and 201 deletions

View File

@@ -157,7 +157,7 @@
</el-table> </el-table>
<!-- 添加或修改{{ functionName }}对话框 --> <!-- 添加或修改{{ functionName }}对话框 -->
<el-dialog :title="title" v-model="open" width="500px" append-to-body> <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
<el-form ref="form" :model="form" :rules="rules" label-width="80px"> <el-form ref="form" :model="form" :rules="rules" label-width="80px">
{% for column in columns %} {% for column in columns %}
{% set field = column.python_field %} {% set field = column.python_field %}
@@ -283,6 +283,9 @@ export default {
{% if dicts %} {% if dicts %}
dicts: [{{ dicts }}], dicts: [{{ dicts }}],
{% endif %} {% endif %}
components: {
Treeselect
},
data() { data() {
return { return {
// 遮罩层 // 遮罩层
@@ -291,6 +294,8 @@ export default {
showSearch: true, showSearch: true,
// {{ functionName }}表格数据 // {{ functionName }}表格数据
{{ businessName }}List: [], {{ businessName }}List: [],
// {{ functionName }}树选项
{{ businessName }}Options: [],
// 弹出层标题 // 弹出层标题
title: "", title: "",
// 是否显示弹出层 // 是否显示弹出层
@@ -375,9 +380,8 @@ export default {
data.children = this.handleTree(response.data, "{{ treeCode }}", "{{ treeParentCode }}"); data.children = this.handleTree(response.data, "{{ treeCode }}", "{{ treeParentCode }}");
this.{{ businessName }}Options.push(data); this.{{ businessName }}Options.push(data);
}); });
} },
}, /** 取消按钮 */
/** 取消按钮 */
cancel() { cancel() {
this.open = false; this.open = false;
this.reset(); this.reset();
@@ -394,94 +398,94 @@ export default {
{% endfor %} {% endfor %}
}; };
this.resetForm("form"); this.resetForm("form");
} },
}, /** 搜索按钮操作 */
/** 搜索按钮操作 */ handleQuery() {
handleQuery() { this.getList();
this.getList(); },
}, /** 重置按钮操作 */
/** 重置按钮操作 */ resetQuery() {
resetQuery() {
{% for column in columns %}
{% if column.html_type == "datetime" and column.query_type == "BETWEEN" %}
{% set AttrName = column.python_field[0] | upper + column.python_field[1:] %}
this.daterange{{ AttrName }} = [];
{% endif %}
{% endfor %}
this.resetForm("queryRef");
this.handleQuery();
},
/** 新增按钮操作 */
handleAdd(row) {
this.reset();
this.getTreeselect();
if (row != null && row.{{ treeCode }}) {
this.form.{{ treeParentCode }} = row.{{ treeCode }};
} else {
this.form.{{ treeParentCode }} = 0;
}
this.open = true;
this.title = "添加{{ functionName }}";
},
/** 展开/折叠操作 */
toggleExpandAll() {
this.refreshTable = false;
this.isExpandAll = !isExpandAll;
nextTick(() => {
this.refreshTable = true;
});
},
/** 修改按钮操作 */
function handleUpdate(row) {
this.reset();
this.getTreeselect();
if (row != null) {
this.form.{{ treeParentCode }} = row.{{ treeParentCode }};
}
get{{ BusinessName }}(row.{{ pkColumn.python_field }}).then(response => {
this.form = response.data;
{% for column in columns %} {% for column in columns %}
{% if column.html_type == "checkbox" %} {% if column.html_type == "datetime" and column.query_type == "BETWEEN" %}
this.form.{{ column.python_field }} = this.form.{{ column.python_field }}.split(","); {% set AttrName = column.python_field[0] | upper + column.python_field[1:] %}
this.daterange{{ AttrName }} = [];
{% endif %} {% endif %}
{% endfor %} {% endfor %}
this.resetForm("queryForm");
this.handleQuery();
},
/** 新增按钮操作 */
handleAdd(row) {
this.reset();
this.getTreeselect();
if (row != null && row.{{ treeCode }}) {
this.form.{{ treeParentCode }} = row.{{ treeCode }};
} else {
this.form.{{ treeParentCode }} = 0;
}
this.open = true; this.open = true;
this.title = "修改{{ functionName }}"; this.title = "添加{{ functionName }}";
}); },
}, /** 展开/折叠操作 */
/** 提交按钮 */ toggleExpandAll() {
submitForm() { this.refreshTable = false;
this.$refs["form"].validate(valid => { this.isExpandAll = !isExpandAll;
if (valid) { nextTick(() => {
this.refreshTable = true;
});
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset();
this.getTreeselect();
if (row != null) {
this.form.{{ treeParentCode }} = row.{{ treeParentCode }};
}
get{{ BusinessName }}(row.{{ pkColumn.python_field }}).then(response => {
this.form = response.data;
{% for column in columns %} {% for column in columns %}
{% if column.html_type == "checkbox" %} {% if column.html_type == "checkbox" %}
this.form.{{ column.python_field }} = this.form.{{ column.python_field }}.join(","); this.form.{{ column.python_field }} = this.form.{{ column.python_field }}.split(",");
{% endif %} {% endif %}
{% endfor %} {% endfor %}
if (this.form.{{ pkColumn.python_field }} != null) { this.open = true;
update{{ BusinessName }}(this.form).then(response => { this.title = "修改{{ functionName }}";
this.$modal.msgSuccess("修改成功"); });
this.open = false; },
this.getList(); /** 提交按钮 */
}); submitForm() {
} else { this.$refs["form"].validate(valid => {
add{{ BusinessName }}(this.form).then(response => { if (valid) {
this.$modal.msgSuccess("新增成功"); {% for column in columns %}
this.open = false; {% if column.html_type == "checkbox" %}
this.getList(); this.form.{{ column.python_field }} = this.form.{{ column.python_field }}.join(",");
}); {% endif %}
{% endfor %}
if (this.form.{{ pkColumn.python_field }} != null) {
update{{ BusinessName }}(this.form).then(response => {
this.$modal.msgSuccess("修改成功");
this.open = false;
this.getList();
});
} else {
add{{ BusinessName }}(this.form).then(response => {
this.$modal.msgSuccess("新增成功");
this.open = false;
this.getList();
});
}
} }
} });
}); },
/** 删除按钮操作 */
handleDelete(row) {
this.$modal.confirm('是否确认删除{{ functionName }}编号为"' + row.{{ pkColumn.python_field }} + '"的数据项?').then(function() {
return del{{ BusinessName }}(row.{{ pkColumn.python_field }});
}).then(() => {
this.getList();
this.$modal.msgSuccess("删除成功");
}).catch(() => {});
}
}, },
/** 删除按钮操作 */
handleDelete(row) {
this.$modal.confirm('是否确认删除{{ functionName }}编号为"' + row.{{ pkColumn.python_field }} + '"的数据项?').then(function() {
return del{{ BusinessName }}(row.{{ pkColumn.python_field }});
}).then(() => {
this.getList();
this.$modal.msgSuccess("删除成功");
}).catch(() => {});
}
}; };
</script> </script>

View File

@@ -169,7 +169,7 @@
/> />
<!-- 添加或修改{{ functionName }}对话框 --> <!-- 添加或修改{{ functionName }}对话框 -->
<el-dialog :title="title" v-model="open" width="500px" append-to-body> <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
<el-form ref="form" :model="form" :rules="rules" label-width="80px"> <el-form ref="form" :model="form" :rules="rules" label-width="80px">
{% for column in columns %} {% for column in columns %}
{% set field = column.python_field %} {% set field = column.python_field %}
@@ -457,130 +457,130 @@ export default {
this.{{ subclassName }}List = []; this.{{ subclassName }}List = [];
{% endif %} {% endif %}
this.resetForm("form"); this.resetForm("form");
} },
}, /** 搜索按钮操作 */
/** 搜索按钮操作 */ handleQuery() {
handleQuery() { this.queryParams.pageNum = 1;
this.queryParams.pageNum = 1; this.getList();
this.getList(); },
}, /** 重置按钮操作 */
/** 重置按钮操作 */ resetQuery() {
resetQuery() {
{% for column in columns %}
{% if column.html_type == "datetime" and column.query_type == "BETWEEN" %}
{% set AttrName = column.python_field[0] | upper + column.python_field[1:] %}
this.daterange{{ AttrName }} = [];
{% endif %}
{% endfor %}
this.resetForm("queryRef");
this.handleQuery();
},
/** 多选框选中数据 */
handleSelectionChange(selection) {
this.ids = selection.map(item => item.{{ pkColumn.python_field }});
this.single = selection.length != 1;
this.multiple = !selection.length;
},
/** 新增按钮操作 */
handleAdd() {
this.reset();
this.open = true;
this.title = "添加{{ functionName }}";
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset();
const {{ pkColumn.python_field }} = row.{{ pkColumn.python_field }} || this.ids;
get{{ BusinessName }}({{ pkColumn.python_field }}).then(response => {
this.form = response.data;
{% for column in columns %} {% for column in columns %}
{% if column.html_type == "checkbox" %} {% if column.html_type == "datetime" and column.query_type == "BETWEEN" %}
this.form.{{ column.python_field }} = this.form.{{ column.python_field }}.split(","); {% set AttrName = column.python_field[0] | upper + column.python_field[1:] %}
this.daterange{{ AttrName }} = [];
{% endif %} {% endif %}
{% endfor %} {% endfor %}
{% if table.sub %} this.resetForm("queryForm");
this.{{ subclassName }}List = response.data.{{ subclassName }}List; this.handleQuery();
{% endif %} },
/** 多选框选中数据 */
handleSelectionChange(selection) {
this.ids = selection.map(item => item.{{ pkColumn.python_field }});
this.single = selection.length != 1;
this.multiple = !selection.length;
},
/** 新增按钮操作 */
handleAdd() {
this.reset();
this.open = true; this.open = true;
this.title = "修改{{ functionName }}"; this.title = "添加{{ functionName }}";
}); },
}, /** 修改按钮操作 */
/** 提交按钮 */ handleUpdate(row) {
submitForm() { this.reset();
this.$refs["form"].validate(valid => { const {{ pkColumn.python_field }} = row.{{ pkColumn.python_field }} || this.ids;
if (valid) { get{{ BusinessName }}({{ pkColumn.python_field }}).then(response => {
this.form = response.data;
{% for column in columns %} {% for column in columns %}
{% if column.html_type == "checkbox" %} {% if column.html_type == "checkbox" %}
this.form.{{ column.python_field }} = this.form.{{ column.python_field }}.join(","); this.form.{{ column.python_field }} = this.form.{{ column.python_field }}.split(",");
{% endif %} {% endif %}
{% endfor %} {% endfor %}
{% if table.sub %} {% if table.sub %}
this.form.{{ subclassName }}List = this.{{ subclassName }}List; this.{{ subclassName }}List = response.data.{{ subclassName }}List;
{% endif %} {% endif %}
if (this.form.{{ pkColumn.python_field }} != null) { this.open = true;
update{{ BusinessName }}(this.form).then(response => { this.title = "修改{{ functionName }}";
this.$modal.msgSuccess("修改成功");
this.open = false;
this.getList();
});
} else {
add{{ BusinessName }}(this.form).then(response => {
this.$modal.msgSuccess("新增成功");
this.open = false;
this.getList();
});
}
}
});
},
/** 删除按钮操作 */
handleDelete(row) {
const {{ pkColumn.python_field }}s = row.{{ pkColumn.python_field }} || this.ids;
this.$modal.confirm('是否确认删除{{ functionName }}编号为"' + {{ pkColumn.python_field }}s + '"的数据项?').then(function() {
return del{{ BusinessName }}({{ pkColumn.python_field }}s);
}).then(() => {
this.getList();
this.$modal.msgSuccess("删除成功");
}).catch(() => {});
},
{% if table.sub %}
/** {{ subTable.functionName }}序号 */
row{{ subClassName }}Index({ row, rowIndex }) {
row.index = rowIndex + 1;
},
/** {{ subTable.functionName }}添加按钮操作 */
handleAdd{{ subClassName }}() {
let obj = {};
{% for column in subTable.columns %}
{% if column.pk or column.python_field == subTableFkclassName %}
{% elif column.list and column.python_field %}
obj.{{ column.python_field }} = "";
{% endif %}
{% endfor %}
this.{{ subclassName }}List.push(obj);
},
/** {{ subTable.functionName }}删除按钮操作 */
handleDelete{{ subClassName }}() {
if (this.checked{{ subClassName }}.length == 0) {
this.$modal.msgError("请先选择要删除的{{ subTable.functionName }}数据");
} else {
const {{ subclassName }}List = this.{{ subclassName }}List;
const checked{{ subClassName }} = this.checked{{ subClassName }};
this.{{ subclassName }}List = {{ subclassName }}List.filter(function(item) {
return checked{{ subClassName }}.indexOf(item.index) == -1
}); });
},
/** 提交按钮 */
submitForm() {
this.$refs["form"].validate(valid => {
if (valid) {
{% for column in columns %}
{% if column.html_type == "checkbox" %}
this.form.{{ column.python_field }} = this.form.{{ column.python_field }}.join(",");
{% endif %}
{% endfor %}
{% if table.sub %}
this.form.{{ subclassName }}List = this.{{ subclassName }}List;
{% endif %}
if (this.form.{{ pkColumn.python_field }} != null) {
update{{ BusinessName }}(this.form).then(response => {
this.$modal.msgSuccess("修改成功");
this.open = false;
this.getList();
});
} else {
add{{ BusinessName }}(this.form).then(response => {
this.$modal.msgSuccess("新增成功");
this.open = false;
this.getList();
});
}
}
});
},
/** 删除按钮操作 */
handleDelete(row) {
const {{ pkColumn.python_field }}s = row.{{ pkColumn.python_field }} || this.ids;
this.$modal.confirm('是否确认删除{{ functionName }}编号为"' + {{ pkColumn.python_field }}s + '"的数据项?').then(function() {
return del{{ BusinessName }}({{ pkColumn.python_field }}s);
}).then(() => {
this.getList();
this.$modal.msgSuccess("删除成功");
}).catch(() => {});
},
{% if table.sub %}
/** {{ subTable.functionName }}序号 */
row{{ subClassName }}Index({ row, rowIndex }) {
row.index = rowIndex + 1;
},
/** {{ subTable.functionName }}添加按钮操作 */
handleAdd{{ subClassName }}() {
let obj = {};
{% for column in subTable.columns %}
{% if column.pk or column.python_field == subTableFkclassName %}
{% elif column.list and column.python_field %}
obj.{{ column.python_field }} = "";
{% endif %}
{% endfor %}
this.{{ subclassName }}List.push(obj);
},
/** {{ subTable.functionName }}删除按钮操作 */
handleDelete{{ subClassName }}() {
if (this.checked{{ subClassName }}.length == 0) {
this.$modal.msgError("请先选择要删除的{{ subTable.functionName }}数据");
} else {
const {{ subclassName }}List = this.{{ subclassName }}List;
const checked{{ subClassName }} = this.checked{{ subClassName }};
this.{{ subclassName }}List = {{ subclassName }}List.filter(function(item) {
return checked{{ subClassName }}.indexOf(item.index) == -1
});
}
},
/** 复选框选中数据 */
handle{{ subClassName }}SelectionChange(selection) {
this.checked{{ subClassName }} = selection.map(item => item.index)
},
{% endif %}
/** 导出按钮操作 */
handleExport() {
this.download('{{ moduleName }}/{{ businessName }}/export', {
...this.queryParams
}, `{{ businessName }}_${new Date().getTime()}.xlsx`);
} }
}, },
/** 复选框选中数据 */
handle{{ subClassName }}SelectionChange(selection) {
this.checked{{ subClassName }} = selection.map(item => item.index)
},
{% endif %}
/** 导出按钮操作 */
handleExport() {
this.download('{{ moduleName }}/{{ businessName }}/export', {
...queryParams.value
}, `{{ businessName }}_${new Date().getTime()}.xlsx`);
}
}; };
</script> </script>

View File

@@ -5,6 +5,7 @@ from jinja2 import Environment, FileSystemLoader
from typing import Dict, List, Set from typing import Dict, List, Set
from config.constant import GenConstant from config.constant import GenConstant
from config.env import DataBaseConfig from config.env import DataBaseConfig
from exceptions.exception import ServiceWarning
from module_generator.entity.vo.gen_vo import GenTableModel, GenTableColumnModel from module_generator.entity.vo.gen_vo import GenTableModel, GenTableColumnModel
from utils.common_util import CamelCaseUtil, SnakeCaseUtil from utils.common_util import CamelCaseUtil, SnakeCaseUtil
from utils.string_util import StringUtil from utils.string_util import StringUtil
@@ -60,6 +61,8 @@ class TemplateUtils:
:param gen_table: 生成表的配置信息 :param gen_table: 生成表的配置信息
:return: 模板上下文字典 :return: 模板上下文字典
""" """
if not gen_table.options:
raise ServiceWarning(message='请先完善生成配置信息')
class_name = gen_table.class_name class_name = gen_table.class_name
module_name = gen_table.module_name module_name = gen_table.module_name
business_name = gen_table.business_name business_name = gen_table.business_name
@@ -445,13 +448,18 @@ class TemplateUtils:
""" """
if '(' in column_type: if '(' in column_type:
column_type_list = column_type.split('(') column_type_list = column_type.split('(')
sqlalchemy_type = ( if column_type_list[0] in GenConstant.COLUMNTYPE_STR:
StringUtil.get_mapping_value_by_key_ignore_case( sqlalchemy_type = (
StringUtil.get_mapping_value_by_key_ignore_case(
GenConstant.DB_TO_SQLALCHEMY_TYPE_MAPPING, column_type_list[0]
)
+ '('
+ column_type_list[1]
)
else:
sqlalchemy_type = StringUtil.get_mapping_value_by_key_ignore_case(
GenConstant.DB_TO_SQLALCHEMY_TYPE_MAPPING, column_type_list[0] GenConstant.DB_TO_SQLALCHEMY_TYPE_MAPPING, column_type_list[0]
) )
+ '('
+ column_type_list[1]
)
else: else:
sqlalchemy_type = StringUtil.get_mapping_value_by_key_ignore_case( sqlalchemy_type = StringUtil.get_mapping_value_by_key_ignore_case(
GenConstant.DB_TO_SQLALCHEMY_TYPE_MAPPING, column_type GenConstant.DB_TO_SQLALCHEMY_TYPE_MAPPING, column_type