fix 系统监控-go程序实时内存占用,代码生成-setup语法糖支持

This commit is contained in:
yxh 2024-07-19 18:08:40 +08:00
parent f10fa5ce75
commit 38f66c91de
8 changed files with 1418 additions and 1619 deletions

View File

@ -10,6 +10,7 @@ import (
"github.com/shirou/gopsutil/v3/host" "github.com/shirou/gopsutil/v3/host"
"github.com/shirou/gopsutil/v3/load" "github.com/shirou/gopsutil/v3/load"
"github.com/shirou/gopsutil/v3/mem" "github.com/shirou/gopsutil/v3/mem"
"github.com/shirou/gopsutil/v3/process"
"github.com/tiger1103/gfast/v3/api/v1/system" "github.com/tiger1103/gfast/v3/api/v1/system"
"github.com/tiger1103/gfast/v3/library/libUtils" "github.com/tiger1103/gfast/v3/library/libUtils"
"os" "os"
@ -62,12 +63,15 @@ func (c *sysMonitorController) List(ctx context.Context, req *system.MonitorSear
var goFree uint64 = 0 //go剩余的内存数 var goFree uint64 = 0 //go剩余的内存数
var goUsage float64 = 0 //使用率 var goUsage float64 = 0 //使用率
var gomem runtime.MemStats p, err := process.NewProcess(int32(os.Getpid()))
runtime.ReadMemStats(&gomem) if err == nil {
goUsed = gomem.Sys memInfo, err := p.MemoryInfo()
goUsage = gconv.Float64(fmt.Sprintf("%.2f", gconv.Float64(goUsed)/gconv.Float64(memTotal)*100)) if err == nil {
goUsed = memInfo.RSS
goUsage = gconv.Float64(fmt.Sprintf("%.2f", gconv.Float64(goUsed)/gconv.Float64(memTotal)*100))
}
}
sysComputerIp := "" //服务器IP sysComputerIp := "" //服务器IP
ip, err := libUtils.GetLocalIP() ip, err := libUtils.GetLocalIP()
if err == nil { if err == nil {
sysComputerIp = ip sysComputerIp = ip

View File

@ -192,7 +192,7 @@ func (s *sToolsGenTableColumn) InitColumnField(column *entity.ToolsGenTableColum
column.SortOrderList = column.SortOrderEdit column.SortOrderList = column.SortOrderEdit
column.SortOrderDetail = column.SortOrderEdit column.SortOrderDetail = column.SortOrderEdit
column.SortOrderQuery = column.SortOrderEdit column.SortOrderQuery = column.SortOrderEdit
column.ColSpan = 12 column.ColSpan = 1
column.RowSpan = 1 column.RowSpan = 1
column.IsRowStart = false column.IsRowStart = false
column.MinWidth = 150 column.MinWidth = 150

View File

@ -9,5 +9,5 @@ package consts
const ( const (
Logo = `CiAgIF9fX19fX19fX19fXyAgICAgICAgICAgX18gCiAgLyBfX19fLyBfX19fL19fXyBfX19fX18vIC9fCiAvIC8gX18vIC9fICAvIF9fIGAvIF9fXy8gX18vCi8gL18vIC8gX18vIC8gL18vIChfXyAgKSAvXyAgClxfX19fL18vICAgIFxfXyxfL19fX18vXF9fLyAg` Logo = `CiAgIF9fX19fX19fX19fXyAgICAgICAgICAgX18gCiAgLyBfX19fLyBfX19fL19fXyBfX19fX18vIC9fCiAvIC8gX18vIC9fICAvIF9fIGAvIF9fXy8gX18vCi8gL18vIC8gX18vIC8gL18vIChfXyAgKSAvXyAgClxfX19fL18vICAgIFxfXyxfL19fX18vXF9fLyAg`
Version = "3.2.27" Version = "3.2.28"
) )

View File

@ -10,109 +10,155 @@
<template #header> <template #header>
<h4>{{.table.TableComment}}详情</h4> <h4>{{.table.TableComment}}详情</h4>
</template> </template>
<el-form ref="formRef" :model="formData" label-width="100px"> <el-descriptions
{{ $hasRowEnd := true }} class="margin-top"
{{range $index, $column := .table.DetailColumns}} :column="3"
{{if and (eq $column.IsRowStart true) (ne $index 0)}} border
{{ $hasRowEnd = true }} style="margin: 8px;"
</el-row> >
{{end}} {{range $index, $column := .table.DetailColumns}}
{{if or (eq $column.IsRowStart true) (eq $index 0)}}
{{ $hasRowEnd = false }}
<el-row>
{{end}}
{{if eq $column.HtmlType "input" "textarea" "radio" "checkbox" "select" "selects" "treeSelect" "treeSelects"}} {{if eq $column.HtmlType "input" "textarea" "radio" "checkbox" "select" "selects" "treeSelect" "treeSelects"}}
<el-col :span="{{$column.ColSpan}}"> <el-descriptions-item :span="{{$column.ColSpan}}">
{{if ne $column.LinkTableName ""}} {{if ne $column.LinkTableName ""}}
{{range $ti, $linkedTable := $.table.LinkedTables}} {{range $ti, $linkedTable := $.table.LinkedTables}}
{{if eq $column.LinkTableClass $linkedTable.ClassName}} {{if eq $column.LinkTableClass $linkedTable.ClassName}}
{{if eq $column.HtmlType "selects" "checkbox" "treeSelects"}} {{if eq $column.HtmlType "selects" "checkbox" "treeSelects"}}
<el-form-item label="{{$column.ColumnComment}}">{{"{{"}} formData.linked{{$column.GoField}}?formData.linked{{$column.GoField}}.map((res:any)=>{return res.{{CaseCamelLower $column.LinkLabelName}}}).join(''):'' {{"}}"}}</el-form-item> <template #label>
<div class="cell-item">
{{$column.ColumnComment}}
</div>
</template>
{{"{{"}} formData.linked{{$column.GoField}}?formData.linked{{$column.GoField}}.map((res:any)=>{return res.{{CaseCamelLower $column.LinkLabelName}}}).join(''):'' {{"}}"}}
{{else}}
<template #label>
<div class="cell-item">
{{$column.ColumnComment}}
</div>
</template>
{{"{{"}} formData.linked{{$column.GoField}}?formData.linked{{$column.GoField}}.{{CaseCamelLower $column.LinkLabelName}}:'' {{"}}"}}
{{end}}
{{end}}
{{end}}
{{else if ne $column.DictType ""}}
{{if eq $column.HtmlType "checkbox" }}
<template #label>
<div class="cell-item">
{{$column.ColumnComment}}
</div>
</template>
<el-tag class="ml-2" type="success" v-for="(item,key) in formData.{{$column.HtmlField}}" :key="'{{$column.HtmlField}}-'+key">
{{"{{"}} proxy.getOptionValue(item, {{$column.HtmlField}}Options,'value','label') {{"}}"}}
</el-tag>
{{else}}
<template #label>
<div class="cell-item">
{{$column.ColumnComment}}
</div>
</template>
{{"{{"}} proxy.getOptionValue({{if eq $column.TsType "boolean"}}formData.{{$column.HtmlField}}?'1':'0'{{else}}formData.{{$column.HtmlField}}{{end}}, {{$column.HtmlField}}Options,'value','label') {{"}}"}}
{{end}}
{{else}} {{else}}
<el-form-item label="{{$column.ColumnComment}}">{{"{{"}} formData.linked{{$column.GoField}}?formData.linked{{$column.GoField}}.{{CaseCamelLower $column.LinkLabelName}}:'' {{"}}"}}</el-form-item> <template #label>
<div class="cell-item">
{{$column.ColumnComment}}
</div>
</template>
{{"{{"}} formData.{{$column.HtmlField}} {{"}}"}}
{{end}} {{end}}
{{end}} </el-descriptions-item>
{{end}}
{{else if ne $column.DictType ""}}
{{if eq $column.HtmlType "checkbox" }}
<el-form-item label="{{$column.ColumnComment}}">
<el-tag class="ml-2" type="success" v-for="(item,key) in formData.{{$column.HtmlField}}" :key="'{{$column.HtmlField}}-'+key">
{{"{{"}} proxy.getOptionValue(item, {{$column.HtmlField}}Options,'value','label') {{"}}"}}
</el-tag>
</el-form-item>
{{else}}
<el-form-item label="{{$column.ColumnComment}}">{{"{{"}} proxy.getOptionValue({{if eq $column.TsType "boolean"}}formData.{{$column.HtmlField}}?'1':'0'{{else}}formData.{{$column.HtmlField}}{{end}}, {{$column.HtmlField}}Options,'value','label') {{"}}"}}</el-form-item>
{{end}}
{{else}}
<el-form-item label="{{$column.ColumnComment}}">{{"{{"}} formData.{{$column.HtmlField}} {{"}}"}}</el-form-item>
{{end}}
</el-col>
{{else if eq $column.HtmlType "date"}} {{else if eq $column.HtmlType "date"}}
<el-col :span="{{$column.ColSpan}}"> <el-descriptions-item :span="{{$column.ColSpan}}">
<el-form-item label="{{$column.ColumnComment}}">{{"{{"}} proxy.parseTime(formData.{{$column.HtmlField}}, '{y}-{m}-{d}') {{"}}"}}</el-form-item> <template #label>
</el-col> <div class="cell-item">
{{$column.ColumnComment}}
</div>
</template>
{{"{{"}} proxy.parseTime(formData.{{$column.HtmlField}}, '{y}-{m}-{d}') {{"}}"}}
</el-descriptions-item>
{{else if eq $column.HtmlType "datetime"}} {{else if eq $column.HtmlType "datetime"}}
<el-col :span="{{$column.ColSpan}}"> <el-descriptions-item :span="{{$column.ColSpan}}">
<el-form-item label="{{$column.ColumnComment}}">{{"{{"}} proxy.parseTime(formData.{{$column.HtmlField}}, '{y}-{m}-{d} {h}:{i}:{s}') {{"}}"}}</el-form-item> <template #label>
</el-col> <div class="cell-item">
{{$column.ColumnComment}}
</div>
</template>
{{"{{"}} proxy.parseTime(formData.{{$column.HtmlField}}, '{y}-{m}-{d} {h}:{i}:{s}') {{"}}"}}
</el-descriptions-item>
{{else if eq $column.HtmlType "richtext"}} {{else if eq $column.HtmlType "richtext"}}
<el-col :span="{{$column.ColSpan}}"> <el-descriptions-item :span="{{$column.ColSpan}}">
<el-form-item label="{{$column.ColumnComment}}"> <template #label>
<p v-html="formData.{{$column.HtmlField}}"></p> <div class="cell-item">
</el-form-item> {{$column.ColumnComment}}
</el-col> </div>
</template>
<div v-html="formData.{{$column.HtmlField}}"></div>
</el-descriptions-item>
{{else if eq $column.HtmlType "imagefile"}} {{else if eq $column.HtmlType "imagefile"}}
<el-col :span="{{$column.ColSpan}}"> <el-descriptions-item :span="{{$column.ColSpan}}">
<el-form-item label="{{$column.ColumnComment}}"> <template #label>
<el-image <div class="cell-item">
style="width: 150px; height: 150px" {{$column.ColumnComment}}
v-if="!proxy.isEmpty(formData.{{$column.HtmlField}})" </div>
:src="proxy.getUpFileUrl(formData.{{$column.HtmlField}})" </template>
fit="contain"></el-image> <el-image
</el-form-item> style="width: 150px; height: 150px"
</el-col> v-if="!proxy.isEmpty(formData.{{$column.HtmlField}})"
:src="proxy.getUpFileUrl(formData.{{$column.HtmlField}})"
fit="contain"></el-image>
</el-descriptions-item>
{{else if eq $column.HtmlType "images"}} {{else if eq $column.HtmlType "images"}}
<el-col :span="{{$column.ColSpan}}"> <el-descriptions-item :span="{{$column.ColSpan}}">
<el-form-item label="{{$column.ColumnComment}}"> <template #label>
<div class="pic-block" v-for="(img,key) in formData.{{$column.HtmlField}}" :key="'{{$column.HtmlField}}-'+key"> <div class="cell-item">
<el-image {{$column.ColumnComment}}
style="width: 150px; height: 150px"
v-if="!proxy.isEmpty(img.url)"
:src="proxy.getUpFileUrl(img.url)"
fit="contain"></el-image>
</div> </div>
</el-form-item> </template>
</el-col> <div class="pic-block" v-for="(img,key) in formData.{{$column.HtmlField}}" :key="'{{$column.HtmlField}}-'+key">
<el-image
style="width: 150px; height: 150px"
v-if="!proxy.isEmpty(img.url)"
:src="proxy.getUpFileUrl(img.url)"
fit="contain"></el-image>
</div>
</el-descriptions-item>
{{else if eq $column.HtmlType "file"}} {{else if eq $column.HtmlType "file"}}
<el-col :span="{{$column.ColSpan}}"> <el-descriptions-item :span="{{$column.ColSpan}}">
<el-form-item label="{{$column.ColumnComment}}"> <template #label>
<div class="file-block" v-for="(item,key) in formData.{{$column.HtmlField}}" :key="'{{$column.HtmlField}}-'+key"> <div class="cell-item">
<el-link type="primary" :underline="false" {{$column.ColumnComment}}
:href="proxy.getUpFileUrl(item.url)" target="_blank">{{"{{"}}item.name{{"}}"}}</el-link>
</div> </div>
</el-form-item> </template>
</el-col> <div class="file-block" v-for="(item,key) in formData.{{$column.HtmlField}}" :key="'{{$column.HtmlField}}-'+key">
<el-link type="primary" :underline="false"
:href="proxy.getUpFileUrl(item.url)" target="_blank">{{"{{"}}item.name{{"}}"}}</el-link>
</div>
</el-descriptions-item>
{{else if eq $column.HtmlType "files"}} {{else if eq $column.HtmlType "files"}}
<el-col :span="{{$column.ColSpan}}"> <el-descriptions-item :span="{{$column.ColSpan}}">
<el-form-item label="{{$column.ColumnComment}}"> <template #label>
<div class="file-block" v-for="(item,key) in formData.{{$column.HtmlField}}" :key="'{{$column.HtmlField}}-'+key"> <div class="cell-item">
<el-link type="primary" :underline="false" {{$column.ColumnComment}}
:href="proxy.getUpFileUrl(item.url)" target="_blank">{{"{{"}}item.name{{"}}"}}</el-link>
</div> </div>
</el-form-item> </template>
</el-col> <div class="file-block" v-for="(item,key) in formData.{{$column.HtmlField}}" :key="'{{$column.HtmlField}}-'+key">
<el-link type="primary" :underline="false"
:href="proxy.getUpFileUrl(item.url)" target="_blank">{{"{{"}}item.name{{"}}"}}</el-link>
</div>
</el-descriptions-item>
{{else if eq $column.HtmlType "keyValue"}} {{else if eq $column.HtmlType "keyValue"}}
<el-form-item label="{{$column.ColumnComment}}"> <el-descriptions-item :span="{{$column.ColSpan}}">
<template #label>
<div class="cell-item">
{{$column.ColumnComment}}
</div>
</template>
<el-tag class="ml-2" v-for="(item,key) in formData.{{$column.HtmlField}}" :key="'{{$column.HtmlField}}-'+key"> <el-tag class="ml-2" v-for="(item,key) in formData.{{$column.HtmlField}}" :key="'{{$column.HtmlField}}-'+key">
{{"{{"}} item.key {{"}}"}} : {{"{{"}} item.value {{"}}"}} {{"{{"}} item.key {{"}}"}} : {{"{{"}} item.value {{"}}"}}
</el-tag> </el-tag>
</el-form-item> </el-descriptions-item>
{{end}} {{end}}
{{end}} {{end}}
{{if not $hasRowEnd}} </el-descriptions>
</el-row>
{{end}}
</el-form>
</el-drawer> </el-drawer>
</div> </div>
</template> </template>
@ -139,7 +185,7 @@
{{end}} {{end}}
{{end}} {{end}}
<script lang="ts"> <script setup lang="ts">
import { reactive, toRefs, defineComponent,ref,unref,getCurrentInstance,computed } from 'vue'; import { reactive, toRefs, defineComponent,ref,unref,getCurrentInstance,computed } from 'vue';
import {ElMessageBox, ElMessage, FormInstance,UploadProps} from 'element-plus'; import {ElMessageBox, ElMessage, FormInstance,UploadProps} from 'element-plus';
{{/*去重处理*/}} {{/*去重处理*/}}
@ -175,298 +221,244 @@
{{.table.ClassName}}TableDataState, {{.table.ClassName}}TableDataState,
{{.table.ClassName}}EditState {{.table.ClassName}}EditState
} from "/@/views/{{.modulePath}}/{{$businessName}}/list/component/model" } from "/@/views/{{.modulePath}}/{{$businessName}}/list/component/model"
export default defineComponent({ defineOptions({ name: "{{.apiVersion|replace "/" "_"|CaseCamel}}{{.modulePath|replace "/" "_"|CaseCamel}}{{.table.ClassName}}Detail"})
name:"{{.apiVersion|replace "/" "_"|CaseCamel}}{{.modulePath|replace "/" "_"|CaseCamel}}{{.table.ClassName}}Detail", {{$hascomponent := false}}
{{$hascomponent := false}} {{if or $imgsImp $tokenImp $fileImp}}
{{if or $imgsImp $tokenImp $fileImp}} {{$hascomponent = true}}
{{$hascomponent = true}} {{end}}
{{end}} {{$hasProps := false}}
{{if $hascomponent}} {{if eq .table.TplCategory "tree"}}
components:{ {{$hasProps = true}}
{{if $editImp}} {{end}}
GfUeditor, {{if not $hasProps}}
{{end}} {{range $index, $column := .table.Columns}}
{{if $imgsImp}} {{if or (ne $column.DictType "") (ne $column.LinkTableName "") }}
uploadImg, {{$hasProps = true}}
{{end}} {{end}}
{{if $fileImp}} {{end}}
uploadFile, {{end}}
{{end}} {{if $hasProps}}
}, const props = defineProps({
{{end}}
{{$hasProps := false}}
{{if eq .table.TplCategory "tree"}}
{{$hasProps = true}}
{{end}}
{{if not $hasProps}}
{{range $index, $column := .table.Columns}} {{range $index, $column := .table.Columns}}
{{if or (ne $column.DictType "") (ne $column.LinkTableName "") }} {{if ne $column.DictType ""}}
{{$hasProps = true}} {{$column.HtmlField}}Options:{
type:Array,
default:()=>[]
},
{{else if ne $column.LinkTableName ""}}
{{if $column.IsCascade}}
{{/*级联处理*/}}
{{end}}
{{/*关联表处理*/}}
{{$column.HtmlField}}Options:{
type:Array,
default:()=>[]
},
{{end}} {{end}}
{{end}} {{end}}
{{if eq .table.TplCategory "tree"}}
// {{.table.TableComment}}树选项
{{$businessName}}Options :{
type:Array,
default:()=>[]
},
{{end}} {{end}}
{{if $hasProps}} })
props:{ {{end}}
{{if or $imgsImp $tokenImp $fileImp}}
const baseURL:string|undefined|boolean = import.meta.env.VITE_API_URL
{{end}}
const {proxy} = <any>getCurrentInstance()
const formRef = ref<HTMLElement | null>(null);
const menuRef = ref();
{{range $index, $column := .table.Columns}}
{{if eq $column.HtmlType "imagefile"}}
//图片上传地址
const imageUrl{{$column.GoField}} = ref('')
//上传加载
const upLoading{{$column.GoField}} = ref(false)
{{end}}
{{end}}
const state = reactive<{{.table.ClassName}}EditState>({
loading:false,
isShowDialog: false,
formData: {
{{range $index, $column := .table.Columns}} {{range $index, $column := .table.Columns}}
{{if ne $column.DictType ""}} {{if eq $column.HtmlType "radio"}}
{{$column.HtmlField}}Options:{ {{$column.HtmlField}}: false ,
type:Array, {{else if eq $column.HtmlType "images" "file" "files" "checkbox" "selects" "treeSelects" "keyValue"}}
default:()=>[] {{$column.HtmlField}}: [] ,
}, {{else}}
{{else if ne $column.LinkTableName ""}} {{$column.HtmlField}}: undefined,
{{if $column.IsCascade}} {{range $ti, $linkedTable := $.table.LinkedTables}}
{{/*级联处理*/}} {{if eq $column.LinkTableClass $linkedTable.ClassName}}
{{end}} {{if eq $column.HtmlType "checkbox" "selects" "treeSelects"}}
{{/*关联表处理*/}} linked{{$column.GoField}}:[],
{{$column.HtmlField}}Options:{ {{else}}
type:Array, linked{{$column.GoField}}:{{ "{" }}{{CaseCamelLower $column.LinkLabelId}}:undefined,{{CaseCamelLower $column.LinkLabelName}}:undefined {{ "}" }},
default:()=>[]
},
{{end}} {{end}}
{{end}} {{end}}
{{if eq .table.TplCategory "tree"}} {{end}}
// {{.table.TableComment}}树选项 {{end}}
{{$businessName}}Options :{ {{end}}
type:Array, {{range $ti, $linkedTable := .table.LinkedTables}}
default:()=>[] linked{{$.table.ClassName}}{{$linkedTable.ClassName}}: {
{{range $ci, $linkedColumn := $linkedTable.RefColumns.Values}}
{{$linkedColumn.HtmlField}}:{{if eq $linkedColumn.HtmlType "images" "file" "files"}}[]{{else}}undefined{{end}}, // {{$linkedColumn.ColumnComment}}
{{end}}
}, },
{{end}} {{end}}
}, },
{{end}} // 表单校验
setup(props,{emit}) { rules: {
{{if or $imgsImp $tokenImp $fileImp}}
const baseURL:string|undefined|boolean = import.meta.env.VITE_API_URL
{{end}}
const {proxy} = <any>getCurrentInstance()
const formRef = ref<HTMLElement | null>(null);
const menuRef = ref();
{{range $index, $column := .table.Columns}} {{range $index, $column := .table.Columns}}
{{if eq $column.HtmlType "imagefile"}} {{if $column.IsRequired}}
//图片上传地址 {{$column.HtmlField}} : [
const imageUrl{{$column.GoField}} = ref('') { required: true, message: "{{$column.ColumnComment}}不能为空", trigger: "blur" }
//上传加载 ]{{if ne $lens $index}},{{end}}
const upLoading{{$column.GoField}} = ref(false)
{{end}} {{end}}
{{end}} {{end}}
const state = reactive<{{.table.ClassName}}EditState>({ }
loading:false, });
isShowDialog: false, const { isShowDialog,formData } = toRefs(state);
formData: { // 打开弹窗
{{range $index, $column := .table.Columns}} const openDialog = (row?: {{.table.ClassName}}InfoData) => {
{{if eq $column.HtmlType "radio"}} resetForm();
{{$column.HtmlField}}: false , if(row) {
{{else if eq $column.HtmlType "images" "file" "files" "checkbox" "selects" "treeSelects" "keyValue"}} get{{.table.ClassName}}(row.{{.table.PkColumn.HtmlField}}!).then((res:any)=>{
{{$column.HtmlField}}: [] , const data = res.data;
{{else}} {{range $index, $column := .table.DetailColumns}}
{{$column.HtmlField}}: undefined, {{if and (ne $treeParentCode "") (eq $column.HtmlField $treeParentCode)}}
{{range $ti, $linkedTable := $.table.LinkedTables}} data.{{$treeParentCode}} = getTreeVal(props.{{$businessName}}Options,data.{{$treeParentCode}})
{{if eq $column.LinkTableClass $linkedTable.ClassName}} {{else if eq $column.HtmlType "checkbox"}}
{{if eq $column.HtmlType "checkbox" "selects" "treeSelects"}} data.{{$column.HtmlField}} = data.{{$column.HtmlField}}.split(",")
linked{{$column.GoField}}:[],
{{else}}
linked{{$column.GoField}}:{{ "{" }}{{CaseCamelLower $column.LinkLabelId}}:undefined,{{CaseCamelLower $column.LinkLabelName}}:undefined {{ "}" }},
{{end}}
{{end}}
{{end}}
{{end}}
{{end}}
{{range $ti, $linkedTable := .table.LinkedTables}}
linked{{$.table.ClassName}}{{$linkedTable.ClassName}}: {
{{range $ci, $linkedColumn := $linkedTable.RefColumns.Values}}
{{$linkedColumn.HtmlField}}:{{if eq $linkedColumn.HtmlType "images" "file" "files"}}[]{{else}}undefined{{end}}, // {{$linkedColumn.ColumnComment}}
{{end}}
},
{{end}}
},
// 表单校验
rules: {
{{range $index, $column := .table.Columns}}
{{if $column.IsRequired}}
{{$column.HtmlField}} : [
{ required: true, message: "{{$column.ColumnComment}}不能为空", trigger: "blur" }
]{{if ne $lens $index}},{{end}}
{{end}}
{{end}}
}
});
// 打开弹窗
const openDialog = (row?: {{.table.ClassName}}InfoData) => {
resetForm();
if(row) {
get{{.table.ClassName}}(row.{{.table.PkColumn.HtmlField}}!).then((res:any)=>{
const data = res.data;
{{range $index, $column := .table.DetailColumns}}
{{if and (ne $treeParentCode "") (eq $column.HtmlField $treeParentCode)}}
data.{{$treeParentCode}} = getTreeVal(props.{{$businessName}}Options,data.{{$treeParentCode}})
{{else if eq $column.HtmlType "checkbox"}}
data.{{$column.HtmlField}} = data.{{$column.HtmlField}}.split(",")
{{else if eq $column.HtmlType "imagefile"}}
//单图地址赋值
imageUrl{{$column.GoField}}.value = data.{{$column.HtmlField}} ? proxy.getUpFileUrl(data.{{$column.HtmlField}}) : ''
{{else if eq $column.HtmlType "images" "file" "files" "keyValue"}}
data.{{$column.HtmlField}} =data.{{$column.HtmlField}}?JSON.parse(data.{{$column.HtmlField}}) : []
{{end}}
{{if eq $column.HtmlField "createdBy"}}
data.createdBy = data.createdUser?.userNickname
{{end}}
{{if eq $column.HtmlField "deptId"}}
data.deptId = data.deptInfo?.deptName
{{end}}
{{if eq $column.HtmlField "updatedBy"}}
data.updatedBy = data.updatedUser?.userNickname
{{end}}
{{end}}
state.formData = data;
})
}
state.isShowDialog = true;
};
// 关闭弹窗
const closeDialog = () => {
state.isShowDialog = false;
};
// 取消
const onCancel = () => {
closeDialog();
};
const resetForm = ()=>{
state.formData = {
{{range $index, $column := .table.Columns}}
{{if eq $column.HtmlType "radio"}}
{{$column.HtmlField}}: false ,
{{else if eq $column.HtmlType "images" "file" "files" "checkbox" "selects" "treeSelects" "keyValue"}}
{{$column.HtmlField}}: [] ,
{{else}}
{{$column.HtmlField}}: undefined,
{{end}}
{{range $ti, $linkedTable := $.table.LinkedTables}}
{{if eq $column.LinkTableClass $linkedTable.ClassName}}
{{if eq $column.HtmlType "checkbox" "selects" "treeSelects"}}
linked{{$column.GoField}}:[],
{{else}}
linked{{$column.GoField}}:{{ "{" }}{{CaseCamelLower $column.LinkLabelId}}:undefined,{{CaseCamelLower $column.LinkLabelName}}:undefined {{ "}" }},
{{end}}
{{end}}
{{end}}
{{end}}
{{range $ti, $linkedTable := .table.LinkedTables}}
linked{{$.table.ClassName}}{{$linkedTable.ClassName}}: {
{{range $ci, $linkedColumn := $linkedTable.RefColumns.Values}}
{{$linkedColumn.HtmlField}}:{{if eq $linkedColumn.HtmlType "images" "file" "files"}}[]{{else}}undefined{{end}}, // {{$linkedColumn.ColumnComment}}
{{end}}
},
{{end}}
}
};
{{$setUpData:=true}}
{{range $index, $column := .table.Columns}}
{{if ne $column.LinkTableName ""}}
//关联{{$column.LinkTableName}}表选项
const get{{$column.LinkTableClass}}Items{{$column.GoField}} = () => {
emit("get{{$column.LinkTableClass}}Items{{$column.GoField}}")
}
const get{{$column.GoField}}Op = computed(()=>{
get{{$column.LinkTableClass}}Items{{$column.GoField}}()
return props.{{$column.HtmlField}}Options
})
{{else if eq $column.HtmlType "richtext"}}
//富文本编辑器{{$column.ColumnComment}}
const set{{$column.GoField}}EditContent = (data:string) => {
state.formData.{{$column.HtmlField}} = data
}
{{else if eq $column.HtmlType "imagefile"}} {{else if eq $column.HtmlType "imagefile"}}
//单图上传{{$column.ColumnComment}} //单图地址赋值
const handleAvatarSuccess{{$column.GoField}}:UploadProps['onSuccess'] = (res, file) => { imageUrl{{$column.GoField}}.value = data.{{$column.HtmlField}} ? proxy.getUpFileUrl(data.{{$column.HtmlField}}) : ''
if (res.code === 0) { {{else if eq $column.HtmlType "images" "file" "files" "keyValue"}}
imageUrl{{$column.GoField}}.value = URL.createObjectURL(file.raw!) data.{{$column.HtmlField}} =data.{{$column.HtmlField}}?JSON.parse(data.{{$column.HtmlField}}) : []
state.formData.{{$column.HtmlField}} = res.data.path
} else {
ElMessage.error(res.msg)
}
upLoading{{$column.GoField}}.value = false
}
const beforeAvatarUpload{{$column.GoField}} = () => {
upLoading{{$column.GoField}}.value = true
return true
}
{{if $setUpData}}
const setUpData = () => {
return { token: getToken() }
}
{{$setUpData = false}}
{{end}} {{end}}
{{else if eq $column.HtmlType "images"}} {{if eq $column.HtmlField "createdBy"}}
const setUpImgList{{$column.GoField}} = (data:any)=>{ data.createdBy = data.createdUser?.userNickname
state.formData.{{$column.HtmlField}} = data {{end}}
} {{if eq $column.HtmlField "deptId"}}
{{else if eq $column.HtmlType "file" "files"}} data.deptId = data.deptInfo?.deptName
const setUpFileList{{$column.GoField}} = (data:any)=>{ {{end}}
state.formData.{{$column.HtmlField}} = data {{if eq $column.HtmlField "updatedBy"}}
} data.updatedBy = data.updatedUser?.userNickname
{{end}} {{end}}
{{end}} {{end}}
{{if eq .table.TplCategory "tree"}} state.formData = data;
const getTreeVal = (data : any[],val : any) : any=>{ })
let findV:any = null }
data.some((item:any)=>{ state.isShowDialog = true;
if(item.{{$treeCode}}==val){ };
findV = item.{{$treeName}} // 关闭弹窗
return true const closeDialog = () => {
} state.isShowDialog = false;
if(item.children) { };
findV = getTreeVal(item.children, val) defineExpose({
if (findV) { openDialog,
return findV });
} // 取消
} const onCancel = () => {
}) closeDialog();
};
const resetForm = ()=>{
state.formData = {
{{range $index, $column := .table.Columns}}
{{if eq $column.HtmlType "radio"}}
{{$column.HtmlField}}: false ,
{{else if eq $column.HtmlType "images" "file" "files" "checkbox" "selects" "treeSelects" "keyValue"}}
{{$column.HtmlField}}: [] ,
{{else}}
{{$column.HtmlField}}: undefined,
{{end}}
{{range $ti, $linkedTable := $.table.LinkedTables}}
{{if eq $column.LinkTableClass $linkedTable.ClassName}}
{{if eq $column.HtmlType "checkbox" "selects" "treeSelects"}}
linked{{$column.GoField}}:[],
{{else}}
linked{{$column.GoField}}:{{ "{" }}{{CaseCamelLower $column.LinkLabelId}}:undefined,{{CaseCamelLower $column.LinkLabelName}}:undefined {{ "}" }},
{{end}}
{{end}}
{{end}}
{{end}}
{{range $ti, $linkedTable := .table.LinkedTables}}
linked{{$.table.ClassName}}{{$linkedTable.ClassName}}: {
{{range $ci, $linkedColumn := $linkedTable.RefColumns.Values}}
{{$linkedColumn.HtmlField}}:{{if eq $linkedColumn.HtmlType "images" "file" "files"}}[]{{else}}undefined{{end}}, // {{$linkedColumn.ColumnComment}}
{{end}}
},
{{end}}
}
};
{{$setUpData:=true}}
{{range $index, $column := .table.Columns}}
{{if ne $column.LinkTableName ""}}
//关联{{$column.LinkTableName}}表选项
const get{{$column.LinkTableClass}}Items{{$column.GoField}} = () => {
emit("get{{$column.LinkTableClass}}Items{{$column.GoField}}")
}
const get{{$column.GoField}}Op = computed(()=>{
get{{$column.LinkTableClass}}Items{{$column.GoField}}()
return props.{{$column.HtmlField}}Options
})
{{else if eq $column.HtmlType "richtext"}}
//富文本编辑器{{$column.ColumnComment}}
const set{{$column.GoField}}EditContent = (data:string) => {
state.formData.{{$column.HtmlField}} = data
}
{{else if eq $column.HtmlType "imagefile"}}
//单图上传{{$column.ColumnComment}}
const handleAvatarSuccess{{$column.GoField}}:UploadProps['onSuccess'] = (res, file) => {
if (res.code === 0) {
imageUrl{{$column.GoField}}.value = URL.createObjectURL(file.raw!)
state.formData.{{$column.HtmlField}} = res.data.path
} else {
ElMessage.error(res.msg)
}
upLoading{{$column.GoField}}.value = false
}
const beforeAvatarUpload{{$column.GoField}} = () => {
upLoading{{$column.GoField}}.value = true
return true
}
{{if $setUpData}}
const setUpData = () => {
return { token: getToken() }
}
{{$setUpData = false}}
{{end}}
{{else if eq $column.HtmlType "images"}}
const setUpImgList{{$column.GoField}} = (data:any)=>{
state.formData.{{$column.HtmlField}} = data
}
{{else if eq $column.HtmlType "file" "files"}}
const setUpFileList{{$column.GoField}} = (data:any)=>{
state.formData.{{$column.HtmlField}} = data
}
{{end}}
{{end}}
{{if eq .table.TplCategory "tree"}}
const getTreeVal = (data : any[],val : any) : any=>{
let findV:any = null
data.some((item:any)=>{
if(item.{{$treeCode}}==val){
findV = item.{{$treeName}}
return true
}
if(item.children) {
findV = getTreeVal(item.children, val)
if (findV) {
return findV return findV
} }
{{end}}
{{$setUpDataR:=true}}
return {
proxy,
openDialog,
closeDialog,
onCancel,
menuRef,
formRef,
{{range $index, $column := .table.Columns}}
{{if ne $column.LinkTableName ""}}
{{if $column.IsCascade}}
{{/*级联处理*/}}
{{else}}
{{/*关联表处理*/}}
get{{$column.LinkTableClass}}Items{{$column.GoField}},
get{{$column.GoField}}Op,
{{end}}
{{else if eq $column.HtmlType "richtext"}}
//富文本编辑器{{$column.ColumnComment}}
set{{$column.GoField}}EditContent,
{{else if eq $column.HtmlType "imagefile"}}
//图片上传地址
imageUrl{{$column.GoField}},
//上传加载
upLoading{{$column.GoField}},
handleAvatarSuccess{{$column.GoField}},
beforeAvatarUpload{{$column.GoField}},
{{if $setUpDataR}}
setUpData,
{{$setUpDataR = false}}
{{end}}
{{else if eq $column.HtmlType "images"}}
setUpImgList{{$column.GoField}},
{{else if eq $column.HtmlType "file" "files"}}
setUpFileList{{$column.GoField}},
{{end}}
{{end}}
{{if or $imgsImp $tokenImp $fileImp}}
baseURL,
{{end}}
...toRefs(state),
};
} }
}) })
return findV
}
{{end}}
</script> </script>
<style scoped> <style scoped>

View File

@ -102,7 +102,7 @@
<el-radio <el-radio
v-for="dict in {{$column.HtmlField}}Options" v-for="dict in {{$column.HtmlField}}Options"
:key="dict.key" :key="dict.key"
:label="dict.key" :value="dict.key"
>{{ VueTag "{{" }}dict.value {{VueTag "}}"}}</el-radio> >{{ VueTag "{{" }}dict.value {{VueTag "}}"}}</el-radio>
</el-radio-group> </el-radio-group>
</el-form-item> </el-form-item>
@ -112,7 +112,7 @@
<el-radio <el-radio
v-for="dict in {{$column.HtmlField}}Options" v-for="dict in {{$column.HtmlField}}Options"
:key="dict.value" :key="dict.value"
:label="dict.value" :value="dict.value"
>{{ VueTag "{{" }}dict.label {{VueTag "}}"}}</el-radio> >{{ VueTag "{{" }}dict.label {{VueTag "}}"}}</el-radio>
</el-radio-group> </el-radio-group>
</el-form-item> </el-form-item>
@ -150,7 +150,7 @@
<el-checkbox <el-checkbox
v-for="dict in {{$column.HtmlField}}Options" v-for="dict in {{$column.HtmlField}}Options"
:key="dict.key" :key="dict.key"
:label="dict.key" :value="dict.key"
>{{ VueTag "{{" }}dict.value {{VueTag "}}"}}</el-checkbox> >{{ VueTag "{{" }}dict.value {{VueTag "}}"}}</el-checkbox>
</el-checkbox-group> </el-checkbox-group>
</el-form-item> </el-form-item>
@ -160,7 +160,7 @@
<el-checkbox <el-checkbox
v-for="dict in {{$column.HtmlField}}Options" v-for="dict in {{$column.HtmlField}}Options"
:key="dict.value" :key="dict.value"
:label="dict.value" :value="dict.value"
>{{ VueTag "{{" }}dict.label {{VueTag "}}"}}</el-checkbox> >{{ VueTag "{{" }}dict.label {{VueTag "}}"}}</el-checkbox>
</el-checkbox-group> </el-checkbox-group>
</el-form-item> </el-form-item>
@ -264,8 +264,8 @@
{{end}} {{end}}
{{end}} {{end}}
<script lang="ts"> <script setup lang="ts">
import { reactive, toRefs, defineComponent,ref,unref,getCurrentInstance } from 'vue'; import { reactive, toRefs, ref,unref,getCurrentInstance } from 'vue';
import {ElMessageBox, ElMessage, FormInstance,UploadProps} from 'element-plus'; import {ElMessageBox, ElMessage, FormInstance,UploadProps} from 'element-plus';
{{/*去重处理*/}} {{/*去重处理*/}}
import { import {
@ -299,38 +299,25 @@ import {
{{.table.ClassName}}TableDataState, {{.table.ClassName}}TableDataState,
{{.table.ClassName}}EditState {{.table.ClassName}}EditState
} from "/@/views/{{.modulePath}}/{{$businessName}}/list/component/model" } from "/@/views/{{.modulePath}}/{{$businessName}}/list/component/model"
export default defineComponent({ defineOptions({ name: "{{.apiVersion|replace "/" "_"|CaseCamel}}{{.modulePath|replace "/" "_"|CaseCamel}}{{.table.ClassName}}Edit"})
name:"{{.apiVersion|replace "/" "_"|CaseCamel}}{{.modulePath|replace "/" "_"|CaseCamel}}{{.table.ClassName}}Edit", const emit = defineEmits(['{{$businessName}}List'])
{{$hascomponent := false}} {{$hascomponent := false}}
{{if or $imgsImp $tokenImp $fileImp}} {{if or $imgsImp $tokenImp $fileImp}}
{{$hascomponent = true}} {{$hascomponent = true}}
{{end}} {{end}}
{{if $hascomponent}} {{$hasProps := false}}
components:{ {{if eq .table.TplCategory "tree"}}
{{if $editImp}} {{$hasProps = true}}
GfUeditor, {{end}}
{{end}} {{if not $hasProps}}
{{if $imgsImp}} {{range $index, $column := .table.Columns}}
uploadImg, {{if or (ne $column.DictType "") (ne $column.LinkTableName "") }}
{{end}} {{$hasProps = true}}
{{if $fileImp}}
uploadFile,
{{end}}
},
{{end}}
{{$hasProps := false}}
{{if eq .table.TplCategory "tree"}}
{{$hasProps = true}}
{{end}}
{{if not $hasProps}}
{{range $index, $column := .table.Columns}}
{{if or (ne $column.DictType "") (ne $column.LinkTableName "") }}
{{$hasProps = true}}
{{end}}
{{end}} {{end}}
{{end}} {{end}}
{{if $hasProps}} {{end}}
props:{ {{if $hasProps}}
const props = defineProps({
{{range $index, $column := .table.Columns}} {{range $index, $column := .table.Columns}}
{{if ne $column.DictType ""}} {{if ne $column.DictType ""}}
{{$column.HtmlField}}Options:{ {{$column.HtmlField}}Options:{
@ -355,275 +342,239 @@ export default defineComponent({
default:()=>[] default:()=>[]
}, },
{{end}} {{end}}
}, })
{{end}} {{end}}
setup(props,{emit}) {
{{if or $imgsImp $tokenImp $fileImp}} {{if or $imgsImp $tokenImp $fileImp}}
const baseURL:string|undefined|boolean = import.meta.env.VITE_API_URL const baseURL:string|undefined|boolean = import.meta.env.VITE_API_URL
{{end}} {{end}}
const {proxy} = <any>getCurrentInstance() const {proxy} = <any>getCurrentInstance()
const formRef = ref<HTMLElement | null>(null); const formRef = ref<HTMLElement | null>(null);
const menuRef = ref(); const menuRef = ref();
{{range $index, $column := .table.Columns}}
{{if eq $column.HtmlType "imagefile"}}
//图片上传地址
const imageUrl{{$column.GoField}} = ref('')
//上传加载
const upLoading{{$column.GoField}} = ref(false)
{{end}}
{{end}}
const state = reactive<{{.table.ClassName}}EditState>({
loading:false,
isShowDialog: false,
formData: {
{{range $index, $column := .table.Columns}} {{range $index, $column := .table.Columns}}
{{if eq $column.HtmlType "imagefile"}} {{if eq $column.HtmlType "radio"}}
//图片上传地址 {{$column.HtmlField}}: false ,
const imageUrl{{$column.GoField}} = ref('') {{else if eq $column.HtmlType "images" "file" "files" "checkbox" "selects" "treeSelects"}}
//上传加载 {{$column.HtmlField}}: [] ,
const upLoading{{$column.GoField}} = ref(false)
{{end}}
{{end}}
const state = reactive<{{.table.ClassName}}EditState>({
loading:false,
isShowDialog: false,
formData: {
{{range $index, $column := .table.Columns}}
{{if eq $column.HtmlType "radio"}}
{{$column.HtmlField}}: false ,
{{else if eq $column.HtmlType "images" "file" "files" "checkbox" "selects" "treeSelects"}}
{{$column.HtmlField}}: [] ,
{{else if eq $column.HtmlType "keyValue"}}
{{$column.HtmlField}}:[{key:"",value:""}],
{{else}}
{{$column.HtmlField}}: undefined,
{{end}}
{{end}}
{{range $ti, $linkedTable := .table.LinkedTables}}
linked{{$.table.ClassName}}{{$linkedTable.ClassName}}: {
{{range $ci, $linkedColumn := $linkedTable.RefColumns.Values}}
{{$linkedColumn.HtmlField}}:{{if eq $linkedColumn.HtmlType "images" "file" "files"}}[]{{else}}undefined{{end}}, // {{$linkedColumn.ColumnComment}}
{{end}}
},
{{end}}
},
// 表单校验
rules: {
{{range $index, $column := .table.Columns}}
{{if $column.IsRequired}}
{{$column.HtmlField}} : [
{ required: true, message: "{{$column.ColumnComment}}不能为空", trigger: "blur" }
]{{if ne $lens $index}},{{end}}
{{end}}
{{end}}
}
});
// 打开弹窗
const openDialog = (row?: {{.table.ClassName}}InfoData) => {
resetForm();
if(row) {
get{{.table.ClassName}}(row.{{.table.PkColumn.HtmlField}}!).then((res:any)=>{
const data = res.data;
{{range $index, $column := .table.EditColumns}}
{{if eq $column.HtmlType "checkbox" "selects"}}
data.{{$column.HtmlField}} = data.{{$column.HtmlField}}.split(",")
{{else if eq $column.HtmlType "treeSelects"}}
{{$isNumber := false}}
{{range $li,$lc := $.table.LinkedTables}}
{{if and (eq $lc.TableName $column.LinkTableName) (ne $lc.OptionsStruct.ColumnAttr.GoType "string")}}
{{$isNumber = true}}
{{end}}
{{end}}
{{if $isNumber}}
data.{{$column.HtmlField}} = data.{{$column.HtmlField}}.split(",").map((item:any)=>{return parseInt(item)})
{{else}}
data.{{$column.HtmlField}} = data.{{$column.HtmlField}}.split(",")
{{end}}
{{else if and (eq $column.HtmlType "radio" "select") (ne $column.DictType "")}}
{{if eq $column.TsType "boolean"}}
data.{{$column.HtmlField}} = data.{{$column.HtmlField}}?'1':'0'
{{else}}
data.{{$column.HtmlField}} = ''+data.{{$column.HtmlField}}
{{end}}
{{else if eq $column.HtmlType "radio" "select" }}
{{if eq $column.TsType "number"}}
data.{{$column.HtmlField}} = parseInt(data.{{$column.HtmlField}})
{{else if eq $column.TsType "string"}}
data.{{$column.HtmlField}} = ''+data.{{$column.HtmlField}}
{{else}}
data.{{$column.HtmlField}} = data.{{$column.HtmlField}}
{{end}}
{{else if eq $column.HtmlType "treeSelect"}}
{{$isNumber := false}}
{{range $li,$lc := $.table.LinkedTables}}
{{if and (eq $lc.TableName $column.LinkTableName) (ne $lc.OptionsStruct.ColumnAttr.GoType "string")}}
{{$isNumber = true}}
{{end}}
{{end}}
{{if and (not $isNumber) (eq $column.TsType "number")}}
{{$isNumber = true}}
{{end}}
{{if $isNumber}}
data.{{$column.HtmlField}} = parseInt(data.{{$column.HtmlField}})
{{else}}
data.{{$column.HtmlField}} = ''+data.{{$column.HtmlField}}
{{end}}
{{else if eq $column.HtmlType "imagefile"}}
//单图地址赋值
imageUrl{{$column.GoField}}.value = data.{{$column.HtmlField}} ? proxy.getUpFileUrl(data.{{$column.HtmlField}}) : ''
{{else if eq $column.HtmlType "images" "file" "files"}}
data.{{$column.HtmlField}} =data.{{$column.HtmlField}}?JSON.parse(data.{{$column.HtmlField}}) : []
{{else if eq $column.HtmlType "keyValue"}}
data.{{$column.HtmlField}} = data.{{$column.HtmlField}}?JSON.parse(data.{{$column.HtmlField}}) : [{key:'',value:''}]
{{end}}
{{end}}
state.formData = data;
})
}
state.isShowDialog = true;
};
// 关闭弹窗
const closeDialog = () => {
state.isShowDialog = false;
};
// 取消
const onCancel = () => {
closeDialog();
};
// 提交
const onSubmit = () => {
const formWrap = unref(formRef) as any;
if (!formWrap) return;
formWrap.validate((valid: boolean) => {
if (valid) {
state.loading = true;
if(!state.formData.{{.table.PkColumn.HtmlField}} || state.formData.{{.table.PkColumn.HtmlField}}===0){
//添加
add{{.table.ClassName}}(state.formData).then(()=>{
ElMessage.success('添加成功');
closeDialog(); // 关闭弹窗
emit('{{$businessName}}List')
}).finally(()=>{
state.loading = false;
})
}else{
//修改
update{{.table.ClassName}}(state.formData).then(()=>{
ElMessage.success('修改成功');
closeDialog(); // 关闭弹窗
emit('{{$businessName}}List')
}).finally(()=>{
state.loading = false;
})
}
}
});
};
const resetForm = ()=>{
state.formData = {
{{range $index, $column := .table.Columns}}
{{if eq $column.HtmlType "radio"}}
{{$column.HtmlField}}: false ,
{{else if eq $column.HtmlType "images" "file" "files" "checkbox" "selects" "treeSelects"}}
{{$column.HtmlField}}: [] ,
{{else if eq $column.HtmlType "keyValue"}}
{{$column.HtmlField}}:[{key:"",value:""}],
{{else}}
{{$column.HtmlField}}: undefined,
{{end}}
{{end}}
{{range $ti, $linkedTable := .table.LinkedTables}}
linked{{$.table.ClassName}}{{$linkedTable.ClassName}}: {
{{range $ci, $linkedColumn := $linkedTable.RefColumns.Values}}
{{$linkedColumn.HtmlField}}:{{if eq $linkedColumn.HtmlType "images" "file" "files"}}[]{{else}}undefined{{end}}, // {{$linkedColumn.ColumnComment}}
{{end}}
},
{{end}}
}
{{range $index, $column := .table.Columns}}
{{if eq $column.HtmlType "imagefile"}}
imageUrl{{$column.GoField}}.value = ''
{{end}}
{{end}}
};
{{$setUpData:=true}}
{{range $index, $column := .table.Columns}}
{{if eq $column.HtmlType "richtext"}}
//富文本编辑器{{$column.ColumnComment}}
const set{{$column.GoField}}EditContent = (data:string) => {
state.formData.{{$column.HtmlField}} = data
}
{{else if eq $column.HtmlType "imagefile"}}
//单图上传{{$column.ColumnComment}}
const handleAvatarSuccess{{$column.GoField}}:UploadProps['onSuccess'] = (res, file) => {
if (res.code === 0) {
imageUrl{{$column.GoField}}.value = URL.createObjectURL(file.raw!)
state.formData.{{$column.HtmlField}} = res.data.path
} else {
ElMessage.error(res.msg)
}
upLoading{{$column.GoField}}.value = false
}
const beforeAvatarUpload{{$column.GoField}} = () => {
upLoading{{$column.GoField}}.value = true
return true
}
{{if $setUpData}}
const setUpData = () => {
return { token: getToken() }
}
{{$setUpData = false}}
{{end}}
{{else if eq $column.HtmlType "images"}}
const setUpImgList{{$column.GoField}} = (data:any)=>{
state.formData.{{$column.HtmlField}} = data
}
{{else if eq $column.HtmlType "file" "files"}}
const setUpFileList{{$column.GoField}} = (data:any)=>{
state.formData.{{$column.HtmlField}} = data
}
{{else if eq $column.HtmlType "keyValue"}} {{else if eq $column.HtmlType "keyValue"}}
// 新增{{$column.ColumnComment}}行 {{$column.HtmlField}}:[{key:"",value:""}],
const onAddRow{{$column.GoField}} = () => { {{else}}
state.formData.{{$column.HtmlField}}.push({ {{$column.HtmlField}}: undefined,
key: '',
value: '',
});
};
// 删除{{$column.ColumnComment}}行
const onDelRow{{$column.GoField}} = (k: number) => {
state.formData.{{$column.HtmlField}}.splice(k, 1);
};
{{end}} {{end}}
{{end}} {{end}}
{{$setUpDataR:=true}} {{range $ti, $linkedTable := .table.LinkedTables}}
return { linked{{$.table.ClassName}}{{$linkedTable.ClassName}}: {
proxy, {{range $ci, $linkedColumn := $linkedTable.RefColumns.Values}}
openDialog, {{$linkedColumn.HtmlField}}:{{if eq $linkedColumn.HtmlType "images" "file" "files"}}[]{{else}}undefined{{end}}, // {{$linkedColumn.ColumnComment}}
closeDialog,
onCancel,
onSubmit,
menuRef,
formRef,
{{range $index, $column := .table.Columns}}
{{if eq $column.HtmlType "richtext"}}
//富文本编辑器{{$column.ColumnComment}}
set{{$column.GoField}}EditContent,
{{else if eq $column.HtmlType "imagefile"}}
//图片上传地址
imageUrl{{$column.GoField}},
//上传加载
upLoading{{$column.GoField}},
handleAvatarSuccess{{$column.GoField}},
beforeAvatarUpload{{$column.GoField}},
{{if $setUpDataR}}
setUpData,
{{$setUpDataR = false}}
{{end}} {{end}}
{{else if eq $column.HtmlType "images"}} },
setUpImgList{{$column.GoField}}, {{end}}
{{else if eq $column.HtmlType "file" "files"}} },
setUpFileList{{$column.GoField}}, // 表单校验
{{else if eq $column.HtmlType "keyValue"}} rules: {
onAddRow{{$column.GoField}}, {{range $index, $column := .table.Columns}}
onDelRow{{$column.GoField}}, {{if $column.IsRequired}}
{{end}} {{$column.HtmlField}} : [
{{end}} { required: true, message: "{{$column.ColumnComment}}不能为空", trigger: "blur" }
{{if or $imgsImp $tokenImp $fileImp}} ]{{if ne $lens $index}},{{end}}
baseURL, {{end}}
{{end}} {{end}}
...toRefs(state),
};
} }
}) });
const { loading,isShowDialog,formData,rules } = toRefs(state);
// 打开弹窗
const openDialog = (row?: {{.table.ClassName}}InfoData) => {
resetForm();
if(row) {
get{{.table.ClassName}}(row.{{.table.PkColumn.HtmlField}}!).then((res:any)=>{
const data = res.data;
{{range $index, $column := .table.EditColumns}}
{{if eq $column.HtmlType "checkbox" "selects"}}
data.{{$column.HtmlField}} = data.{{$column.HtmlField}}.split(",")
{{else if eq $column.HtmlType "treeSelects"}}
{{$isNumber := false}}
{{range $li,$lc := $.table.LinkedTables}}
{{if and (eq $lc.TableName $column.LinkTableName) (ne $lc.OptionsStruct.ColumnAttr.GoType "string")}}
{{$isNumber = true}}
{{end}}
{{end}}
{{if $isNumber}}
data.{{$column.HtmlField}} = data.{{$column.HtmlField}}.split(",").map((item:any)=>{return parseInt(item)})
{{else}}
data.{{$column.HtmlField}} = data.{{$column.HtmlField}}.split(",")
{{end}}
{{else if and (eq $column.HtmlType "radio" "select") (ne $column.DictType "")}}
{{if eq $column.TsType "boolean"}}
data.{{$column.HtmlField}} = data.{{$column.HtmlField}}?'1':'0'
{{else}}
data.{{$column.HtmlField}} = ''+data.{{$column.HtmlField}}
{{end}}
{{else if eq $column.HtmlType "radio" "select" }}
{{if eq $column.TsType "number"}}
data.{{$column.HtmlField}} = parseInt(data.{{$column.HtmlField}})
{{else if eq $column.TsType "string"}}
data.{{$column.HtmlField}} = ''+data.{{$column.HtmlField}}
{{else}}
data.{{$column.HtmlField}} = data.{{$column.HtmlField}}
{{end}}
{{else if eq $column.HtmlType "treeSelect"}}
{{$isNumber := false}}
{{range $li,$lc := $.table.LinkedTables}}
{{if and (eq $lc.TableName $column.LinkTableName) (ne $lc.OptionsStruct.ColumnAttr.GoType "string")}}
{{$isNumber = true}}
{{end}}
{{end}}
{{if and (not $isNumber) (eq $column.TsType "number")}}
{{$isNumber = true}}
{{end}}
{{if $isNumber}}
data.{{$column.HtmlField}} = parseInt(data.{{$column.HtmlField}})
{{else}}
data.{{$column.HtmlField}} = ''+data.{{$column.HtmlField}}
{{end}}
{{else if eq $column.HtmlType "imagefile"}}
//单图地址赋值
imageUrl{{$column.GoField}}.value = data.{{$column.HtmlField}} ? proxy.getUpFileUrl(data.{{$column.HtmlField}}) : ''
{{else if eq $column.HtmlType "images" "file" "files"}}
data.{{$column.HtmlField}} =data.{{$column.HtmlField}}?JSON.parse(data.{{$column.HtmlField}}) : []
{{else if eq $column.HtmlType "keyValue"}}
data.{{$column.HtmlField}} = data.{{$column.HtmlField}}?JSON.parse(data.{{$column.HtmlField}}) : [{key:'',value:''}]
{{end}}
{{end}}
state.formData = data;
})
}
state.isShowDialog = true;
};
// 关闭弹窗
const closeDialog = () => {
state.isShowDialog = false;
};
defineExpose({
openDialog,
});
// 取消
const onCancel = () => {
closeDialog();
};
// 提交
const onSubmit = () => {
const formWrap = unref(formRef) as any;
if (!formWrap) return;
formWrap.validate((valid: boolean) => {
if (valid) {
state.loading = true;
if(!state.formData.{{.table.PkColumn.HtmlField}} || state.formData.{{.table.PkColumn.HtmlField}}===0){
//添加
add{{.table.ClassName}}(state.formData).then(()=>{
ElMessage.success('添加成功');
closeDialog(); // 关闭弹窗
emit('{{$businessName}}List')
}).finally(()=>{
state.loading = false;
})
}else{
//修改
update{{.table.ClassName}}(state.formData).then(()=>{
ElMessage.success('修改成功');
closeDialog(); // 关闭弹窗
emit('{{$businessName}}List')
}).finally(()=>{
state.loading = false;
})
}
}
});
};
const resetForm = ()=>{
state.formData = {
{{range $index, $column := .table.Columns}}
{{if eq $column.HtmlType "radio"}}
{{$column.HtmlField}}: false ,
{{else if eq $column.HtmlType "images" "file" "files" "checkbox" "selects" "treeSelects"}}
{{$column.HtmlField}}: [] ,
{{else if eq $column.HtmlType "keyValue"}}
{{$column.HtmlField}}:[{key:"",value:""}],
{{else}}
{{$column.HtmlField}}: undefined,
{{end}}
{{end}}
{{range $ti, $linkedTable := .table.LinkedTables}}
linked{{$.table.ClassName}}{{$linkedTable.ClassName}}: {
{{range $ci, $linkedColumn := $linkedTable.RefColumns.Values}}
{{$linkedColumn.HtmlField}}:{{if eq $linkedColumn.HtmlType "images" "file" "files"}}[]{{else}}undefined{{end}}, // {{$linkedColumn.ColumnComment}}
{{end}}
},
{{end}}
}
{{range $index, $column := .table.Columns}}
{{if eq $column.HtmlType "imagefile"}}
imageUrl{{$column.GoField}}.value = ''
{{end}}
{{end}}
};
{{$setUpData:=true}}
{{range $index, $column := .table.Columns}}
{{if eq $column.HtmlType "richtext"}}
//富文本编辑器{{$column.ColumnComment}}
const set{{$column.GoField}}EditContent = (data:string) => {
state.formData.{{$column.HtmlField}} = data
}
{{else if eq $column.HtmlType "imagefile"}}
//单图上传{{$column.ColumnComment}}
const handleAvatarSuccess{{$column.GoField}}:UploadProps['onSuccess'] = (res, file) => {
if (res.code === 0) {
imageUrl{{$column.GoField}}.value = URL.createObjectURL(file.raw!)
state.formData.{{$column.HtmlField}} = res.data.path
} else {
ElMessage.error(res.msg)
}
upLoading{{$column.GoField}}.value = false
}
const beforeAvatarUpload{{$column.GoField}} = () => {
upLoading{{$column.GoField}}.value = true
return true
}
{{if $setUpData}}
const setUpData = () => {
return { token: getToken() }
}
{{$setUpData = false}}
{{end}}
{{else if eq $column.HtmlType "images"}}
const setUpImgList{{$column.GoField}} = (data:any)=>{
state.formData.{{$column.HtmlField}} = data
}
{{else if eq $column.HtmlType "file" "files"}}
const setUpFileList{{$column.GoField}} = (data:any)=>{
state.formData.{{$column.HtmlField}} = data
}
{{else if eq $column.HtmlType "keyValue"}}
// 新增{{$column.ColumnComment}}行
const onAddRow{{$column.GoField}} = () => {
state.formData.{{$column.HtmlField}}.push({
key: '',
value: '',
});
};
// 删除{{$column.ColumnComment}}行
const onDelRow{{$column.GoField}} = (k: number) => {
state.formData.{{$column.HtmlField}}.splice(k, 1);
};
{{end}}
{{end}}
</script> </script>
<style scoped> <style scoped>

View File

@ -410,7 +410,7 @@
</div> </div>
</template> </template>
<script lang="ts"> <script setup lang="ts">
{{$tokenImp := false}} {{$tokenImp := false}}
{{$imgsImp := false}} {{$imgsImp := false}}
@ -468,273 +468,220 @@ import {downLoadXml} from "/@/utils/zipdownload";
{{if .table.ExcelImp}} {{if .table.ExcelImp}}
import loadExcel from "/@/components/loadExcel/index.vue" import loadExcel from "/@/components/loadExcel/index.vue"
{{end}} {{end}}
export default defineComponent({ defineOptions({ name: "{{.apiVersion|replace "/" "_"|CaseCamelLower}}{{.modulePath|replace "/" "_"|CaseCamel}}{{.table.ClassName}}List"})
name: "{{.apiVersion|replace "/" "_"|CaseCamelLower}}{{.modulePath|replace "/" "_"|CaseCamel}}{{.table.ClassName}}List", const {proxy} = <any>getCurrentInstance()
components:{ const loading = ref(false)
{{if .table.ExcelImp}} const queryRef = ref()
loadExcel, const editRef = ref();
{{end}} const detailRef = ref();
{{.apiVersion|replace "/" "_"|CaseCamel}}{{.modulePath|replace "/" "_"|CaseCamel}}{{.table.ClassName}}Edit, {{if .table.ExcelImp}}
{{.apiVersion|replace "/" "_"|CaseCamel}}{{.modulePath|replace "/" "_"|CaseCamel}}{{.table.ClassName}}Detail const loadExcel{{.table.ClassName}}Ref = ref();
}, {{end}}
setup() { // 是否显示所有搜索选项
const {proxy} = <any>getCurrentInstance() const showAll = ref(false)
const loading = ref(false) // 非单个禁用
const queryRef = ref() const single = ref(true)
const editRef = ref(); // 非多个禁用
const detailRef = ref(); const multiple =ref(true)
{{if .table.ExcelImp}} const word = computed(()=>{
const loadExcel{{.table.ClassName}}Ref = ref(); if(showAll.value === false) {
{{end}} //对文字进行处理
// 是否显示所有搜索选项 return "展开搜索";
const showAll = ref(false) } else {
// 非单个禁用 return "收起搜索";
const single = ref(true)
// 非多个禁用
const multiple =ref(true)
const word = computed(()=>{
if(showAll.value === false) {
//对文字进行处理
return "展开搜索";
} else {
return "收起搜索";
}
})
// 字典选项数据
{{$dictArr:=newArray}}
{{range $index, $column := .table.Columns}}
{{if and (ne $column.DictType "") (ne (inArray $dictArr $column.DictType) true)}}
{{$dictArr = append $dictArr $column.DictType}}
{{end}}
{{end}}
const {
{{range $index, $column := $dictArr}}
{{$column}},
{{end}}
} = proxy.useDict(
{{range $index, $column := $dictArr}}
'{{$column}}',
{{end}}
)
{{range $index, $column := .table.Columns}}
{{if ne $column.LinkTableName ""}}
{{if $column.IsCascade }}
// {{$column.HtmlField}}QueryOptions关联表数据
const {{$column.HtmlField}}QueryOptions = ref<Array<ItemOptions>>([])
// {{$column.HtmlField}}FormOptions关联表数据
const {{$column.HtmlField}}FormOptions = ref<Array<ItemOptions>>([])
{{else}}
// {{$column.HtmlField}}Options关联表数据
const {{$column.HtmlField}}Options = ref<Array<ItemOptions>>([])
{{end}}
{{end}}
{{end}}
const state = reactive<{{.table.ClassName}}TableDataState>({
{{.table.PkColumn.HtmlField}}s:[],
tableData: {
data: [],
total: 0,
loading: false,
param: {
pageNum: 1,
pageSize: 10,
{{range $index, $column := .table.QueryColumns}}
{{if eq $column.QueryType "BETWEEN"}}
{{$column.HtmlField}}: [],
{{else}}
{{$column.HtmlField}}: undefined,
{{end}}{{end}}
dateRange: []
},
},
});
// 页面加载时
onMounted(() => {
initTableData();
});
// 初始化表格数据
const initTableData = () => {
{{if gt (len .table.LinkedTables) 0}}
linkedData()
{{end}}
{{$businessName}}List()
};
{{if gt (len .table.LinkedTables) 0}}
const linkedData = ()=>{
linkedDataSearch().then((res:any)=>{
{{range $index, $column := .table.Columns}}
{{if ne $column.LinkTableName ""}}
//关联{{$column.LinkTableName}}表选项
{{range $li,$lc := $.table.LinkedTables}}
{{if eq $lc.TableName $column.LinkTableName}}
{{if eq $lc.TplCategory "tree"}}
{{$column.HtmlField}}Options.value = proxy.handleTree(res.data.linked{{$.table.ClassName}}{{$column.LinkTableClass}}, '{{$lc.OptionsStruct.TreeCode}}', '{{$lc.OptionsStruct.TreeParentCode}}')
{{else}}
{{$column.HtmlField}}Options.value = proxy.setItems(res, '{{$column.LinkLabelId | CaseCamelLower}}', '{{$column.LinkLabelName | CaseCamelLower}}','linked{{$.table.ClassName}}{{$column.LinkTableClass}}')
{{end}}
{{end}}
{{end}}
{{end}}
{{end}}
})
}
{{end}}
/** 重置按钮操作 */
const resetQuery = (formEl: FormInstance | undefined) => {
if (!formEl) return
formEl.resetFields()
{{$businessName}}List()
};
// 获取列表数据
const {{$businessName}}List = ()=>{
loading.value = true
list{{.table.ClassName}}(state.tableData.param).then((res:any)=>{
let list = res.data.list??[];
{{range $index,$column := .table.ListColumns}}
{{if eq $column.HtmlField "createdBy" "updatedBy" "deptId"}}
list.map((item:any)=>{
{{if eq $column.HtmlField "createdBy"}}
item.createdBy = item.createdUser?.userNickname
{{end}}
{{if eq $column.HtmlField "deptId"}}
item.deptId = item.deptInfo?.deptName
{{end}}
{{if eq $column.HtmlField "updatedBy"}}
item.updatedBy = item.updatedUser?.userNickname
{{end}}
})
{{end}}
{{end}}
state.tableData.data = list;
state.tableData.total = res.data.total;
loading.value = false
})
};
const toggleSearch = () => {
showAll.value = !showAll.value;
}
{{range $index, $column := .table.Columns}}
{{if ne $column.DictType ""}}
{{if eq $column.HtmlType "checkbox"}}
// {{$column.ColumnComment}}字典翻译
const {{$column.HtmlField}}Format = (row:{{$.table.ClassName}}TableColumns) => {
let {{$column.HtmlField}} = row.{{$column.HtmlField}}.split(",")
let data:Array<string> = [];
{{$column.HtmlField}}.map(item=>{
data.push(proxy.selectDictLabel({{$column.DictType}}.value, item))
})
return data.join(",")
}
{{else}}
// {{$column.ColumnComment}}字典翻译
const {{$column.HtmlField}}Format = (row:{{$.table.ClassName}}TableColumns) => {
return proxy.selectDictLabel({{$column.DictType}}.value, row.{{$column.HtmlField}});
}
{{end}}
{{end}}
{{end}}
// 多选框选中数据
const handleSelectionChange = (selection:Array<{{.table.ClassName}}InfoData>) => {
state.{{.table.PkColumn.HtmlField}}s = selection.map(item => item.{{.table.PkColumn.HtmlField}})
single.value = selection.length!=1
multiple.value = !selection.length
}
const handleAdd = ()=>{
editRef.value.openDialog()
}
const handleUpdate = (row: {{$.table.ClassName}}TableColumns) => {
if(!row){
row = state.tableData.data.find((item:{{$.table.ClassName}}TableColumns)=>{
return item.{{.table.PkColumn.HtmlField}} ===state.{{.table.PkColumn.HtmlField}}s[0]
}) as {{$.table.ClassName}}TableColumns
}
editRef.value.openDialog(toRaw(row));
};
const handleDelete = (row: {{$.table.ClassName}}TableColumns) => {
let msg = '你确定要删除所选数据?';
let {{.table.PkColumn.HtmlField}}:number[] = [] ;
if(row){
msg = `此操作将永久删除数据,是否继续?`
{{.table.PkColumn.HtmlField}} = [row.{{.table.PkColumn.HtmlField}}]
}else{
{{.table.PkColumn.HtmlField}} = state.{{.table.PkColumn.HtmlField}}s
}
if({{.table.PkColumn.HtmlField}}.length===0){
ElMessage.error('请选择要删除的数据。');
return
}
ElMessageBox.confirm(msg, '提示', {
confirmButtonText: '确认',
cancelButtonText: '取消',
type: 'warning',
})
.then(() => {
del{{.table.ClassName}}({{.table.PkColumn.HtmlField}}).then(()=>{
ElMessage.success('删除成功');
{{$businessName}}List();
})
})
.catch(() => {});
}
const handleView = (row:{{$.table.ClassName}}TableColumns)=>{
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}}
return {
proxy,
editRef,
detailRef,
showAll,
loading,
single,
multiple,
word,
queryRef,
resetQuery,
{{$businessName}}List,
toggleSearch,
{{range $index, $column := .table.Columns}}
{{if ne $column.DictType ""}}
{{$column.HtmlField}}Format,
{{$column.DictType}},
{{end}}
{{if ne $column.LinkTableName ""}}
{{if $column.IsCascade}}
//级联关联{{$column.LinkTableName}}表选项
{{else}}
//关联表数据选项
{{$column.HtmlField}}Options,
{{end}}
{{end}}
{{end}}
handleSelectionChange,
handleAdd,
handleUpdate,
handleDelete,
{{if eq .table.ShowDetail "true"}}
handleView,
{{end}}
{{if .table.ExcelPort }}
handleExport,
{{end}}
{{if .table.ExcelImp }}
handleImport,
loadExcel{{.table.ClassName}}Ref,
{{end}}
...toRefs(state),
}
} }
}) })
// 字典选项数据
{{$dictArr:=newArray}}
{{range $index, $column := .table.Columns}}
{{if and (ne $column.DictType "") (ne (inArray $dictArr $column.DictType) true)}}
{{$dictArr = append $dictArr $column.DictType}}
{{end}}
{{end}}
const {
{{range $index, $column := $dictArr}}
{{$column}},
{{end}}
} = proxy.useDict(
{{range $index, $column := $dictArr}}
'{{$column}}',
{{end}}
)
{{range $index, $column := .table.Columns}}
{{if ne $column.LinkTableName ""}}
{{if $column.IsCascade }}
// {{$column.HtmlField}}QueryOptions关联表数据
const {{$column.HtmlField}}QueryOptions = ref<Array<ItemOptions>>([])
// {{$column.HtmlField}}FormOptions关联表数据
const {{$column.HtmlField}}FormOptions = ref<Array<ItemOptions>>([])
{{else}}
// {{$column.HtmlField}}Options关联表数据
const {{$column.HtmlField}}Options = ref<Array<ItemOptions>>([])
{{end}}
{{end}}
{{end}}
const state = reactive<{{.table.ClassName}}TableDataState>({
{{.table.PkColumn.HtmlField}}s:[],
tableData: {
data: [],
total: 0,
loading: false,
param: {
pageNum: 1,
pageSize: 10,
{{range $index, $column := .table.QueryColumns}}
{{if eq $column.QueryType "BETWEEN"}}
{{$column.HtmlField}}: [],
{{else}}
{{$column.HtmlField}}: undefined,
{{end}}{{end}}
dateRange: []
},
},
});
const { tableData } = toRefs(state);
// 页面加载时
onMounted(() => {
initTableData();
});
// 初始化表格数据
const initTableData = () => {
{{if gt (len .table.LinkedTables) 0}}
linkedData()
{{end}}
{{$businessName}}List()
};
{{if gt (len .table.LinkedTables) 0}}
const linkedData = ()=>{
linkedDataSearch().then((res:any)=>{
{{range $index, $column := .table.Columns}}
{{if ne $column.LinkTableName ""}}
//关联{{$column.LinkTableName}}表选项
{{range $li,$lc := $.table.LinkedTables}}
{{if eq $lc.TableName $column.LinkTableName}}
{{if eq $lc.TplCategory "tree"}}
{{$column.HtmlField}}Options.value = proxy.handleTree(res.data.linked{{$.table.ClassName}}{{$column.LinkTableClass}}, '{{$lc.OptionsStruct.TreeCode}}', '{{$lc.OptionsStruct.TreeParentCode}}')
{{else}}
{{$column.HtmlField}}Options.value = proxy.setItems(res, '{{$column.LinkLabelId | CaseCamelLower}}', '{{$column.LinkLabelName | CaseCamelLower}}','linked{{$.table.ClassName}}{{$column.LinkTableClass}}')
{{end}}
{{end}}
{{end}}
{{end}}
{{end}}
})
}
{{end}}
/** 重置按钮操作 */
const resetQuery = (formEl: FormInstance | undefined) => {
if (!formEl) return
formEl.resetFields()
{{$businessName}}List()
};
// 获取列表数据
const {{$businessName}}List = ()=>{
loading.value = true
list{{.table.ClassName}}(state.tableData.param).then((res:any)=>{
let list = res.data.list??[];
{{range $index,$column := .table.ListColumns}}
{{if eq $column.HtmlField "createdBy" "updatedBy" "deptId"}}
list.map((item:any)=>{
{{if eq $column.HtmlField "createdBy"}}
item.createdBy = item.createdUser?.userNickname
{{end}}
{{if eq $column.HtmlField "deptId"}}
item.deptId = item.deptInfo?.deptName
{{end}}
{{if eq $column.HtmlField "updatedBy"}}
item.updatedBy = item.updatedUser?.userNickname
{{end}}
})
{{end}}
{{end}}
state.tableData.data = list;
state.tableData.total = res.data.total;
loading.value = false
})
};
const toggleSearch = () => {
showAll.value = !showAll.value;
}
{{range $index, $column := .table.Columns}}
{{if ne $column.DictType ""}}
{{if eq $column.HtmlType "checkbox"}}
// {{$column.ColumnComment}}字典翻译
const {{$column.HtmlField}}Format = (row:{{$.table.ClassName}}TableColumns) => {
let {{$column.HtmlField}} = row.{{$column.HtmlField}}.split(",")
let data:Array<string> = [];
{{$column.HtmlField}}.map(item=>{
data.push(proxy.selectDictLabel({{$column.DictType}}.value, item))
})
return data.join(",")
}
{{else}}
// {{$column.ColumnComment}}字典翻译
const {{$column.HtmlField}}Format = (row:{{$.table.ClassName}}TableColumns) => {
return proxy.selectDictLabel({{$column.DictType}}.value, row.{{$column.HtmlField}});
}
{{end}}
{{end}}
{{end}}
// 多选框选中数据
const handleSelectionChange = (selection:Array<{{.table.ClassName}}InfoData>) => {
state.{{.table.PkColumn.HtmlField}}s = selection.map(item => item.{{.table.PkColumn.HtmlField}})
single.value = selection.length!=1
multiple.value = !selection.length
}
const handleAdd = ()=>{
editRef.value.openDialog()
}
const handleUpdate = (row: {{$.table.ClassName}}TableColumns|null) => {
if(!row){
row = state.tableData.data.find((item:{{$.table.ClassName}}TableColumns)=>{
return item.{{.table.PkColumn.HtmlField}} ===state.{{.table.PkColumn.HtmlField}}s[0]
}) as {{$.table.ClassName}}TableColumns
}
editRef.value.openDialog(toRaw(row));
};
const handleDelete = (row: {{$.table.ClassName}}TableColumns|null) => {
let msg = '你确定要删除所选数据?';
let {{.table.PkColumn.HtmlField}}:number[] = [] ;
if(row){
msg = `此操作将永久删除数据,是否继续?`
{{.table.PkColumn.HtmlField}} = [row.{{.table.PkColumn.HtmlField}}]
}else{
{{.table.PkColumn.HtmlField}} = state.{{.table.PkColumn.HtmlField}}s
}
if({{.table.PkColumn.HtmlField}}.length===0){
ElMessage.error('请选择要删除的数据。');
return
}
ElMessageBox.confirm(msg, '提示', {
confirmButtonText: '确认',
cancelButtonText: '取消',
type: 'warning',
})
.then(() => {
del{{.table.ClassName}}({{.table.PkColumn.HtmlField}}).then(()=>{
ElMessage.success('删除成功');
{{$businessName}}List();
})
})
.catch(() => {});
}
const handleView = (row:{{$.table.ClassName}}TableColumns)=>{
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 {

View File

@ -285,7 +285,7 @@
</div> </div>
</template> </template>
<script lang="ts"> <script setup lang="ts">
{{$tokenImp := false}} {{$tokenImp := false}}
{{$imgsImp := false}} {{$imgsImp := false}}
@ -339,451 +339,400 @@ 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'
export default defineComponent({ defineOptions({ name: "{{.apiVersion|replace "/" "_"|CaseCamelLower}}{{.modulePath|replace "/" "_"|CaseCamel}}{{.table.ClassName}}List"})
name: "{{.apiVersion|replace "/" "_"|CaseCamelLower}}{{.modulePath|replace "/" "_"|CaseCamel}}{{.table.ClassName}}List", const {proxy} = <any>getCurrentInstance()
components:{ const loading = ref(false)
{{.apiVersion|replace "/" "_"|CaseCamel}}{{.modulePath|replace "/" "_"|CaseCamel}}{{.table.ClassName}}Edit, const queryRef = ref()
{{.apiVersion|replace "/" "_"|CaseCamel}}{{.modulePath|replace "/" "_"|CaseCamel}}{{.table.ClassName}}Detail const editRef = ref();
}, const detailRef = ref();
setup() { // 是否显示所有搜索选项
const {proxy} = <any>getCurrentInstance() const showAll = ref(false)
const loading = ref(false) // 非单个禁用
const queryRef = ref() const single = ref(true)
const editRef = ref(); // 非多个禁用
const detailRef = ref(); const multiple =ref(true)
// 是否显示所有搜索选项 const word = computed(()=>{
const showAll = ref(false) if(showAll.value === false) {
// 非单个禁用 //对文字进行处理
const single = ref(true) return "展开搜索";
// 非多个禁用 } else {
const multiple =ref(true) return "收起搜索";
const word = computed(()=>{
if(showAll.value === false) {
//对文字进行处理
return "展开搜索";
} else {
return "收起搜索";
}
})
// 字典选项数据
{{$dictArr:=newArray}}
{{range $index, $column := .table.Columns}}
{{if and (ne $column.DictType "") (ne (inArray $dictArr $column.DictType) true)}}
{{$dictArr = append $dictArr $column.DictType}}
{{end}}
{{end}}
const {
{{range $index, $column := $dictArr}}
{{$column}},
{{end}}
} = proxy.useDict(
{{range $index, $column := $dictArr}}
'{{$column}}',
{{end}}
)
{{range $index, $column := .table.Columns}}
{{if ne $column.LinkTableName ""}}
{{if $column.IsCascade }}
// {{$column.HtmlField}}QueryOptions关联表数据
const {{$column.HtmlField}}QueryOptions = ref<Array<ItemOptions>>([])
// {{$column.HtmlField}}FormOptions关联表数据
const {{$column.HtmlField}}FormOptions = ref<Array<ItemOptions>>([])
{{else}}
// {{$column.HtmlField}}Options关联表数据
const {{$column.HtmlField}}Options = ref<Array<ItemOptions>>([])
{{end}}
{{end}}
{{end}}
const dataList = ref<Array<{{$.table.ClassName}}TableColumns>>([])
const state = reactive<{{.table.ClassName}}TableDataState>({
{{.table.PkColumn.HtmlField}}s:[],
tableData: {
data: [],
total: 0,
loading: false,
param: {
pageNum: 1,
pageSize: 10,
{{range $index, $column := .table.QueryColumns}}
{{if eq $column.QueryType "BETWEEN"}}
{{$column.HtmlField}}: [],
{{else}}
{{$column.HtmlField}}: undefined,
{{end}}{{end}}
dateRange: []
},
},
});
// 页面加载时
onMounted(() => {
initTableData();
});
// 初始化表格数据
const initTableData = () => {
{{if gt (len .table.LinkedTables) 0}}
linkedData()
{{end}}
{{$businessName}}List()
};
{{if gt (len .table.LinkedTables) 0}}
const linkedData = ()=>{
linkedDataSearch().then((res:any)=>{
{{range $index, $column := .table.Columns}}
{{if ne $column.LinkTableName ""}}
//关联{{$column.LinkTableName}}表选项
{{range $li,$lc := $.table.LinkedTables}}
{{if eq $lc.TableName $column.LinkTableName}}
{{if eq $lc.TplCategory "tree"}}
{{$column.HtmlField}}Options.value = proxy.handleTree(res.data.linked{{$.table.ClassName}}{{$column.LinkTableClass}}, '{{$lc.OptionsStruct.TreeCode}}', '{{$lc.OptionsStruct.TreeParentCode}}')
{{else}}
{{$column.HtmlField}}Options.value = proxy.setItems(res, '{{$column.LinkLabelId | CaseCamelLower}}', '{{$column.LinkLabelName | CaseCamelLower}}','linked{{$.table.ClassName}}{{$column.LinkTableClass}}')
{{end}}
{{end}}
{{end}}
{{end}}
{{end}}
})
}
{{end}}
/** 重置按钮操作 */
const resetQuery = (formEl: FormInstance | undefined) => {
if (!formEl) return
formEl.resetFields()
{{$businessName}}List()
};
// 获取列表数据
const {{$businessName}}List = ()=>{
loading.value = true
list{{.table.ClassName}}(state.tableData.param).then((res:any)=>{
let list = res.data.list??[];
{{range $index,$column := .table.ListColumns}}
{{if eq $column.HtmlField "createdBy" "updatedBy" "dept_id"}}
list.map((item:any)=>{
{{if eq $column.HtmlField "createdBy"}}
item.createdBy = item?.createdUser.userNickname
{{end}}
{{if eq $column.HtmlField "deptId"}}
item.deptId = item.deptInfo?.deptName
{{end}}
{{if eq $column.HtmlField "updatedBy"}}
item.updatedBy = item?.updatedUser.userNickname
{{end}}
})
{{end}}
{{end}}
if(list.length > 0 && typeof list[0].id == "undefined"){
list.map((item:any)=>{
item.id = item.{{.table.PkColumn.HtmlField}}
})
}
dataList.value = _.clone(res.data.list)
list = proxy.handleTree(res.data.list||[], "{{$treeCode}}", "{{$treeParentCode}}");
state.tableData.data = list;
loading.value = false
setVrData(list)
})
};
const toggleSearch = () => {
showAll.value = !showAll.value;
}
{{range $index, $column := .table.Columns}}
{{if ne $column.DictType ""}}
{{if eq $column.HtmlType "checkbox"}}
// {{$column.ColumnComment}}字典翻译
const {{$column.HtmlField}}Format = (row:{{$.table.ClassName}}TableColumns) => {
let {{$column.HtmlField}} = row.{{$column.HtmlField}}.split(",")
let data:Array<string> = [];
{{$column.HtmlField}}.map(item=>{
data.push(proxy.selectDictLabel({{$column.DictType}}.value, item))
})
return data.join(",")
}
{{else}}
// {{$column.ColumnComment}}字典翻译
const {{$column.HtmlField}}Format = (row:{{$.table.ClassName}}TableColumns) => {
return proxy.selectDictLabel({{$column.DictType}}.value, row.{{$column.HtmlField}});
}
{{end}}
{{end}}
{{end}}
// 多选框选中数据
const handleSelectionChange = (selection:Array<{{.table.ClassName}}InfoData>) => {
state.{{.table.PkColumn.HtmlField}}s = selection.map(item => item.{{.table.PkColumn.HtmlField}})
single.value = selection.length!=1
multiple.value = !selection.length
}
const handleAdd = ()=>{
editRef.value.openDialog()
}
const handleUpdate = (row: {{$.table.ClassName}}TableColumns) => {
if(!row){
row = dataList.value.find((item:{{$.table.ClassName}}TableColumns)=>{
return item.{{.table.PkColumn.HtmlField}} ===state.{{.table.PkColumn.HtmlField}}s[0]
}) as {{$.table.ClassName}}TableColumns
}
editRef.value.openDialog(toRaw(row));
};
const handleDelete = (row: {{$.table.ClassName}}TableColumns) => {
let msg = '你确定要删除所选数据?';
let {{.table.PkColumn.HtmlField}}:number[] = [] ;
if(row){
msg = `此操作将永久删除数据,是否继续?`
{{.table.PkColumn.HtmlField}} = [row.{{.table.PkColumn.HtmlField}}]
}else{
{{.table.PkColumn.HtmlField}} = state.{{.table.PkColumn.HtmlField}}s
}
if({{.table.PkColumn.HtmlField}}.length===0){
ElMessage.error('请选择要删除的数据。');
return
}
ElMessageBox.confirm(msg, '提示', {
confirmButtonText: '确认',
cancelButtonText: '取消',
type: 'warning',
})
.then(() => {
del{{.table.ClassName}}({{.table.PkColumn.HtmlField}}).then(()=>{
ElMessage.success('删除成功');
{{$businessName}}List();
})
})
.catch(() => {});
}
const handleView = (row:{{$.table.ClassName}}TableColumns)=>{
detailRef.value.openDialog(toRaw(row));
}
//========================================================================================================
const columns = ref<Column[]>([])
const treeData = ref<any[]>([])
type SelectionCellProps = {
value: boolean
intermediate?: boolean
onChange: (value: CheckboxValueType) => void
}
const SelectionCell: FunctionalComponent<SelectionCellProps> = ({
value,
intermediate = false,
onChange,
}) => {
return h(ElCheckbox,{modelValue:value,indeterminate:intermediate,onChange:onChange})
}
const setVrData = (list:{{$.table.ClassName}}TableColumns[])=>{
const _columns:any[] = [
{key: 'selection',dataKey: '{{.table.PkColumn.HtmlField}}',title: ``,width:80,
{{if .table.PkColumn.IsFixed}}fixed: TableV2FixedDir.LEFT,{{end}}
headerCellRenderer:()=>{
let _data = unref(dataList.value)
const onChange = (value: CheckboxValueType) =>{
_data = _data.map((row:any) => {
row.checked = value
return row
})
treeData.value = proxy.handleTree(_data||[], "{{$treeCode}}", "{{$treeParentCode}}")
state.{{.table.PkColumn.HtmlField}}s = _data.map((item:any) => {
if(item.checked){
return item.{{.table.PkColumn.HtmlField}}
}
}).filter(item=>item!==undefined)
single.value = state.{{.table.PkColumn.HtmlField}}s.length!=1
multiple.value = !state.{{.table.PkColumn.HtmlField}}s.length
}
const allSelected = _data.every((row:any) => row.checked)
const containsChecked = _data.some((row:any) => row.checked)
return h(ElCheckbox,{value:allSelected,intermediate:containsChecked && !allSelected,onChange:onChange})
},
cellRenderer:({rowData: row})=>{
return h(SelectionCell, {value:row.checked,intermediate:false,onChange:(v:CheckboxValueType)=>{
row.checked=v
if(v){
state.{{.table.PkColumn.HtmlField}}s.push(row.{{.table.PkColumn.HtmlField}})
state.{{.table.PkColumn.HtmlField}}s = [...new Set(state.{{.table.PkColumn.HtmlField}}s)]
}else{
state.{{.table.PkColumn.HtmlField}}s = state.{{.table.PkColumn.HtmlField}}s.filter(item=>item!==row.{{.table.PkColumn.HtmlField}})
}
single.value = state.{{.table.PkColumn.HtmlField}}s.length!=1
multiple.value = !state.{{.table.PkColumn.HtmlField}}s.length
}
})
}
}
]
{{range $index, $column := .table.ListColumns}}
{{if $column.IsPk}}
_columns.push({key: '{{$column.HtmlField}}',dataKey: '{{$column.HtmlField}}',title: `{{$column.ColumnComment}}`,
{{if gt $column.MinWidth 0}}width:{{$column.MinWidth}},{{end}}
{{if $column.IsFixed}}fixed: TableV2FixedDir.LEFT,{{end}}
})
{{else if eq $column.HtmlType "date"}}
_columns.push({key: '{{$column.HtmlField}}',dataKey: '{{$column.HtmlField}}',title: `{{$column.ColumnComment}}`,
{{if gt $column.MinWidth 0}}width:{{$column.MinWidth}},{{end}}
{{if $column.IsFixed}}fixed: TableV2FixedDir.LEFT,{{end}}
cellRenderer: ({ cellData: {{$column.HtmlField}} }) => {
return h('span', proxy.parseTime({{$column.HtmlField}}, '{y}-{m}-{d}'));
}
})
{{else if eq $column.HtmlType "datetime"}}
_columns.push({key: '{{$column.HtmlField}}',dataKey: '{{$column.HtmlField}}',title: `{{$column.ColumnComment}}`,
{{if gt $column.MinWidth 0}}width:{{$column.MinWidth}},{{end}}
{{if $column.IsFixed}}fixed: TableV2FixedDir.LEFT,{{end}}
cellRenderer: ({ cellData: {{$column.HtmlField}} }) => {
return h('span', proxy.parseTime({{$column.HtmlField}}, '{y}-{m}-{d} {h}:{i}:{s}'));
}
})
{{else if eq $column.HtmlField "createdBy"}}
_columns.push({key: '{{$column.HtmlField}}',dataKey: '{{$column.HtmlField}}',title: `{{$column.ColumnComment}}`,
{{if gt $column.MinWidth 0}}width:{{$column.MinWidth}},{{end}}
{{if $column.IsFixed}}fixed: TableV2FixedDir.LEFT,{{end}}
})
{{else if eq $column.HtmlField "updatedBy"}}
_columns.push({key: '{{$column.HtmlField}}',dataKey: '{{$column.HtmlField}}',title: `{{$column.ColumnComment}}`,
{{if gt $column.MinWidth 0}}width:{{$column.MinWidth}},{{end}}
{{if $column.IsFixed}}fixed: TableV2FixedDir.LEFT,{{end}}
})
{{else if eq $column.HtmlType "imagefile"}}
_columns.push({key: '{{$column.HtmlField}}',dataKey: '{{$column.HtmlField}}',title: `{{$column.ColumnComment}}`,
{{if gt $column.MinWidth 0}}width:{{$column.MinWidth}},{{end}}
{{if $column.IsFixed}}fixed: TableV2FixedDir.LEFT,{{end}}
cellRenderer: ({cellData: {{$column.HtmlField}} }) => {
const children = []
if(!proxy.isEmpty({{$column.HtmlField}})){
children.push(h(ElImage,{fit:'contain',style:'width:50px;height:50px',src:proxy.getUpFileUrl({{$column.HtmlField}})}))
}
return ('div',children)
}
})
{{else if eq $column.HtmlType "selects" "checkbox" "treeSelects"}}
{{if ne $column.LinkTableName ""}}
_columns.push({key: '{{$column.HtmlField}}',dataKey: '{{$column.HtmlField}}',title: `{{$column.ColumnComment}}`,
{{if gt $column.MinWidth 0}}width:{{$column.MinWidth}},{{end}}
{{if $column.IsFixed}}fixed: TableV2FixedDir.LEFT,{{end}}
cellRenderer: ({cellData: {{$column.HtmlField}} }) => {
const children = []
if(linked{{$column.GoField}}){
linked{{$column.GoField}}.map(item=>{
children.push(h(ElTag,{class:"ml-2",type:'success'},[item.{{$column.LinkLabelName|CaseCamelLower}}]))
})
}
return ('div',children)
}
})
{{else if ne $column.DictType ""}}
_columns.push({key: '{{$column.HtmlField}}',dataKey: '{{$column.HtmlField}}',title: `{{$column.ColumnComment}}`,
{{if gt $column.MinWidth 0}}width:{{$column.MinWidth}},{{end}}
{{if $column.IsFixed}}fixed: TableV2FixedDir.LEFT,{{end}}
cellRenderer: ({rowData:row}) => {
return ('span',[{{$column.HtmlField}}Format(row)])
}
})
{{end}}
{{else if ne $column.LinkTableName ""}}
_columns.push({key: '{{$column.HtmlField}}',dataKey: 'linked{{$column.GoField}}.{{$column.LinkLabelName | CaseCamelLower}}',title: `{{$column.ColumnComment}}`,
{{if gt $column.MinWidth 0}}width:{{$column.MinWidth}},{{end}}
{{if $column.IsFixed}}fixed: TableV2FixedDir.LEFT,{{end}}
})
{{else if ne $column.DictType ""}}
_columns.push({key: '{{$column.HtmlField}}',dataKey: '{{$column.HtmlField}}',title: `{{$column.ColumnComment}}`,
{{if gt $column.MinWidth 0}}width:{{$column.MinWidth}},{{end}}
{{if $column.IsFixed}}fixed: TableV2FixedDir.LEFT,{{end}}
cellRenderer: ({rowData:row}) => {
return ('span',[{{$column.HtmlField}}Format(row)])
}
})
{{else if ne $column.HtmlField ""}}
_columns.push({key: '{{$column.HtmlField}}',dataKey: '{{$column.HtmlField}}',title: `{{$column.ColumnComment}}`,
{{if gt $column.MinWidth 0}}width:{{$column.MinWidth}},{{end}}
{{if $column.IsFixed}}fixed: TableV2FixedDir.LEFT,{{end}}
})
{{end}}
{{end}}
_columns.push({key: 'operations',dataKey: '{{$.table.PkColumn.HtmlField}}',title: `操作`,width:200,fixed: TableV2FixedDir.RIGHT,
cellRenderer: ({rowData:row,cellData:{{$.table.PkColumn.HtmlField}}}) => {
return h('div',{class:'tb-operations'},[
h(ElLink, { type: 'primary',underline:false, onClick: () => { handleView(row) } },
() => [
h(ElIcon, () => [h(View)]),
'详情'
],
),
h(ElLink, { type: 'primary',underline:false, onClick: () => { handleUpdate(row) } },
() => [
h(ElIcon, () => [h(EditPen)]),
'修改'
],
),
h(ElLink, { type: 'primary',underline:false, onClick: () => { handleDelete(row) } },
() => [
h(ElIcon, () => [h(DeleteFilled)]),
'删除'
],
)
])
}
})
columns.value = _columns
treeData.value = list
}
//=============================================================================================================
const expandColumnKey = '{{$firstColumn.HtmlField}}'
const expandedRowKeys = ref<string[]>([])
const onRowExpanded = (exp: Parameters<RowExpandHandler<any>>[0]) => {
console.log('Expanded:', exp)
}
const onExpandedRowsChange = (
expandedKeys: Parameters<ExpandedRowsChangeHandler>[0]
) => {
console.log('expandedKeys:',expandedKeys)
}
return {
proxy,
editRef,
detailRef,
showAll,
loading,
single,
multiple,
word,
queryRef,
resetQuery,
{{$businessName}}List,
toggleSearch,
{{range $index, $column := .table.Columns}}
{{if ne $column.DictType ""}}
{{$column.HtmlField}}Format,
{{$column.DictType}},
{{end}}
{{if ne $column.LinkTableName ""}}
{{if $column.IsCascade}}
//级联关联{{$column.LinkTableName}}表选项
{{else}}
//关联表数据选项
{{$column.HtmlField}}Options,
//关联{{$column.LinkTableName}}表选项获取数据方法
{{end}}
{{end}}
{{end}}
handleSelectionChange,
handleAdd,
handleUpdate,
handleDelete,
{{if eq .table.ShowDetail "true"}}
handleView,
{{end}}
columns,
treeData,
expandedRowKeys,
onRowExpanded,
expandColumnKey,
onExpandedRowsChange,
...toRefs(state),
}
} }
}) })
// 字典选项数据
{{$dictArr:=newArray}}
{{range $index, $column := .table.Columns}}
{{if and (ne $column.DictType "") (ne (inArray $dictArr $column.DictType) true)}}
{{$dictArr = append $dictArr $column.DictType}}
{{end}}
{{end}}
const {
{{range $index, $column := $dictArr}}
{{$column}},
{{end}}
} = proxy.useDict(
{{range $index, $column := $dictArr}}
'{{$column}}',
{{end}}
)
{{range $index, $column := .table.Columns}}
{{if ne $column.LinkTableName ""}}
{{if $column.IsCascade }}
// {{$column.HtmlField}}QueryOptions关联表数据
const {{$column.HtmlField}}QueryOptions = ref<Array<ItemOptions>>([])
// {{$column.HtmlField}}FormOptions关联表数据
const {{$column.HtmlField}}FormOptions = ref<Array<ItemOptions>>([])
{{else}}
// {{$column.HtmlField}}Options关联表数据
const {{$column.HtmlField}}Options = ref<Array<ItemOptions>>([])
{{end}}
{{end}}
{{end}}
const dataList = ref<Array<{{$.table.ClassName}}TableColumns>>([])
const state = reactive<{{.table.ClassName}}TableDataState>({
{{.table.PkColumn.HtmlField}}s:[],
tableData: {
data: [],
total: 0,
loading: false,
param: {
pageNum: 1,
pageSize: 10,
{{range $index, $column := .table.QueryColumns}}
{{if eq $column.QueryType "BETWEEN"}}
{{$column.HtmlField}}: [],
{{else}}
{{$column.HtmlField}}: undefined,
{{end}}{{end}}
dateRange: []
},
},
});
const { tableData } = toRefs(state);
// 页面加载时
onMounted(() => {
initTableData();
});
// 初始化表格数据
const initTableData = () => {
{{if gt (len .table.LinkedTables) 0}}
linkedData()
{{end}}
{{$businessName}}List()
};
{{if gt (len .table.LinkedTables) 0}}
const linkedData = ()=>{
linkedDataSearch().then((res:any)=>{
{{range $index, $column := .table.Columns}}
{{if ne $column.LinkTableName ""}}
//关联{{$column.LinkTableName}}表选项
{{range $li,$lc := $.table.LinkedTables}}
{{if eq $lc.TableName $column.LinkTableName}}
{{if eq $lc.TplCategory "tree"}}
{{$column.HtmlField}}Options.value = proxy.handleTree(res.data.linked{{$.table.ClassName}}{{$column.LinkTableClass}}, '{{$lc.OptionsStruct.TreeCode}}', '{{$lc.OptionsStruct.TreeParentCode}}')
{{else}}
{{$column.HtmlField}}Options.value = proxy.setItems(res, '{{$column.LinkLabelId | CaseCamelLower}}', '{{$column.LinkLabelName | CaseCamelLower}}','linked{{$.table.ClassName}}{{$column.LinkTableClass}}')
{{end}}
{{end}}
{{end}}
{{end}}
{{end}}
})
}
{{end}}
/** 重置按钮操作 */
const resetQuery = (formEl: FormInstance | undefined) => {
if (!formEl) return
formEl.resetFields()
{{$businessName}}List()
};
// 获取列表数据
const {{$businessName}}List = ()=>{
loading.value = true
list{{.table.ClassName}}(state.tableData.param).then((res:any)=>{
let list = res.data.list??[];
{{range $index,$column := .table.ListColumns}}
{{if eq $column.HtmlField "createdBy" "updatedBy" "dept_id"}}
list.map((item:any)=>{
{{if eq $column.HtmlField "createdBy"}}
item.createdBy = item?.createdUser.userNickname
{{end}}
{{if eq $column.HtmlField "deptId"}}
item.deptId = item.deptInfo?.deptName
{{end}}
{{if eq $column.HtmlField "updatedBy"}}
item.updatedBy = item?.updatedUser.userNickname
{{end}}
})
{{end}}
{{end}}
if(list.length > 0 && typeof list[0].id == "undefined"){
list.map((item:any)=>{
item.id = item.{{.table.PkColumn.HtmlField}}
})
}
dataList.value = _.clone(res.data.list)
list = proxy.handleTree(res.data.list||[], "{{$treeCode}}", "{{$treeParentCode}}");
state.tableData.data = list;
loading.value = false
setVrData(list)
})
};
const toggleSearch = () => {
showAll.value = !showAll.value;
}
{{range $index, $column := .table.Columns}}
{{if ne $column.DictType ""}}
{{if eq $column.HtmlType "checkbox"}}
// {{$column.ColumnComment}}字典翻译
const {{$column.HtmlField}}Format = (row:{{$.table.ClassName}}TableColumns) => {
let {{$column.HtmlField}} = row.{{$column.HtmlField}}.split(",")
let data:Array<string> = [];
{{$column.HtmlField}}.map(item=>{
data.push(proxy.selectDictLabel({{$column.DictType}}.value, item))
})
return data.join(",")
}
{{else}}
// {{$column.ColumnComment}}字典翻译
const {{$column.HtmlField}}Format = (row:{{$.table.ClassName}}TableColumns) => {
return proxy.selectDictLabel({{$column.DictType}}.value, row.{{$column.HtmlField}});
}
{{end}}
{{end}}
{{end}}
// 多选框选中数据
const handleSelectionChange = (selection:Array<{{.table.ClassName}}InfoData>) => {
state.{{.table.PkColumn.HtmlField}}s = selection.map(item => item.{{.table.PkColumn.HtmlField}})
single.value = selection.length!=1
multiple.value = !selection.length
}
const handleAdd = ()=>{
editRef.value.openDialog()
}
const handleUpdate = (row: {{$.table.ClassName}}TableColumns|null) => {
if(!row){
row = dataList.value.find((item:{{$.table.ClassName}}TableColumns)=>{
return item.{{.table.PkColumn.HtmlField}} ===state.{{.table.PkColumn.HtmlField}}s[0]
}) as {{$.table.ClassName}}TableColumns
}
editRef.value.openDialog(toRaw(row));
};
const handleDelete = (row: {{$.table.ClassName}}TableColumns|null) => {
let msg = '你确定要删除所选数据?';
let {{.table.PkColumn.HtmlField}}:{{.table.PkColumn.TsType}}[] = [] ;
if(row){
msg = `此操作将永久删除数据,是否继续?`
{{.table.PkColumn.HtmlField}} = [row.{{.table.PkColumn.HtmlField}}]
}else{
{{.table.PkColumn.HtmlField}} = state.{{.table.PkColumn.HtmlField}}s
}
if({{.table.PkColumn.HtmlField}}.length===0){
ElMessage.error('请选择要删除的数据。');
return
}
ElMessageBox.confirm(msg, '提示', {
confirmButtonText: '确认',
cancelButtonText: '取消',
type: 'warning',
})
.then(() => {
del{{.table.ClassName}}({{.table.PkColumn.HtmlField}}).then(()=>{
ElMessage.success('删除成功');
{{$businessName}}List();
})
})
.catch(() => {});
}
const handleView = (row:{{$.table.ClassName}}TableColumns)=>{
detailRef.value.openDialog(toRaw(row));
}
//========================================================================================================
const columns = ref<Column[]>([])
const treeData = ref<any[]>([])
type SelectionCellProps = {
value: boolean
intermediate?: boolean
onChange: (value: CheckboxValueType) => void
}
const SelectionCell: FunctionalComponent<SelectionCellProps> = ({
value,
intermediate = false,
onChange,
}) => {
return h(ElCheckbox,{modelValue:value,indeterminate:intermediate,onChange:onChange})
}
const setVrData = (list:{{$.table.ClassName}}TableColumns[])=>{
const _columns:any[] = [
{key: 'selection',dataKey: '{{.table.PkColumn.HtmlField}}',title: ``,width:80,
{{if .table.PkColumn.IsFixed}}fixed: TableV2FixedDir.LEFT,{{end}}
headerCellRenderer:()=>{
let _data = unref(dataList.value)
const onChange = (value: CheckboxValueType) =>{
_data = _data.map((row:any) => {
row.checked = value
return row
})
treeData.value = proxy.handleTree(_data||[], "{{$treeCode}}", "{{$treeParentCode}}")
state.{{.table.PkColumn.HtmlField}}s = _data.map((item:any) => {
if(item.checked){
return item.{{.table.PkColumn.HtmlField}}
}
}).filter(item=>item!==undefined)
single.value = state.{{.table.PkColumn.HtmlField}}s.length!=1
multiple.value = !state.{{.table.PkColumn.HtmlField}}s.length
}
const allSelected = _data.every((row:any) => row.checked)
const containsChecked = _data.some((row:any) => row.checked)
return h(ElCheckbox,{value:allSelected,intermediate:containsChecked && !allSelected,onChange:onChange})
},
cellRenderer:({rowData: row})=>{
return h(SelectionCell, {value:row.checked,intermediate:false,onChange:(v:CheckboxValueType)=>{
row.checked=v
if(v){
state.{{.table.PkColumn.HtmlField}}s.push(row.{{.table.PkColumn.HtmlField}})
state.{{.table.PkColumn.HtmlField}}s = [...new Set(state.{{.table.PkColumn.HtmlField}}s)]
}else{
state.{{.table.PkColumn.HtmlField}}s = state.{{.table.PkColumn.HtmlField}}s.filter(item=>item!==row.{{.table.PkColumn.HtmlField}})
}
single.value = state.{{.table.PkColumn.HtmlField}}s.length!=1
multiple.value = !state.{{.table.PkColumn.HtmlField}}s.length
}
})
}
}
]
{{range $index, $column := .table.ListColumns}}
{{if $column.IsPk}}
_columns.push({key: '{{$column.HtmlField}}',dataKey: '{{$column.HtmlField}}',title: `{{$column.ColumnComment}}`,
{{if gt $column.MinWidth 0}}width:{{$column.MinWidth}},{{end}}
{{if $column.IsFixed}}fixed: TableV2FixedDir.LEFT,{{end}}
})
{{else if eq $column.HtmlType "date"}}
_columns.push({key: '{{$column.HtmlField}}',dataKey: '{{$column.HtmlField}}',title: `{{$column.ColumnComment}}`,
{{if gt $column.MinWidth 0}}width:{{$column.MinWidth}},{{end}}
{{if $column.IsFixed}}fixed: TableV2FixedDir.LEFT,{{end}}
cellRenderer: ({ cellData: {{$column.HtmlField}} }) => {
return h('span', proxy.parseTime({{$column.HtmlField}}, '{y}-{m}-{d}'));
}
})
{{else if eq $column.HtmlType "datetime"}}
_columns.push({key: '{{$column.HtmlField}}',dataKey: '{{$column.HtmlField}}',title: `{{$column.ColumnComment}}`,
{{if gt $column.MinWidth 0}}width:{{$column.MinWidth}},{{end}}
{{if $column.IsFixed}}fixed: TableV2FixedDir.LEFT,{{end}}
cellRenderer: ({ cellData: {{$column.HtmlField}} }) => {
return h('span', proxy.parseTime({{$column.HtmlField}}, '{y}-{m}-{d} {h}:{i}:{s}'));
}
})
{{else if eq $column.HtmlField "createdBy"}}
_columns.push({key: '{{$column.HtmlField}}',dataKey: '{{$column.HtmlField}}',title: `{{$column.ColumnComment}}`,
{{if gt $column.MinWidth 0}}width:{{$column.MinWidth}},{{end}}
{{if $column.IsFixed}}fixed: TableV2FixedDir.LEFT,{{end}}
})
{{else if eq $column.HtmlField "updatedBy"}}
_columns.push({key: '{{$column.HtmlField}}',dataKey: '{{$column.HtmlField}}',title: `{{$column.ColumnComment}}`,
{{if gt $column.MinWidth 0}}width:{{$column.MinWidth}},{{end}}
{{if $column.IsFixed}}fixed: TableV2FixedDir.LEFT,{{end}}
})
{{else if eq $column.HtmlType "imagefile"}}
_columns.push({key: '{{$column.HtmlField}}',dataKey: '{{$column.HtmlField}}',title: `{{$column.ColumnComment}}`,
{{if gt $column.MinWidth 0}}width:{{$column.MinWidth}},{{end}}
{{if $column.IsFixed}}fixed: TableV2FixedDir.LEFT,{{end}}
cellRenderer: ({cellData: {{$column.HtmlField}} }) => {
const children = []
if(!proxy.isEmpty({{$column.HtmlField}})){
children.push(h(ElImage,{fit:'contain',style:'width:50px;height:50px',src:proxy.getUpFileUrl({{$column.HtmlField}})}))
}
return ('div',children)
}
})
{{else if eq $column.HtmlType "selects" "checkbox" "treeSelects"}}
{{if ne $column.LinkTableName ""}}
_columns.push({key: '{{$column.HtmlField}}',dataKey: '{{$column.HtmlField}}',title: `{{$column.ColumnComment}}`,
{{if gt $column.MinWidth 0}}width:{{$column.MinWidth}},{{end}}
{{if $column.IsFixed}}fixed: TableV2FixedDir.LEFT,{{end}}
cellRenderer: ({cellData: {{$column.HtmlField}} }) => {
const children = []
if(linked{{$column.GoField}}){
linked{{$column.GoField}}.map(item=>{
children.push(h(ElTag,{class:"ml-2",type:'success'},[item.{{$column.LinkLabelName|CaseCamelLower}}]))
})
}
return ('div',children)
}
})
{{else if ne $column.DictType ""}}
_columns.push({key: '{{$column.HtmlField}}',dataKey: '{{$column.HtmlField}}',title: `{{$column.ColumnComment}}`,
{{if gt $column.MinWidth 0}}width:{{$column.MinWidth}},{{end}}
{{if $column.IsFixed}}fixed: TableV2FixedDir.LEFT,{{end}}
cellRenderer: ({rowData:row}) => {
return ('span',[{{$column.HtmlField}}Format(row)])
}
})
{{end}}
{{else if ne $column.LinkTableName ""}}
_columns.push({key: '{{$column.HtmlField}}',dataKey: 'linked{{$column.GoField}}.{{$column.LinkLabelName | CaseCamelLower}}',title: `{{$column.ColumnComment}}`,
{{if gt $column.MinWidth 0}}width:{{$column.MinWidth}},{{end}}
{{if $column.IsFixed}}fixed: TableV2FixedDir.LEFT,{{end}}
})
{{else if ne $column.DictType ""}}
_columns.push({key: '{{$column.HtmlField}}',dataKey: '{{$column.HtmlField}}',title: `{{$column.ColumnComment}}`,
{{if gt $column.MinWidth 0}}width:{{$column.MinWidth}},{{end}}
{{if $column.IsFixed}}fixed: TableV2FixedDir.LEFT,{{end}}
cellRenderer: ({rowData:row}) => {
return ('span',[{{$column.HtmlField}}Format(row)])
}
})
{{else if ne $column.HtmlField ""}}
_columns.push({key: '{{$column.HtmlField}}',dataKey: '{{$column.HtmlField}}',title: `{{$column.ColumnComment}}`,
{{if gt $column.MinWidth 0}}width:{{$column.MinWidth}},{{end}}
{{if $column.IsFixed}}fixed: TableV2FixedDir.LEFT,{{end}}
})
{{end}}
{{end}}
_columns.push({key: 'operations',dataKey: '{{$.table.PkColumn.HtmlField}}',title: `操作`,width:200,fixed: TableV2FixedDir.RIGHT,
cellRenderer: ({rowData:row,cellData:{{$.table.PkColumn.HtmlField}}}) => {
return h('div',{class:'tb-operations'},[
h(ElLink, { type: 'primary',underline:false, onClick: () => { handleView(row) } },
() => [
h(ElIcon, () => [h(View)]),
'详情'
],
),
h(ElLink, { type: 'primary',underline:false, onClick: () => { handleUpdate(row) } },
() => [
h(ElIcon, () => [h(EditPen)]),
'修改'
],
),
h(ElLink, { type: 'primary',underline:false, onClick: () => { handleDelete(row) } },
() => [
h(ElIcon, () => [h(DeleteFilled)]),
'删除'
],
)
])
}
})
columns.value = _columns
treeData.value = list
}
//=============================================================================================================
const expandColumnKey = '{{$firstColumn.HtmlField}}'
const expandedRowKeys = ref<string[]>([])
const onRowExpanded = (exp: Parameters<RowExpandHandler<any>>[0]) => {
console.log('Expanded:', exp)
}
const onExpandedRowsChange = (
expandedKeys: Parameters<ExpandedRowsChangeHandler>[0]
) => {
console.log('expandedKeys:',expandedKeys)
}
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.colBlock { .colBlock {

View File

@ -393,7 +393,7 @@
</div> </div>
</template> </template>
<script lang="ts"> <script setup lang="ts">
{{$tokenImp := false}} {{$tokenImp := false}}
{{$imgsImp := false}} {{$imgsImp := false}}
@ -446,252 +446,208 @@ 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'
export default defineComponent({ defineOptions({ name: "{{.apiVersion|replace "/" "_"|CaseCamelLower}}{{.modulePath|replace "/" "_"|CaseCamel}}{{.table.ClassName}}List"})
name: "{{.apiVersion|replace "/" "_"|CaseCamelLower}}{{.modulePath|replace "/" "_"|CaseCamel}}{{.table.ClassName}}List", const {proxy} = <any>getCurrentInstance()
components:{ const loading = ref(false)
{{.apiVersion|replace "/" "_"|CaseCamel}}{{.modulePath|replace "/" "_"|CaseCamel}}{{.table.ClassName}}Edit, const queryRef = ref()
{{.apiVersion|replace "/" "_"|CaseCamel}}{{.modulePath|replace "/" "_"|CaseCamel}}{{.table.ClassName}}Detail const editRef = ref();
}, const detailRef = ref();
setup() { // 是否显示所有搜索选项
const {proxy} = <any>getCurrentInstance() const showAll = ref(false)
const loading = ref(false) // 非单个禁用
const queryRef = ref() const single = ref(true)
const editRef = ref(); // 非多个禁用
const detailRef = ref(); const multiple =ref(true)
// 是否显示所有搜索选项 const word = computed(()=>{
const showAll = ref(false) if(showAll.value === false) {
// 非单个禁用 //对文字进行处理
const single = ref(true) return "展开搜索";
// 非多个禁用 } else {
const multiple =ref(true) return "收起搜索";
const word = computed(()=>{
if(showAll.value === false) {
//对文字进行处理
return "展开搜索";
} else {
return "收起搜索";
}
})
// 字典选项数据
{{$dictArr:=newArray}}
{{range $index, $column := .table.Columns}}
{{if and (ne $column.DictType "") (ne (inArray $dictArr $column.DictType) true)}}
{{$dictArr = append $dictArr $column.DictType}}
{{end}}
{{end}}
const {
{{range $index, $column := $dictArr}}
{{$column}},
{{end}}
} = proxy.useDict(
{{range $index, $column := $dictArr}}
'{{$column}}',
{{end}}
)
{{range $index, $column := .table.Columns}}
{{if ne $column.LinkTableName ""}}
{{if $column.IsCascade }}
// {{$column.HtmlField}}QueryOptions关联表数据
const {{$column.HtmlField}}QueryOptions = ref<Array<ItemOptions>>([])
// {{$column.HtmlField}}FormOptions关联表数据
const {{$column.HtmlField}}FormOptions = ref<Array<ItemOptions>>([])
{{else}}
// {{$column.HtmlField}}Options关联表数据
const {{$column.HtmlField}}Options = ref<Array<ItemOptions>>([])
{{end}}
{{end}}
{{end}}
const dataList = ref<Array<{{$.table.ClassName}}TableColumns>>([])
const state = reactive<{{.table.ClassName}}TableDataState>({
{{.table.PkColumn.HtmlField}}s:[],
tableData: {
data: [],
total: 0,
loading: false,
param: {
pageNum: 1,
pageSize: 10,
{{range $index, $column := .table.QueryColumns}}
{{if eq $column.QueryType "BETWEEN"}}
{{$column.HtmlField}}: [],
{{else}}
{{$column.HtmlField}}: undefined,
{{end}}{{end}}
dateRange: []
},
},
});
// 页面加载时
onMounted(() => {
initTableData();
});
// 初始化表格数据
const initTableData = () => {
{{if gt (len .table.LinkedTables) 0}}
linkedData()
{{end}}
{{$businessName}}List()
};
{{if gt (len .table.LinkedTables) 0}}
const linkedData = ()=>{
linkedDataSearch().then((res:any)=>{
{{range $index, $column := .table.Columns}}
{{if ne $column.LinkTableName ""}}
//关联{{$column.LinkTableName}}表选项
{{range $li,$lc := $.table.LinkedTables}}
{{if eq $lc.TableName $column.LinkTableName}}
{{if eq $lc.TplCategory "tree"}}
{{$column.HtmlField}}Options.value = proxy.handleTree(res.data.linked{{$.table.ClassName}}{{$column.LinkTableClass}}, '{{$lc.OptionsStruct.TreeCode}}', '{{$lc.OptionsStruct.TreeParentCode}}')
{{else}}
{{$column.HtmlField}}Options.value = proxy.setItems(res, '{{$column.LinkLabelId | CaseCamelLower}}', '{{$column.LinkLabelName | CaseCamelLower}}','linked{{$.table.ClassName}}{{$column.LinkTableClass}}')
{{end}}
{{end}}
{{end}}
{{end}}
{{end}}
})
}
{{end}}
/** 重置按钮操作 */
const resetQuery = (formEl: FormInstance | undefined) => {
if (!formEl) return
formEl.resetFields()
{{$businessName}}List()
};
// 获取列表数据
const {{$businessName}}List = ()=>{
loading.value = true
list{{.table.ClassName}}(state.tableData.param).then((res:any)=>{
let list = res.data.list??[];
{{range $index,$column := .table.ListColumns}}
{{if eq $column.HtmlField "createdBy" "updatedBy" "deptId"}}
list.map((item:any)=>{
{{if eq $column.HtmlField "createdBy"}}
item.createdBy = item?.createdUser.userNickname
{{end}}
{{if eq $column.HtmlField "deptId"}}
item.deptId = item.deptInfo?.deptName
{{end}}
{{if eq $column.HtmlField "updatedBy"}}
item.updatedBy = item?.updatedUser.userNickname
{{end}}
})
{{end}}
{{end}}
dataList.value = _.clone(res.data.list)
list = proxy.handleTree(res.data.list||[], "{{$treeCode}}", "{{$treeParentCode}}");
state.tableData.data = list;
loading.value = false
})
};
const toggleSearch = () => {
showAll.value = !showAll.value;
}
{{range $index, $column := .table.Columns}}
{{if ne $column.DictType ""}}
{{if eq $column.HtmlType "checkbox"}}
// {{$column.ColumnComment}}字典翻译
const {{$column.HtmlField}}Format = (row:{{$.table.ClassName}}TableColumns) => {
let {{$column.HtmlField}} = row.{{$column.HtmlField}}.split(",")
let data:Array<string> = [];
{{$column.HtmlField}}.map(item=>{
data.push(proxy.selectDictLabel({{$column.DictType}}.value, item))
})
return data.join(",")
}
{{else}}
// {{$column.ColumnComment}}字典翻译
const {{$column.HtmlField}}Format = (row:{{$.table.ClassName}}TableColumns) => {
return proxy.selectDictLabel({{$column.DictType}}.value, row.{{$column.HtmlField}});
}
{{end}}
{{end}}
{{end}}
// 多选框选中数据
const handleSelectionChange = (selection:Array<{{.table.ClassName}}InfoData>) => {
state.{{.table.PkColumn.HtmlField}}s = selection.map(item => item.{{.table.PkColumn.HtmlField}})
single.value = selection.length!=1
multiple.value = !selection.length
}
const handleAdd = ()=>{
editRef.value.openDialog()
}
const handleUpdate = (row: {{$.table.ClassName}}TableColumns) => {
if(!row){
row = dataList.value.find((item:{{$.table.ClassName}}TableColumns)=>{
return item.{{.table.PkColumn.HtmlField}} ===state.{{.table.PkColumn.HtmlField}}s[0]
}) as {{$.table.ClassName}}TableColumns
}
editRef.value.openDialog(toRaw(row));
};
const handleDelete = (row: {{$.table.ClassName}}TableColumns) => {
let msg = '你确定要删除所选数据?';
let {{.table.PkColumn.HtmlField}}:number[] = [] ;
if(row){
msg = `此操作将永久删除数据,是否继续?`
{{.table.PkColumn.HtmlField}} = [row.{{.table.PkColumn.HtmlField}}]
}else{
{{.table.PkColumn.HtmlField}} = state.{{.table.PkColumn.HtmlField}}s
}
if({{.table.PkColumn.HtmlField}}.length===0){
ElMessage.error('请选择要删除的数据。');
return
}
ElMessageBox.confirm(msg, '提示', {
confirmButtonText: '确认',
cancelButtonText: '取消',
type: 'warning',
})
.then(() => {
del{{.table.ClassName}}({{.table.PkColumn.HtmlField}}).then(()=>{
ElMessage.success('删除成功');
{{$businessName}}List();
})
})
.catch(() => {});
}
const handleView = (row:{{$.table.ClassName}}TableColumns)=>{
detailRef.value.openDialog(toRaw(row));
}
return {
proxy,
editRef,
detailRef,
showAll,
loading,
single,
multiple,
word,
queryRef,
resetQuery,
{{$businessName}}List,
toggleSearch,
{{range $index, $column := .table.Columns}}
{{if ne $column.DictType ""}}
{{$column.HtmlField}}Format,
{{$column.DictType}},
{{end}}
{{if ne $column.LinkTableName ""}}
{{if $column.IsCascade}}
//级联关联{{$column.LinkTableName}}表选项
{{else}}
//关联表数据选项
{{$column.HtmlField}}Options,
//关联{{$column.LinkTableName}}表选项获取数据方法
{{end}}
{{end}}
{{end}}
handleSelectionChange,
handleAdd,
handleUpdate,
handleDelete,
{{if eq .table.ShowDetail "true"}}
handleView,
{{end}}
...toRefs(state),
}
} }
}) })
// 字典选项数据
{{$dictArr:=newArray}}
{{range $index, $column := .table.Columns}}
{{if and (ne $column.DictType "") (ne (inArray $dictArr $column.DictType) true)}}
{{$dictArr = append $dictArr $column.DictType}}
{{end}}
{{end}}
const {
{{range $index, $column := $dictArr}}
{{$column}},
{{end}}
} = proxy.useDict(
{{range $index, $column := $dictArr}}
'{{$column}}',
{{end}}
)
{{range $index, $column := .table.Columns}}
{{if ne $column.LinkTableName ""}}
{{if $column.IsCascade }}
// {{$column.HtmlField}}QueryOptions关联表数据
const {{$column.HtmlField}}QueryOptions = ref<Array<ItemOptions>>([])
// {{$column.HtmlField}}FormOptions关联表数据
const {{$column.HtmlField}}FormOptions = ref<Array<ItemOptions>>([])
{{else}}
// {{$column.HtmlField}}Options关联表数据
const {{$column.HtmlField}}Options = ref<Array<ItemOptions>>([])
{{end}}
{{end}}
{{end}}
const dataList = ref<Array<{{$.table.ClassName}}TableColumns>>([])
const state = reactive<{{.table.ClassName}}TableDataState>({
{{.table.PkColumn.HtmlField}}s:[],
tableData: {
data: [],
total: 0,
loading: false,
param: {
pageNum: 1,
pageSize: 10,
{{range $index, $column := .table.QueryColumns}}
{{if eq $column.QueryType "BETWEEN"}}
{{$column.HtmlField}}: [],
{{else}}
{{$column.HtmlField}}: undefined,
{{end}}{{end}}
dateRange: []
},
},
});
const { tableData } = toRefs(state);
// 页面加载时
onMounted(() => {
initTableData();
});
// 初始化表格数据
const initTableData = () => {
{{if gt (len .table.LinkedTables) 0}}
linkedData()
{{end}}
{{$businessName}}List()
};
{{if gt (len .table.LinkedTables) 0}}
const linkedData = ()=>{
linkedDataSearch().then((res:any)=>{
{{range $index, $column := .table.Columns}}
{{if ne $column.LinkTableName ""}}
//关联{{$column.LinkTableName}}表选项
{{range $li,$lc := $.table.LinkedTables}}
{{if eq $lc.TableName $column.LinkTableName}}
{{if eq $lc.TplCategory "tree"}}
{{$column.HtmlField}}Options.value = proxy.handleTree(res.data.linked{{$.table.ClassName}}{{$column.LinkTableClass}}, '{{$lc.OptionsStruct.TreeCode}}', '{{$lc.OptionsStruct.TreeParentCode}}')
{{else}}
{{$column.HtmlField}}Options.value = proxy.setItems(res, '{{$column.LinkLabelId | CaseCamelLower}}', '{{$column.LinkLabelName | CaseCamelLower}}','linked{{$.table.ClassName}}{{$column.LinkTableClass}}')
{{end}}
{{end}}
{{end}}
{{end}}
{{end}}
})
}
{{end}}
/** 重置按钮操作 */
const resetQuery = (formEl: FormInstance | undefined) => {
if (!formEl) return
formEl.resetFields()
{{$businessName}}List()
};
// 获取列表数据
const {{$businessName}}List = ()=>{
loading.value = true
list{{.table.ClassName}}(state.tableData.param).then((res:any)=>{
let list = res.data.list??[];
{{range $index,$column := .table.ListColumns}}
{{if eq $column.HtmlField "createdBy" "updatedBy" "deptId"}}
list.map((item:any)=>{
{{if eq $column.HtmlField "createdBy"}}
item.createdBy = item?.createdUser.userNickname
{{end}}
{{if eq $column.HtmlField "deptId"}}
item.deptId = item.deptInfo?.deptName
{{end}}
{{if eq $column.HtmlField "updatedBy"}}
item.updatedBy = item?.updatedUser.userNickname
{{end}}
})
{{end}}
{{end}}
dataList.value = _.clone(res.data.list)
list = proxy.handleTree(res.data.list||[], "{{$treeCode}}", "{{$treeParentCode}}");
state.tableData.data = list;
loading.value = false
})
};
const toggleSearch = () => {
showAll.value = !showAll.value;
}
{{range $index, $column := .table.Columns}}
{{if ne $column.DictType ""}}
{{if eq $column.HtmlType "checkbox"}}
// {{$column.ColumnComment}}字典翻译
const {{$column.HtmlField}}Format = (row:{{$.table.ClassName}}TableColumns) => {
let {{$column.HtmlField}} = row.{{$column.HtmlField}}.split(",")
let data:Array<string> = [];
{{$column.HtmlField}}.map(item=>{
data.push(proxy.selectDictLabel({{$column.DictType}}.value, item))
})
return data.join(",")
}
{{else}}
// {{$column.ColumnComment}}字典翻译
const {{$column.HtmlField}}Format = (row:{{$.table.ClassName}}TableColumns) => {
return proxy.selectDictLabel({{$column.DictType}}.value, row.{{$column.HtmlField}});
}
{{end}}
{{end}}
{{end}}
// 多选框选中数据
const handleSelectionChange = (selection:Array<{{.table.ClassName}}InfoData>) => {
state.{{.table.PkColumn.HtmlField}}s = selection.map(item => item.{{.table.PkColumn.HtmlField}})
single.value = selection.length!=1
multiple.value = !selection.length
}
const handleAdd = ()=>{
editRef.value.openDialog()
}
const handleUpdate = (row: {{$.table.ClassName}}TableColumns) => {
if(!row){
row = dataList.value.find((item:{{$.table.ClassName}}TableColumns)=>{
return item.{{.table.PkColumn.HtmlField}} ===state.{{.table.PkColumn.HtmlField}}s[0]
}) as {{$.table.ClassName}}TableColumns
}
editRef.value.openDialog(toRaw(row));
};
const handleDelete = (row: {{$.table.ClassName}}TableColumns) => {
let msg = '你确定要删除所选数据?';
let {{.table.PkColumn.HtmlField}}:number[] = [] ;
if(row){
msg = `此操作将永久删除数据,是否继续?`
{{.table.PkColumn.HtmlField}} = [row.{{.table.PkColumn.HtmlField}}]
}else{
{{.table.PkColumn.HtmlField}} = state.{{.table.PkColumn.HtmlField}}s
}
if({{.table.PkColumn.HtmlField}}.length===0){
ElMessage.error('请选择要删除的数据。');
return
}
ElMessageBox.confirm(msg, '提示', {
confirmButtonText: '确认',
cancelButtonText: '取消',
type: 'warning',
})
.then(() => {
del{{.table.ClassName}}({{.table.PkColumn.HtmlField}}).then(()=>{
ElMessage.success('删除成功');
{{$businessName}}List();
})
})
.catch(() => {});
}
const handleView = (row:{{$.table.ClassName}}TableColumns)=>{
detailRef.value.openDialog(toRaw(row));
}
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.colBlock { .colBlock {