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.

154 lines
4.4 KiB

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