index.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <template>
  2. <div class="app-navbar" :style="styles">
  3. <app-navback class="app-navbar__backbutton" @back="goback" v-if="showBackButton" />
  4. <app-statusbar class="app-navbar__wrapper" @ready="onReady">
  5. <div class="app-navbar__header">
  6. <div class="column column--left">
  7. <div class="column-block">
  8. <slot name="left"></slot>
  9. </div>
  10. </div>
  11. <div class="column column--center">
  12. <div class="column-block">
  13. <slot>
  14. <span>{{ title }}</span>
  15. </slot>
  16. </div>
  17. </div>
  18. <div class="column column--right">
  19. <div class="column-block">
  20. <slot name="right"></slot>
  21. </div>
  22. </div>
  23. </div>
  24. <div class="app-navbar__footer">
  25. <slot name="footer"></slot>
  26. </div>
  27. </app-statusbar>
  28. </div>
  29. </template>
  30. <script lang="ts" setup>
  31. import { useAttrs, computed } from 'vue'
  32. import { useRouter } from 'vue-router'
  33. import { useGlobalStore } from '@/stores'
  34. const emit = defineEmits<{ (event: string, ...args: unknown[]): void }>()
  35. const props = defineProps({
  36. // 导航栏标题
  37. title: String,
  38. // 是否固定导航栏
  39. fixed: Boolean,
  40. // 是否显示返回按钮
  41. showBackButton: {
  42. type: Boolean,
  43. default: true,
  44. }
  45. })
  46. const router = useRouter();
  47. const attrs = useAttrs();
  48. const globalStore = useGlobalStore()
  49. const styles = computed(() => ({
  50. position: props.fixed ? 'fixed' : 'static',
  51. width: globalStore.clientWidth + 'px',
  52. }))
  53. // 返回按钮事件
  54. const goback = () => {
  55. if (attrs.onBack) {
  56. emit('back');
  57. } else {
  58. router.go(-1);
  59. }
  60. }
  61. const onReady = (el: HTMLElement) => {
  62. emit('ready', el);
  63. }
  64. </script>
  65. <style lang="less" scoped>
  66. @import './index.less';
  67. </style>