fix 代码生成细节修复,树形结构支持导入导出

This commit is contained in:
yxh 2025-06-11 09:26:01 +08:00
parent 60da0c349b
commit bab5948a49
4 changed files with 94 additions and 6 deletions

View File

@ -274,8 +274,10 @@ func (c *{{$structName}}Controller) Export(ctx context.Context, req *{{.table.Mo
linked{{$column.GoField}}[lk] = {{$serviceVal}}.SysDept().GetByDept(ctx, lv) linked{{$column.GoField}}[lk] = {{$serviceVal}}.SysDept().GetByDept(ctx, lv)
} }
for _, dv := range linked{{$column.GoField}} { for _, dv := range linked{{$column.GoField}} {
if dv != nil {
{{$column.HtmlField}}Str += dv.DeptName + "," {{$column.HtmlField}}Str += dv.DeptName + ","
} }
}
{{end}} {{end}}
{{end}} {{end}}
{{end}} {{end}}

View File

@ -395,7 +395,7 @@
{{if $column.IsOverflowTooltip}}:show-overflow-tooltip="true"{{end}} {{if $column.IsOverflowTooltip}}:show-overflow-tooltip="true"{{end}}
{{if $column.IsFixed}}fixed="left"{{end}}> {{if $column.IsFixed}}fixed="left"{{end}}>
<template #default="scope"> <template #default="scope">
{{"{{"}} scope.row.linked{{$column.GoField}}?scope.row.linked{{$column.GoField}}.map((res:any)=>{return res.deptName}).join(''):'' {{"}}"}} {{"{{"}} scope.row.linked{{$column.GoField}}?scope.row.linked{{$column.GoField}}.map((res:any)=>{return res?.deptName}).join(''):'' {{"}}"}}
</template> </template>
</el-table-column> </el-table-column>
{{else if ne $column.LinkTableName ""}} {{else if ne $column.LinkTableName ""}}

View File

@ -247,7 +247,6 @@
<el-col :span="1.5"> <el-col :span="1.5">
<el-button <el-button
type="success" type="success"
:disabled="single" :disabled="single"
@click="handleUpdate(null)" @click="handleUpdate(null)"
v-auth="'{{.apiVersion}}/{{.table.ModuleName}}/{{$businessName}}/edit'" v-auth="'{{.apiVersion}}/{{.table.ModuleName}}/{{$businessName}}/edit'"
@ -256,12 +255,29 @@
<el-col :span="1.5"> <el-col :span="1.5">
<el-button <el-button
type="danger" type="danger"
:disabled="multiple" :disabled="multiple"
@click="handleDelete(null)" @click="handleDelete(null)"
v-auth="'{{.apiVersion}}/{{.table.ModuleName}}/{{$businessName}}/delete'" v-auth="'{{.apiVersion}}/{{.table.ModuleName}}/{{$businessName}}/delete'"
><el-icon><ele-Delete /></el-icon>删除</el-button> ><el-icon><ele-Delete /></el-icon>删除</el-button>
</el-col> </el-col>
{{if .table.ExcelPort }}
<el-col :span="1.5">
<el-button
type="warning"
@click="handleExport()"
v-auth="'{{.apiVersion}}/{{.table.ModuleName}}/{{$businessName}}/export'"
><el-icon><ele-Download /></el-icon>导出Excel</el-button>
</el-col>
{{end}}
{{if .table.ExcelImp }}
<el-col :span="1.5">
<el-button
type="success"
@click="handleImport()"
v-auth="'{{.apiVersion}}/{{.table.ModuleName}}/{{$businessName}}/import'"
><el-icon><ele-Upload /></el-icon>导入Excel</el-button>
</el-col>
{{end}}
</el-row> </el-row>
</div> </div>
<div style="height: 800px;"> <div style="height: 800px;">
@ -316,6 +332,11 @@
:{{$businessName}}Options="tableData.data" :{{$businessName}}Options="tableData.data"
@{{$businessName}}List="{{$businessName}}List" @{{$businessName}}List="{{$businessName}}List"
></{{.apiVersion|replace "/" "_"|CaseCamel}}{{.modulePath|replace "/" "_"|CaseCamel}}{{.table.ClassName}}Detail> ></{{.apiVersion|replace "/" "_"|CaseCamel}}{{.modulePath|replace "/" "_"|CaseCamel}}{{.table.ClassName}}Detail>
{{if .table.ExcelImp}}
<loadExcel ref="loadExcel{{.table.ClassName}}Ref" @getList="{{$businessName}}List"
upUrl="{{.apiVersion}}/{{.table.ModuleName}}/{{$businessName}}/import"
tplUrl="/{{.apiVersion}}/{{.table.ModuleName}}/{{$businessName}}/excelTemplate"></loadExcel>
{{end}}
</div> </div>
</template> </template>
@ -379,6 +400,12 @@ import {
import {{.apiVersion|replace "/" "_"|CaseCamel}}{{.modulePath|replace "/" "_"|CaseCamel}}{{.table.ClassName}}Edit from "/@/views/{{.modulePath}}/{{$businessName}}/list/component/edit.vue" import {{.apiVersion|replace "/" "_"|CaseCamel}}{{.modulePath|replace "/" "_"|CaseCamel}}{{.table.ClassName}}Edit from "/@/views/{{.modulePath}}/{{$businessName}}/list/component/edit.vue"
import {{.apiVersion|replace "/" "_"|CaseCamel}}{{.modulePath|replace "/" "_"|CaseCamel}}{{.table.ClassName}}Detail from "/@/views/{{.modulePath}}/{{$businessName}}/list/component/detail.vue" import {{.apiVersion|replace "/" "_"|CaseCamel}}{{.modulePath|replace "/" "_"|CaseCamel}}{{.table.ClassName}}Detail from "/@/views/{{.modulePath}}/{{$businessName}}/list/component/detail.vue"
import _ from 'lodash' import _ from 'lodash'
{{if .table.ExcelPort }}
import {downLoadXml} from "/@/utils/zipdownload";
{{end}}
{{if .table.ExcelImp}}
import loadExcel from "/@/components/loadExcel/index.vue"
{{end}}
{{if $selectorUserImp}} {{if $selectorUserImp}}
import selectUser from "/@/components/selectUser/index.vue" import selectUser from "/@/components/selectUser/index.vue"
{{end}} {{end}}
@ -391,6 +418,9 @@ const loading = ref(false)
const queryRef = ref() const queryRef = ref()
const editRef = ref(); const editRef = ref();
const detailRef = ref(); const detailRef = ref();
{{if .table.ExcelImp}}
const loadExcel{{.table.ClassName}}Ref = ref();
{{end}}
// 是否显示所有搜索选项 // 是否显示所有搜索选项
const showAll = ref(false) const showAll = ref(false)
// 非单个禁用 // 非单个禁用
@ -526,11 +556,13 @@ const {{$businessName}}List = ()=>{
}) })
{{end}} {{end}}
{{end}} {{end}}
{{if ne .table.PkColumn.HtmlField "id"}}
if(list.length > 0 && typeof list[0].id == "undefined"){ if(list.length > 0 && typeof list[0].id == "undefined"){
list.map((item:any)=>{ list.map((item:any)=>{
item.id = item.{{.table.PkColumn.HtmlField}} item.id = item.{{.table.PkColumn.HtmlField}}
}) })
} }
{{end}}
dataList.value = _.clone(res.data.list) dataList.value = _.clone(res.data.list)
list = proxy.handleTree(res.data.list||[], "{{$treeCode}}", "{{$treeParentCode}}"); list = proxy.handleTree(res.data.list||[], "{{$treeCode}}", "{{$treeParentCode}}");
state.tableData.data = list; state.tableData.data = list;
@ -760,7 +792,7 @@ const setVrData = (list:{{$.table.ClassName}}TableColumns[])=>{
{{if gt $column.MinWidth 0}}width:{{$column.MinWidth}},{{end}} {{if gt $column.MinWidth 0}}width:{{$column.MinWidth}},{{end}}
{{if $column.IsFixed}}fixed: TableV2FixedDir.LEFT,{{end}} {{if $column.IsFixed}}fixed: TableV2FixedDir.LEFT,{{end}}
cellRenderer: ({ cellData: linked{{$column.GoField}} }) => { cellRenderer: ({ cellData: linked{{$column.GoField}} }) => {
return h('span',linked{{$column.GoField}}?linked{{$column.GoField}}.map((res:any)=>{return res.deptName}).join(''):''); return h('span',linked{{$column.GoField}}?linked{{$column.GoField}}.map((res:any)=>{return res?.deptName}).join(''):'');
} }
}) })
{{else if eq $column.HtmlType "selects" "checkbox" "treeSelects"}} {{else if eq $column.HtmlType "selects" "checkbox" "treeSelects"}}
@ -848,6 +880,17 @@ const onExpandedRowsChange = (
) => { ) => {
console.log('expandedKeys:',expandedKeys) console.log('expandedKeys:',expandedKeys)
} }
{{if .table.ExcelPort }}
//导出excel
const handleExport = ()=>{
downLoadXml('/{{.apiVersion}}/{{.modulePath}}/{{$businessName}}/export',state.tableData.param,'get')
}
{{end}}
{{if .table.ExcelImp}}
const handleImport=()=>{
loadExcel{{$.table.ClassName}}Ref.value.open()
}
{{end}}
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.colBlock { .colBlock {

View File

@ -260,6 +260,24 @@
v-auth="'{{.apiVersion}}/{{.table.ModuleName}}/{{$businessName}}/delete'" v-auth="'{{.apiVersion}}/{{.table.ModuleName}}/{{$businessName}}/delete'"
><el-icon><ele-Delete /></el-icon>删除</el-button> ><el-icon><ele-Delete /></el-icon>删除</el-button>
</el-col> </el-col>
{{if .table.ExcelPort }}
<el-col :span="1.5">
<el-button
type="warning"
@click="handleExport()"
v-auth="'{{.apiVersion}}/{{.table.ModuleName}}/{{$businessName}}/export'"
><el-icon><ele-Download /></el-icon>导出Excel</el-button>
</el-col>
{{end}}
{{if .table.ExcelImp }}
<el-col :span="1.5">
<el-button
type="success"
@click="handleImport()"
v-auth="'{{.apiVersion}}/{{.table.ModuleName}}/{{$businessName}}/import'"
><el-icon><ele-Upload /></el-icon>导入Excel</el-button>
</el-col>
{{end}}
</el-row> </el-row>
</div> </div>
<el-table <el-table
@ -389,7 +407,7 @@
{{if $column.IsOverflowTooltip}}:show-overflow-tooltip="true"{{end}} {{if $column.IsOverflowTooltip}}:show-overflow-tooltip="true"{{end}}
{{if $column.IsFixed}}fixed="left"{{end}}> {{if $column.IsFixed}}fixed="left"{{end}}>
<template #default="scope"> <template #default="scope">
{{"{{"}} scope.row.linked{{$column.GoField}}?scope.row.linked{{$column.GoField}}.map((res:any)=>{return res.deptName}).join(''):'' {{"}}"}} {{"{{"}} scope.row.linked{{$column.GoField}}?scope.row.linked{{$column.GoField}}.map((res:any)=>{return res?.deptName}).join(''):'' {{"}}"}}
</template> </template>
</el-table-column> </el-table-column>
{{else if ne $column.LinkTableName ""}} {{else if ne $column.LinkTableName ""}}
@ -469,6 +487,11 @@
:{{$businessName}}Options="tableData.data" :{{$businessName}}Options="tableData.data"
@{{$businessName}}List="{{$businessName}}List" @{{$businessName}}List="{{$businessName}}List"
></{{.apiVersion|replace "/" "_"|CaseCamel}}{{.modulePath|replace "/" "_"|CaseCamel}}{{.table.ClassName}}Detail> ></{{.apiVersion|replace "/" "_"|CaseCamel}}{{.modulePath|replace "/" "_"|CaseCamel}}{{.table.ClassName}}Detail>
{{if .table.ExcelImp}}
<loadExcel ref="loadExcel{{.table.ClassName}}Ref" @getList="{{$businessName}}List"
upUrl="{{.apiVersion}}/{{.table.ModuleName}}/{{$businessName}}/import"
tplUrl="/{{.apiVersion}}/{{.table.ModuleName}}/{{$businessName}}/excelTemplate"></loadExcel>
{{end}}
</div> </div>
</template> </template>
@ -531,6 +554,12 @@ import {
import {{.apiVersion|replace "/" "_"|CaseCamel}}{{.modulePath|replace "/" "_"|CaseCamel}}{{.table.ClassName}}Edit from "/@/views/{{.modulePath}}/{{$businessName}}/list/component/edit.vue" import {{.apiVersion|replace "/" "_"|CaseCamel}}{{.modulePath|replace "/" "_"|CaseCamel}}{{.table.ClassName}}Edit from "/@/views/{{.modulePath}}/{{$businessName}}/list/component/edit.vue"
import {{.apiVersion|replace "/" "_"|CaseCamel}}{{.modulePath|replace "/" "_"|CaseCamel}}{{.table.ClassName}}Detail from "/@/views/{{.modulePath}}/{{$businessName}}/list/component/detail.vue" import {{.apiVersion|replace "/" "_"|CaseCamel}}{{.modulePath|replace "/" "_"|CaseCamel}}{{.table.ClassName}}Detail from "/@/views/{{.modulePath}}/{{$businessName}}/list/component/detail.vue"
import _ from 'lodash' import _ from 'lodash'
{{if .table.ExcelPort }}
import {downLoadXml} from "/@/utils/zipdownload";
{{end}}
{{if .table.ExcelImp}}
import loadExcel from "/@/components/loadExcel/index.vue"
{{end}}
{{if $selectorUserImp}} {{if $selectorUserImp}}
import selectUser from "/@/components/selectUser/index.vue" import selectUser from "/@/components/selectUser/index.vue"
{{end}} {{end}}
@ -543,6 +572,9 @@ const loading = ref(false)
const queryRef = ref() const queryRef = ref()
const editRef = ref(); const editRef = ref();
const detailRef = ref(); const detailRef = ref();
{{if .table.ExcelImp}}
const loadExcel{{.table.ClassName}}Ref = ref();
{{end}}
// 是否显示所有搜索选项 // 是否显示所有搜索选项
const showAll = ref(false) const showAll = ref(false)
// 非单个禁用 // 非单个禁用
@ -763,6 +795,17 @@ const handleDelete = (row: {{$.table.ClassName}}TableColumns) => {
const handleView = (row:{{$.table.ClassName}}TableColumns)=>{ const handleView = (row:{{$.table.ClassName}}TableColumns)=>{
detailRef.value.openDialog(toRaw(row)); detailRef.value.openDialog(toRaw(row));
} }
{{if .table.ExcelPort }}
//导出excel
const handleExport = ()=>{
downLoadXml('/{{.apiVersion}}/{{.modulePath}}/{{$businessName}}/export',state.tableData.param,'get')
}
{{end}}
{{if .table.ExcelImp}}
const handleImport=()=>{
loadExcel{{$.table.ClassName}}Ref.value.open()
}
{{end}}
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.colBlock { .colBlock {