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.

124 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 .Fields}}
  52. {{- if .DictType }}
  53. {{ .DictType }}Options: [],
  54. {{- end }}
  55. {{- end }}
  56. formData: {
  57. {{- range .Fields}}
  58. {{- if eq .FieldType "bool" }}
  59. {{.FieldJson}}: false,
  60. {{- end }}
  61. {{- if eq .FieldType "string" }}
  62. {{.FieldJson}}: '',
  63. {{- end }}
  64. {{- if eq .FieldType "int" }}
  65. {{.FieldJson}}: 0,
  66. {{- end }}
  67. {{- if eq .FieldType "time.Time" }}
  68. {{.FieldJson}}: new Date(),
  69. {{- end }}
  70. {{- if eq .FieldType "float64" }}
  71. {{.FieldJson}}: 0,
  72. {{- end }}
  73. {{- end }}
  74. }
  75. }
  76. },
  77. async created() {
  78. // 建议通过url传参获取目标数据ID 调用 find方法进行查询数据操作 从而决定本页面是create还是update 以下为id作为url参数示例
  79. if (this.$route.query.id) {
  80. const res = await find{{.StructName}}({ ID: this.$route.query.id })
  81. if (res.code === 0) {
  82. this.formData = res.data.re{{.Abbreviation}}
  83. this.type = 'update'
  84. }
  85. } else {
  86. this.type = 'create'
  87. }
  88. {{- range .Fields }}
  89. {{- if .DictType }}
  90. await this.getDict('{{.DictType}}')
  91. {{- end }}
  92. {{- end }}
  93. },
  94. methods: {
  95. async save() {
  96. let res
  97. switch (this.type) {
  98. case 'create':
  99. res = await create{{.StructName}}(this.formData)
  100. break
  101. case 'update':
  102. res = await update{{.StructName}}(this.formData)
  103. break
  104. default:
  105. res = await create{{.StructName}}(this.formData)
  106. break
  107. }
  108. if (res.code === 0) {
  109. this.$message({
  110. type: 'success',
  111. message: '创建/更改成功'
  112. })
  113. }
  114. },
  115. back() {
  116. this.$router.go(-1)
  117. }
  118. }
  119. }
  120. </script>
  121. <style>
  122. </style>