Skip to content

Commit d23d6c3

Browse files
committed
feature:自动化增加前端可控显隐。
1 parent 90549a0 commit d23d6c3

File tree

5 files changed

+11
-116
lines changed

5 files changed

+11
-116
lines changed

server/model/system/sys_auto_code.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ type Field struct {
6969
FieldSearchType string `json:"fieldSearchType"` // 搜索条件
7070
DictType string `json:"dictType"` // 字典
7171
Front bool `json:"front"` // 是否前端可见
72-
Class string `json:"class"` // 前端样式类
7372
Require bool `json:"require"` // 是否必填
7473
DefaultValue string `json:"defaultValue"` // 是否必填
7574
ErrorText string `json:"errorText"` // 校验失败文字

server/resource/autocode_template/web/table.vue.tpl

Lines changed: 8 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
<template #default="scope">{{ "{{ formatDate(scope.row.CreatedAt) }}" }}</template>
104104
</el-table-column>
105105
{{ end }}
106-
{{- range .Fields}}
106+
{{- range .FrontFields}}
107107
{{- if .DictType}}
108108
<el-table-column {{- if .Sort}} sortable{{- end}} align="left" label="{{.FieldDesc}}" prop="{{.FieldJson}}" width="120">
109109
<template #default="scope">
@@ -203,7 +203,7 @@
203203
</template>
204204

205205
<el-form :model="formData" label-position="top" ref="elFormRef" :rules="rule" label-width="80px">
206-
{{- range .Fields}}
206+
{{- range .FrontFields}}
207207
<el-form-item label="{{.FieldDesc}}:" prop="{{.FieldJson}}" >
208208
{{- if eq .FieldType "bool" }}
209209
<el-switch v-model="formData.{{.FieldJson}}" active-color="#13ce66" inactive-color="#ff4949" active-text="" inactive-text="" clearable ></el-switch>
@@ -270,52 +270,6 @@
270270
{{- end }}
271271
</el-form>
272272
</el-drawer>
273-
274-
<el-drawer size="800" v-model="detailShow" :before-close="closeDetailShow" destroy-on-close>
275-
<template #header>
276-
<div class="flex justify-between items-center">
277-
<span class="text-lg">查看详情</span>
278-
</div>
279-
</template>
280-
<el-descriptions :column="1" border>
281-
{{- range .Fields}}
282-
<el-descriptions-item label="{{ .FieldDesc }}">
283-
{{- if .DictType}}
284-
{{"{{"}} filterDict(formData.{{.FieldJson}},{{.DictType}}Options) {{"}}"}}
285-
{{- else if eq .FieldType "picture" }}
286-
<el-image style="width: 50px; height: 50px" :preview-src-list="ReturnArrImg(formData.{{ .FieldJson }})" :src="getUrl(formData.{{ .FieldJson }})" fit="cover" />
287-
{{- else if eq .FieldType "video" }}
288-
<video
289-
style="width: 50px; height: 50px"
290-
muted
291-
preload="metadata"
292-
>
293-
<source :src="getUrl(formData.{{ .FieldJson }}) + '#t=1'">
294-
</video>
295-
{{- else if eq .FieldType "pictures" }}
296-
<el-image style="width: 50px; height: 50px; margin-right: 10px" :preview-src-list="ReturnArrImg(formData.{{ .FieldJson }})" :initial-index="index" v-for="(item,index) in formData.{{ .FieldJson }}" :key="index" :src="getUrl(item)" fit="cover" />
297-
{{- else if eq .FieldType "file" }}
298-
<div class="fileBtn" v-for="(item,index) in formData.{{ .FieldJson }}" :key="index">
299-
<el-button type="primary" text bg @click="onDownloadFile(item.url)">
300-
<el-icon style="margin-right: 5px"><Download /></el-icon>
301-
{{"{{"}} item.name {{"}}"}}
302-
</el-button>
303-
</div>
304-
{{- else if eq .FieldType "bool" }}
305-
{{"{{"}} formatBoolean(formData.{{.FieldJson}}) {{"}}"}}
306-
{{- else if eq .FieldType "time.Time" }}
307-
{{"{{"}} formatDate(formData.{{.FieldJson}}) {{"}}"}}
308-
{{- else if eq .FieldType "richtext" }}
309-
[富文本内容]
310-
{{- else if eq .FieldType "json" }}
311-
[JSON]
312-
{{- else}}
313-
{{"{{"}} formData.{{.FieldJson}} {{"}}"}}
314-
{{- end }}
315-
</el-descriptions-item>
316-
{{- end }}
317-
</el-descriptions>
318-
</el-drawer>
319273
</div>
320274
</template>
321275

@@ -362,7 +316,7 @@ defineOptions({
362316
const {{ $element }}Options = ref([])
363317
{{- end }}
364318
const formData = ref({
365-
{{- range .Fields}}
319+
{{- range .FrontFields}}
366320
{{- if eq .FieldType "bool" }}
367321
{{.FieldJson}}: false,
368322
{{- end }}
@@ -402,7 +356,7 @@ const formData = ref({
402356
403357
// 验证规则
404358
const rule = reactive({
405-
{{- range .Fields }}
359+
{{- range .FrontFields }}
406360
{{- if eq .Require true }}
407361
{{.FieldJson }} : [{
408362
required: true,
@@ -435,7 +389,7 @@ const searchRule = reactive({
435389
}
436390
}, trigger: 'change' }
437391
],
438-
{{- range .Fields }}
392+
{{- range .FrontFields }}
439393
{{- if .FieldSearchType}}
440394
{{- if eq .FieldType "time.Time" }}
441395
{{.FieldJson }} : [{ validator: (rule, value, callback) => {
@@ -468,7 +422,7 @@ const searchInfo = ref({})
468422
// 排序
469423
const sortChange = ({ prop, order }) => {
470424
const sortMap = {
471-
{{- range .Fields}}
425+
{{- range .FrontFields}}
472426
{{- if and .Sort}}
473427
{{- if not (eq .ColumnName "")}}
474428
{{.FieldJson}}: '{{.ColumnName}}',
@@ -500,7 +454,7 @@ const onSubmit = () => {
500454
if (!valid) return
501455
page.value = 1
502456
pageSize.value = 10
503-
{{- range .Fields}}{{- if eq .FieldType "bool" }}
457+
{{- range .FrontFields}}{{- if eq .FieldType "bool" }}
504458
if (searchInfo.value.{{.FieldJson}} === ""){
505459
searchInfo.value.{{.FieldJson}}=null
506460
}{{ end }}{{ end }}
@@ -629,53 +583,6 @@ const delete{{.StructName}}Func = async (row) => {
629583
// 弹窗控制标记
630584
const dialogFormVisible = ref(false)
631585
632-
633-
// 查看详情控制标记
634-
const detailShow = ref(false)
635-
636-
637-
// 打开详情弹窗
638-
const openDetailShow = () => {
639-
detailShow.value = true
640-
}
641-
642-
643-
// 打开详情
644-
const getDetails = async (row) => {
645-
// 打开弹窗
646-
const res = await find{{.StructName}}({ {{.PrimaryField.FieldJson}}: row.{{.PrimaryField.FieldJson}} })
647-
if (res.code === 0) {
648-
formData.value = res.data.re{{.Abbreviation}}
649-
openDetailShow()
650-
}
651-
}
652-
653-
654-
// 关闭详情弹窗
655-
const closeDetailShow = () => {
656-
detailShow.value = false
657-
formData.value = {
658-
{{- range .Fields}}
659-
{{- if eq .FieldType "bool" }}
660-
{{.FieldJson}}: false,
661-
{{- end }}
662-
{{- if eq .FieldType "string" }}
663-
{{.FieldJson}}: '',
664-
{{- end }}
665-
{{- if eq .FieldType "int" }}
666-
{{.FieldJson}}: {{- if .DictType }} undefined{{ else }} 0{{- end }},
667-
{{- end }}
668-
{{- if eq .FieldType "time.Time" }}
669-
{{.FieldJson}}: new Date(),
670-
{{- end }}
671-
{{- if eq .FieldType "float64" }}
672-
{{.FieldJson}}: 0,
673-
{{- end }}
674-
{{- end }}
675-
}
676-
}
677-
678-
679586
// 打开弹窗
680587
const openDialog = () => {
681588
type.value = 'create'
@@ -686,7 +593,7 @@ const openDialog = () => {
686593
const closeDialog = () => {
687594
dialogFormVisible.value = false
688595
formData.value = {
689-
{{- range .Fields}}
596+
{{- range .FrontFields}}
690597
{{- if eq .FieldType "bool" }}
691598
{{.FieldJson}}: false,
692599
{{- end }}

server/service/system/sys_auto_code.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,9 @@ func fmtField(autoCode *system.AutoCodeStruct) {
976976
autoCode.HasPic = true
977977
autoCode.NeedJSON = true
978978
}
979+
if autoCode.Fields[i].FieldType == "json" {
980+
autoCode.NeedJSON = true
981+
}
979982
if autoCode.Fields[i].FieldType == "file" {
980983
autoCode.HasFile = true
981984
autoCode.NeedJSON = true

web/src/view/systemTools/autoCode/component/fieldDialog.vue

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,6 @@
135135
placeholder="请输入默认值"
136136
/>
137137
</el-form-item>
138-
<el-form-item label="前端class">
139-
<el-input v-model="middleDate.class" />
140-
</el-form-item>
141138
<el-form-item label="主键">
142139
<el-checkbox v-model="middleDate.primaryKey" />
143140
</el-form-item>

web/src/view/systemTools/autoCode/index.vue

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -452,16 +452,6 @@
452452
<el-input v-model="row.comment" />
453453
</template>
454454
</el-table-column>
455-
<el-table-column
456-
align="left"
457-
prop="comment"
458-
label="前端class"
459-
width="160"
460-
>
461-
<template #default="{row}">
462-
<el-input v-model="row.class" />
463-
</template>
464-
</el-table-column>
465455
<el-table-column
466456
align="left"
467457
prop="fieldSearchType"
@@ -720,7 +710,6 @@ const fieldTemplate = {
720710
require: false,
721711
sort: false,
722712
front: true,
723-
class: '',
724713
errorText: '',
725714
primaryKey: false,
726715
clearable: true,

0 commit comments

Comments
 (0)