|
37 | 37 | </template>
|
38 | 38 |
|
39 | 39 | <script>
|
| 40 | +export default { |
| 41 | + name: '{{.StructName}}' |
| 42 | +} |
| 43 | +</script> |
| 44 | + |
| 45 | +<script setup> |
40 | 46 | import {
|
41 | 47 | create{{.StructName}},
|
42 | 48 | update{{.StructName}},
|
43 | 49 | find{{.StructName}}
|
44 |
| -} from '@/api/{{.PackageName}}' // 此处请自行替换地址 |
45 |
| -import infoList from '@/mixins/infoList' |
46 |
| -export default { |
47 |
| - name: '{{.StructName}}', |
48 |
| - mixins: [infoList], |
49 |
| - data() { |
50 |
| - return { |
51 |
| - type: '', |
52 |
| - {{- range $index, $element := .DictTypes}} |
53 |
| - {{ $element }}Options: [], |
54 |
| - {{- end }} |
55 |
| - formData: { |
| 50 | +} from '@/api/{{.PackageName}}' |
| 51 | +
|
| 52 | +import { getDictFunc } from '@/utils/format' |
| 53 | +import { useRoute, useRouter } from "vue-router" |
| 54 | +import { ElMessage } from 'element-plus' |
| 55 | +import { ref } from 'vue' |
| 56 | +const route = useRoute() |
| 57 | +const router = useRouter() |
| 58 | +const type = ref('') |
| 59 | + {{- range $index, $element := .DictTypes}} |
| 60 | +const {{ $element }}Options = ref([]) |
| 61 | + {{- end }} |
| 62 | +const formData = ref({ |
56 | 63 | {{- range .Fields}}
|
57 |
| - {{- if eq .FieldType "bool" }} |
| 64 | + {{- if eq .FieldType "bool" }} |
58 | 65 | {{.FieldJson}}: false,
|
59 |
| - {{- end }} |
60 |
| - {{- if eq .FieldType "string" }} |
| 66 | + {{- end }} |
| 67 | + {{- if eq .FieldType "string" }} |
61 | 68 | {{.FieldJson}}: '',
|
62 |
| - {{- end }} |
63 |
| - {{- if eq .FieldType "int" }} |
| 69 | + {{- end }} |
| 70 | + {{- if eq .FieldType "int" }} |
64 | 71 | {{.FieldJson}}: {{- if .DictType }} undefined{{ else }} 0{{- end }},
|
65 |
| - {{- end }} |
66 |
| - {{- if eq .FieldType "time.Time" }} |
| 72 | + {{- end }} |
| 73 | + {{- if eq .FieldType "time.Time" }} |
67 | 74 | {{.FieldJson}}: new Date(),
|
68 |
| - {{- end }} |
69 |
| - {{- if eq .FieldType "float64" }} |
| 75 | + {{- end }} |
| 76 | + {{- if eq .FieldType "float64" }} |
70 | 77 | {{.FieldJson}}: 0,
|
71 |
| - {{- end }} |
72 | 78 | {{- end }}
|
73 |
| - } |
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 }) |
| 79 | + {{- end }} |
| 80 | + }) |
| 81 | +const init = async () => { |
| 82 | + // 建议通过url传参获取目标数据ID 调用 find方法进行查询数据操作 从而决定本页面是create还是update 以下为id作为url参数示例 |
| 83 | + if (route.query.id) { |
| 84 | + const res = await find{{.StructName}}({ ID: route.query.id }) |
80 | 85 | if (res.code === 0) {
|
81 |
| - this.formData = res.data.re{{.Abbreviation}} |
82 |
| - this.type = 'update' |
| 86 | + formData.value = res.data.re{{.Abbreviation}} |
| 87 | + type.value = 'update' |
83 | 88 | }
|
84 | 89 | } else {
|
85 |
| - this.type = 'create' |
| 90 | + type.value = 'create' |
86 | 91 | }
|
87 | 92 | {{- range $index, $element := .DictTypes }}
|
88 |
| - await this.getDict('{{$element}}') |
| 93 | + {{ $element }}Options.value = await getDictFunc('{{$element}}') |
89 | 94 | {{- end }}
|
90 |
| - }, |
91 |
| - methods: { |
92 |
| - async save() { |
| 95 | +} |
| 96 | +
|
| 97 | +init() |
| 98 | +
|
| 99 | + const save = async() => { |
93 | 100 | let res
|
94 |
| - switch (this.type) { |
| 101 | + switch (type.value) { |
95 | 102 | case 'create':
|
96 |
| - res = await create{{.StructName}}(this.formData) |
| 103 | + res = await create{{.StructName}}(formData.value) |
97 | 104 | break
|
98 | 105 | case 'update':
|
99 |
| - res = await update{{.StructName}}(this.formData) |
| 106 | + res = await update{{.StructName}}(formData.value) |
100 | 107 | break
|
101 | 108 | default:
|
102 |
| - res = await create{{.StructName}}(this.formData) |
| 109 | + res = await create{{.StructName}}(formData.value) |
103 | 110 | break
|
104 | 111 | }
|
105 | 112 | if (res.code === 0) {
|
106 |
| - this.$message({ |
| 113 | + ElMessage({ |
107 | 114 | type: 'success',
|
108 | 115 | message: '创建/更改成功'
|
109 | 116 | })
|
110 | 117 | }
|
111 |
| - }, |
112 |
| - back() { |
113 |
| - this.$router.go(-1) |
114 | 118 | }
|
115 |
| - } |
| 119 | +const back = () => { |
| 120 | + router.go(-1) |
116 | 121 | }
|
| 122 | +
|
117 | 123 | </script>
|
118 | 124 |
|
119 | 125 | <style>
|
|
0 commit comments