index.vue 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <!--
  2. * @Author: Badguy
  3. * @Date: 2022-05-25 14:09:35
  4. * @LastEditTime: 2022-05-25 14:53:56
  5. * @LastEditors: your name
  6. * @Description: 表头下拉筛选
  7. * have a nice day!
  8. -->
  9. <template>
  10. <el-popover
  11. placement="bottom"
  12. trigger="click"
  13. @show="expand = true"
  14. @hide="expand = false"
  15. >
  16. <i
  17. slot="reference"
  18. :class="['filter-arrow', 'el-icon-arrow-down', { 'arrow-active': active, 'arrow-expand': expand }]"
  19. />
  20. <el-form>
  21. <el-form-item :label="label">
  22. <el-select
  23. v-model="selection"
  24. size="small"
  25. placeholder="筛选"
  26. default-first-option
  27. filterable
  28. clearable
  29. @change="newVal => { $emit('update:filter-value', newVal) }"
  30. >
  31. <el-option
  32. v-for="(option, optionIndex) in filterOptions"
  33. :key="option.value + optionIndex"
  34. :value="option.value"
  35. :label="option.text"
  36. />
  37. </el-select>
  38. </el-form-item>
  39. </el-form>
  40. </el-popover>
  41. </template>
  42. <script>
  43. export default {
  44. name: 'TableHeaderCellWithFilter',
  45. props: {
  46. filterOptions: {
  47. type: Array,
  48. required: true
  49. },
  50. filterValue: {
  51. type: String || Number,
  52. required: true
  53. },
  54. label: {
  55. type: String,
  56. default: ''
  57. }
  58. },
  59. data() {
  60. return {
  61. selection: '',
  62. expand: false
  63. }
  64. },
  65. computed: {
  66. active() {
  67. return (this.selection ?? '') !== ''
  68. }
  69. },
  70. watch: {
  71. filterValue(val) {
  72. this.selection = val
  73. }
  74. }
  75. }
  76. </script>
  77. <style lang="scss" scoped>
  78. .filter-arrow {
  79. cursor: pointer;
  80. transition: 0.3s transform;
  81. &.arrow-expand {
  82. transform: rotate(-180deg);
  83. }
  84. &.arrow-active {
  85. color: #2d7cff;
  86. font-weight: bold;
  87. }
  88. }
  89. .el-select-dropdown__item.hover {
  90. background: #d2d6df;
  91. }
  92. </style>