index.vue 8.5 KB

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