cwg-header.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <template>
  2. <view class="pages-header" v-if="showBack">
  3. <view class="header">
  4. <view v-if="showBackIcon" class="back">
  5. <cwg-icon name="dropdown" class="back-icon" :color="isDark ? '#fff' : '#000000'" @click="handleBack" />
  6. </view>
  7. <view>{{ headerTitleReady ? headerTitle : '' }}</view>
  8. </view>
  9. <view class="header-r">
  10. <slot></slot>
  11. </view>
  12. </view>
  13. </template>
  14. <script setup lang="ts">
  15. import useRouter from "@/hooks/useRouter";
  16. import useRoute from '@/hooks/useRoute'
  17. import { computed } from 'vue'
  18. import { useI18n } from 'vue-i18n'
  19. const { t } = useI18n()
  20. const router = useRouter()
  21. const route = useRoute()
  22. import useGlobalStore from '@/stores/use-global-store'
  23. const globalStore = useGlobalStore()
  24. const isDark = computed(() => globalStore.theme === 'dark')
  25. const showBack = computed(() => {
  26. // 不显示返回按钮的页面
  27. const noBackPages = [
  28. '/',
  29. '/pages/customer/index',
  30. '/pages/wallet/index',
  31. '/pages/mine/index',
  32. '/pages/login/index'
  33. ]
  34. return !noBackPages.includes(route.path)
  35. })
  36. const showBackIcon = computed(() => {
  37. // 不显示返回图标的页面
  38. const noBackIconPages = [
  39. '/',
  40. '/pages/customer/index',
  41. '/pages/customer/trade-history',
  42. '/pages/customer/trade-position',
  43. '/pages/customer/recording-history',
  44. '/pages/customer/deposit-select',
  45. '/pages/customer/withdrawal-select',
  46. '/pages/customer/payment-history',
  47. '/pages/customer/transfer',
  48. '/pages/customer/wallet-transfer',
  49. '/pages/customer/wallet-history',
  50. '/pages/activities/index',
  51. '/pages/analytics/analystViews',
  52. '/pages/analytics/news',
  53. '/pages/common/download',
  54. '/pages/common/chat',
  55. '/pages/mine/info',
  56. '/pages/common/notice',
  57. '/pages/ib/index',
  58. '/pages/ib/customer',
  59. '/pages/ib/subsList',
  60. '/pages/ib/agentList',
  61. '/pages/ib/accountList',
  62. '/pages/ib/transfer',
  63. '/pages/ib/withdraw-select',
  64. '/pages/ib/agent-transfer',
  65. '/pages/ib/recording',
  66. '/pages/ib/report',
  67. '/pages/ib/complexReport',
  68. '/pages/follow/index',
  69. '/pages/follow/trading-center',
  70. '/pages/follow/report',
  71. '/pages/follow/transfer',
  72. '/pages/follow/transfer-history',
  73. '/pages/follow/trading-management',
  74. '/pages/follow/follow-list',
  75. '/pages/follow/account-management',
  76. '/pages/follow/subscribe-list',
  77. '/pages/follow/record',
  78. '/pages/wallet/index',
  79. '/pages/mine/index',
  80. '/pages/login/index'
  81. ]
  82. return !noBackIconPages.includes(route.path)
  83. })
  84. function slashToDash(str: string) {
  85. return str.replace(/\//g, '.');
  86. }
  87. function getTranslationKey(): string {
  88. const path = route.path
  89. let key = ''
  90. if (!path) return ''
  91. if (path === '/') {
  92. key = 'pages.mine.info'
  93. } else if (path.startsWith()) {
  94. key = path.slice(7)
  95. } else {
  96. key = path.slice(1)
  97. }
  98. return slashToDash(key)
  99. }
  100. const headerTitleReady = computed(() => {
  101. if (props.title) return true
  102. if (!route.path) return false
  103. const key = getTranslationKey()
  104. return !!t(key)
  105. })
  106. const headerTitle = computed(() => {
  107. if (props.title) return props.title
  108. const key = getTranslationKey()
  109. return t(key) || ''
  110. })
  111. const props = defineProps<{
  112. title: string;
  113. backgrounds: Record<string, any>;
  114. }>();
  115. function handleBack() {
  116. router.back();
  117. }
  118. </script>
  119. <style scoped lang="scss">
  120. @import "@/uni.scss";
  121. .pages-header {
  122. width: 100%;
  123. // z-index: 1111;
  124. display: flex;
  125. align-items: center;
  126. justify-content: space-between;
  127. box-sizing: border-box;
  128. margin-bottom: px2rpx(24);
  129. }
  130. .header {
  131. position: relative;
  132. text-align: left;
  133. font-size: px2rpx(24);
  134. color: var(--bs-emphasis-color);
  135. font-weight: 700;
  136. margin: px2rpx(10) 0;
  137. height: px2rpx(40);
  138. display: flex;
  139. align-items: center;
  140. line-height: px2rpx(40);
  141. .back {
  142. display: flex;
  143. align-items: center;
  144. justify-content: center;
  145. width: px2rpx(24);
  146. height: px2rpx(24);
  147. border-radius: 50%;
  148. margin-right: px2rpx(12);
  149. }
  150. .back-icon {
  151. line-height: px2rpx(71);
  152. font-size: var(--font-size-20);
  153. cursor: pointer;
  154. }
  155. }
  156. .wallet-header {
  157. .header {
  158. color: var(--bs-emphasis-color);
  159. }
  160. }
  161. </style>