cwg-droplist-item.vue 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <template>
  2. <view class="cwg-droplist-item" :class="{ 'is-disabled': disabled }" @click.stop="handleClick">
  3. <slot></slot>
  4. </view>
  5. </template>
  6. <script setup>
  7. import { getCurrentInstance } from 'vue'
  8. const props = defineProps({
  9. command: {
  10. type: [String, Number, Object],
  11. default: ''
  12. },
  13. disabled: {
  14. type: Boolean,
  15. default: false
  16. }
  17. })
  18. const instance = getCurrentInstance()
  19. const emit = defineEmits(['click'])
  20. const handleClick = () => {
  21. if (props.disabled) return
  22. emit('click')
  23. // 查找父级的 cwg-droplist 实例并触发事件
  24. let parent = instance.parent
  25. while (parent) {
  26. if (parent.type.__file && parent.type.__file.includes('cwg-droplist.vue')) {
  27. if (parent.exposed && parent.exposed.handleItemClick) {
  28. parent.exposed.handleItemClick(props.command)
  29. }
  30. break
  31. }
  32. parent = parent.parent
  33. }
  34. }
  35. </script>
  36. <style lang="scss" scoped>
  37. @import '@/uni.scss';
  38. .cwg-droplist-item {
  39. display: flex;
  40. align-items: center;
  41. padding: px2rpx(10) px2rpx(20);
  42. font-size: px2rpx(14);
  43. line-height: px2rpx(22);
  44. color: var(--bs-emphasis-color);
  45. white-space: nowrap;
  46. cursor: pointer;
  47. transition: background-color 0.2s, color 0.2s;
  48. box-sizing: border-box;
  49. &:hover, &:active {
  50. background-color: var(--bs-light-bg-subtle);
  51. color: var(--bs-emphasis-color);
  52. }
  53. &.is-disabled {
  54. color: #c0c4cc;
  55. cursor: not-allowed;
  56. background-color: transparent;
  57. }
  58. }
  59. </style>