You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
<template>
<div>
<div class="gva-form-box">
<el-form :model="formData" label-position="right" label-width="80px">
{{- range .Fields}}
<el-form-item label="{{.FieldDesc}}:">
{{- if eq .FieldType "bool" }}
<el-switch v-model="formData.{{.FieldJson}}" active-color="#13ce66" inactive-color="#ff4949" active-text="是" inactive-text="否" clearable ></el-switch>
{{- end }}
{{- if eq .FieldType "string" }}
<el-input v-model="formData.{{.FieldJson}}" clearable placeholder="请输入" />
{{- end }}
{{- if eq .FieldType "int" }}
{{- if .DictType }}
<el-select v-model="formData.{{ .FieldJson }}" placeholder="请选择" clearable>
<el-option v-for="(item,key) in {{ .DictType }}Options" :key="key" :label="item.label" :value="item.value" />
</el-select>
{{- else }}
<el-input v-model.number="formData.{{ .FieldJson }}" clearable placeholder="请输入" />
{{- end }}
{{- end }}
{{- if eq .FieldType "time.Time" }}
<el-date-picker v-model="formData.{{ .FieldJson }}" type="date" placeholder="选择日期" clearable></el-date-picker>
{{- end }}
{{- if eq .FieldType "float64" }}
<el-input-number v-model="formData.{{ .FieldJson }}" :precision="2" clearable></el-input-number>
{{- end }}
</el-form-item>
{{- end }}
<el-form-item>
<el-button size="mini" type="primary" @click="save">保存</el-button>
<el-button size="mini" type="primary" @click="back">返回</el-button>
</el-form-item>
</el-form>
</div>
</div>
</template>
<script>
import { create{{.StructName}},
update{{.StructName}},
find{{.StructName}}
} from '@/api/{{.PackageName}}' // 此处请自行替换地址
import infoList from '@/mixins/infoList'
export default { name: '{{.StructName}}',
mixins: [infoList],
data() { return { type: '',
{{- range $index, $element := .DictTypes}}
{{ $element }}Options: [],
{{- end }}
formData: { {{- 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 }}
}
}
},
async created() { // 建议通过url传参获取目标数据ID 调用 find方法进行查询数据操作 从而决定本页面是create还是update 以下为id作为url参数示例
if (this.$route.query.id) { const res = await find{{.StructName}}({ ID: this.$route.query.id })
if (res.code === 0) { this.formData = res.data.re{{.Abbreviation}}
this.type = 'update'
}
} else { this.type = 'create'
}
{{- range $index, $element := .DictTypes }}
await this.getDict('{{$element}}')
{{- end }}
},
methods: { async save() { let res
switch (this.type) { case 'create':
res = await create{{.StructName}}(this.formData)
break
case 'update':
res = await update{{.StructName}}(this.formData)
break
default:
res = await create{{.StructName}}(this.formData)
break
}
if (res.code === 0) { this.$message({ type: 'success',
message: '创建/更改成功'
})
}
},
back() { this.$router.go(-1)
}
}
}
</script>
<style>
</style>
|