|
1 | 1 | <template> |
2 | | -<div> |
| 2 | + <div> |
3 | 3 | <el-form :model="formData" label-position="right" label-width="80px"> |
4 | | - {{- range .Fields}} |
5 | | - <el-form-item label="{{.FieldDesc}}:"> |
6 | | - {{- if eq .FieldType "bool" }} |
7 | | - <el-switch active-color="#13ce66" inactive-color="#ff4949" active-text="是" inactive-text="否" v-model="formData.{{.FieldJson}}" clearable ></el-switch> |
8 | | - {{ end -}} |
9 | | - {{- if eq .FieldType "string" }} |
10 | | - <el-input v-model="formData.{{.FieldJson}}" clearable placeholder="请输入" ></el-input> |
11 | | - {{ end -}} |
12 | | - {{- if eq .FieldType "int" }} |
13 | | - {{- if .DictType}} |
14 | | - <el-select v-model="formData.{{ .FieldJson }}" placeholder="请选择" clearable> |
15 | | - <el-option v-for="(item,key) in {{ .DictType }}Options" :key="key" :label="item.label" :value="item.value"></el-option> |
16 | | - </el-select> |
17 | | - {{ else -}} |
18 | | - <el-input v-model.number="formData.{{ .FieldJson }}" clearable placeholder="请输入"></el-input> |
19 | | - {{ end -}} |
20 | | - {{ end -}} |
21 | | - {{- if eq .FieldType "time.Time" }} |
22 | | - <el-date-picker type="date" placeholder="选择日期" v-model="formData.{{ .FieldJson }}" clearable></el-date-picker> |
23 | | - {{ end -}} |
24 | | - {{- if eq .FieldType "float64" }} |
25 | | - <el-input-number v-model="formData.{{ .FieldJson }}" :precision="2" clearable></el-input-number> |
26 | | - {{ end -}} |
27 | | - </el-form-item> |
28 | | - {{ end -}} |
29 | | - |
30 | | - <el-form-item> |
31 | | - <el-button @click="save" type="primary">保存</el-button> |
32 | | - <el-button @click="back" type="primary">返回</el-button> |
33 | | - </el-form-item> |
| 4 | + {{- range .Fields}} |
| 5 | + <el-form-item label="{{.FieldDesc}}:"> |
| 6 | + {{ if eq .FieldType "bool" -}} |
| 7 | + <el-switch active-color="#13ce66" inactive-color="#ff4949" active-text="是" inactive-text="否" v-model="formData.{{.FieldJson}}" clearable ></el-switch> |
| 8 | + {{ end -}} |
| 9 | + {{ if eq .FieldType "string" -}} |
| 10 | + <el-input v-model="formData.{{.FieldJson}}" clearable placeholder="请输入" /> |
| 11 | + {{ end -}} |
| 12 | + {{ if eq .FieldType "int" -}} |
| 13 | + {{ if .DictType -}} |
| 14 | + <el-select v-model="formData.{{ .FieldJson }}" placeholder="请选择" clearable> |
| 15 | + <el-option v-for="(item,key) in {{ .DictType }}Options" :key="key" :label="item.label" :value="item.value"></el-option> |
| 16 | + </el-select> |
| 17 | + {{ else -}} |
| 18 | + <el-input v-model.number="formData.{{ .FieldJson }}" clearable placeholder="请输入"/> |
| 19 | + {{ end -}} |
| 20 | + {{ end -}} |
| 21 | + {{ if eq .FieldType "time.Time" }} |
| 22 | + <el-date-picker type="date" placeholder="选择日期" v-model="formData.{{ .FieldJson }}" clearable></el-date-picker> |
| 23 | + {{ end -}} |
| 24 | + {{ if eq .FieldType "float64" }} |
| 25 | + <el-input-number v-model="formData.{{ .FieldJson }}" :precision="2" clearable></el-input-number> |
| 26 | + {{ end -}} |
| 27 | + </el-form-item> |
| 28 | + {{ end -}} |
| 29 | + <el-form-item> |
| 30 | + <el-button type="primary" @click="save">保存</el-button> |
| 31 | + <el-button type="primary" @click="back">返回</el-button> |
| 32 | + </el-form-item> |
34 | 33 | </el-form> |
35 | 34 | </div> |
36 | 35 | </template> |
37 | 36 |
|
38 | 37 | <script> |
39 | 38 | import { |
40 | | - create{{.StructName}}, |
41 | | - update{{.StructName}}, |
42 | | - find{{.StructName}} |
43 | | -} from "@/api/{{.PackageName}}"; // 此处请自行替换地址 |
44 | | -import infoList from "@/mixins/infoList"; |
| 39 | + create{{.StructName}}, |
| 40 | + update{{.StructName}}, |
| 41 | + find{{.StructName}} |
| 42 | +} from '@/api/{{.PackageName}}' // 此处请自行替换地址 |
| 43 | +import infoList from '@/mixins/infoList' |
45 | 44 | export default { |
46 | | - name: "{{.StructName}}", |
| 45 | + name: '{{.StructName}}', |
47 | 46 | mixins: [infoList], |
48 | 47 | data() { |
49 | 48 | return { |
50 | | - type: "", |
51 | | -
|
52 | | - {{- range .Fields}} |
| 49 | + type: '', |
| 50 | + {{range .Fields}} |
53 | 51 | {{- if .DictType }} |
54 | | - {{ .DictType }}Options:[], |
| 52 | + {{ .DictType }}Options: [], |
55 | 53 | {{ end -}} |
56 | 54 | {{end -}} |
57 | | -
|
58 | 55 | formData: { |
59 | 56 | {{range .Fields}} |
60 | 57 | {{- if eq .FieldType "bool" -}} |
61 | | - {{.FieldJson}}:false, |
| 58 | + {{.FieldJson}}: false, |
62 | 59 | {{ end -}} |
63 | 60 | {{- if eq .FieldType "string" -}} |
64 | | - {{.FieldJson}}:"", |
| 61 | + {{.FieldJson}}: '', |
65 | 62 | {{ end -}} |
66 | 63 | {{- if eq .FieldType "int" -}} |
67 | | - {{.FieldJson}}:0, |
| 64 | + {{.FieldJson}}: 0, |
68 | 65 | {{ end -}} |
69 | 66 | {{- if eq .FieldType "time.Time" -}} |
70 | | - {{.FieldJson}}:new Date(), |
| 67 | + {{.FieldJson}}: new Date(), |
71 | 68 | {{ end -}} |
72 | 69 | {{- if eq .FieldType "float64" -}} |
73 | | - {{.FieldJson}}:0, |
| 70 | + {{.FieldJson}}: 0, |
74 | 71 | {{ end -}} |
75 | 72 | {{ end }} |
76 | 73 | } |
77 | | - }; |
| 74 | + } |
| 75 | + }, |
| 76 | + async created() { |
| 77 | + // 建议通过url传参获取目标数据ID 调用 find方法进行查询数据操作 从而决定本页面是create还是update 以下为id作为url参数示例 |
| 78 | + if (this.$route.query.id) { |
| 79 | + const res = await find{{.StructName}}({ ID: this.$route.query.id }) |
| 80 | + if (res.code === 0) { |
| 81 | + this.formData = res.data.re{{.Abbreviation}} |
| 82 | + this.type = 'update' |
| 83 | + } |
| 84 | + } else { |
| 85 | + this.type = 'create' |
| 86 | + } |
| 87 | + {{ range .Fields -}} |
| 88 | + {{- if .DictType }} |
| 89 | + await this.getDict("{{.DictType}}") |
| 90 | + {{ end -}} |
| 91 | + {{- end }} |
78 | 92 | }, |
79 | 93 | methods: { |
80 | 94 | async save() { |
81 | | - let res; |
| 95 | + let res |
82 | 96 | switch (this.type) { |
83 | | - case "create": |
84 | | - res = await create{{.StructName}}(this.formData); |
85 | | - break; |
86 | | - case "update": |
87 | | - res = await update{{.StructName}}(this.formData); |
88 | | - break; |
| 97 | + case 'create': |
| 98 | + res = await create{{.StructName}}(this.formData) |
| 99 | + break |
| 100 | + case 'update': |
| 101 | + res = await update{{.StructName}}(this.formData) |
| 102 | + break |
89 | 103 | default: |
90 | | - res = await create{{.StructName}}(this.formData); |
91 | | - break; |
| 104 | + res = await create{{.StructName}}(this.formData) |
| 105 | + break |
92 | 106 | } |
93 | | - if (res.code == 0) { |
| 107 | + if (res.code === 0) { |
94 | 108 | this.$message({ |
95 | | - type:"success", |
96 | | - message:"创建/更改成功" |
| 109 | + type: 'success', |
| 110 | + message: '创建/更改成功' |
97 | 111 | }) |
98 | 112 | } |
99 | 113 | }, |
100 | | - back(){ |
101 | | - this.$router.go(-1) |
| 114 | + back() { |
| 115 | + this.$router.go(-1) |
102 | 116 | } |
103 | | - }, |
104 | | - async created() { |
105 | | - // 建议通过url传参获取目标数据ID 调用 find方法进行查询数据操作 从而决定本页面是create还是update 以下为id作为url参数示例 |
106 | | - if(this.$route.query.id){ |
107 | | - const res = await find{{.StructName}}({ ID: this.$route.query.id }) |
108 | | - if(res.code == 0){ |
109 | | - this.formData = res.data.re{{.Abbreviation}} |
110 | | - this.type = "update" |
111 | | - } |
112 | | - }else{ |
113 | | - this.type = "create" |
114 | | - } |
115 | | - {{ range .Fields -}} |
116 | | - {{- if .DictType }} |
117 | | - await this.getDict("{{.DictType}}"); |
118 | | - {{ end -}} |
119 | | - {{- end }} |
| 117 | + } |
120 | 118 | } |
121 | | -}; |
122 | 119 | </script> |
123 | 120 |
|
124 | 121 | <style> |
|
0 commit comments