table.vue.tpl 6.0 KB

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