cwg-header.vue 3.9 KB

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