wangrong
2026-08-30 761e5c5fa871959f60e15c971c8d83f2b53d0af5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<script lang="ts" setup>
import iconSetting from '@/assets/svg/icon-setting.svg'
import { reactive, ref, toRaw } from 'vue'
import { Icon } from '@/components/icon-custom'
import {
  ElDropdown,
  ElDropdownMenu,
  ElCheckbox,
  ElCheckboxGroup,
  ElIcon,
  ElButton
} from 'element-plus-secondary'
 
import type { CheckboxValueType } from 'element-plus-secondary'
import { propTypes } from '@/utils/propTypes'
 
const props = defineProps({
  columnNames: propTypes.arrayOf(
    propTypes.shape({
      label: propTypes.string,
      props: propTypes.string
    })
  ),
  isPluginLoaded: propTypes.bool.def(false)
})
 
const emit = defineEmits(['columnChange'])
 
const checkAll = ref(true)
const isIndeterminate = ref(false)
 
const state = reactive({
  checkedColumnNames: props.columnNames.map(ele => ele.props)
})
 
const handleCheckedColumnNamesChange = (value: string[]) => {
  const checkedCount = value.length
  checkAll.value = checkedCount === props.columnNames.length
  isIndeterminate.value = checkedCount > 0 && checkedCount < props.columnNames.length
 
  emit('columnChange', toRaw(state.checkedColumnNames))
}
const handleCheckAllChange = (val: CheckboxValueType) => {
  state.checkedColumnNames = val ? props.columnNames.map(ele => ele.props) : []
  if (!props.isPluginLoaded) {
    state.checkedColumnNames = state.checkedColumnNames.filter(
      ele => !['dept', 'roles'].includes(ele)
    )
  }
  isIndeterminate.value = false
  emit('columnChange', toRaw(state.checkedColumnNames))
}
</script>
 
<template>
  <el-dropdown trigger="click" :hide-on-click="false">
    <el-button secondary>
      <template #icon>
        <el-icon>
          <Icon name="icon-setting"><iconSetting class="svg-icon" /></Icon>
        </el-icon>
      </template>
      {{ $t('component.columnList') }}
    </el-button>
    <template #dropdown>
      <el-dropdown-menu class="list-columns-select">
        <el-main class="main-div-select">
          <p class="title">{{ $t('component.selectInfo') }}</p>
          <el-checkbox
            v-model="checkAll"
            :indeterminate="isIndeterminate"
            @change="handleCheckAllChange"
            >{{ $t('component.allSelect') }}</el-checkbox
          >
          <el-checkbox-group
            v-model="state.checkedColumnNames"
            @change="handleCheckedColumnNamesChange"
          >
            <el-checkbox v-for="column in columnNames" :key="column.props" :label="column.props">{{
              $t(column.label)
            }}</el-checkbox>
          </el-checkbox-group>
        </el-main>
      </el-dropdown-menu>
    </template>
  </el-dropdown>
</template>
 
<style lang="less" scoped>
.list-columns-select {
  padding: 8px 11px !important;
  width: 238px;
 
  .title,
  .ed-checkbox {
    font-family: var(--de-custom_font, 'PingFang');
    font-size: 14px;
    font-weight: 400;
    padding: 5px 0;
    margin: 0;
    color: #8f959e;
  }
 
  .ed-checkbox {
    width: 100%;
  }
  .main-div-select {
    max-height: 320px;
    padding: 0;
  }
}
</style>