settingColumns.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <template>
  2. <div>
  3. <a-popover trigger="click" placement="left" :getPopupContainer="triggerNode => {return triggerNode.parentNode || document.body;}">
  4. <template #title>
  5. <div class="title-panel">
  6. <span>筛选列</span>
  7. <a-button class="fl-r" type="link" @click="reloadConfig">重置</a-button>
  8. </div>
  9. </template>
  10. <template #content>
  11. <div style="width:150px">
  12. <a-checkbox-group v-model:value="checkedColumns" name="checkboxgroup" @change="onChange">
  13. <a-row>
  14. <a-col class="mt-10" v-for="(box,index) in columnsData" :key="box.index" :span="24" :draggable="true" @dragstart="dragStart(index)" @dragover="dragOver(index)" @drop="drop(index)" @dragend="dragEnd">
  15. <div class="flex">
  16. <a-checkbox :value="box.value">{{box.label}}</a-checkbox>
  17. <drag-outlined />
  18. </div>
  19. </a-col>
  20. </a-row>
  21. </a-checkbox-group>
  22. </div>
  23. </template>
  24. <setting-outlined />
  25. </a-popover>
  26. </div>
  27. </template>
  28. <script setup>
  29. import { SettingOutlined,DragOutlined } from '@ant-design/icons-vue';
  30. import {defineProps,ref,computed,defineEmits,defineExpose,onMounted,onActivated, nextTick} from 'vue'
  31. import utils from '@/utils/utils'
  32. import { storeToRefs } from 'pinia'
  33. import { useColumnsStore } from '@/stores/modules/columns'
  34. import { useAuthStore } from '@/stores/modules/auth'
  35. const colStore = useColumnsStore()
  36. const store = useAuthStore()
  37. let { app } = storeToRefs(store)
  38. let { checkedColumns,columnsIndex } = storeToRefs(colStore)
  39. const props = defineProps(['tableName','columns'])
  40. const emit = defineEmits(['change'])
  41. const columnsData = ref([]) // checkboxGroup数据
  42. const reloadConfig = ()=>{
  43. columnsIndex.value = checkedColumns.value = utils.TBLayout(props.tableName).map(e=>e.dataIndex)
  44. colStore.userSetting(props.tableName)
  45. }
  46. /**
  47. * 根据选中的数据过滤出表格列数据集
  48. * @param {Array} selectedColumns 当前选中的表格列
  49. */
  50. const onChange = (val)=>{
  51. colStore.userSetting(props.tableName)
  52. }
  53. const draggedIndex = ref(0)
  54. const dragStart = (index)=> {
  55. draggedIndex.value = index;
  56. }
  57. const dragOver = (index)=> {
  58. event.preventDefault();
  59. const movedIndex = draggedIndex.value;
  60. if (movedIndex !== index) {
  61. const list = [...columnsData.value];
  62. const movedItem = list[movedIndex];
  63. list.splice(movedIndex, 1);
  64. list.splice(index, 0, movedItem);
  65. columnsData.value = list;
  66. draggedIndex.value = index;
  67. columnsIndex.value = columnsData.value.map(e=>e.value)
  68. }
  69. }
  70. const drop = (index)=> {
  71. event.preventDefault();
  72. }
  73. const dragEnd = ()=> {
  74. colStore.userSetting(props.tableName)
  75. draggedIndex.value = null;
  76. }
  77. const initData = () => {
  78. columnsData.value = colStore.getUserSetting(props.tableName)
  79. }
  80. onMounted(()=>{
  81. initData()
  82. })
  83. onActivated (()=>{
  84. initData()
  85. })
  86. defineExpose({
  87. })
  88. </script>
  89. <style scoped>
  90. .flex{
  91. padding: 2px 5px;
  92. display: flex;
  93. align-items: center;
  94. justify-content: space-between;
  95. }
  96. .title-panel{
  97. display: flex;
  98. align-items: center;
  99. justify-content: space-between;
  100. overflow: hidden;
  101. }
  102. .fl-r{
  103. float: right;
  104. }
  105. </style>