Skip to content

Commit

Permalink
feature:自动化增加前端可控显隐。
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelmaxQm committed Apr 25, 2024
1 parent 90549a0 commit d23d6c3
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 116 deletions.
1 change: 0 additions & 1 deletion server/model/system/sys_auto_code.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ type Field struct {
FieldSearchType string `json:"fieldSearchType"` // 搜索条件
DictType string `json:"dictType"` // 字典
Front bool `json:"front"` // 是否前端可见
Class string `json:"class"` // 前端样式类
Require bool `json:"require"` // 是否必填
DefaultValue string `json:"defaultValue"` // 是否必填
ErrorText string `json:"errorText"` // 校验失败文字
Expand Down
109 changes: 8 additions & 101 deletions server/resource/autocode_template/web/table.vue.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
<template #default="scope">{{ "{{ formatDate(scope.row.CreatedAt) }}" }}</template>
</el-table-column>
{{ end }}
{{- range .Fields}}
{{- range .FrontFields}}
{{- if .DictType}}
<el-table-column {{- if .Sort}} sortable{{- end}} align="left" label="{{.FieldDesc}}" prop="{{.FieldJson}}" width="120">
<template #default="scope">
Expand Down Expand Up @@ -203,7 +203,7 @@
</template>

<el-form :model="formData" label-position="top" ref="elFormRef" :rules="rule" label-width="80px">
{{- range .Fields}}
{{- range .FrontFields}}
<el-form-item label="{{.FieldDesc}}:" prop="{{.FieldJson}}" >
{{- if eq .FieldType "bool" }}
<el-switch v-model="formData.{{.FieldJson}}" active-color="#13ce66" inactive-color="#ff4949" active-text="" inactive-text="" clearable ></el-switch>
Expand Down Expand Up @@ -270,52 +270,6 @@
{{- end }}
</el-form>
</el-drawer>

<el-drawer size="800" v-model="detailShow" :before-close="closeDetailShow" destroy-on-close>
<template #header>
<div class="flex justify-between items-center">
<span class="text-lg">查看详情</span>
</div>
</template>
<el-descriptions :column="1" border>
{{- range .Fields}}
<el-descriptions-item label="{{ .FieldDesc }}">
{{- if .DictType}}
{{"{{"}} filterDict(formData.{{.FieldJson}},{{.DictType}}Options) {{"}}"}}
{{- else if eq .FieldType "picture" }}
<el-image style="width: 50px; height: 50px" :preview-src-list="ReturnArrImg(formData.{{ .FieldJson }})" :src="getUrl(formData.{{ .FieldJson }})" fit="cover" />
{{- else if eq .FieldType "video" }}
<video
style="width: 50px; height: 50px"
muted
preload="metadata"
>
<source :src="getUrl(formData.{{ .FieldJson }}) + '#t=1'">
</video>
{{- else if eq .FieldType "pictures" }}
<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" />
{{- else if eq .FieldType "file" }}
<div class="fileBtn" v-for="(item,index) in formData.{{ .FieldJson }}" :key="index">
<el-button type="primary" text bg @click="onDownloadFile(item.url)">
<el-icon style="margin-right: 5px"><Download /></el-icon>
{{"{{"}} item.name {{"}}"}}
</el-button>
</div>
{{- else if eq .FieldType "bool" }}
{{"{{"}} formatBoolean(formData.{{.FieldJson}}) {{"}}"}}
{{- else if eq .FieldType "time.Time" }}
{{"{{"}} formatDate(formData.{{.FieldJson}}) {{"}}"}}
{{- else if eq .FieldType "richtext" }}
[富文本内容]
{{- else if eq .FieldType "json" }}
[JSON]
{{- else}}
{{"{{"}} formData.{{.FieldJson}} {{"}}"}}
{{- end }}
</el-descriptions-item>
{{- end }}
</el-descriptions>
</el-drawer>
</div>
</template>

Expand Down Expand Up @@ -362,7 +316,7 @@ defineOptions({
const {{ $element }}Options = ref([])
{{- end }}
const formData = ref({
{{- range .Fields}}
{{- range .FrontFields}}
{{- if eq .FieldType "bool" }}
{{.FieldJson}}: false,
{{- end }}
Expand Down Expand Up @@ -402,7 +356,7 @@ const formData = ref({
// 验证规则
const rule = reactive({
{{- range .Fields }}
{{- range .FrontFields }}
{{- if eq .Require true }}
{{.FieldJson }} : [{
required: true,
Expand Down Expand Up @@ -435,7 +389,7 @@ const searchRule = reactive({
}
}, trigger: 'change' }
],
{{- range .Fields }}
{{- range .FrontFields }}
{{- if .FieldSearchType}}
{{- if eq .FieldType "time.Time" }}
{{.FieldJson }} : [{ validator: (rule, value, callback) => {
Expand Down Expand Up @@ -468,7 +422,7 @@ const searchInfo = ref({})
// 排序
const sortChange = ({ prop, order }) => {
const sortMap = {
{{- range .Fields}}
{{- range .FrontFields}}
{{- if and .Sort}}
{{- if not (eq .ColumnName "")}}
{{.FieldJson}}: '{{.ColumnName}}',
Expand Down Expand Up @@ -500,7 +454,7 @@ const onSubmit = () => {
if (!valid) return
page.value = 1
pageSize.value = 10
{{- range .Fields}}{{- if eq .FieldType "bool" }}
{{- range .FrontFields}}{{- if eq .FieldType "bool" }}
if (searchInfo.value.{{.FieldJson}} === ""){
searchInfo.value.{{.FieldJson}}=null
}{{ end }}{{ end }}
Expand Down Expand Up @@ -629,53 +583,6 @@ const delete{{.StructName}}Func = async (row) => {
// 弹窗控制标记
const dialogFormVisible = ref(false)
// 查看详情控制标记
const detailShow = ref(false)
// 打开详情弹窗
const openDetailShow = () => {
detailShow.value = true
}
// 打开详情
const getDetails = async (row) => {
// 打开弹窗
const res = await find{{.StructName}}({ {{.PrimaryField.FieldJson}}: row.{{.PrimaryField.FieldJson}} })
if (res.code === 0) {
formData.value = res.data.re{{.Abbreviation}}
openDetailShow()
}
}
// 关闭详情弹窗
const closeDetailShow = () => {
detailShow.value = false
formData.value = {
{{- range .Fields}}
{{- if eq .FieldType "bool" }}
{{.FieldJson}}: false,
{{- end }}
{{- if eq .FieldType "string" }}
{{.FieldJson}}: '',
{{- end }}
{{- if eq .FieldType "int" }}
{{.FieldJson}}: {{- if .DictType }} undefined{{ else }} 0{{- end }},
{{- end }}
{{- if eq .FieldType "time.Time" }}
{{.FieldJson}}: new Date(),
{{- end }}
{{- if eq .FieldType "float64" }}
{{.FieldJson}}: 0,
{{- end }}
{{- end }}
}
}
// 打开弹窗
const openDialog = () => {
type.value = 'create'
Expand All @@ -686,7 +593,7 @@ const openDialog = () => {
const closeDialog = () => {
dialogFormVisible.value = false
formData.value = {
{{- range .Fields}}
{{- range .FrontFields}}
{{- if eq .FieldType "bool" }}
{{.FieldJson}}: false,
{{- end }}
Expand Down
3 changes: 3 additions & 0 deletions server/service/system/sys_auto_code.go
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,9 @@ func fmtField(autoCode *system.AutoCodeStruct) {
autoCode.HasPic = true
autoCode.NeedJSON = true
}
if autoCode.Fields[i].FieldType == "json" {
autoCode.NeedJSON = true
}
if autoCode.Fields[i].FieldType == "file" {
autoCode.HasFile = true
autoCode.NeedJSON = true
Expand Down
3 changes: 0 additions & 3 deletions web/src/view/systemTools/autoCode/component/fieldDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,6 @@
placeholder="请输入默认值"
/>
</el-form-item>
<el-form-item label="前端class">
<el-input v-model="middleDate.class" />
</el-form-item>
<el-form-item label="主键">
<el-checkbox v-model="middleDate.primaryKey" />
</el-form-item>
Expand Down
11 changes: 0 additions & 11 deletions web/src/view/systemTools/autoCode/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -452,16 +452,6 @@
<el-input v-model="row.comment" />
</template>
</el-table-column>
<el-table-column
align="left"
prop="comment"
label="前端class"
width="160"
>
<template #default="{row}">
<el-input v-model="row.class" />
</template>
</el-table-column>
<el-table-column
align="left"
prop="fieldSearchType"
Expand Down Expand Up @@ -720,7 +710,6 @@ const fieldTemplate = {
require: false,
sort: false,
front: true,
class: '',
errorText: '',
primaryKey: false,
clearable: true,
Expand Down

0 comments on commit d23d6c3

Please sign in to comment.