index.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <template>
  2. <div class="top-right-btn" :style="style">
  3. <el-row>
  4. <el-tooltip
  5. v-if="search"
  6. class="item"
  7. effect="dark"
  8. :content="showSearch ? t('components.rightToolbar.hideSearch') : t('components.rightToolbar.showSearch')"
  9. placement="top"
  10. >
  11. <el-button circle icon="Search" @click="toggleSearch()" />
  12. </el-tooltip>
  13. <el-tooltip class="item" effect="dark" :content="t('components.rightToolbar.refresh')" placement="top">
  14. <el-button circle icon="Refresh" @click="refresh()" />
  15. </el-tooltip>
  16. <el-tooltip v-if="columns" class="item" effect="dark" :content="t('components.rightToolbar.columnSetting')" placement="top">
  17. <div class="show-btn">
  18. <el-popover placement="bottom" trigger="click">
  19. <div class="tree-header">{{ t('components.rightToolbar.columnSetting') }}</div>
  20. <el-tree
  21. ref="columnRef"
  22. :data="columns"
  23. show-checkbox
  24. node-key="key"
  25. :props="{ label: 'label', children: 'children' } as any"
  26. @check="columnChange"
  27. ></el-tree>
  28. <template #reference>
  29. <el-button circle icon="Menu" />
  30. </template>
  31. </el-popover>
  32. </div>
  33. </el-tooltip>
  34. </el-row>
  35. </div>
  36. </template>
  37. <script setup lang="ts">
  38. import { propTypes } from '@/utils/propTypes';
  39. import { useI18n } from 'vue-i18n';
  40. const { t } = useI18n();
  41. const props = defineProps({
  42. showSearch: propTypes.bool.def(true),
  43. columns: propTypes.fieldOption,
  44. search: propTypes.bool.def(true),
  45. gutter: propTypes.number.def(10)
  46. });
  47. const columnRef = ref<ElTreeInstance>();
  48. const emits = defineEmits(['update:showSearch', 'queryTable']);
  49. const style = computed(() => {
  50. const ret: any = {};
  51. if (props.gutter) {
  52. ret.marginRight = `${props.gutter / 2}px`;
  53. }
  54. return ret;
  55. });
  56. // 搜索
  57. function toggleSearch() {
  58. emits('update:showSearch', !props.showSearch);
  59. }
  60. // 刷新
  61. function refresh() {
  62. emits('queryTable');
  63. }
  64. // 更改数据列的显示和隐藏
  65. function columnChange(...args: any[]) {
  66. props.columns?.forEach((item) => {
  67. item.visible = args[1].checkedKeys.includes(item.key);
  68. });
  69. }
  70. // 显隐列初始默认隐藏列
  71. onMounted(() => {
  72. props.columns?.forEach((item) => {
  73. if (item.visible) {
  74. columnRef.value?.setChecked(item.key, true, false);
  75. // value.value.push(item.key);
  76. }
  77. });
  78. });
  79. </script>
  80. <style lang="scss" scoped>
  81. :deep(.el-transfer__button) {
  82. border-radius: 50%;
  83. display: block;
  84. margin-left: 0px;
  85. }
  86. :deep(.el-transfer__button:first-child) {
  87. margin-bottom: 10px;
  88. }
  89. .my-el-transfer {
  90. text-align: center;
  91. }
  92. .tree-header {
  93. width: 100%;
  94. line-height: 24px;
  95. text-align: center;
  96. }
  97. .show-btn {
  98. margin-left: 12px;
  99. }
  100. </style>