table.vue.tpl 6.3 KB

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