cwg-header.vue 4.2 KB

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