index.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. <template>
  2. <view class="tab-bar-wrap" v-if="isLoggedIn">
  3. <!-- 普通用户TabBar:4 Tab + 中间五维启动器 -->
  4. <view v-if="currentRole !== 'teacher'" class="tab-bar">
  5. <!-- 前2个Tab -->
  6. <view v-for="(item, index) in mainTabs.slice(0, 2)" :key="index"
  7. class="tab-item"
  8. :class="{ active: currentIndex === index }"
  9. @click="switchTab(item, index)">
  10. <image class="tab-icon" :src="currentIndex === index ? item.selectedIcon : item.icon" mode="aspectFit" />
  11. <text class="tab-text">{{ item.text }}</text>
  12. </view>
  13. <!-- 中间五维启动器按钮 -->
  14. <view class="tab-center-btn" @click="toggleDimOverlay">
  15. <view class="center-btn-inner">
  16. <text class="center-btn-icon">⭐</text>
  17. </view>
  18. </view>
  19. <!-- 后2个Tab -->
  20. <view v-for="(item, index) in mainTabs.slice(2, 4)" :key="index + 2"
  21. class="tab-item"
  22. :class="{ active: currentIndex === index + 2 }"
  23. @click="switchTab(item, index + 2)">
  24. <image class="tab-icon" :src="currentIndex === index + 2 ? item.selectedIcon : item.icon" mode="aspectFit" />
  25. <text class="tab-text">{{ item.text }}</text>
  26. </view>
  27. </view>
  28. <!-- 规划师TabBar(保持不变) -->
  29. <view v-else class="tab-bar">
  30. <view v-for="(item, index) in teacherTabs" :key="index"
  31. class="tab-item"
  32. :class="{ active: currentIndex === index }"
  33. @click="switchTab(item, index)">
  34. <image class="tab-icon" :src="currentIndex === index ? item.selectedIcon : item.icon" mode="aspectFit" />
  35. <text class="tab-text">{{ item.text }}</text>
  36. </view>
  37. </view>
  38. <!-- 五维半屏浮层 -->
  39. <view class="dim-overlay-mask" v-if="showDimOverlay" @click="toggleDimOverlay">
  40. <view class="dim-overlay" @click.stop>
  41. <view class="dim-overlay-header">
  42. <text class="dim-overlay-title">五维能量</text>
  43. <text class="dim-overlay-close" @click="toggleDimOverlay">✕</text>
  44. </view>
  45. <view class="dim-grid">
  46. <view class="dim-item" v-for="dim in dimensions" :key="dim.code" @click="goDimPage(dim)">
  47. <view class="dim-icon-wrap" :style="{ background: dim.bgColor }">
  48. <text class="dim-icon">{{ dim.icon }}</text>
  49. </view>
  50. <text class="dim-name">{{ dim.name }}</text>
  51. <text class="dim-title">{{ dim.title }}</text>
  52. </view>
  53. </view>
  54. </view>
  55. </view>
  56. </view>
  57. </template>
  58. <script>
  59. var nav = require('../utils/nav.js')
  60. export default {
  61. data() {
  62. return {
  63. currentIndex: 0,
  64. showDimOverlay: false,
  65. mainTabs: [
  66. { text: '首页', pagePath: '/pages/index-home/index', icon: '/static/tab-action.png', selectedIcon: '/static/tab-action-active.png' },
  67. { text: '健康', pagePath: '/pages/health/index', icon: '/static/tab-body.png', selectedIcon: '/static/tab-body-active.png' },
  68. { text: '成长', pagePath: '/pages/growth/index', icon: '/static/tab-growth.png', selectedIcon: '/static/tab-growth-active.png' },
  69. { text: '我的', pagePath: '/pages/profile/profile', icon: '/static/tab-profile.png', selectedIcon: '/static/tab-profile-active.png' }
  70. ],
  71. teacherTabs: [
  72. { text: '首页', pagePath: '/pages/teacher/index', icon: '/static/tab-action.png', selectedIcon: '/static/tab-action-active.png' },
  73. { text: '家庭', pagePath: '/pages/teacher/families', icon: '/static/tab-family.png', selectedIcon: '/static/tab-family-active.png' },
  74. { text: '团队', pagePath: '/pages/teacher/team', icon: '/static/tab-team.png', selectedIcon: '/static/tab-team-active.png' },
  75. { text: '成长档案', pagePath: '/pages/growth/index', icon: '/static/tab-growth.png', selectedIcon: '/static/tab-growth-active.png' },
  76. { text: '我的', pagePath: '/pages/teacher/teacher-profile', icon: '/static/tab-profile.png', selectedIcon: '/static/tab-profile-active.png' }
  77. ],
  78. dimensions: [
  79. { code: 'action', name: '行', title: '知行合一', icon: '🌿', color: '#10B981', bgColor: 'rgba(16,185,129,0.15)' },
  80. { code: 'mind', name: '心', title: '大爱传承', icon: '🔥', color: '#FF6B9D', bgColor: 'rgba(255,107,157,0.15)' },
  81. { code: 'body', name: '身', title: '主动健康', icon: '🌏', color: '#FF8C42', bgColor: 'rgba(255,140,66,0.15)' },
  82. { code: 'wisdom', name: '智', title: '赋能未来', icon: '⚡', color: '#6366F1', bgColor: 'rgba(99,102,241,0.15)' },
  83. { code: 'wealth', name: '富', title: '利他创富', icon: '💧', color: '#F59E0B', bgColor: 'rgba(245,158,11,0.15)' }
  84. ]
  85. }
  86. },
  87. computed: {
  88. isLoggedIn() {
  89. return !!uni.getStorageSync('token')
  90. },
  91. currentRole() {
  92. return uni.getStorageSync('currentRole') || 'parent'
  93. }
  94. },
  95. mounted() {
  96. this.updateSelected()
  97. uni.$on('switchRole', () => {
  98. this.updateSelected()
  99. })
  100. },
  101. methods: {
  102. toggleDimOverlay() {
  103. this.showDimOverlay = !this.showDimOverlay
  104. },
  105. goDimPage(dim) {
  106. this.showDimOverlay = false
  107. nav.goDimension(dim.code)
  108. },
  109. updateSelected() {
  110. const pages = getCurrentPages()
  111. if (pages.length) {
  112. const currentPage = pages[pages.length - 1]
  113. const currentPath = '/' + currentPage.route
  114. if (this.currentRole === 'teacher') {
  115. const idx = this.teacherTabs.findIndex(t => t.pagePath === currentPath)
  116. this.currentIndex = idx >= 0 ? idx : 0
  117. } else {
  118. const idx = this.mainTabs.findIndex(t => t.pagePath === currentPath)
  119. this.currentIndex = idx >= 0 ? idx : 0
  120. }
  121. }
  122. },
  123. switchTab(item, index) {
  124. this.currentIndex = index
  125. // 只有 TabBar 注册页才能用 switchTab
  126. const nativeTabPages = ['/pages/index-home/index', '/pages/health/index', '/pages/growth/index', '/pages/profile/profile']
  127. if (nativeTabPages.includes(item.pagePath)) {
  128. uni.switchTab({ url: item.pagePath })
  129. } else {
  130. uni.redirectTo({ url: item.pagePath })
  131. }
  132. }
  133. }
  134. }
  135. </script>
  136. <style scoped>
  137. .tab-bar-wrap {
  138. position: fixed;
  139. bottom: 0;
  140. left: 0;
  141. right: 0;
  142. z-index: 999;
  143. }
  144. .tab-bar {
  145. display: flex;
  146. height: 100rpx;
  147. background: #fff;
  148. padding-bottom: env(safe-area-inset-bottom);
  149. border-top: 1rpx solid #eee;
  150. align-items: center;
  151. }
  152. .tab-item {
  153. flex: 1;
  154. display: flex;
  155. flex-direction: column;
  156. align-items: center;
  157. justify-content: center;
  158. }
  159. .tab-icon {
  160. width: 48rpx;
  161. height: 48rpx;
  162. margin-bottom: 4rpx;
  163. }
  164. .tab-text {
  165. font-size: 22rpx;
  166. color: #999;
  167. }
  168. .tab-item.active .tab-text {
  169. color: #F97316;
  170. }
  171. /* 中间五维启动器按钮 */
  172. .tab-center-btn {
  173. flex: 0 0 auto;
  174. display: flex;
  175. align-items: center;
  176. justify-content: center;
  177. width: 100rpx;
  178. position: relative;
  179. top: -20rpx;
  180. }
  181. .center-btn-inner {
  182. width: 88rpx;
  183. height: 88rpx;
  184. border-radius: 50%;
  185. background: linear-gradient(135deg, #F97316, #FB923C);
  186. display: flex;
  187. align-items: center;
  188. justify-content: center;
  189. box-shadow: 0 4rpx 16rpx rgba(249,115,22,0.4);
  190. }
  191. .center-btn-icon {
  192. font-size: 40rpx;
  193. }
  194. /* 五维半屏浮层 */
  195. .dim-overlay-mask {
  196. position: fixed;
  197. top: 0;
  198. left: 0;
  199. right: 0;
  200. bottom: 0;
  201. background: rgba(0,0,0,0.5);
  202. z-index: 1000;
  203. display: flex;
  204. align-items: flex-end;
  205. }
  206. .dim-overlay {
  207. width: 100%;
  208. background: #fff;
  209. border-radius: 32rpx 32rpx 0 0;
  210. padding: 40rpx 30rpx 60rpx;
  211. animation: slideUp 0.3s ease;
  212. }
  213. @keyframes slideUp {
  214. from { transform: translateY(100%); }
  215. to { transform: translateY(0); }
  216. }
  217. .dim-overlay-header {
  218. display: flex;
  219. justify-content: space-between;
  220. align-items: center;
  221. margin-bottom: 32rpx;
  222. }
  223. .dim-overlay-title {
  224. font-size: 32rpx;
  225. font-weight: bold;
  226. color: #333;
  227. }
  228. .dim-overlay-close {
  229. font-size: 36rpx;
  230. color: #999;
  231. padding: 8rpx;
  232. }
  233. .dim-grid {
  234. display: flex;
  235. flex-wrap: wrap;
  236. gap: 20rpx;
  237. }
  238. .dim-item {
  239. width: calc(33.33% - 14rpx);
  240. display: flex;
  241. flex-direction: column;
  242. align-items: center;
  243. padding: 24rpx 0;
  244. border-radius: 16rpx;
  245. background: #f8f9fa;
  246. }
  247. .dim-item:active {
  248. opacity: 0.7;
  249. }
  250. .dim-icon-wrap {
  251. width: 80rpx;
  252. height: 80rpx;
  253. border-radius: 50%;
  254. display: flex;
  255. align-items: center;
  256. justify-content: center;
  257. margin-bottom: 12rpx;
  258. }
  259. .dim-icon {
  260. font-size: 36rpx;
  261. }
  262. .dim-name {
  263. font-size: 28rpx;
  264. font-weight: bold;
  265. color: #333;
  266. }
  267. .dim-title {
  268. font-size: 20rpx;
  269. color: #999;
  270. margin-top: 4rpx;
  271. }
  272. </style>