column.vue 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <template>
  2. <el-table ref="table" :data="columnData" row-key="prop" style="width: 100%" border>
  3. <el-table-column prop="" label="排序" width="60">
  4. <el-tag disable-transitions class="move" style="cursor: move;"><el-icon style="cursor: move;"><el-icon-d-caret/></el-icon></el-tag>
  5. </el-table-column>
  6. <el-table-column prop="label" label="列名">
  7. <template #default="scope">
  8. <el-tag round disable-transitions :effect="scope.row.hide?'light':'dark'" :type="scope.row.hide?'info':''">{{ scope.row.label }}</el-tag>
  9. </template>
  10. </el-table-column>
  11. <el-table-column prop="hide" label="显示" width="60">
  12. <template #default="scope">
  13. <el-switch v-model="scope.row.hide" size="small" :active-value="false" :inactive-value="true"/>
  14. </template>
  15. </el-table-column>
  16. </el-table>
  17. </template>
  18. <script>
  19. import Sortable from 'sortablejs'
  20. export default {
  21. emits: ['success'],
  22. props: {
  23. column: { type: Array, default: () => [] }
  24. },
  25. data() {
  26. return {
  27. columnData: this.column
  28. }
  29. },
  30. mounted() {
  31. this.rowDrop()
  32. },
  33. methods: {
  34. rowDrop(){
  35. const _this = this
  36. const tbody = this.$refs.table.$el.querySelector('.el-table__body-wrapper tbody')
  37. Sortable.create(tbody, {
  38. handle: ".move",
  39. animation: 200,
  40. ghostClass: "ghost",
  41. onEnd({ newIndex, oldIndex }) {
  42. const tableData = _this.columnData
  43. const currRow = tableData.splice(oldIndex, 1)[0]
  44. tableData.splice(newIndex, 0, currRow)
  45. }
  46. })
  47. }
  48. }
  49. }
  50. </script>