index.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. <template>
  2. <view class="tab-bar-wrap">
  3. <!-- 统一TabBar:4 Tab(首页/健康/成长/我的)5 等分,中间放五维按钮,所有人同一套入口 -->
  4. <view class="tab-bar">
  5. <view
  6. v-for="(item, index) in leftTabs"
  7. :key="index"
  8. class="tab-item"
  9. :class="{ active: isActive(item) }"
  10. @click="switchTab(item)"
  11. >
  12. <image
  13. class="tab-icon"
  14. :src="isActive(item) ? item.selectedIcon : item.icon"
  15. mode="aspectFit"
  16. ></image>
  17. <text class="tab-text">{{ item.text }}</text>
  18. </view>
  19. <!-- 中间五维按钮(占 20% 槽位) -->
  20. <view class="center-btn" @click="openDimPanel">
  21. <view class="center-btn-inner">
  22. <text class="center-btn-icon">⭐</text>
  23. </view>
  24. <text class="center-btn-label">五维</text>
  25. </view>
  26. <view
  27. v-for="(item, index) in rightTabs"
  28. :key="index"
  29. class="tab-item"
  30. :class="{ active: isActive(item) }"
  31. @click="switchTab(item)"
  32. >
  33. <image
  34. class="tab-icon"
  35. :src="isActive(item) ? item.selectedIcon : item.icon"
  36. mode="aspectFit"
  37. ></image>
  38. <text class="tab-text">{{ item.text }}</text>
  39. </view>
  40. </view>
  41. <!-- 五维横排展开 -->
  42. <view class="dim-fan-overlay" v-if="showDimPanel" @click="closeDimPanel">
  43. <view class="dim-fan-row">
  44. <view
  45. v-for="(dim, idx) in dimensions"
  46. :key="idx"
  47. :class="['dim-fan-item', { 'dim-fan-item-up': dim.code === 'mind', 'dim-fan-item-mid': dim.code === 'action' || dim.code === 'body' }]"
  48. @click.stop="goDimension(dim)"
  49. >
  50. <view
  51. class="dim-fan-circle"
  52. :class="{ 'fan-active': fanActive }"
  53. :style="{ backgroundColor: dim.color, transitionDelay: (0.05 * idx) + 's' }"
  54. >
  55. <text class="dim-fan-emoji">{{ dim.icon }}</text>
  56. </view>
  57. <text
  58. class="dim-fan-label"
  59. :class="{ 'fan-active': fanActive }"
  60. :style="{ transitionDelay: (0.05 * idx) + 's' }"
  61. >{{ dim.name }}</text>
  62. </view>
  63. </view>
  64. </view>
  65. </view>
  66. </template>
  67. <script>
  68. import { BrandColors } from '../utils/brand-colors.js'
  69. export default {
  70. data() {
  71. return {
  72. currentIndex: 0,
  73. showDimPanel: false,
  74. fanActive: false,
  75. normalTabs: [
  76. { text: '首页', pagePath: '/pages/index-home/index', icon: '/static/tab-home.png', selectedIcon: '/static/tab-home-active.png' },
  77. { text: '健康', pagePath: '/pages/health-main/index', icon: '/static/tab-health.png', selectedIcon: '/static/tab-health-active.png' },
  78. { text: '成长', pagePath: '/pages/growth-main/index', icon: '/static/tab-growth.png', selectedIcon: '/static/tab-growth-active.png' },
  79. { text: '我的', pagePath: '/pages/profile-main/profile', icon: '/static/tab-profile.png', selectedIcon: '/static/tab-profile-active.png' }
  80. ],
  81. dimensions: [
  82. { code: 'wealth', name: '富', desc: '利他创富', icon: '💧', color: BrandColors.wealth, bgColor: 'rgba(245,158,11,0.15)' },
  83. { code: 'action', name: '行', desc: '知行合一', icon: '🌿', color: BrandColors.success, bgColor: 'rgba(16,185,129,0.15)' },
  84. { code: 'mind', name: '心', desc: '大爱传承', icon: '🔥', color: BrandColors.mind, bgColor: 'rgba(255,107,157,0.15)' },
  85. { code: 'body', name: '身', desc: '主动健康', icon: '🌏', color: BrandColors.body, bgColor: 'rgba(255,140,66,0.15)' },
  86. { code: 'wisdom', name: '智', desc: '赋能未来', icon: '⚡', color: BrandColors.wisdom, bgColor: 'rgba(99,102,241,0.15)' }
  87. ]
  88. }
  89. },
  90. computed: {
  91. // 5 等分:左 2 Tab + 中间五维按钮 + 右 2 Tab
  92. leftTabs() {
  93. return this.normalTabs.slice(0, 2)
  94. },
  95. rightTabs() {
  96. return this.normalTabs.slice(2)
  97. }
  98. },
  99. mounted() {
  100. this.updateSelected()
  101. },
  102. methods: {
  103. isActive(item) {
  104. var pages = getCurrentPages()
  105. if (!pages.length) return false
  106. var currentPath = '/' + pages[pages.length - 1].route
  107. return item.pagePath === currentPath
  108. },
  109. updateSelected() {
  110. var pages = getCurrentPages()
  111. if (pages.length) {
  112. var currentPage = pages[pages.length - 1]
  113. var currentPath = '/' + currentPage.route
  114. var idx = this.normalTabs.findIndex(function(t) { return t.pagePath === currentPath })
  115. this.currentIndex = idx >= 0 ? idx : 0
  116. }
  117. },
  118. switchTab(item) {
  119. var tabBarPages = ['/pages/index-home/index', '/pages/health-main/index', '/pages/growth-main/index', '/pages/profile-main/profile']
  120. if (tabBarPages.indexOf(item.pagePath) !== -1) {
  121. uni.switchTab({ url: item.pagePath })
  122. } else {
  123. uni.redirectTo({ url: item.pagePath })
  124. }
  125. },
  126. openDimPanel() {
  127. this.showDimPanel = true
  128. this.fanActive = false
  129. var self = this
  130. setTimeout(function() {
  131. self.fanActive = true
  132. }, 30)
  133. },
  134. closeDimPanel() {
  135. this.fanActive = false
  136. var self = this
  137. setTimeout(function() {
  138. self.showDimPanel = false
  139. }, 200)
  140. },
  141. goDimension(dim) {
  142. this.closeDimPanel()
  143. var dimMap = {
  144. action: '/pages/action-detail/index',
  145. mind: '/pages/mind-detail/index',
  146. body: '/pages/body-detail/index',
  147. wisdom: '/pages/wisdom-detail/index',
  148. wealth: '/pages/wealth/index'
  149. }
  150. var url = dimMap[dim.code]
  151. if (!url) return
  152. var tabBarPages = ['/pages/index-home/index', '/pages/health-main/index', '/pages/growth-main/index', '/pages/profile-main/profile']
  153. if (tabBarPages.indexOf(url) !== -1) {
  154. uni.switchTab({ url: url })
  155. } else {
  156. uni.navigateTo({ url: url })
  157. }
  158. }
  159. }
  160. }
  161. </script>
  162. <style scoped lang="scss">
  163. .tab-bar-wrap {
  164. position: fixed;
  165. bottom: 0;
  166. left: 0;
  167. right: 0;
  168. z-index: 999;
  169. }
  170. .tab-bar {
  171. display: flex;
  172. height: 100rpx;
  173. background: $app-surface;
  174. padding-bottom: env(safe-area-inset-bottom);
  175. border-top: 1rpx solid $facade-hairline-2;
  176. position: relative;
  177. }
  178. .tab-item {
  179. width: 20%;
  180. flex: none;
  181. display: flex;
  182. flex-direction: column;
  183. align-items: center;
  184. justify-content: center;
  185. position: relative;
  186. z-index: 1;
  187. }
  188. .tab-icon {
  189. width: 48rpx;
  190. height: 48rpx;
  191. margin-bottom: 4rpx;
  192. }
  193. .tab-text {
  194. font-size: 22rpx;
  195. color: $facade-text-muted;
  196. }
  197. .tab-item.active .tab-text {
  198. color: $brand-primary;
  199. }
  200. /* 中间五维按钮(占 20% 槽位) */
  201. .center-btn {
  202. width: 20%;
  203. flex: none;
  204. display: flex;
  205. flex-direction: column;
  206. align-items: center;
  207. justify-content: flex-start;
  208. padding-top: 0;
  209. position: relative;
  210. z-index: 2;
  211. }
  212. .center-btn-inner {
  213. width: 88rpx;
  214. height: 88rpx;
  215. border-radius: 50%;
  216. background: linear-gradient(135deg, $brand-primary, $brand-primary-light);
  217. display: flex;
  218. align-items: center;
  219. justify-content: center;
  220. margin-top: -20rpx;
  221. flex-shrink: 0;
  222. box-shadow: 0 4rpx 16rpx rgba(249,115,22,0.4);
  223. }
  224. .center-btn-icon {
  225. font-size: 40rpx;
  226. line-height: 1;
  227. }
  228. .center-btn-label {
  229. font-size: 20rpx;
  230. color: $facade-text-muted;
  231. text-align: center;
  232. margin-top: 2rpx;
  233. }
  234. /* 五维横排展开 */
  235. .dim-fan-overlay {
  236. position: fixed;
  237. top: 0;
  238. left: 0;
  239. right: 0;
  240. bottom: 0;
  241. z-index: 1000;
  242. background: rgba(0,0,0,0.4);
  243. animation: fadeIn 0.2s ease;
  244. }
  245. .dim-fan-row {
  246. position: absolute;
  247. bottom: 140rpx;
  248. left: 0;
  249. right: 0;
  250. display: flex;
  251. justify-content: center;
  252. padding: 0 16rpx;
  253. }
  254. .dim-fan-item {
  255. display: flex;
  256. flex-direction: column;
  257. align-items: center;
  258. width: 120rpx;
  259. }
  260. .dim-fan-item.dim-fan-item-up {
  261. margin-top: -120rpx;
  262. }
  263. .dim-fan-item.dim-fan-item-mid {
  264. margin-top: -60rpx;
  265. }
  266. .dim-fan-circle {
  267. width: 88rpx;
  268. height: 88rpx;
  269. border-radius: 50%;
  270. display: flex;
  271. align-items: center;
  272. justify-content: center;
  273. opacity: 0;
  274. transform: scale(0);
  275. transition: opacity 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  276. box-shadow: 0 4rpx 16rpx rgba(0,0,0,0.15);
  277. }
  278. .dim-fan-circle.fan-active {
  279. opacity: 1;
  280. transform: scale(1);
  281. }
  282. .dim-fan-emoji {
  283. font-size: 40rpx;
  284. line-height: 1;
  285. }
  286. .dim-fan-label {
  287. font-size: 22rpx;
  288. color: $app-surface;
  289. font-weight: 600;
  290. margin-top: 8rpx;
  291. text-align: center;
  292. opacity: 0;
  293. transform: translateY(-10rpx);
  294. transition: opacity 0.3s ease, transform 0.3s ease;
  295. }
  296. .dim-fan-label.fan-active {
  297. opacity: 1;
  298. transform: translateY(0);
  299. }
  300. @keyframes fadeIn {
  301. from { opacity: 0; }
  302. to { opacity: 1; }
  303. }
  304. </style>