index.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <!--
  2. * @Author: wjc
  3. * @Date: 2024-07-03 10:35:44
  4. * @LastEditors: wjc
  5. * @LastEditTime: 2024-07-10 17:20:56
  6. * @Description:
  7. -->
  8. <template>
  9. <up-navbar ref="mNavBarRef" v-bind="$attrs" class="m-navbar" placeholder :bg-color="bgColor">
  10. <template #left>
  11. <view v-if="notBack" class="wh-24px"></view>
  12. <view v-else class="i-ep-arrow-left wh-24px cursor-pointer" @click="goBack"></view>
  13. </template>
  14. <template #center>
  15. <view class="m-navbar-title">{{ title }}</view>
  16. </template>
  17. <template #right>
  18. <slot name="right">
  19. <view v-if="rightMenu && rightMenu.length > 0" class="right-box">
  20. <view class="i-ep-more-filled wh-24px cursor-pointer" @click="triggerMore"></view>
  21. <view v-if="showMore" class="overlay" @click="() => (showMore = false)"></view>
  22. <view v-if="showMore" class="menu-box">
  23. <view
  24. v-for="menu in rightMenu"
  25. :key="menu.command"
  26. class="menu-item"
  27. hover-class="menu-item-hover"
  28. @click="handleMenuClick(menu.command)"
  29. >
  30. <view v-if="menu.icon" :class="menu.icon" class="menu-item-icon"></view>
  31. <view class="menu-item-text">{{ menu.text }}</view>
  32. </view>
  33. </view>
  34. </view>
  35. </slot>
  36. </template>
  37. </up-navbar>
  38. </template>
  39. <script setup lang="ts">
  40. export interface RightMenuItem {
  41. icon?: string
  42. text: string
  43. command: string
  44. }
  45. defineOptions({ name: 'MNavBar' })
  46. withDefaults(
  47. defineProps<{
  48. title?: string
  49. placeholder?: boolean
  50. notBack?: boolean
  51. bgColor?: string
  52. rightMenu?: RightMenuItem[]
  53. }>(),
  54. {
  55. title: '',
  56. notBack: false,
  57. bgColor: 'var(--bg-card)',
  58. rightMenu: () => [],
  59. }
  60. )
  61. const emits = defineEmits<{
  62. (e: 'right-click', command: string): void
  63. }>()
  64. const mNavBarRef = ref()
  65. const showMore = ref(false)
  66. const goBack = () => {
  67. uni.navigateBack()
  68. }
  69. const triggerMore = () => {
  70. showMore.value = !showMore.value
  71. }
  72. const handleMenuClick = (command: string) => {
  73. emits('right-click', command)
  74. showMore.value = false
  75. }
  76. </script>
  77. <style scoped lang="scss">
  78. .m-navbar {
  79. .m-navbar-title {
  80. @apply text-16px color-text-1;
  81. }
  82. .right-box {
  83. @apply relative w-full z-1;
  84. .overlay {
  85. @apply fixed inset-0px opacity-100;
  86. background: rgba(0, 0, 0, 0);
  87. }
  88. .menu-box {
  89. @apply absolute right-0px z-10 flex flex-col gap-6px w-auto whitespace-nowrap rounded-6px bg-bg-card;
  90. box-shadow: 0px 0px 10px rgba(0, 0, 0, 20%);
  91. .menu-item {
  92. @apply flex items-center gap-8px h-full flex-1 px-16px py-8px text-left;
  93. .menu-item-icon {
  94. @apply wh-30px;
  95. }
  96. .menu-item-text {
  97. @apply w-full text-left;
  98. }
  99. }
  100. .menu-item-hover {
  101. @apply bg-gray-100;
  102. }
  103. }
  104. }
  105. }
  106. </style>