奇淼(piexlmax
3 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 292 additions and 302 deletions
-
85server/resource/template/web/api.js.tpl
-
157server/resource/template/web/form.vue.tpl
-
352server/resource/template/web/table.vue.tpl
@ -1,124 +1,121 @@ |
|||||
<template> |
<template> |
||||
<div> |
|
||||
|
<div> |
||||
<el-form :model="formData" label-position="right" label-width="80px"> |
<el-form :model="formData" label-position="right" label-width="80px"> |
||||
{{- range .Fields}} |
|
||||
<el-form-item label="{{.FieldDesc}}:"> |
|
||||
{{- if eq .FieldType "bool" }} |
|
||||
<el-switch active-color="#13ce66" inactive-color="#ff4949" active-text="是" inactive-text="否" v-model="formData.{{.FieldJson}}" clearable ></el-switch> |
|
||||
{{ end -}} |
|
||||
{{- if eq .FieldType "string" }} |
|
||||
<el-input v-model="formData.{{.FieldJson}}" clearable placeholder="请输入" ></el-input> |
|
||||
{{ 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-option> |
|
||||
</el-select> |
|
||||
{{ else -}} |
|
||||
<el-input v-model.number="formData.{{ .FieldJson }}" clearable placeholder="请输入"></el-input> |
|
||||
{{ end -}} |
|
||||
{{ end -}} |
|
||||
{{- if eq .FieldType "time.Time" }} |
|
||||
<el-date-picker type="date" placeholder="选择日期" v-model="formData.{{ .FieldJson }}" 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 @click="save" type="primary">保存</el-button> |
|
||||
<el-button @click="back" type="primary">返回</el-button> |
|
||||
</el-form-item> |
|
||||
|
{{- range .Fields}} |
||||
|
<el-form-item label="{{.FieldDesc}}:"> |
||||
|
{{ if eq .FieldType "bool" -}} |
||||
|
<el-switch active-color="#13ce66" inactive-color="#ff4949" active-text="是" inactive-text="否" v-model="formData.{{.FieldJson}}" 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-option> |
||||
|
</el-select> |
||||
|
{{ else -}} |
||||
|
<el-input v-model.number="formData.{{ .FieldJson }}" clearable placeholder="请输入"/> |
||||
|
{{ end -}} |
||||
|
{{ end -}} |
||||
|
{{ if eq .FieldType "time.Time" }} |
||||
|
<el-date-picker type="date" placeholder="选择日期" v-model="formData.{{ .FieldJson }}" 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 type="primary" @click="save">保存</el-button> |
||||
|
<el-button type="primary" @click="back">返回</el-button> |
||||
|
</el-form-item> |
||||
</el-form> |
</el-form> |
||||
</div> |
</div> |
||||
</template> |
</template> |
||||
|
|
||||
<script> |
<script> |
||||
import { |
import { |
||||
create{{.StructName}}, |
|
||||
update{{.StructName}}, |
|
||||
find{{.StructName}} |
|
||||
} from "@/api/{{.PackageName}}"; // 此处请自行替换地址 |
|
||||
import infoList from "@/mixins/infoList"; |
|
||||
|
create{{.StructName}}, |
||||
|
update{{.StructName}}, |
||||
|
find{{.StructName}} |
||||
|
} from '@/api/{{.PackageName}}' // 此处请自行替换地址 |
||||
|
import infoList from '@/mixins/infoList' |
||||
export default { |
export default { |
||||
name: "{{.StructName}}", |
|
||||
|
name: '{{.StructName}}', |
||||
mixins: [infoList], |
mixins: [infoList], |
||||
data() { |
data() { |
||||
return { |
return { |
||||
type: "", |
|
||||
|
|
||||
{{- range .Fields}} |
|
||||
|
type: '', |
||||
|
{{range .Fields}} |
||||
{{- if .DictType }} |
{{- if .DictType }} |
||||
{{ .DictType }}Options:[], |
|
||||
|
{{ .DictType }}Options: [], |
||||
{{ end -}} |
{{ end -}} |
||||
{{end -}} |
{{end -}} |
||||
|
|
||||
formData: { |
formData: { |
||||
{{range .Fields}} |
{{range .Fields}} |
||||
{{- if eq .FieldType "bool" -}} |
{{- if eq .FieldType "bool" -}} |
||||
{{.FieldJson}}:false, |
|
||||
|
{{.FieldJson}}: false, |
||||
{{ end -}} |
{{ end -}} |
||||
{{- if eq .FieldType "string" -}} |
{{- if eq .FieldType "string" -}} |
||||
{{.FieldJson}}:"", |
|
||||
|
{{.FieldJson}}: '', |
||||
{{ end -}} |
{{ end -}} |
||||
{{- if eq .FieldType "int" -}} |
{{- if eq .FieldType "int" -}} |
||||
{{.FieldJson}}:0, |
|
||||
|
{{.FieldJson}}: 0, |
||||
{{ end -}} |
{{ end -}} |
||||
{{- if eq .FieldType "time.Time" -}} |
{{- if eq .FieldType "time.Time" -}} |
||||
{{.FieldJson}}:new Date(), |
|
||||
|
{{.FieldJson}}: new Date(), |
||||
{{ end -}} |
{{ end -}} |
||||
{{- if eq .FieldType "float64" -}} |
{{- if eq .FieldType "float64" -}} |
||||
{{.FieldJson}}:0, |
|
||||
|
{{.FieldJson}}: 0, |
||||
{{ end -}} |
{{ end -}} |
||||
{{ 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 .Fields -}} |
||||
|
{{- if .DictType }} |
||||
|
await this.getDict("{{.DictType}}") |
||||
|
{{ end -}} |
||||
|
{{- end }} |
||||
}, |
}, |
||||
methods: { |
methods: { |
||||
async save() { |
async save() { |
||||
let res; |
|
||||
|
let res |
||||
switch (this.type) { |
switch (this.type) { |
||||
case "create": |
|
||||
res = await create{{.StructName}}(this.formData); |
|
||||
break; |
|
||||
case "update": |
|
||||
res = await update{{.StructName}}(this.formData); |
|
||||
break; |
|
||||
|
case 'create': |
||||
|
res = await create{{.StructName}}(this.formData) |
||||
|
break |
||||
|
case 'update': |
||||
|
res = await update{{.StructName}}(this.formData) |
||||
|
break |
||||
default: |
default: |
||||
res = await create{{.StructName}}(this.formData); |
|
||||
break; |
|
||||
|
res = await create{{.StructName}}(this.formData) |
||||
|
break |
||||
} |
} |
||||
if (res.code == 0) { |
|
||||
|
if (res.code === 0) { |
||||
this.$message({ |
this.$message({ |
||||
type:"success", |
|
||||
message:"创建/更改成功" |
|
||||
|
type: 'success', |
||||
|
message: '创建/更改成功' |
||||
}) |
}) |
||||
} |
} |
||||
}, |
}, |
||||
back(){ |
|
||||
this.$router.go(-1) |
|
||||
|
back() { |
||||
|
this.$router.go(-1) |
||||
} |
} |
||||
}, |
|
||||
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 .Fields -}} |
|
||||
{{- if .DictType }} |
|
||||
await this.getDict("{{.DictType}}"); |
|
||||
{{ end -}} |
|
||||
{{- end }} |
|
||||
|
} |
||||
} |
} |
||||
}; |
|
||||
</script> |
</script> |
||||
|
|
||||
<style> |
<style> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue