index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  1. <template>
  2. <view class="wisdom-container">
  3. <!-- Tabbar 切换过渡页 -->
  4. <tab-transition v-if="showTabTransition" dimCode="wisdom" />
  5. <!-- 1. 品牌头部 -->
  6. <PageBanner theme="wisdom"
  7. tagline="学以启智 · 慧及未来"
  8. quote="知者不惑,仁者不忧" />
  9. <!-- 2. 游客专属区块 -->
  10. <template v-if="!isLoggedIn">
  11. <LoginGuideCard
  12. title="登录后查看全家智慧成长数据"
  13. :items="[
  14. '查看全家认知能量数据和测评报告',
  15. '记录每日成长,获取智慧能量',
  16. '参与认知训练,提升综合能力'
  17. ]" />
  18. </template>
  19. <!-- 3. 五维能量条(登录后) -->
  20. <FamilyEnergyBar
  21. v-if="isLoggedIn"
  22. dimensionCode="wisdom"
  23. :sandboxData="sandboxData"
  24. :dualDimension="dualDimension" />
  25. <!-- 4. 认知雷达图(登录后) -->
  26. <view class="section" v-if="isLoggedIn && cognitiveReport">
  27. <view class="section-header">
  28. <text class="section-title">认知雷达</text>
  29. <text class="section-more" @click="goCognitiveReport">查看详情 ›</text>
  30. </view>
  31. <RadarChart
  32. :dimensions="cognitiveDimensions"
  33. :scores="cognitiveScores"
  34. :childName="activeChildName"
  35. fillColor="#6366F1"
  36. gridColor="#E0E7FF"
  37. labelColor="#3730A3" />
  38. </view>
  39. <!-- 5. 家庭成员关系图谱(登录后) -->
  40. <FamilyRelationGraph
  41. v-if="isLoggedIn && familyMembersVisible.length > 0"
  42. dimensionCode="wisdom"
  43. :selfId="activeChildId"
  44. :members="familyMembersVisible"
  45. :energyMap="energyMapForGraph"
  46. :intimacyMap="intimacyMapForGraph"
  47. @memberTap="goMemberDetail" />
  48. <!-- 6. 用户快捷入口 -->
  49. <UserQuickEntry
  50. v-if="isLoggedIn"
  51. :userName="userName"
  52. roleName="家长"
  53. :currentChildName="activeChildName"
  54. :children="children"
  55. @childChanged="onChildChanged"
  56. @scrollTo="scrollToSection" />
  57. <!-- 7. 功能入口 -->
  58. <view class="func-section" v-if="sectionVisible('func_entries')">
  59. <view class="func-grid">
  60. <view class="func-item" v-for="item in funcList" :key="item.label" @click="onFuncClick(item)">
  61. <view class="func-icon-wrap">
  62. <text class="func-icon">{{ item.icon }}</text>
  63. </view>
  64. <text class="func-label">{{ item.label }}</text>
  65. </view>
  66. </view>
  67. </view>
  68. <!-- 8. 维度任务 -->
  69. <DimensionTasks
  70. v-if="isLoggedIn"
  71. dimensionCode="wisdom"
  72. :tasks="dimensionTasks"
  73. @taskClick="onTaskClick"
  74. @moreTasks="goTasks" />
  75. <!-- 9. 维度活动 -->
  76. <DimensionActivities
  77. dimensionCode="wisdom"
  78. :activities="dimensionActivities"
  79. @activityClick="goActivityDetail"
  80. @moreActivities="goMoreActivities" />
  81. <!-- 10. 维度商品 -->
  82. <DimensionProducts
  83. dimensionCode="wisdom"
  84. :products="dimensionProducts"
  85. @productClick="goProductDetail"
  86. @moreProducts="goMoreProducts" />
  87. <!-- 11. 推荐阅读 -->
  88. <DimensionArticles
  89. v-if="sectionVisible('recommended_reading')"
  90. dimensionCode="wisdom"
  91. :articles="wisdomArticles"
  92. :isLoggedIn="isLoggedIn"
  93. @articleClick="goArticleDetail"
  94. @moreArticles="goMoreArticles" />
  95. <!-- 12. 智慧小贴士 -->
  96. <view class="section" v-if="sectionVisible('wisdom_tips')">
  97. <view class="section-header">
  98. <text class="section-title">智慧小贴士</text>
  99. </view>
  100. <view class="tips-list">
  101. <view class="tip-card" v-for="item in wisdomTips" :key="item.id">
  102. <text class="tip-title">{{ item.title }}</text>
  103. <text class="tip-summary">{{ item.summary }}</text>
  104. </view>
  105. </view>
  106. </view>
  107. <!-- 13. 快捷操作按钮 -->
  108. <view class="section quick-actions" v-if="isLoggedIn">
  109. <view class="action-btn" @click="goCognitiveReport">
  110. <text class="action-icon">📊</text>
  111. <text class="action-text">认知报告</text>
  112. </view>
  113. <view class="action-btn" @click="goTrainingHub">
  114. <text class="action-icon">🧠</text>
  115. <text class="action-text">认知训练</text>
  116. </view>
  117. <view class="action-btn" @click="goAssessment">
  118. <text class="action-icon">📋</text>
  119. <text class="action-text">测评预约</text>
  120. </view>
  121. <view class="action-btn" @click="goHome">
  122. <text class="action-icon">🏠</text>
  123. <text class="action-text">返回首页</text>
  124. </view>
  125. </view>
  126. <!-- 底部占位 -->
  127. <view class="bottom-spacer"></view>
  128. </view>
  129. </template>
  130. <script>
  131. import TabTransition from '../../components/tab-transition.vue'
  132. import PageBanner from '../../components/PageBanner.vue'
  133. import LoginGuideCard from '../../components/LoginGuideCard.vue'
  134. import RadarChart from '../../components/RadarChart.vue'
  135. import FamilyEnergyBar from '../../components/FamilyEnergyBar.vue'
  136. import UserQuickEntry from '../../components/UserQuickEntry.vue'
  137. import DimensionTasks from '../../components/DimensionTasks.vue'
  138. import DimensionActivities from '../../components/DimensionActivities.vue'
  139. import DimensionProducts from '../../components/DimensionProducts.vue'
  140. import DimensionArticles from '../../components/DimensionArticles.vue'
  141. import FamilyRelationGraph from '../../components/FamilyRelationGraph.vue'
  142. import { getVisibleSections, getChildren, getTodayTasksByCategory, getActivityList, getProductsByDomain, getFamilyEnergySandbox, getAssessmentLatestResult, getFeaturedArticles } from '../../utils/api.js'
  143. export default {
  144. components: { TabTransition, PageBanner, LoginGuideCard, RadarChart, FamilyEnergyBar, UserQuickEntry, DimensionTasks, DimensionActivities, DimensionProducts, DimensionArticles, FamilyRelationGraph },
  145. data() {
  146. return {
  147. isLoggedIn: false,
  148. role: null,
  149. showTabTransition: false,
  150. activeChildId: null,
  151. activeChildName: '',
  152. userName: '',
  153. children: [],
  154. familyMembersVisible: [],
  155. sandboxData: null,
  156. dualDimension: null,
  157. visibleSections: [],
  158. cognitiveReport: null,
  159. dimensionTasks: [],
  160. dimensionActivities: [],
  161. dimensionProducts: [],
  162. articles: [],
  163. wisdomTips: [],
  164. funcList: [
  165. { icon: '\u{1F4CA}', label: '认知报告', needLogin: true, page: '/pages/wisdom-detail/cognitive-report' },
  166. { icon: '\u{270F}\uFE0F', label: '自己出题', needLogin: true, page: '/pages/wisdom-detail/self-quiz' },
  167. { icon: '\u{1F9E0}', label: '训练中心', needLogin: true, page: '/pages/wisdom-detail/training-hub' },
  168. { icon: '\u{1F3AF}', label: '测评预约', needLogin: false, page: '/pages/assessment/apply' },
  169. { icon: '\u{1F4D6}', label: '阅读天地', needLogin: false, page: '/pages/mind/articles' }
  170. ]
  171. }
  172. },
  173. computed: {
  174. energyMapForGraph: function() {
  175. var map = {}
  176. if (this.sandboxData && this.sandboxData.members) {
  177. for (var i = 0; i < this.sandboxData.members.length; i++) {
  178. var m = this.sandboxData.members[i]
  179. map[m.memberId || m.id] = {
  180. bodyScore: m.bodyScore || 0,
  181. mindScore: m.mindScore || 0,
  182. actionScore: m.actionScore || 0,
  183. wisdomScore: m.wisdomScore || 0
  184. }
  185. }
  186. }
  187. return map
  188. },
  189. intimacyMapForGraph: function() {
  190. return {}
  191. },
  192. wisdomArticles: function() {
  193. if (!this.articles || this.articles.length === 0) return []
  194. var result = []
  195. for (var i = 0; i < this.articles.length; i++) {
  196. var a = this.articles[i]
  197. if (a.relatedDimensions && a.relatedDimensions.indexOf('wisdom') !== -1) {
  198. result.push(a)
  199. }
  200. }
  201. if (result.length === 0) return this.articles.slice(0, 5)
  202. return result.slice(0, 5)
  203. },
  204. cognitiveDimensions: function() {
  205. return [
  206. { label: '感知能力', key: 'perceptionScore' },
  207. { label: '专注力', key: 'focusScore' },
  208. { label: '记忆力', key: 'memoryScore' },
  209. { label: '逻辑思维', key: 'logicScore' },
  210. { label: '空间思维', key: 'spatialScore' },
  211. { label: '加工速度', key: 'processingSpeedScore' }
  212. ]
  213. },
  214. cognitiveScores: function() {
  215. if (!this.cognitiveReport) return []
  216. var dims = this.cognitiveDimensions
  217. var scores = []
  218. for (var i = 0; i < dims.length; i++) {
  219. scores.push(this.cognitiveReport[dims[i].key] || 0)
  220. }
  221. return scores
  222. }
  223. },
  224. onShow() {
  225. // Tabbar 切换过渡动画(最少停留 1 秒)
  226. this.showTabTransition = true
  227. var self = this
  228. setTimeout(function() {
  229. self.showTabTransition = false
  230. }, 1100)
  231. var token = uni.getStorageSync('token')
  232. this.isLoggedIn = !!token
  233. if (this.isLoggedIn) {
  234. this.role = uni.getStorageSync('currentRole') || uni.getStorageSync('role') || null
  235. this.userName = uni.getStorageSync('nickname') || uni.getStorageSync('userName') || '家长'
  236. }
  237. this.loadSectionConfig()
  238. if (this.isLoggedIn) {
  239. this.loadChildren()
  240. this.loadFamilyMembersVisible()
  241. this.loadCognitiveReport()
  242. }
  243. this.loadDimensionActivities()
  244. this.loadDimensionProducts()
  245. // 游客也能浏览文章
  246. this.loadFeaturedArticles()
  247. },
  248. methods: {
  249. loadSectionConfig: function() {
  250. var baseSections = ['func_entries', 'wisdom_tips']
  251. if (!uni.getStorageSync('token')) {
  252. this.visibleSections = baseSections
  253. return
  254. }
  255. var role = uni.getStorageSync('currentRole') || uni.getStorageSync('role') || null
  256. var self = this
  257. getVisibleSections({ pageKey: 'wisdom', role: role }).then(function(res) {
  258. if (res.code === 200 && res.data) {
  259. var keys = res.data.map(function(s) { return s.sectionKey })
  260. var merged = baseSections.slice()
  261. keys.forEach(function(k) { if (merged.indexOf(k) === -1) merged.push(k) })
  262. self.visibleSections = merged
  263. }
  264. }).catch(function(e) {
  265. self.visibleSections = ['func_entries', 'wisdom_tips']
  266. })
  267. },
  268. loadChildren: function() {
  269. var self = this
  270. getChildren().then(function(res) {
  271. if (res.code === 200 && res.data) {
  272. self.children = res.data
  273. if (self.children.length > 0) {
  274. var activeId = uni.getStorageSync('currentChildId')
  275. if (activeId) {
  276. for (var i = 0; i < self.children.length; i++) {
  277. if (self.children[i].id == activeId) {
  278. self.activeChildId = activeId
  279. self.activeChildName = self.children[i].nickname || self.children[i].name || ''
  280. break
  281. }
  282. }
  283. }
  284. if (!self.activeChildId) {
  285. self.activeChildId = self.children[0].id
  286. self.activeChildName = self.children[0].nickname || self.children[0].name || ''
  287. uni.setStorageSync('currentChildId', self.activeChildId)
  288. }
  289. }
  290. }
  291. }).catch(function(e) {})
  292. },
  293. loadFamilyMembersVisible: function() {
  294. var self = this
  295. getFamilyEnergySandbox().then(function(res) {
  296. if (res && res.data) {
  297. self.sandboxData = res.data.sandboxData || null
  298. self.dualDimension = res.data.dualDimension || null
  299. if (res.data.members) {
  300. self.familyMembersVisible = res.data.members
  301. }
  302. }
  303. }).catch(function(e) {})
  304. },
  305. loadCognitiveReport: function() {
  306. var self = this
  307. var childId = this.activeChildId
  308. if (!childId) return
  309. getAssessmentLatestResult(childId).then(function(res) {
  310. if (res.code === 200 && res.data) {
  311. self.cognitiveReport = res.data
  312. }
  313. }).catch(function(e) {})
  314. },
  315. onChildChanged: function(childId) {
  316. this.activeChildId = childId
  317. uni.setStorageSync('currentChildId', childId)
  318. for (var i = 0; i < this.children.length; i++) {
  319. if (this.children[i].id == childId) {
  320. this.activeChildName = this.children[i].nickname || this.children[i].name || ''
  321. break
  322. }
  323. }
  324. this.loadFamilyMembersVisible()
  325. this.loadCognitiveReport()
  326. },
  327. loadDimensionTasks: function() {
  328. var self = this
  329. var childId = this.activeChildId
  330. if (!childId) return
  331. getTodayTasksByCategory(childId, 'wisdom').then(function(res) {
  332. if (res && res.data) {
  333. self.dimensionTasks = res.data.slice(0, 5)
  334. }
  335. }).catch(function(e) {})
  336. },
  337. loadDimensionActivities: function() {
  338. var self = this
  339. getActivityList({ dimensionCode: 'wisdom', page: 1, size: 5 }).then(function(res) {
  340. if (res && res.data) {
  341. self.dimensionActivities = res.data.records || res.data
  342. }
  343. }).catch(function(e) {})
  344. },
  345. loadDimensionProducts: function() {
  346. var self = this
  347. getProductsByDomain('wisdom', 1, 4).then(function(res) {
  348. if (res && res.data) {
  349. self.dimensionProducts = res.data.records || res.data
  350. }
  351. }).catch(function(e) {})
  352. },
  353. sectionVisible: function(key) {
  354. return this.visibleSections.length === 0 || this.visibleSections.indexOf(key) !== -1
  355. },
  356. onFuncClick: function(item) {
  357. if (item.needLogin && !this.isLoggedIn) {
  358. uni.showModal({
  359. title: '提示',
  360. content: '请先登录后使用此功能',
  361. success: function(res) { if (res.confirm) uni.navigateTo({ url: '/pages/login/login' }) }
  362. })
  363. return
  364. }
  365. if (item.page) {
  366. var nativeTabs = ['/pages/tasks/tasks', '/pages/index/index', '/pages/body/index', '/pages/mind/index', '/pages/action/index', '/pages/wisdom/index', '/pages/profile/profile']
  367. if (nativeTabs.indexOf(item.page) !== -1) {
  368. uni.switchTab({ url: item.page })
  369. } else {
  370. uni.navigateTo({ url: item.page })
  371. }
  372. }
  373. },
  374. scrollToSection: function(section) {},
  375. goMemberDetail: function(memberId) {
  376. uni.navigateTo({ url: '/pages/wisdom-detail/member-wisdom-detail?memberId=' + memberId })
  377. },
  378. goCognitiveReport: function() {
  379. uni.navigateTo({ url: '/pages/wisdom-detail/cognitive-report' })
  380. },
  381. goSelfQuiz: function() {
  382. uni.navigateTo({ url: '/pages/wisdom-detail/self-quiz' })
  383. },
  384. goTrainingHub: function() {
  385. uni.navigateTo({ url: '/pages/wisdom-detail/training-hub' })
  386. },
  387. goAssessment: function() {
  388. uni.navigateTo({ url: '/pages/assessment/apply' })
  389. },
  390. goHome: function() {
  391. uni.switchTab({ url: '/pages/index/index' })
  392. },
  393. onTaskClick: function(task) {},
  394. goTasks: function() { uni.switchTab({ url: '/pages/tasks/tasks' }) },
  395. goActivityDetail: function(id) {},
  396. goMoreActivities: function() {},
  397. goProductDetail: function(id) {
  398. var token = uni.getStorageSync('token')
  399. if (token) {
  400. uni.navigateTo({ url: '/pages/discover/product-detail/product-detail?id=' + id })
  401. } else {
  402. uni.navigateTo({ url: '/pages/login/login?redirect=' + encodeURIComponent('/pages/wisdom/index') })
  403. }
  404. },
  405. goMoreProducts: function() {},
  406. loadFeaturedArticles: function() {
  407. var self = this
  408. getFeaturedArticles({ size: 5 }).then(function(res) {
  409. if (res.code === 200 && res.data) {
  410. var gradientColors = [
  411. 'linear-gradient(135deg, #6366F1, #818CF8)',
  412. 'linear-gradient(135deg, #8B5CF6, #A78BFA)',
  413. 'linear-gradient(135deg, #5B9BD5, #8FC5E8)',
  414. 'linear-gradient(135deg, #10B981, #34D399)',
  415. 'linear-gradient(135deg, #F97316, #FB923C)'
  416. ]
  417. var list = Array.isArray(res.data) ? res.data : (res.data.records || [])
  418. self.articles = list.map(function(item, index) {
  419. return {
  420. id: item.id,
  421. category: item.categoryName || '智慧文章',
  422. categoryColor: gradientColors[index % gradientColors.length],
  423. title: item.title || '',
  424. summary: item.summary || '',
  425. views: item.viewCount ? String(item.viewCount) : '0',
  426. likes: '0',
  427. date: item.publishedAt ? item.publishedAt.slice(0, 10) : '',
  428. relatedDimensions: item.relatedDimensions || []
  429. }
  430. })
  431. }
  432. }).catch(function() {})
  433. },
  434. goMoreArticles: function() {
  435. uni.navigateTo({ url: '/pages/mind/articles' })
  436. },
  437. goArticleDetail: function(article) {
  438. uni.navigateTo({ url: '/pages/mind-detail/article-detail?id=' + (article.id || article) })
  439. }
  440. }
  441. }
  442. </script>
  443. <style scoped>
  444. .wisdom-container {
  445. min-height: 100vh;
  446. background: #f5f7fa;
  447. padding-bottom: 120rpx;
  448. }
  449. .func-section {
  450. margin: -40rpx 20rpx 0;
  451. position: relative;
  452. z-index: 2;
  453. }
  454. .func-grid {
  455. background: #fff;
  456. border-radius: 24rpx;
  457. padding: 30rpx 16rpx;
  458. display: flex;
  459. box-shadow: 0 4rpx 20rpx rgba(0,0,0,0.06);
  460. }
  461. .func-item {
  462. flex: 1;
  463. display: flex;
  464. flex-direction: column;
  465. align-items: center;
  466. }
  467. .func-item:active {
  468. opacity: 0.7;
  469. }
  470. .func-icon-wrap {
  471. width: 88rpx;
  472. height: 88rpx;
  473. border-radius: 50%;
  474. background: #FFF8E1;
  475. display: flex;
  476. align-items: center;
  477. justify-content: center;
  478. margin-bottom: 10rpx;
  479. }
  480. .func-icon {
  481. font-size: 40rpx;
  482. }
  483. .func-label {
  484. font-size: 24rpx;
  485. color: #333;
  486. font-weight: 500;
  487. }
  488. /* ===== Section ===== */
  489. .section {
  490. margin: 20rpx 20rpx;
  491. }
  492. .section-header {
  493. display: flex;
  494. justify-content: space-between;
  495. align-items: center;
  496. margin-bottom: 20rpx;
  497. }
  498. .section-title {
  499. font-size: 30rpx;
  500. font-weight: bold;
  501. color: #333;
  502. }
  503. .section-more {
  504. font-size: 24rpx;
  505. color: #999;
  506. }
  507. /* ===== 智慧小贴士 ===== */
  508. .tips-list {
  509. display: flex;
  510. flex-direction: column;
  511. }
  512. .tip-card {
  513. background: #fff;
  514. border-radius: 16rpx;
  515. padding: 24rpx 20rpx;
  516. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  517. margin-bottom: 16rpx;
  518. }
  519. .tip-title {
  520. font-size: 28rpx;
  521. font-weight: bold;
  522. color: #333;
  523. display: block;
  524. margin-bottom: 8rpx;
  525. }
  526. .tip-summary {
  527. font-size: 24rpx;
  528. color: #888;
  529. line-height: 1.5;
  530. display: block;
  531. }
  532. /* ===== 快捷操作按钮 ===== */
  533. .quick-actions {
  534. display: flex;
  535. flex-direction: row;
  536. flex-wrap: wrap;
  537. justify-content: space-between;
  538. }
  539. .action-btn {
  540. width: 48%;
  541. background: #fff;
  542. border-radius: 16rpx;
  543. padding: 24rpx 0;
  544. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  545. display: flex;
  546. flex-direction: column;
  547. align-items: center;
  548. margin-bottom: 20rpx;
  549. }
  550. .action-btn:active {
  551. opacity: 0.8;
  552. }
  553. .action-icon {
  554. font-size: 40rpx;
  555. margin-bottom: 10rpx;
  556. }
  557. .action-text {
  558. font-size: 26rpx;
  559. color: #333;
  560. font-weight: 500;
  561. }
  562. /* ===== 底部占位 ===== */
  563. .bottom-spacer {
  564. height: 120rpx;
  565. }
  566. </style>