11{ {- $global := . } }
2- { {- $top := . -} }
32{ {- $templateID := printf " %s_%s" .Package .StructName } }
4-
53{ {- if .IsAdd } }
64
75// 请在搜索条件中增加如下代码
3533 { {- end } }
3634 { {- end } }
3735
36+ // 字典增加如下代码
37+ { {- range $index , $element := .DictTypes} }
38+ const { { $element } }Options = ref([])
39+ { {- end } }
40+
41+ // setOptions方法中增加如下调用
42+
43+ { {- range $index , $element := .DictTypes } }
44+ { { $element } }Options.value = await getDictFunc('{ {$element } }')
45+ { {- end } }
46+
47+ // 基础formData结构(变量处和关闭表单处)增加如下字段
48+ { {- range .Fields} }
49+ { {- if .Form} }
50+ { { GenerateDefaultFormValue . } }
51+ { {- end } }
52+ { {- end } }
53+ // 验证规则中增加如下字段
54+
55+ { {- range .Fields } }
56+ { {- if .Form } }
57+ { {- if eq .Require true } }
58+ { {.FieldJson } } : [{
59+ required: true ,
60+ message: ' {{ .ErrorText }}' ,
61+ trigger: [' input' ,' blur' ],
62+ } ,
63+ { {- if eq .FieldType " string" } }
64+ {
65+ whitespace: true ,
66+ message: t(' general.noOnlySpace' ),
67+ trigger: [' input' , ' blur' ],
68+ }
69+ { {- end } }
70+ ],
71+ { {- end } }
72+ { {- end } }
73+ { {- end } }
74+
75+
76+
77+ { {- if .HasDataSource } }
78+ // 请引用
79+ get{ {.StructName} }DataSource,
80+
81+ // 获取数据源
82+ const dataSource = ref({ } )
83+ const getDataSourceFunc = async()=>{
84+ const res = await get{{.StructName} }DataSource()
85+ if (res.code === 0) {
86+ dataSource.value = res.data
87+ }
88+ }
89+ getDataSourceFunc()
90+ { {- end } }
91+
92+ { {- else } }
93+
94+ { {- if not .OnlyTemplate} }
95+ <template >
96+ <div >
97+ { {- if not .IsTree } }
98+ <div class =" gva-search-box" >
99+ <el-form ref =" elSearchFormRef" :inline =" true" :model =" searchInfo" class =" demo-form-inline" @keyup.enter =" onSubmit" >
100+ { {- if .GvaModel } }
101+ <el-form-item label =" 创建日期" prop =" createdAtRange" >
102+ <template #label >
103+ <span >
104+ 创建日期
105+ <el-tooltip content =" 搜索范围是开始日期(包含)至结束日期(不包含)" >
106+ <el-icon ><QuestionFilled /></el-icon >
107+ </el-tooltip >
38108 </span >
39109 </template >
40110
70140 { {- end } }
71141 <div class =" gva-table-box" >
72142 <div class =" gva-btn-list" >
73- <el-button { { if $global .AutoCreateBtnAuth } } v-auth =" btnAuth.add" { { end } } type =" primary" icon =" plus" @click =" openDialog()" >新增 </el-button >
74- <el-button { { if $global .AutoCreateBtnAuth } } v-auth =" btnAuth.batchDelete" { { end } } icon =" delete" style =" margin-left : 10px ;" :disabled =" !multipleSelection.length" @click =" onDelete" >删除 </el-button >
143+ <el-button { { if $global .AutoCreateBtnAuth } } v-auth =" btnAuth.add" { { end } } type =" primary" icon =" plus" @click =" openDialog()" >{ { " {{ " } }t('general.add') { { " }} " } } </el-button >
144+ <el-button { { if $global .AutoCreateBtnAuth } } v-auth =" btnAuth.batchDelete" { { end } } icon =" delete" style =" margin-left : 10px ;" :disabled =" !multipleSelection.length" @click =" onDelete" >{ { " {{ " } }t('general.delete') { { " }} " } } </el-button >
75145 { { if .HasExcel -} }
76146 <ExportTemplate { { if $global .AutoCreateBtnAuth } } v-auth =" btnAuth.exportTemplate" { { end } } template-id =" { { $templateID } } " />
77147 <ExportExcel { { if $global .AutoCreateBtnAuth } } v-auth =" btnAuth.exportExcel" { { end } } template-id =" { { $templateID } } " filterDeleted />
91161 >
92162 <el-table-column type =" selection" width =" 55" />
93163 { { if .GvaModel } }
94- <el-table-column sortable align =" left" label =" 日期" prop =" CreatedAt" { { - if .IsTree } } min-{{- end }}width =" 180" >
164+ <el-table-column sortable align =" left" label =" 日期" prop =" CreatedAt" { { - if .IsTree } } min-{{- end - }}width =" 180" >
95165 <template #default =" scope" >{ { " {{ formatDate(scope.row.CreatedAt) }}" } }</template >
96166 </el-table-column >
97167 { { end } }
100170 { { GenerateTableColumn . } }
101171 { {- end } }
102172 { {- end } }
103- <el-table-column align =" left" label =" 操作 " fixed =" right" :min-width =" appStore.operateMinWith" >
173+ <el-table-column align =" left" : label =" t('general.operations') " fixed =" right" :min-width =" appStore.operateMinWith" >
104174 <template #default =" scope" >
105175 { {- if .IsTree } }
106- <el-button { { if $global .AutoCreateBtnAuth } } v-auth =" btnAuth.add" { { end } } type =" primary" link class =" table-button" @click =" openDialog(scope.row)" ><el-icon style =" margin-right : 5px " ><InfoFilled /></el-icon >新增子节点 </el-button >
176+ <el-button { { if $global .AutoCreateBtnAuth } } v-auth =" btnAuth.add" { { end } } type =" primary" link class =" table-button" @click =" openDialog(scope.row)" ><el-icon style =" margin-right : 5px " ><InfoFilled /></el-icon >{ { " {{ " } }t('general.addChild') { { " }} " } } </el-button >
107177 { {- end } }
108- <el-button { { if $global .AutoCreateBtnAuth } } v-auth =" btnAuth.info" { { end } } type =" primary" link class =" table-button" @click =" getDetails(scope.row)" ><el-icon style =" margin-right : 5px " ><InfoFilled /></el-icon >查看 </el-button >
109- <el-button { { if $global .AutoCreateBtnAuth } } v-auth =" btnAuth.edit" { { end } } type =" primary" link icon =" edit" class =" table-button" @click =" update{ { .StructName} } Func(scope.row)" >编辑 </el-button >
110- <el-button { { if .IsTree } } v-if =" !scope.row.children?.length" { { end } } { { if $global .AutoCreateBtnAuth } } v-auth =" btnAuth.delete" { { end } } type =" primary" link icon =" delete" @click =" deleteRow(scope.row)" >删除 </el-button >
178+ <el-button { { if $global .AutoCreateBtnAuth } } v-auth =" btnAuth.info" { { end } } type =" primary" link class =" table-button" @click =" getDetails(scope.row)" ><el-icon style =" margin-right : 5px " ><InfoFilled /></el-icon >{ { " {{ " } }t('general.detail') { { " }} " } } </el-button >
179+ <el-button { { if $global .AutoCreateBtnAuth } } v-auth =" btnAuth.edit" { { end } } type =" primary" link icon =" edit" class =" table-button" @click =" update{ { .StructName} } Func(scope.row)" >{ { " {{ " } }t('general.edit') { { " }} " } } </el-button >
180+ <el-button { { if .IsTree } } v-if =" !scope.row.children?.length" { { end } } { { if $global .AutoCreateBtnAuth } } v-auth =" btnAuth.delete" { { end } } type =" primary" link icon =" delete" @click =" deleteRow(scope.row)" >{ { " {{ " } }t('general.delete') { { " }} " } } </el-button >
111181 </template >
112182 </el-table-column >
113183 </el-table >
128198 <div class =" flex justify-between items-center" >
129199 <span class =" text-lg" >{ {" {{" } }type==='create'?t('general.add'):t('general.edit'){ {" }}" } }</span >
130200 <div >
131- <el-button type =" primary" @click =" enterDialog" >{ {" {{" } }t('general.confirm'){ {" }}" } }</el-button >
132- <el-button @click =" closeDialog" >{ {" {{" } }t('general.close '){ {" }}" } }</el-button >
201+ <el-button :loading = " btnLoading " type =" primary" @click =" enterDialog" >{ {" {{" } }t('general.confirm'){ {" }}" } }</el-button >
202+ <el-button @click =" closeDialog" >{ {" {{" } }t('general.cancel '){ {" }}" } }</el-button >
133203 </div >
134204 </div >
135205 </template >
136206
137207 <el-form :model =" formData" label-position =" top" ref =" elFormRef" :rules =" rule" label-width =" 80px" >
138208 { {- if .IsTree } }
139- <el-form-item label =" 父节点: " prop =" parentID" >
209+ <el-form-item : label =" t('general.parentNode') " prop =" parentID" >
140210 <el-tree-select
141211 v-model =" formData.parentID"
142212 :data =" [rootNode,...tableData]"
145215 :props =" defaultProps"
146216 clearable
147217 style =" width : 240px "
148- placeholder =" 根节点 "
218+ : placeholder =" t('general.rootNode') "
149219 />
150220 </el-form-item >
151221 { {- end } }
152222 { {- range .Fields} }
153223 { {- if .Form} }
154- <el-form-item :label =" t('{ { $top .Package} } .{ { $top .StructName} } .{ { .FieldName} } ')" prop =" { { .FieldJson} } " >
155- { {- if .CheckDataSource} }
156- <el-select { { if eq .DataSource.Association 2} } multiple { { end } } v-model =" formData.{ { .FieldJson} } " :placeholder =" t('{ { $top .Package} } .{ { $top .StructName} } .{ { .FieldName} } ')" style =" width :100% " :clearable =" { { .Clearable} } " >
157- <el-option v-for =" (item,key) in dataSource.{ { .FieldJson} } " :key =" key" :label =" item.label" :value =" item.value" />
158- </el-select >
159- { {- else } }
160- { {- if eq .FieldType " bool" } }
161- <el-switch v-model =" formData.{ { .FieldJson} } " active-color =" #13ce66" inactive-color =" #ff4949" :active-text =" t('general.yes')" :inactive-text =" t('general.no')" clearable ></el-switch >
162- { {- end } }
163- { {- if eq .FieldType " string" } }
164- { {- if .DictType} }
165- <el-select v-model =" formData.{ { .FieldJson } } " :placeholder =" t('{ { $top .Package} } .{ { $top .StructName} } .{ { .FieldName} } ')" style =" width :100% " :clearable =" { { .Clearable} } " >
166- <el-option v-for =" (item,key) in { { .DictType } } Options" :key =" key" :label =" item.label" :value =" item.value" />
167- </el-select >
168- { {- else } }
169- <el-input v-model =" formData.{ { .FieldJson} } " :clearable =" { { .Clearable} } " :placeholder =" t('{ { $top .Package} } .{ { $top .StructName} } .{ { .FieldName} } ')" />
170- { {- end } }
224+ { { GenerateFormItem . } }
171225 { {- end } }
172- { {- if eq .FieldType " richtext" } }
173- <RichEdit v-model =" formData.{ { .FieldJson} } " />
174226 { {- end } }
175- { {- if eq .FieldType " json" } }
176- // 此字段为json结构,可以前端自行控制展示和数据绑定模式 需绑定json的key为 formData.{ {.FieldJson} } 后端会按照json的类型进行存取
177- { {" {{" } } formData.{ {.FieldJson} } { {" }}" } }
227+ </el-form >
228+ </el-drawer >
229+
230+ <el-drawer destroy-on-close :size =" appStore.drawerSize" v-model =" detailShow" :show-close =" true" :before-close =" closeDetailShow" :title =" t('general.detail')" >
231+ <el-descriptions :column =" 1" border >
232+ { {- if .IsTree } }
233+ <el-descriptions-item :label =" t('general.parentNode')" >
234+ <el-tree-select
235+ v-model =" detailForm.parentID"
236+ :data =" [rootNode,...tableData]"
237+ check-strictly
238+ disabled
239+ :render-after-expand =" false"
240+ :props =" defaultProps"
241+ clearable
242+ style =" width : 240px "
243+ :placeholder =" t('general.rootNode')"
244+ />
245+ </el-descriptions-item >
246+ { {- end } }
247+ { {- range .Fields} }
248+ { {- if .Desc } }
249+ { { GenerateDescriptionItem . } }
250+ { {- end } }
251+ { {- end } }
252+ </el-descriptions >
253+ </el-drawer >
254+
255+ </div >
256+ </template >
257+
258+ <script setup >
259+ import {
260+ { { - if .HasDataSource } }
178261 get{ { .StructName} } DataSource,
262+ { { - end } }
179263 create{ { .StructName} } ,
180264 delete{ { .StructName} } ,
181265 delete{ { .StructName} } ByIds,
@@ -214,7 +298,6 @@ import { ElMessage, ElMessageBox } from 'element-plus'
214298import { ref, reactive } from ' vue'
215299import { useI18n } from ' vue-i18n'
216300const { t } = useI18n ()
217-
218301{ { - if .AutoCreateBtnAuth } }
219302// 引入按钮权限标识
220303import { useBtnAuth } from ' @/utils/btnAuth'
@@ -230,6 +313,7 @@ import ImportExcel from '@/components/exportExcel/importExcel.vue'
230313import ExportTemplate from ' @/components/exportExcel/exportTemplate.vue'
231314{ { - end} }
232315
316+
233317defineOptions ({
234318 name: ' { { .StructName} } '
235319} )
@@ -297,39 +381,6 @@ const rule = reactive({
297381 { { - end } }
298382} )
299383
300- const searchRule = reactive({
301- createdAt: [
302- { validator: (rule, value, callback) => {
303- if (searchInfo.value.startCreatedAt && ! searchInfo.value.endCreatedAt) {
304- callback(new Error(t(' general.placeInputEndData' )))
305- } else if (!searchInfo.value.startCreatedAt && searchInfo.value.endCreatedAt) {
306- callback(new Error(t(' general.placeInputStartData' )))
307- } else if (searchInfo.value.startCreatedAt && searchInfo.value.endCreatedAt && (searchInfo.value.startCreatedAt.getTime() === searchInfo.value.endCreatedAt.getTime() || searchInfo.value.startCreatedAt.getTime() > searchInfo.value.endCreatedAt.getTime())) {
308- callback(new Error(t(' general.startDataMustBeforeEndData' )))
309- } else {
310- callback()
311- }
312- }, trigger: 'change' }
313- ],
314- { {- range .Fields } }
315- { {- if .FieldSearchType} }
316- { {- if eq .FieldType " time.Time" } }
317- { {.FieldJson } } : [{ validator: (rule, value, callback) => {
318- if (searchInfo.value.start{{.FieldName} } && !searchInfo.value.end{ {.FieldName} }) {
319- callback(new Error(t(' general.placeInputEndData' )))
320- } else if (!searchInfo.value.start{ {.FieldName} } && searchInfo.value.end{ {.FieldName} }) {
321- callback(new Error(t(' general.placeInputStartData' )))
322- } else if (searchInfo.value.start{ {.FieldName} } && searchInfo.value.end{ {.FieldName} } && (searchInfo.value.start{ {.FieldName} }.getTime() === searchInfo.value.end{ {.FieldName} }.getTime() || searchInfo.value.start{ {.FieldName} }.getTime() > searchInfo.value.end{ {.FieldName} }.getTime())) {
323- callback(new Error(t(' general.startDataMustBeforeEndData' )))
324- } else {
325- callback()
326- }
327- }, trigger: 'change' }],
328- { {- end } }
329- { {- end } }
330- { {- end } }
331- })
332-
333384const elFormRef = ref ()
334385const elSearchFormRef = ref ()
335386
@@ -420,7 +471,7 @@ const defaultProps = {
420471
421472const rootNode = {
422473 { { .PrimaryField.FieldJson } } : 0,
423- { { .TreeJson } }: '根节点' ,
474+ { { .TreeJson } } : t( ' general.rootNode ' ) ,
424475 children: []
425476}
426477
@@ -457,9 +508,9 @@ const handleSelectionChange = (val) => {
457508
458509// 删除行
459510const deleteRow = (row ) => {
460- ElMessageBox.confirm(t(' general.deleteConfirm' ), t(' general.hint' ), {
461- confirmButtonText: t(' general.confirm' ),
462- cancelButtonText: t(' general.cancel' ),
511+ ElMessageBox.confirm(t(' general.deleteConfirm' ), t(' general.hint' ), {
512+ confirmButtonText: t(' general.confirm' ),
513+ cancelButtonText: t(' general.cancel' ),
463514 type: ' warning'
464515 } ).then(() => {
465516 delete{ { .StructName} } Func(row)
@@ -519,7 +570,7 @@ const delete{{.StructName}}Func = async (row) => {
519570 if (res.code === 0) {
520571 ElMessage({
521572 type: ' success' ,
522- message: t( ' general.deleteSuccess ' )
573+ message: ' 删除成功 '
523574 } )
524575 if (tableData.value.length === 1 && page.value > 1) {
525576 page.value--
@@ -553,8 +604,9 @@ const closeDialog = () => {
553604}
554605// 弹窗确定
555606const enterDialog = async () => {
607+ btnLoading.value = true
556608 elFormRef.value?.validate( async (valid) => {
557- if (! valid) return
609+ if (! valid) return btnLoading.value = false
558610 let res
559611 switch (type.value) {
560612 case ' create' :
@@ -567,6 +619,7 @@ const enterDialog = async () => {
567619 res = await create{ { .StructName} } (formData.value)
568620 break
569621 }
622+ btnLoading.value = false
570623 if (res.code === 0) {
571624 ElMessage({
572625 type: ' success' ,
@@ -578,7 +631,7 @@ const enterDialog = async () => {
578631 } )
579632}
580633
581- const detailFrom = ref({ } )
634+ const detailForm = ref ({ } )
582635
583636// 查看详情控制标记
584637const detailShow = ref (false )
@@ -595,7 +648,7 @@ const getDetails = async (row) => {
595648 // 打开弹窗
596649 const res = await find{ { .StructName} } ({ { { .PrimaryField.FieldJson} } : row.{ { .PrimaryField.FieldJson} } } )
597650 if (res.code === 0) {
598- detailFrom .value = res.data
651+ detailForm .value = res.data
599652 openDetailShow()
600653 }
601654}
@@ -604,7 +657,7 @@ const getDetails = async (row) => {
604657// 关闭详情弹窗
605658const closeDetailShow = () => {
606659 detailShow.value = false
607- detailFrom .value = {}
660+ detailForm .value = { }
608661}
609662
610663
@@ -638,6 +691,6 @@ defineOptions({
638691</script >
639692<style >
640693</style >
641- { { - end} }
642-
643694{ { - end } }
695+
696+ { { - end } }
0 commit comments