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.

120 lines
3.7 KiB

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