TableTool.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <template>
  2. <div style="float: right">
  3. <!-- <div v-show="stripe" class="stripe-panel">-->
  4. <!-- <el-checkbox v-model="stripe">斑马纹</el-checkbox>-->
  5. <!-- </div>-->
  6. <!-- <div class="border-panel">-->
  7. <!-- <el-checkbox v-model="border">边框(可拉伸列)</el-checkbox>-->
  8. <!-- </div>-->
  9. <!-- <el-button-->
  10. <!-- style="margin: 0 10px 10px 0 !important"-->
  11. <!-- type="primary"-->
  12. <!-- @click="clickFullScreen">-->
  13. <!-- <vab-icon-->
  14. <!-- :icon="isFullscreen ? 'fullscreen-exit-fill' : 'fullscreen-fill'" />-->
  15. <!-- 表格全屏-->
  16. <!-- </el-button>-->
  17. <!-- <el-popover-->
  18. <!-- ref="popover"-->
  19. <!-- popper-class="custom-table-checkbox"-->
  20. <!-- trigger="hover">-->
  21. <!-- <el-radio-group v-model="lineHeight">-->
  22. <!-- <el-radio label="medium">大</el-radio>-->
  23. <!-- <el-radio label="small">中</el-radio>-->
  24. <!-- <el-radio label="mini">小</el-radio>-->
  25. <!-- </el-radio-group>-->
  26. <!-- <template #reference>-->
  27. <!-- <el-button style="margin: 0 10px 10px 0 !important" type="primary">-->
  28. <!-- <vab-icon icon="line-height" />-->
  29. <!-- 表格尺寸-->
  30. <!-- </el-button>-->
  31. <!-- </template>-->
  32. <!-- </el-popover>-->
  33. <el-popover popper-class="custom-table-checkbox" trigger="hover">
  34. <el-checkbox-group v-model="checkColumns" class="checkboxes">
  35. <vab-draggable v-bind="dragOptions" :list="columns">
  36. <div v-for="item in columns" :key="item.label">
  37. <vab-icon icon="drag-drop-line" />
  38. <el-checkbox :disabled="item.disableCheck === true" :label="item.label">
  39. {{ item.label }}
  40. </el-checkbox>
  41. </div>
  42. </vab-draggable>
  43. </el-checkbox-group>
  44. <template #reference>
  45. <el-button icon="el-icon-setting" style="margin: 0 10px 10px 0 !important" />
  46. </template>
  47. </el-popover>
  48. </div>
  49. </template>
  50. <script>
  51. import VabDraggable from 'vuedraggable'
  52. import tableColsConfigApi from '@/api/plat/tableColsConfig'
  53. export default {
  54. name: 'TableTool',
  55. components: {
  56. VabDraggable,
  57. },
  58. props: {
  59. tableType: {
  60. type: String,
  61. required: true,
  62. },
  63. columns: {
  64. type: Array,
  65. default() {
  66. return []
  67. },
  68. },
  69. showColumns: {
  70. type: Array,
  71. default() {
  72. return []
  73. },
  74. },
  75. },
  76. data() {
  77. return {
  78. isFullscreen: false,
  79. border: true,
  80. height: this.$baseTableHeight(1),
  81. stripe: false,
  82. lineHeight: 'medium',
  83. dragOptions: {
  84. animation: 600,
  85. group: 'description',
  86. },
  87. // checkList: ['标题', '作者', '评级', '点击量', '时间'],
  88. // columns: [
  89. // {
  90. // label: '标题',
  91. // width: 'auto',
  92. // prop: 'title',
  93. // sortable: true,
  94. // disableCheck: true,
  95. // },
  96. // ],
  97. flag: false,
  98. id: 0,
  99. checkColumns: [],
  100. }
  101. },
  102. watch: {
  103. async checkColumns(newValue) {
  104. let list = this.columns.filter((item) => newValue.includes(item.label))
  105. this.$emit('update:showColumns', list)
  106. if (this.flag) {
  107. const { data: id } = await tableColsConfigApi.save({
  108. id: this.id,
  109. table: this.tableType,
  110. columns: JSON.stringify(list.map((item) => item.label)),
  111. })
  112. this.id = id
  113. }
  114. this.flag = true
  115. },
  116. },
  117. created() {
  118. this.getInitData()
  119. },
  120. methods: {
  121. async getInitData() {
  122. this.flag = false
  123. this.id = 0
  124. let list = this.columns
  125. const { data: data } = await tableColsConfigApi.getEntityByTable({ table: this.tableType })
  126. if (data) {
  127. this.id = data.id
  128. if (data.columns !== '' && data.columns !== '[]') {
  129. const arr = JSON.parse(data.columns)
  130. for (const item of list) {
  131. const idx = arr.findIndex((it) => item.label == it)
  132. item.sort = idx > -1 ? idx : 0
  133. }
  134. list.sort((pre, cur) => {
  135. return pre.sort - cur.sort
  136. })
  137. }
  138. }
  139. this.checkColumns = list.map((item) => item.label)
  140. },
  141. },
  142. }
  143. </script>
  144. <style lang="scss" scoped>
  145. .custom-table-checkbox {
  146. [class*='ri'] {
  147. vertical-align: -2.5px;
  148. cursor: pointer;
  149. }
  150. .el-checkbox {
  151. margin: 5px 0 5px 8px;
  152. }
  153. }
  154. .checkboxes {
  155. max-height: 500px;
  156. overflow-y: auto;
  157. }
  158. </style>