SelectColumn.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <template>
  2. <div class="select-column">
  3. <div class="text" @click="handleSetShowColumnBtnClick">
  4. <setting-outlined class="icon1" />
  5. 设置显示字段
  6. </div>
  7. <!-- 对话框 当点击"设置显示列"按钮时弹出对话框 -->
  8. <a-modal
  9. title="设置表格列显隐"
  10. width="700px"
  11. v-model:visible="dialogVisible"
  12. @ok="dialogOk"
  13. @cancel="dialogVisible = false"
  14. >
  15. <!-- 多选框组件 勾选需要在表格中显示的列 -->
  16. <a-checkbox-group v-model:value="selectedColumn">
  17. <a-checkbox v-for="item in columnOptions" :key="item.value" :value="item.value">{{ item.label }}</a-checkbox>
  18. </a-checkbox-group>
  19. <template #footer>
  20. <a-button @click="dialogVisible = false">取 消</a-button>
  21. <a-button type="primary" @click="dialogOk()">确 定</a-button>
  22. </template>
  23. </a-modal>
  24. </div>
  25. </template>
  26. <script setup>
  27. import { ref, onMounted } from 'vue'
  28. import { useMyResourceStore } from '@/store/myResource'
  29. import { SettingOutlined } from '@ant-design/icons-vue'
  30. const myResourceStore = useMyResourceStore()
  31. const dialogVisible = ref(false)
  32. const selectedColumn = ref([]) // 被选中的表格需要显示的列
  33. const columnOptions = ref([
  34. {
  35. value: 'extendName',
  36. label: '类型'
  37. },
  38. {
  39. value: 'fileSize',
  40. label: '大小'
  41. },
  42. {
  43. value: 'uploadTime',
  44. label: '修改日期'
  45. },
  46. {
  47. value: 'deleteTime',
  48. label: '删除日期'
  49. }
  50. ])
  51. /**
  52. * 设置显示列按钮点击事件
  53. * @description 获取 Vuex 中存储的表格显示列
  54. * 并打开对话框
  55. */
  56. const handleSetShowColumnBtnClick = () => {
  57. selectedColumn.value = myResourceStore.selectedColumnList
  58. dialogVisible.value = true
  59. }
  60. /**
  61. * 对话框 确定按钮点击事件
  62. * @description 通过提交 mutation 更新表格显示列
  63. * 并关闭对话框
  64. */
  65. const dialogOk = () => {
  66. myResourceStore.changeSelectedColumnList(selectedColumn.value)
  67. dialogVisible.value = false
  68. }
  69. onMounted(() => {
  70. // 可以在这里进行一些初始化操作,例如从本地存储加载列设置
  71. })
  72. </script>
  73. <style lang="less" scoped>
  74. @import '@/style/myResource/varibles.less';
  75. .select-column {
  76. .text {
  77. padding-top: 8px;
  78. cursor: pointer;
  79. &:hover {
  80. color: #29175b;
  81. }
  82. }
  83. }
  84. :deep(.ant-checkbox-wrapper-checked) {
  85. .ant-checkbox-inner {
  86. background-color: #29175b;
  87. border-color: #29175b;
  88. }
  89. .ant-checkbox + span {
  90. color: #29175b;
  91. }
  92. }
  93. :deep(.ant-btn-primary) {
  94. color: #fff;
  95. background-color: #29175b;
  96. border-color: #29175b;
  97. }
  98. .icon1:hover {
  99. color: #29175b;
  100. }
  101. :deep(.ant-btn:focus),
  102. :deep(.ant-btn:hover) {
  103. color: white;
  104. border-color: #a093c3;
  105. background-color: #a093c3;
  106. }
  107. </style>