优化树表管理代码生成模板,左树右表代码生成模板

This commit is contained in:
thinkgem
2025-03-29 22:22:30 +08:00
parent c2fc3e5c96
commit c5cbb22621
3 changed files with 45 additions and 23 deletions

View File

@@ -104,6 +104,11 @@ $('#dataGrid').dataGrid({
treeGrid: true, // 启用树结构表格
defaultExpandLevel: 0, // 默认展开的层次
expandNodeClearPostData: '<%
if(table.isTreeEntity){
for(pk in table.pkList){
print(pk.attrName + ',');
}
}
for(c in table.columnList){
if(c.isQuery == "1" && !c.isTreeEntityColumn && c.attrName != 'status'){
print(c.attrName + ',');
@@ -112,7 +117,14 @@ $('#dataGrid').dataGrid({
//# }
\//# // 加载成功后执行事件
ajaxSuccess: function(data){
<% if(table.isTreeEntity){
for(pk in table.pkList){ %>
if ($('#${pk.attrName}').val() != ''){
$('#${pk.attrName}').val('');
$('#btnExpandTreeNode').click();
}
<% }
} %>
}
});
</script>

View File

@@ -19,12 +19,13 @@
:title="t('${functionNameSimple}')"
:search="true"
:toolbar="true"
:showIcon="true"
:api="${className}TreeData"
:defaultExpandLevel="2"
@select="handleSelect"
v-model:selectedKeys="treeCodes"
/>
</template>
<ListView :treeCode="treeCode" />
<ListView v-model:treeCodes="treeCodes" />
</PageWrapper>
</template>
<script lang="ts" setup name="${compNamePrefix}Index">
@@ -36,11 +37,7 @@
import ListView from './list.vue';
const { t } = useI18n('${moduleName}${isNotEmpty(subModuleName)?'.'+subModuleName:''}.${className}');
const treeCode = ref<string>('');
function handleSelect(keys: string[]) {
treeCode.value = keys[0];
}
const treeCodes = ref<string[]>([]);
</script>
<% } %>
<% %>

View File

@@ -56,7 +56,7 @@ if(table.isTreeEntity){
( {{ record.${table.treeViewCodeAttrName} }} )
</span>
<% } %>
<a @click="handleForm({ ${idParam} })">
<a @click="handleForm({ ${idParam} })" :title="record.${table.treeViewNameAttrName}">
{{ record.${table.treeViewNameAttrName} }}
</a>
<%
@@ -71,7 +71,7 @@ if(table.isTreeEntity){
continue;
}
%>
<a @click="handleForm({ ${idParam} })">
<a @click="handleForm({ ${idParam} })" :title="record.${c.attrName}">
{{ record.${c.attrName} }}
</a>
<%
@@ -154,6 +154,9 @@ if(table.isTreeEntity){
import { BpmRuntimeTrace } from '/@/components/Bpm';
<% } %>
import { FormProps } from '/@/components/Form';
<% if(table.isTreeEntity || isNotBlank(table.optionMap['leftTreeRightTableFk'])) { %>
import { isEmpty } from '/@/utils/is';
<% } %>
<% if(!@StringUtils.contains(table.tplCategory, '_route')) { %>
import InputForm from './form.vue';
<% } %>
@@ -163,8 +166,10 @@ if(table.isTreeEntity){
<% if(table.isTreeEntity || isNotBlank(table.optionMap['leftTreeRightTableFk'])){ %>
const props = defineProps({
treeCode: String,
treeCodes: Array as PropType<String[]>,
});
const emit = defineEmits(['update:treeCodes']);
<% } %>
<% if(@StringUtils.contains(table.tplCategory, '_route')) { %>
@@ -273,6 +278,11 @@ if(table.isTreeEntity){
<% } %>
<% } %>
],
<% if(table.isTreeEntity || isNotBlank(table.optionMap['leftTreeRightTableFk'])) { %>
resetFunc: async () => {
emit('update:treeCodes', []);
},
<% } %>
};
const tableColumns: BasicColumn[] = [
@@ -420,6 +430,11 @@ for(c in table.columnList){
|| toBoolean(table.optionMap['isImportExport'])){ %>, getForm<% } %> }] = useTable({
api: ${className}ListData,
beforeFetch: (params) => {
<% if(table.isTreeEntity){ %>
<% for(pk in table.pkList){ %>
params.${pk.attrName} = !isEmpty(props.treeCodes) ? props.treeCodes[0] : '';
<% } %>
<% } %>
return params;
},
columns: tableColumns,
@@ -440,25 +455,23 @@ for(c in table.columnList){
<% if(table.isTreeEntity || isNotBlank(table.optionMap['leftTreeRightTableFk'])){ %>
watch(
() => props.treeCode,
() => props.treeCodes,
async () => {
await getForm().setFieldsValue({
<% if (isNotBlank(table.optionMap['leftTreeRightTableFk'])) { %>
'${table.optionMap['leftTreeRightTableFk']}': props.treeCode,
<% }else if(table.isTreeEntity){ %>
<% for(pk in table.pkList){ %>
'${pk.attrName}': props.treeCode,
<% } %>
<% } %>
});
reload();
if (!isEmpty(props.treeCodes)) {
<% if (isNotBlank(table.optionMap['leftTreeRightTableFk'])) { %>
await getForm().setFieldsValue({
'${table.optionMap['leftTreeRightTableFk']}': props.treeCodes[0],
});
<% } %>
reload();
}
},
);
<% } %>
<% if(table.isTreeEntity){ %>
function fetchSuccess() {
if (props.treeCode) {
if (!isEmpty(props.treeCodes)) {
nextTick(expandAll);
}
}