fix 代码生成-卡关字段功能

This commit is contained in:
yxh 2024-09-30 16:24:56 +08:00
parent 9008192ef5
commit 00428f540b
12 changed files with 162 additions and 15 deletions

View File

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

View File

@ -134,3 +134,19 @@ type {{.table.ClassName}}DeleteReq struct {
type {{.table.ClassName}}DeleteRes struct {
commonApi.EmptyRes
}
{{range $index,$column:= .table.Columns}}
{{if eq $column.HtmlType "switch"}}
// {{$.table.FunctionName}}{{$column.ColumnComment}}修改(状态)
type {{$column.GoField}}SwitchReq struct {
g.Meta `path:"/change{{$column.GoField}}" tags:"{{$.table.FunctionName}}" method:"put" summary:"修改{{$column.ColumnComment}}"`
commonApi.Author
{{$.table.PkColumn.GoField}} {{$.table.PkColumn.GoType}} `p:"{{$.table.PkColumn.HtmlField}}" v:"required#主键必须"` //通过主键修改
{{$column.GoField}} {{$column.GoType}} `p:"{{$column.HtmlField}}" v:"required#状态必须"` //通过主键获取
}
type {{$column.GoField}}SwitchRes struct {
commonApi.EmptyRes
}
{{end}}
{{end}}

View File

@ -19,6 +19,10 @@ package controller
{{$hasSystemApi:=false}}
{{$hasCommonService:=false}}
{{$excel :=false}}
{{$serviceVal := "service"}}
{{if ne .table.ModuleName "system"}}
{{$serviceVal = "systemService"}}
{{end}}
{{if or .table.ExcelPort .table.ExcelImp}}
{{$excel = true}}
{{end}}
@ -320,10 +324,6 @@ func(c *{{$structName}}Controller)Import(ctx context.Context,req *{{.table.Modul
{{if gt (len .table.LinkedTables) 0}}
// Linked{{$.table.ClassName}}DataSearch 相关连表查询数据
func(c *{{$structName}}Controller) Linked{{$.table.ClassName}}DataSearch(ctx context.Context, req *{{.table.ModuleName}}.Linked{{$.table.ClassName}}DataSearchReq) (res *{{.table.ModuleName}}.Linked{{$.table.ClassName}}DataSearchRes, err error) {
{{$serviceVal := "service"}}
{{if ne $.table.ModuleName "system"}}
{{$serviceVal = "systemService"}}
{{end}}
if !{{$serviceVal}}.SysUser().AccessRule(ctx, {{$serviceVal}}.Context().GetUserId(ctx), "{{.apiVersion}}/{{.modulePath}}/{{.table.BusinessName | CaseCamelLower}}/list") {
err = errors.New("没有访问权限")
return
@ -363,3 +363,16 @@ func (c *{{$structName}}Controller) Delete(ctx context.Context, req *{{.table.Mo
return
}
{{range $index,$column:= .table.Columns}}
{{if eq $column.HtmlType "switch"}}
// {{$.table.FunctionName}}{{$column.ColumnComment}}修改(状态)
func(c *{{$structName}}Controller)Change{{$column.GoField}}(ctx context.Context, req *{{$.table.ModuleName}}.{{$column.GoField}}SwitchReq)(res *{{$.table.ModuleName}}.{{$column.GoField}}SwitchRes,err error){
if !{{$serviceVal}}.SysUser().AccessRule(ctx, {{$serviceVal}}.Context().GetUserId(ctx), "{{$.apiVersion}}/{{$.modulePath}}/{{$.table.BusinessName | CaseCamelLower}}/edit") {
err = errors.New("没有修改权限")
return
}
err = service.{{$.table.ClassName}}().Change{{$column.GoField}}(ctx,req.{{$.table.PkColumn.GoField}},req.{{$column.GoField}})
return
}
{{end}}
{{end}}

View File

@ -613,4 +613,20 @@ func (s *s{{$.table.ClassName}}) List{{$.table.ClassName}}{{$column.ClassName}}(
////
{{end}}
{{end}}
{{end}}
{{range $index,$column:= .table.Columns}}
{{if eq $column.HtmlType "switch"}}
// {{$.table.FunctionName}}{{$column.ColumnComment}}修改(状态)
func (s *s{{$.table.ClassName}}) Change{{$column.GoField}} (ctx context.Context,{{$.table.PkColumn.HtmlField}} {{$.table.PkColumn.GoType}},{{$column.HtmlField}} {{$column.GoType}})(err error){
err = g.Try(ctx, func(ctx context.Context) {
_, err = dao.{{$.table.ClassName}}.Ctx(ctx).WherePri({{$.table.PkColumn.HtmlField}}).
Update(do.{{$.table.ClassName}}{
{{$column.GoField}}:{{$column.HtmlField}},
})
liberr.ErrIsNil(ctx, err, "修改失败")
})
return
}
{{end}}
{{end}}

View File

@ -46,6 +46,12 @@ type I{{.table.ClassName}} interface {
{{if gt (len .table.LinkedTables) 0}}
Linked{{$.table.ClassName}}DataSearch(ctx context.Context)(res *model.Linked{{$.table.ClassName}}DataSearchRes,err error)
{{end}}
{{range $index,$column:= .table.Columns}}
{{if eq $column.HtmlType "switch"}}
// {{$.table.FunctionName}}{{$column.ColumnComment}}修改(状态)
Change{{$column.GoField}} (ctx context.Context,{{$.table.PkColumn.HtmlField}} {{$.table.PkColumn.GoType}},{{$column.HtmlField}} {{$column.GoType}})(err error)
{{end}}
{{end}}
}
////

View File

@ -58,7 +58,7 @@ export function del{{.table.ClassName}}({{.table.PkColumn.HtmlField}}s:{{.table.
{{/*去重处理*/}}
{{$hasMethods:=newArray}}
{{range $index,$column:= .table.Columns}}
{{if and $column.IsStatus $column.IsList}}
{{if eq $column.HtmlType "switch"}}
// {{$.table.FunctionName}}{{$column.ColumnComment}}修改
export function change{{$.table.ClassName}}{{$column.GoField}}({{$.table.PkColumn.HtmlField}}:{{$.table.PkColumn.TsType}},{{$column.HtmlField}}:{{$column.TsType}}) {
const data = {

View File

@ -40,7 +40,7 @@ export interface {{.table.ClassName}}TableColumns {
////
export interface {{.table.ClassName}}InfoData {
{{range $index, $column := .table.Columns}}
{{if $column.IsPk}}{{$column.HtmlField}}:{{if eq $column.HtmlType "images" "file" "files" "checkbox" "selects" "treeSelects"}}any[]{{else if eq $column.HtmlType "radio"}}boolean{{else if eq $column.HtmlType "keyValue"}}{key:string,value:any}[]{{else}}{{$column.TsType}}|undefined{{end}}; // {{$column.ColumnComment}} {{else}}{{$column.HtmlField}}:{{if eq $column.HtmlType "images" "file" "files" "checkbox" "selects" "treeSelects"}}any[]{{else if eq $column.HtmlType "radio"}}boolean{{else if eq $column.HtmlType "keyValue"}}{key:string,value:any}[]{{else}}{{$column.TsType}}|undefined{{end}}; // {{$column.ColumnComment}} {{end}}
{{if $column.IsPk}}{{$column.HtmlField}}:{{if eq $column.HtmlType "images" "file" "files" "checkbox" "selects" "treeSelects"}}any[]{{else if eq $column.HtmlType "switch"}}boolean{{else if eq $column.HtmlType "keyValue"}}{key:string,value:any}[]{{else}}{{$column.TsType}}|undefined{{end}}; // {{$column.ColumnComment}} {{else}}{{$column.HtmlField}}:{{if eq $column.HtmlType "images" "file" "files" "checkbox" "selects" "treeSelects"}}any[]{{else if eq $column.HtmlType "switch"}}boolean{{else if eq $column.HtmlType "keyValue"}}{key:string,value:any}[]{{else}}{{$column.TsType}}|undefined{{end}}; // {{$column.ColumnComment}} {{end}}
{{range $ti, $linkedTable := $.table.LinkedTables}}
{{if eq $column.LinkTableClass $linkedTable.ClassName}}
linked{{$column.GoField}}?:Linked{{$.table.ClassName}}{{$linkedTable.ClassName}}{{if eq $column.HtmlType "checkbox" "selects" "treeSelects"}}[]{{end}}; // {{$column.ColumnComment}}

View File

@ -66,6 +66,15 @@
{{"{{"}} formData.{{$column.HtmlField}} {{"}}"}}
{{end}}
</el-descriptions-item>
{{else if eq $column.HtmlType "switch"}}
<el-descriptions-item :span="{{$column.ColSpan}}">
<template #label>
<div class="cell-item">
{{$column.ColumnComment}}
</div>
</template>
<el-switch v-model="formData.{{$column.HtmlField}}" class="ml-2" disabled />
</el-descriptions-item>
{{else if eq $column.HtmlType "date"}}
<el-descriptions-item :span="{{$column.ColSpan}}">
<template #label>

View File

@ -95,7 +95,11 @@
/>
</el-form-item>
{{end}}
{{else if eq $column.HtmlType "radio" }} {{/* else if eq $column.HtmlType "select" */}}
{{else if eq $column.HtmlType "switch"}}
<el-form-item label="{{$column.ColumnComment}}" prop="{{$column.HtmlField}}">
<el-switch v-model="formData.{{$column.HtmlField}}" class="ml-2" />
</el-form-item>
{{else if eq $column.HtmlType "radio" }}
{{if ne $column.LinkTableName ""}}
<el-form-item label="{{$column.ColumnComment}}" prop="{{$column.HtmlField}}">
<el-radio-group v-model="formData.{{$column.HtmlField}}">
@ -364,7 +368,7 @@ const state = reactive<{{.table.ClassName}}EditState>({
isShowDialog: false,
formData: {
{{range $index, $column := .table.Columns}}
{{if eq $column.HtmlType "radio"}}
{{if eq $column.HtmlType "switch"}}
{{$column.HtmlField}}: false ,
{{else if eq $column.HtmlType "images" "file" "files" "checkbox" "selects" "treeSelects"}}
{{$column.HtmlField}}: [] ,
@ -415,6 +419,8 @@ const openDialog = (row?: {{.table.ClassName}}InfoData) => {
{{else}}
data.{{$column.HtmlField}} = data.{{$column.HtmlField}}.split(",")
{{end}}
{{else if eq $column.HtmlType "switch"}}
data.{{$column.HtmlField}} = Boolean(data.{{$column.HtmlField}})
{{else if and (eq $column.HtmlType "radio" "select") (ne $column.DictType "")}}
{{if eq $column.TsType "boolean"}}
data.{{$column.HtmlField}} = data.{{$column.HtmlField}}?'1':'0'
@ -501,8 +507,10 @@ const onSubmit = () => {
const resetForm = ()=>{
state.formData = {
{{range $index, $column := .table.Columns}}
{{if eq $column.HtmlType "radio"}}
{{if eq $column.HtmlType "switch"}}
{{$column.HtmlField}}: false ,
{{else if eq $column.HtmlType "radio"}}
{{$column.HtmlField}}: '' ,
{{else if eq $column.HtmlType "images" "file" "files" "checkbox" "selects" "treeSelects"}}
{{$column.HtmlField}}: [] ,
{{else if eq $column.HtmlType "keyValue"}}

View File

@ -44,6 +44,12 @@
</el-form-item>
</el-col>
{{$colIndex = ($colIndex | plus 1)}}
{{else if eq $column.HtmlType "switch"}}
<el-col :span="8" {{if lt $colIndex 2}}class="colBlock"{{else}}:class="showAll ? 'colBlock' : 'colNone'"{{end}}>
<el-form-item label="{{$column.ColumnComment}}" prop="{{$column.HtmlField}}">
<el-switch v-model="tableData.param.{{$column.HtmlField}}" class="ml-2" />
</el-form-item>
</el-col>
{{else if and (eq $column.HtmlType "select" "radio" "checkbox" "selects") (ne $column.DictType "") }}
<el-col :span="8" {{if lt $colIndex 2}}class="colBlock"{{else}}:class="showAll ? 'colBlock' : 'colNone'"{{end}}>
<el-form-item label="{{$column.ColumnComment}}" prop="{{$column.HtmlField}}">
@ -289,6 +295,15 @@
fit="contain"></el-image>
</template>
</el-table-column>
{{else if eq $column.HtmlType "switch"}}
<el-table-column label="{{$column.ColumnComment}}" align="center" prop="{{$column.HtmlField}}"
{{if gt $column.MinWidth 0}}min-width="{{$column.MinWidth}}px"{{end}}
{{if $column.IsOverflowTooltip}}:show-overflow-tooltip="true"{{end}}
{{if $column.IsFixed}}fixed="left"{{end}}>
<template #default="scope">
<el-switch v-model="scope.row.{{$column.HtmlField}}" class="ml-2" @change="change{{$column.GoField}}(scope.row)"/>
</template>
</el-table-column>
{{else if eq $column.HtmlType "selects" "checkbox" "treeSelects"}}
{{if ne $column.LinkTableName ""}}
<el-table-column align="center" label="{{$column.ColumnComment}}" prop="linked{{$column.GoField}}"
@ -315,7 +330,7 @@
v-model="scope.row.{{$column.HtmlField}}"
:active-value="1"
:inactive-value="0"
@change="{{$column.HtmlField}}Change(scope.row)"
@change="change{{$column.GoField}}(scope.row)"
></el-switch>
</template>
</el-table-column>
@ -444,7 +459,7 @@ import {
add{{.table.ClassName}},
update{{.table.ClassName}},
{{range $index,$column:= .table.Columns}}
{{if and $column.IsStatus $column.IsList}}
{{if eq $column.HtmlType "switch"}}
change{{$.table.ClassName}}{{$column.GoField}},
{{end}}
{{end}}
@ -624,6 +639,16 @@ const {{$column.HtmlField}}Format = (row:{{$.table.ClassName}}TableColumns) => {
}
{{end}}
{{end}}
{{if eq $column.HtmlType "switch"}}
const change{{$column.GoField}} = (row:{{$.table.ClassName}}TableColumns) => {
change{{$.table.ClassName}}{{$column.GoField}}(row.{{$.table.PkColumn.HtmlField}},row.{{$column.HtmlField}})
.catch(()=>{
setTimeout(()=>{
row.{{$column.HtmlField}} = !row.{{$column.HtmlField}}
},300)
})
}
{{end}}
{{end}}
// 多选框选中数据
const handleSelectionChange = (selection:Array<{{.table.ClassName}}InfoData>) => {

View File

@ -49,6 +49,12 @@
</el-form-item>
</el-col>
{{$colIndex = ($colIndex | plus 1)}}
{{else if eq $column.HtmlType "switch"}}
<el-col :span="8" {{if lt $colIndex 2}}class="colBlock"{{else}}:class="showAll ? 'colBlock' : 'colNone'"{{end}}>
<el-form-item label="{{$column.ColumnComment}}" prop="{{$column.HtmlField}}">
<el-switch v-model="tableData.param.{{$column.HtmlField}}" class="ml-2" />
</el-form-item>
</el-col>
{{else if and (eq $column.HtmlType "select" "radio" "checkbox" "selects") (ne $column.DictType "") }}
<el-col :span="8" {{if lt $colIndex 2}}class="colBlock"{{else}}:class="showAll ? 'colBlock' : 'colNone'"{{end}}>
<el-form-item label="{{$column.ColumnComment}}" prop="{{$column.HtmlField}}">
@ -311,7 +317,7 @@
{{$hasImports:=newArray}}
import {ItemOptions} from "/@/api/items";
import {toRefs, reactive, onMounted, ref, defineComponent, computed,getCurrentInstance,toRaw,h,unref,FunctionalComponent} from 'vue';
import {ElMessageBox, ElMessage, FormInstance,RowExpandHandler,ExpandedRowsChangeHandler,TableV2FixedDir, Column, ElLink, ElIcon, ElCheckbox, CheckboxValueType,ElImage,ElTag} from 'element-plus';
import {ElMessageBox, ElMessage, FormInstance,RowExpandHandler,ExpandedRowsChangeHandler,TableV2FixedDir, Column, ElLink, ElIcon, ElCheckbox, CheckboxValueType,ElImage,ElTag,ElSwitch} from 'element-plus';
import { EditPen,View,DeleteFilled } from '@element-plus/icons-vue'
import {
list{{.table.ClassName}},
@ -320,7 +326,7 @@ import {
add{{.table.ClassName}},
update{{.table.ClassName}},
{{range $index,$column:= .table.Columns}}
{{if and $column.IsStatus $column.IsList}}
{{if eq $column.HtmlType "switch"}}
change{{$.table.ClassName}}{{$column.GoField}},
{{end}}
{{end}}
@ -500,6 +506,16 @@ const {{$column.HtmlField}}Format = (row:{{$.table.ClassName}}TableColumns) => {
}
{{end}}
{{end}}
{{if eq $column.HtmlType "switch"}}
const change{{$column.GoField}} = (row:{{$.table.ClassName}}TableColumns) => {
change{{$.table.ClassName}}{{$column.GoField}}(row.{{$.table.PkColumn.HtmlField}},row.{{$column.HtmlField}})
.catch(()=>{
setTimeout(()=>{
row.{{$column.HtmlField}} = !row.{{$column.HtmlField}}
},300)
})
}
{{end}}
{{end}}
// 多选框选中数据
const handleSelectionChange = (selection:Array<{{.table.ClassName}}InfoData>) => {
@ -648,6 +664,19 @@ const setVrData = (list:{{$.table.ClassName}}TableColumns[])=>{
return ('div',children)
}
})
{{else if eq $column.HtmlType "switch"}}
_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,cellData:{{$column.HtmlField}} }) => {
return h(ElSwitch,{modelValue:{{$column.HtmlField}},
'onUpdate:modelValue': (value) => {
// 更新数据
row.{{$column.HtmlField}} = value;
},
onClick: () => { change{{$column.GoField}}(row)}});
}
})
{{else if eq $column.HtmlType "selects" "checkbox" "treeSelects"}}
{{if ne $column.LinkTableName ""}}
_columns.push({key: '{{$column.HtmlField}}',dataKey: '{{$column.HtmlField}}',title: `{{$column.ColumnComment}}`,

View File

@ -47,6 +47,12 @@
</el-form-item>
</el-col>
{{$colIndex = ($colIndex | plus 1)}}
{{else if eq $column.HtmlType "switch"}}
<el-col :span="8" {{if lt $colIndex 2}}class="colBlock"{{else}}:class="showAll ? 'colBlock' : 'colNone'"{{end}}>
<el-form-item label="{{$column.ColumnComment}}" prop="{{$column.HtmlField}}">
<el-switch v-model="tableData.param.{{$column.HtmlField}}" class="ml-2" />
</el-form-item>
</el-col>
{{else if and (eq $column.HtmlType "select" "radio" "checkbox" "selects") (ne $column.DictType "") }}
<el-col :span="8" {{if lt $colIndex 2}}class="colBlock"{{else}}:class="showAll ? 'colBlock' : 'colNone'"{{end}}>
<el-form-item label="{{$column.ColumnComment}}" prop="{{$column.HtmlField}}">
@ -283,6 +289,15 @@
fit="contain"></el-image>
</template>
</el-table-column>
{{else if eq $column.HtmlType "switch"}}
<el-table-column label="{{$column.ColumnComment}}" align="center" prop="{{$column.HtmlField}}"
{{if gt $column.MinWidth 0}}min-width="{{$column.MinWidth}}px"{{end}}
{{if $column.IsOverflowTooltip}}:show-overflow-tooltip="true"{{end}}
{{if $column.IsFixed}}fixed="left"{{end}}>
<template #default="scope">
<el-switch v-model="scope.row.{{$column.HtmlField}}" class="ml-2" @change="change{{$column.GoField}}(scope.row)"/>
</template>
</el-table-column>
{{else if eq $column.HtmlType "selects" "checkbox" "treeSelects"}}
{{if ne $column.LinkTableName ""}}
<el-table-column align="center" label="{{$column.ColumnComment}}" prop="linked{{$column.GoField}}"
@ -427,7 +442,7 @@ import {
add{{.table.ClassName}},
update{{.table.ClassName}},
{{range $index,$column:= .table.Columns}}
{{if and $column.IsStatus $column.IsList}}
{{if eq $column.HtmlType "switch"}}
change{{$.table.ClassName}}{{$column.GoField}},
{{end}}
{{end}}
@ -601,6 +616,16 @@ const {{$column.HtmlField}}Format = (row:{{$.table.ClassName}}TableColumns) => {
}
{{end}}
{{end}}
{{if eq $column.HtmlType "switch"}}
const change{{$column.GoField}} = (row:{{$.table.ClassName}}TableColumns) => {
change{{$.table.ClassName}}{{$column.GoField}}(row.{{$.table.PkColumn.HtmlField}},row.{{$column.HtmlField}})
.catch(()=>{
setTimeout(()=>{
row.{{$column.HtmlField}} = !row.{{$column.HtmlField}}
},300)
})
}
{{end}}
{{end}}
// 多选框选中数据
const handleSelectionChange = (selection:Array<{{.table.ClassName}}InfoData>) => {