cwg-header.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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/complexReport',
  69. '/pages/follow/index',
  70. '/pages/follow/trading-center',
  71. '/pages/follow/report',
  72. '/pages/follow/transfer',
  73. '/pages/follow/transfer-history',
  74. '/pages/follow/trading-management',
  75. '/pages/follow/follow-list',
  76. '/pages/follow/account-management',
  77. '/pages/follow/subscribe-list',
  78. '/pages/follow/record',
  79. '/pages/wallet/index',
  80. '/pages/mine/index',
  81. '/pages/login/index'
  82. ]
  83. return !noBackIconPages.includes(route.path)
  84. })
  85. function slashToDash(str: string) {
  86. return str.replace(/\//g, '.');
  87. }
  88. function getTranslationKey(): string {
  89. const path = route.path
  90. let key = ''
  91. if (!path) return ''
  92. if (path === '/') {
  93. key = 'pages.mine.info'
  94. } else if (path.startsWith()) {
  95. key = path.slice(7)
  96. } else {
  97. key = path.slice(1)
  98. }
  99. return slashToDash(key)
  100. }
  101. const headerTitleReady = computed(() => {
  102. if (props.title) return true
  103. if (!route.path) return false
  104. const key = getTranslationKey()
  105. return !!t(key)
  106. })
  107. const headerTitle = computed(() => {
  108. if (props.title) return props.title
  109. const key = getTranslationKey()
  110. return t(key) || ''
  111. })
  112. const props = defineProps<{
  113. title: string;
  114. backgrounds: Record<string, any>;
  115. }>();
  116. function handleBack() {
  117. router.back();
  118. }
  119. </script>
  120. <style scoped lang="scss">
  121. @import "@/uni.scss";
  122. .pages-header {
  123. width: 100%;
  124. // z-index: 1111;
  125. display: flex;
  126. align-items: center;
  127. justify-content: space-between;
  128. box-sizing: border-box;
  129. margin-bottom: px2rpx(24);
  130. }
  131. .header {
  132. position: relative;
  133. text-align: left;
  134. font-size: px2rpx(24);
  135. color: var(--bs-emphasis-color);
  136. font-weight: 700;
  137. margin: px2rpx(0) 0;
  138. //height: px2rpx(40);
  139. display: flex;
  140. align-items: center;
  141. //line-height: px2rpx(40);
  142. .back {
  143. display: flex;
  144. align-items: center;
  145. justify-content: center;
  146. width: px2rpx(24);
  147. height: px2rpx(24);
  148. border-radius: 50%;
  149. margin-right: px2rpx(12);
  150. }
  151. .back-icon {
  152. line-height: px2rpx(71);
  153. font-size: var(--font-size-20);
  154. cursor: pointer;
  155. }
  156. }
  157. .wallet-header {
  158. .header {
  159. color: var(--bs-emphasis-color);
  160. }
  161. }
  162. </style>