index.hbs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <template>
  2. <div class="{{ dashCase name }}-container">
  3. <vab-query-form>
  4. <vab-query-form-left-panel :span="12">
  5. <el-button icon="el-icon-plus" type="primary" @click="handleEdit">
  6. 添加
  7. </el-button>
  8. <el-button icon="el-icon-delete" type="danger" @click="handleDelete">
  9. 删除
  10. </el-button>
  11. </vab-query-form-left-panel>
  12. <vab-query-form-right-panel :span="12">
  13. <table-tool :check-list.sync="checkList" :columns="columns" />
  14. </vab-query-form-right-panel>
  15. </vab-query-form>
  16. <el-table
  17. v-loading="listLoading"
  18. :data="list"
  19. :height="height"
  20. @selection-change="setSelectRows"
  21. >
  22. <el-table-column align="center" show-overflow-tooltip type="selection" />
  23. <el-table-column
  24. v-for="(item, index) in finallyColumns"
  25. :key="index"
  26. align="center"
  27. :label="item.label"
  28. :prop="item.prop"
  29. show-overflow-tooltip
  30. :sortable="item.sortable"
  31. :width="item.width"
  32. >
  33. </el-table-column>
  34. <el-table-column align="center" label="操作" width="85">
  35. <template #default="{ row }">
  36. <el-button type="text" @click="handleEdit(row)">编辑</el-button>
  37. <el-button type="text" @click="handleDelete(row)">删除</el-button>
  38. </template>
  39. </el-table-column>
  40. </el-table>
  41. <el-pagination
  42. background
  43. :current-page="queryForm.pageNo"
  44. :layout="layout"
  45. :page-size="queryForm.pageSize"
  46. :total="total"
  47. @current-change="handleCurrentChange"
  48. @size-change="handleSizeChange"
  49. />
  50. <edit ref="edit" @fetch-data="fetchData" />
  51. </div>
  52. </template>
  53. <script>
  54. import { getList, doDelete } from '@/api/{{moduleName}}/{{ camelCase name }}'
  55. import Edit from './components/{{ properCase name }}Edit'
  56. import TableTool from '@/components/table/TableTool'
  57. export default {
  58. name: '{{ properCase name }}',
  59. components: { Edit, TableTool },
  60. data() {
  61. return {
  62. height: this.$baseTableHeight(1),
  63. checkList: [],
  64. columns: [],
  65. list: [],
  66. listLoading: true,
  67. layout: 'total, sizes, prev, pager, next, jumper',
  68. total: 0,
  69. selectRows: '',
  70. queryForm: {
  71. pageNo: 1,
  72. pageSize: 10,
  73. title: '',
  74. },
  75. }
  76. },
  77. computed: {
  78. finallyColumns() {
  79. return this.columns.filter((item) =>
  80. this.checkList.includes(item.label)
  81. )
  82. },
  83. },
  84. created() {
  85. this.fetchData()
  86. },
  87. methods: {
  88. setSelectRows(val) {
  89. this.selectRows = val
  90. },
  91. handleEdit(row) {
  92. if (row.id) {
  93. this.$refs['edit'].showEdit(row)
  94. } else {
  95. this.$refs['edit'].showEdit()
  96. }
  97. },
  98. handleDelete(row) {
  99. if (row.id) {
  100. this.$baseConfirm('你确定要删除当前项吗', null, async () => {
  101. const { msg } = await doDelete({ ids: [row.id] })
  102. this.$baseMessage(msg, 'success')
  103. await this.fetchData()
  104. })
  105. } else {
  106. if (this.selectRows.length > 0) {
  107. const ids = this.selectRows.map((item) => item.id)
  108. this.$baseConfirm('你确定要删除选中项吗', null, async () => {
  109. const { msg } = await doDelete({ ids })
  110. this.$baseMessage(msg, 'success')
  111. await this.fetchData()
  112. })
  113. } else {
  114. this.$baseMessage('未选中任何行', 'error')
  115. return false
  116. }
  117. }
  118. },
  119. handleSizeChange(val) {
  120. this.queryForm.pageSize = val
  121. this.fetchData()
  122. },
  123. handleCurrentChange(val) {
  124. this.queryForm.pageNo = val
  125. this.fetchData()
  126. },
  127. queryData() {
  128. this.queryForm.pageNo = 1
  129. this.fetchData()
  130. },
  131. async fetchData() {
  132. this.listLoading = true
  133. const { data } = await getList(this.queryForm)
  134. const { list, total } = data
  135. this.list = list
  136. this.total = total
  137. this.listLoading = false
  138. },
  139. },
  140. }
  141. </script>