table.vue.tpl 6.3 KB

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