table.vue.tpl 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <template>
  2. <div>
  3. <div class="search-term">
  4. <el-form :inline="true" :model="searchInfo" class="demo-form-inline">
  5. {{- range .Fields}}
  6. {{- if .FieldSearchType}}
  7. <el-form-item label="{{.FieldDesc}}">
  8. <el-input placeholder="搜索条件" v-model="searchInfo.{{.FieldJson}}"></el-input>
  9. </el-form-item>
  10. {{ end }}
  11. {{ end }}
  12. <el-form-item>
  13. <el-button @click="onSubmit" type="primary">查询</el-button>
  14. </el-form-item>
  15. <el-form-item>
  16. <el-button @click="openDialog" type="primary">新增api</el-button>
  17. </el-form-item>
  18. </el-form>
  19. </div>
  20. <el-table
  21. :data="tableData"
  22. border
  23. ref="multipleTable"
  24. stripe
  25. style="width: 100%"
  26. tooltip-effect="dark"
  27. >
  28. <el-table-column type="selection" width="55"></el-table-column>
  29. <el-table-column label="日期" width="180">
  30. <template slot-scope="scope">{{ "{{scope.row.CreatedAt|formatDate}}" }}</template>
  31. </el-table-column>
  32. {{range .Fields}}
  33. <el-table-column label="{{.FieldDesc}}" prop="{{.FieldJson}}" width="120"></el-table-column>
  34. {{ end }}
  35. <el-table-column label="按钮组">
  36. <template slot-scope="scope">
  37. <el-button @click="update{{.StructName}}(scope.row)" size="small" type="text">变更</el-button>
  38. <el-popover placement="top" width="160" v-model="scope.row.visible">
  39. <p>确定要删除吗?</p>
  40. <div style="text-align: right; margin: 0">
  41. <el-button size="mini" type="text" @click="scope.row.visible = false">取消</el-button>
  42. <el-button type="primary" size="mini" @click="delete{{.StructName}}(scope.row)">确定</el-button>
  43. </div>
  44. <el-button type="text" size="mini" slot="reference">删除</el-button>
  45. </el-popover>
  46. </template>
  47. </el-table-column>
  48. </el-table>
  49. <el-pagination
  50. :current-page="page"
  51. :page-size="pageSize"
  52. :page-sizes="[10, 30, 50, 100]"
  53. :style="{float:'right',padding:'20px'}"
  54. :total="total"
  55. @current-change="handleCurrentChange"
  56. @size-change="handleSizeChange"
  57. layout="total, sizes, prev, pager, next, jumper"
  58. ></el-pagination>
  59. <el-dialog :before-close="closeDialog" :visible.sync="dialogFormVisible" title="弹窗操作">
  60. 此处请使用表单生成器生成form填充 表单默认绑定 formData 如手动修改过请自行修改key
  61. <div class="dialog-footer" slot="footer">
  62. <el-button @click="closeDialog">取 消</el-button>
  63. <el-button @click="enterDialog" type="primary">确 定</el-button>
  64. </div>
  65. </el-dialog>
  66. </div>
  67. </template>
  68. <script>
  69. import {
  70. create{{.StructName}},
  71. delete{{.StructName}},
  72. update{{.StructName}},
  73. find{{.StructName}},
  74. get{{.StructName}}List
  75. } from "@/api/{{.PackageName}}"; // 此处请自行替换地址
  76. import { formatTimeToStr } from "@/utils/data";
  77. import infoList from "@/components/mixins/infoList";
  78. export default {
  79. name: "{{.StructName}}",
  80. mixins: [infoList],
  81. data() {
  82. return {
  83. listApi: get{{.StructName}}List,
  84. dialogFormVisible: false,
  85. visible: false,
  86. type: "",
  87. formData: {
  88. {{range .Fields}}{{.FieldJson}}:null,{{ end }}
  89. }
  90. };
  91. },
  92. filters: {
  93. formatDate: function(time) {
  94. if (time != null && time != "") {
  95. var date = new Date(time);
  96. return formatTimeToStr(date, "yyyy-MM-dd hh:mm:ss");
  97. } else {
  98. return "";
  99. }
  100. }
  101. },
  102. methods: {
  103. //条件搜索前端看此方法
  104. onSubmit() {
  105. this.page = 1
  106. this.pageSize = 10
  107. this.getTableData()
  108. },
  109. async update{{.StructName}}(row) {
  110. const res = await find{{.StructName}}({ ID: row.ID });
  111. this.type = "update";
  112. if (res.code == 0) {
  113. this.formData = res.data.re{{.Abbreviation}};
  114. this.dialogFormVisible = true;
  115. }
  116. },
  117. closeDialog() {
  118. this.dialogFormVisible = false;
  119. this.formData = {
  120. {{range .Fields}}
  121. {{.FieldJson}}:null,{{ end }}
  122. };
  123. },
  124. async delete{{.StructName}}(row) {
  125. this.visible = false;
  126. const res = await delete{{.StructName}}({ ID: row.ID });
  127. if (res.code == 0) {
  128. this.$message({
  129. type: "success",
  130. message: "删除成功"
  131. });
  132. this.getTableData();
  133. }
  134. },
  135. async enterDialog() {
  136. let res;
  137. switch (this.type) {
  138. case "create":
  139. res = await create{{.StructName}}(this.formData);
  140. break;
  141. case "update":
  142. res = await update{{.StructName}}(this.formData);
  143. break;
  144. default:
  145. res = await create{{.StructName}}(this.formData);
  146. break;
  147. }
  148. if (res.code == 0) {
  149. this.closeDialog();
  150. this.getTableData();
  151. }
  152. },
  153. openDialog() {
  154. this.type = "create";
  155. this.dialogFormVisible = true;
  156. }
  157. },
  158. created() {
  159. this.getTableData();
  160. }
  161. };
  162. </script>
  163. <style>
  164. </style>