index.vue 9.7 KB

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