index.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <template>
  2. <div class="config-container">
  3. <vab-query-form>
  4. <vab-query-form-left-panel :span="12">
  5. <el-button icon="el-icon-plus" type="primary" @click="handleEdit">添加</el-button>
  6. <el-button icon="el-icon-delete" type="danger" @click="handleDelete">批量删除</el-button>
  7. </vab-query-form-left-panel>
  8. <vab-query-form-right-panel :span="12">
  9. <el-popover popper-class="custom-table-checkbox" trigger="hover">
  10. <el-checkbox-group v-model="checkList">
  11. <vab-draggable v-bind="dragOptions" :list="columns">
  12. <div v-for="(item, index) in columns" :key="item + index">
  13. <vab-icon icon="drag-drop-line" />
  14. <el-checkbox :disabled="item.disableCheck === true" :label="item.label" />
  15. </div>
  16. </vab-draggable>
  17. </el-checkbox-group>
  18. <template #reference>
  19. <el-button icon="el-icon-setting" style="margin: 0 0 10px 0 !important" type="primary">
  20. 可拖拽列设置
  21. </el-button>
  22. </template>
  23. </el-popover>
  24. </vab-query-form-right-panel>
  25. </vab-query-form>
  26. <el-table
  27. v-loading="listLoading"
  28. border
  29. :data="list"
  30. :height="$baseTableHeight(1)"
  31. @selection-change="setSelectRows">
  32. <el-table-column align="center" show-overflow-tooltip type="selection" />
  33. <el-table-column
  34. v-for="(item, index) in finallyColumns"
  35. :key="index"
  36. align="center"
  37. :label="item.label"
  38. :prop="item.prop"
  39. :sortable="item.sortable"
  40. :width="item.width" />
  41. <el-table-column align="center" label="操作" width="85">
  42. <template #default="{ row }">
  43. <el-button type="text" @click="handleEdit(row)">编辑</el-button>
  44. <el-button type="text" @click="handleDelete(row)">删除</el-button>
  45. </template>
  46. </el-table-column>
  47. </el-table>
  48. <el-pagination
  49. background
  50. :current-page="queryForm.pageNo"
  51. :layout="layout"
  52. :page-size="queryForm.pageSize"
  53. :total="total"
  54. @current-change="handleCurrentChange"
  55. @size-change="handleSizeChange" />
  56. <edit ref="edit" @fetch-data="fetchData" />
  57. </div>
  58. </template>
  59. <script>
  60. import { getList, doDelete } from '@/api/system/config'
  61. import Edit from './components/ConfigEdit'
  62. import VabDraggable from 'vuedraggable'
  63. export default {
  64. name: 'Config',
  65. components: { Edit, VabDraggable },
  66. data() {
  67. return {
  68. checkList: [],
  69. columns: [
  70. {
  71. prop: 'id',
  72. label: '参数主键',
  73. type: 'int',
  74. width: 'auto',
  75. },
  76. {
  77. prop: 'config_name',
  78. label: '参数名称',
  79. type: 'varchar',
  80. width: 'auto',
  81. },
  82. {
  83. prop: 'config_key',
  84. label: '参数键名',
  85. type: 'varchar',
  86. width: 'auto',
  87. },
  88. {
  89. prop: 'config_value',
  90. label: '参数键值',
  91. type: 'varchar',
  92. width: 'auto',
  93. },
  94. {
  95. prop: 'config_type',
  96. label: '系统内置',
  97. type: 'varchar',
  98. width: 'auto',
  99. },
  100. {
  101. prop: 'remark',
  102. label: '备注',
  103. type: 'text',
  104. width: 'auto',
  105. },
  106. {
  107. prop: 'created_name',
  108. label: '创建人',
  109. type: 'varchar',
  110. width: 'auto',
  111. },
  112. {
  113. prop: 'created_time',
  114. label: '创建时间',
  115. type: 'datetime',
  116. width: 'auto',
  117. },
  118. ],
  119. list: [],
  120. listLoading: false,
  121. layout: 'total, sizes, prev, pager, next, jumper',
  122. total: 0,
  123. selectRows: '',
  124. queryForm: {
  125. pageNo: 1,
  126. pageSize: 10,
  127. title: '',
  128. },
  129. }
  130. },
  131. computed: {
  132. dragOptions() {
  133. return {
  134. animation: 600,
  135. group: 'description',
  136. }
  137. },
  138. finallyColumns() {
  139. return this.columns.filter((item) => this.checkList.includes(item.label))
  140. },
  141. },
  142. created() {
  143. for (const elem of this.columns) {
  144. this.checkList.push(elem.label)
  145. }
  146. // this.fetchData()
  147. },
  148. methods: {
  149. setSelectRows(val) {
  150. this.selectRows = val
  151. },
  152. handleEdit(row) {
  153. if (row.id) {
  154. this.$refs['edit'].showEdit(row)
  155. } else {
  156. this.$refs['edit'].showEdit()
  157. }
  158. },
  159. handleDelete(row) {
  160. if (row.id) {
  161. this.$baseConfirm('你确定要删除当前项吗', null, async () => {
  162. const { msg } = await doDelete({ ids: row.id })
  163. this.$baseMessage(msg, 'success')
  164. await this.fetchData()
  165. })
  166. } else {
  167. if (this.selectRows.length > 0) {
  168. const ids = this.selectRows.map((item) => item.id).join()
  169. this.$baseConfirm('你确定要删除选中项吗', null, async () => {
  170. const { msg } = await doDelete({ ids })
  171. this.$baseMessage(msg, 'success')
  172. await this.fetchData()
  173. })
  174. } else {
  175. this.$baseMessage('未选中任何行', 'error')
  176. return false
  177. }
  178. }
  179. },
  180. handleSizeChange(val) {
  181. this.queryForm.pageSize = val
  182. this.fetchData()
  183. },
  184. handleCurrentChange(val) {
  185. this.queryForm.pageNo = val
  186. this.fetchData()
  187. },
  188. queryData() {
  189. this.queryForm.pageNo = 1
  190. this.fetchData()
  191. },
  192. async fetchData() {
  193. this.listLoading = true
  194. const { data } = await getList(this.queryForm)
  195. const { list, total } = data
  196. this.list = list
  197. this.total = total
  198. this.listLoading = false
  199. },
  200. },
  201. }
  202. </script>