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.9 KiB

  1. <template>
  2. <div>
  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. <el-form-item>
  30. <el-button @click="save" type="primary">保存</el-button>
  31. <el-button @click="back" type="primary">返回</el-button>
  32. </el-form-item>
  33. </el-form>
  34. </div>
  35. </template>
  36. <script>
  37. import {
  38. create{{.StructName}},
  39. update{{.StructName}},
  40. find{{.StructName}}
  41. } from "@/api/{{.PackageName}}"; // 此处请自行替换地址
  42. import infoList from "@/mixins/infoList";
  43. export default {
  44. name: "{{.StructName}}",
  45. mixins: [infoList],
  46. data() {
  47. return {
  48. type: "",
  49. {{- range .Fields}}
  50. {{- if .DictType }}
  51. {{ .DictType }}Options:[],
  52. {{ end -}}
  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}}:0,
  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. methods: {
  76. async save() {
  77. let res;
  78. switch (this.type) {
  79. case "create":
  80. res = await create{{.StructName}}(this.formData);
  81. break;
  82. case "update":
  83. res = await update{{.StructName}}(this.formData);
  84. break;
  85. default:
  86. res = await create{{.StructName}}(this.formData);
  87. break;
  88. }
  89. if (res.code == 0) {
  90. this.$message({
  91. type:"success",
  92. message:"创建/更改成功"
  93. })
  94. }
  95. },
  96. back(){
  97. this.$router.go(-1)
  98. }
  99. },
  100. async created() {
  101. // 建议通过url传参获取目标数据ID 调用 find方法进行查询数据操作 从而决定本页面是create还是update 以下为id作为url参数示例
  102. if(this.$route.query.id){
  103. const res = await find{{.StructName}}({ ID: this.$route.query.id })
  104. if(res.code == 0){
  105. this.formData = res.data.re{{.Abbreviation}}
  106. this.type = "update"
  107. }
  108. }else{
  109. this.type = "create"
  110. }
  111. {{ range .Fields -}}
  112. {{- if .DictType }}
  113. await this.getDict("{{.DictType}}");
  114. {{ end -}}
  115. {{- end }}
  116. }
  117. };
  118. </script>
  119. <style>
  120. </style>