index.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  1. <template>
  2. <view class="container">
  3. <PageBanner theme="action" tagline="方案 · 执行 · 成长" quote="知行合一,每天进步一点点" />
  4. <!-- 无家庭状态 -->
  5. <view v-if="!hasFamily">
  6. <FamilyEmptyState type="card" />
  7. </view>
  8. <view v-else>
  9. <!-- 家庭成员选择条 -->
  10. <FamilyMemberStrip />
  11. <!-- 今日待办卡片 -->
  12. <view class="section">
  13. <view class="todo-card">
  14. <view class="todo-header">
  15. <text class="todo-title">今日执行概览</text>
  16. </view>
  17. <view class="todo-grid">
  18. <view class="todo-item">
  19. <text class="todo-icon">✅</text>
  20. <text class="todo-label">今日打卡</text>
  21. <text class="todo-value" :class="todayCheckedIn ? 'text-success' : 'text-muted'">{{ todayCheckedIn ? '已完成' : '未完成' }}</text>
  22. </view>
  23. <view class="todo-item">
  24. <text class="todo-icon">📋</text>
  25. <text class="todo-label">待完成任务</text>
  26. <text class="todo-value">{{ pendingTasks }} 项</text>
  27. </view>
  28. <view class="todo-item">
  29. <text class="todo-icon">🔥</text>
  30. <text class="todo-label">进行中挑战</text>
  31. <text class="todo-value">{{ activeChallenges }} 个</text>
  32. </view>
  33. <view class="todo-item">
  34. <text class="todo-icon">🍽️</text>
  35. <text class="todo-label">今日饮食</text>
  36. <text class="todo-value">{{ mealCount }} 餐</text>
  37. </view>
  38. </view>
  39. </view>
  40. </view>
  41. <!-- 功能入口网格 -->
  42. <view class="section">
  43. <view class="grid-3col">
  44. <view class="grid-item" @click="goPage('/pages/health/daily-checkin')">
  45. <view class="grid-icon" style="background:rgba(16,185,129,0.15)"><text>✅</text></view>
  46. <text class="grid-label">每日打卡</text>
  47. </view>
  48. <view class="grid-item" @click="goPage('/pages/tasks/daily-tasks')">
  49. <view class="grid-icon" style="background:rgba(99,102,241,0.15)"><text>📋</text></view>
  50. <text class="grid-label">日常任务</text>
  51. </view>
  52. <view class="grid-item" @click="goPage('/pages/health/challenge-manage')">
  53. <view class="grid-icon" style="background:rgba(239,68,68,0.15)"><text>🔥</text></view>
  54. <text class="grid-label">家庭挑战</text>
  55. </view>
  56. <view class="grid-item" @click="goPage('/pages/diet/index')">
  57. <view class="grid-icon" style="background:rgba(245,158,11,0.15)"><text>🍽️</text></view>
  58. <text class="grid-label">饮食记录</text>
  59. </view>
  60. <view class="grid-item" @click="goPage('/pages/health/exercise-index')">
  61. <view class="grid-icon" style="background:rgba(34,197,94,0.15)"><text>🏃</text></view>
  62. <text class="grid-label">运动记录</text>
  63. </view>
  64. <view class="grid-item" @click="goPage('/pages/health/sleep-index')">
  65. <view class="grid-icon" style="background:rgba(139,92,246,0.15)"><text>😴</text></view>
  66. <text class="grid-label">作息记录</text>
  67. </view>
  68. <view class="grid-item" @click="goPage('/pages/growth/detail')">
  69. <view class="grid-icon" style="background:rgba(249,115,22,0.15)"><text>📈</text></view>
  70. <text class="grid-label">成长档案</text>
  71. </view>
  72. <view class="grid-item" @click="goPage('/pages/health/meditation-index')">
  73. <view class="grid-icon" style="background:rgba(255,107,157,0.15)"><text>🧘</text></view>
  74. <text class="grid-label">冥想练习</text>
  75. </view>
  76. </view>
  77. </view>
  78. <!-- 活动推荐(从首页移过来) -->
  79. <DimensionActivities
  80. dimensionCode="action"
  81. :activities="dimensionActivities"
  82. :isLoggedIn="true"
  83. @activityClick="goActivityDetail"
  84. @moreActivities="goMoreActivities" />
  85. <!-- 成长档案(原有内容) -->
  86. <view class="section">
  87. <view class="section-header">
  88. <text class="section-title">成长档案</text>
  89. <text class="section-more" v-if="records.length > 0" @click="viewAllRecords">查看全部 ›</text>
  90. </view>
  91. <!-- 孩子选择 -->
  92. <view class="children-list" v-if="!selectedChild">
  93. <view class="child-card" v-for="child in children" :key="child.id" @click="viewChildRecords(child)">
  94. <view class="child-info">
  95. <text class="child-name">{{ child.nickname || child.name }}</text>
  96. <text class="child-age" v-if="child.age">年龄:{{ child.age }}岁</text>
  97. </view>
  98. <view class="arrow">
  99. <text class="arrow-icon">›</text>
  100. </view>
  101. </view>
  102. <view class="empty-state" v-if="children.length === 0 && !loading">
  103. <text class="empty-icon">📋</text>
  104. <text class="empty-text">还没有添加孩子</text>
  105. <text class="empty-hint">请先在"我的"页面添加孩子</text>
  106. </view>
  107. </view>
  108. <!-- 档案记录 -->
  109. <view class="records-section" v-if="selectedChild">
  110. <view class="filter-tabs">
  111. <view class="filter-tab" :class="activeFilter === 'all' ? 'tab-active' : ''" @click="setFilter('all')">
  112. <text class="tab-text" :class="activeFilter === 'all' ? 'tab-active-text' : ''">全部</text>
  113. </view>
  114. <view class="filter-tab" :class="activeFilter === 'manual' ? 'tab-active' : ''" @click="setFilter('manual')">
  115. <text class="tab-text" :class="activeFilter === 'manual' ? 'tab-active-text' : ''">手动</text>
  116. </view>
  117. <view class="filter-tab" :class="activeFilter === 'assessment' ? 'tab-active' : ''" @click="setFilter('assessment')">
  118. <text class="tab-text" :class="activeFilter === 'assessment' ? 'tab-active-text' : ''">测评</text>
  119. </view>
  120. <view class="filter-tab" :class="activeFilter === 'upload' ? 'tab-active' : ''" @click="setFilter('upload')">
  121. <text class="tab-text" :class="activeFilter === 'upload' ? 'tab-active-text' : ''">上传</text>
  122. </view>
  123. <view class="filter-tab" :class="activeFilter === 'supplement' ? 'tab-active' : ''" @click="setFilter('supplement')">
  124. <text class="tab-text" :class="activeFilter === 'supplement' ? 'tab-active-text' : ''">补充</text>
  125. </view>
  126. </view>
  127. <view class="record-card" v-for="record in filteredRecords" :key="record.id" @click="viewDetail(record)">
  128. <view class="record-header">
  129. <text class="record-title">{{ record.recordTitle || '成长档案' }}</text>
  130. <view class="record-badges">
  131. <text class="record-source-tag" v-if="record.sourceType">{{ sourceTypeLabel(record.sourceType) }}</text>
  132. <text class="record-tag" :class="record.status === 'completed' ? 'tag-completed' : 'tag-pending'">
  133. {{ record.status === 'completed' ? '已完成' : '待同步' }}
  134. </text>
  135. </view>
  136. </view>
  137. <view class="record-scores" v-if="record.overallScore || record.reportDate">
  138. <text class="score-item" v-if="record.overallScore">得分: {{ record.overallScore }}</text>
  139. <text class="score-item" v-if="record.reportDate">{{ record.reportDate }}</text>
  140. <text class="score-item" v-if="!record.reportDate && record.createdAt">{{ formatDate(record.createdAt) }}</text>
  141. </view>
  142. </view>
  143. <view class="empty-state" v-if="filteredRecords.length === 0 && records.length > 0">
  144. <text class="empty-text">该类型暂无记录</text>
  145. </view>
  146. <view class="empty-state" v-if="records.length === 0">
  147. <text class="empty-text">暂无成长档案记录</text>
  148. </view>
  149. </view>
  150. <!-- 创建按钮 -->
  151. <view class="footer-btn" v-if="selectedChild">
  152. <button class="btn-create" @click="createRecord">创建成长档案</button>
  153. </view>
  154. <view class="footer-btn" v-if="!selectedChild && children.length > 0">
  155. <button class="btn-invite-guide" open-type="share" @click="prepareGuideInvite">邀请成长规划师</button>
  156. </view>
  157. </view>
  158. </view>
  159. </view>
  160. </template>
  161. <script>
  162. import PageBanner from '../../components/PageBanner.vue'
  163. import FamilyMemberStrip from '../../components/FamilyMemberStrip.vue'
  164. import DimensionActivities from '../../components/DimensionActivities.vue'
  165. import { getChildren, getChildRecords, getActivityList } from '../../utils/api.js'
  166. export default {
  167. components: {
  168. PageBanner,
  169. FamilyMemberStrip,
  170. DimensionActivities
  171. },
  172. data() {
  173. return {
  174. loading: false,
  175. children: [],
  176. selectedChild: null,
  177. selectedChildName: '',
  178. records: [],
  179. memberId: '',
  180. activeFilter: 'all',
  181. shareData: null,
  182. todayCheckedIn: false,
  183. pendingTasks: 0,
  184. activeChallenges: 0,
  185. mealCount: 0,
  186. dimensionActivities: []
  187. }
  188. },
  189. computed: {
  190. hasFamily: function() {
  191. if (this.memberId) return true
  192. if (this.children && this.children.length > 0) return true
  193. if (this.records && this.records.length > 0) return true
  194. return this.$store.getters.hasFamily
  195. },
  196. filteredRecords: function() {
  197. if (this.activeFilter === 'all') return this.records
  198. var filter = this.activeFilter
  199. return this.records.filter(function(r) { return r.sourceType === filter })
  200. }
  201. },
  202. onShareAppMessage() {
  203. if (this.shareData) {
  204. return {
  205. title: this.shareData.title,
  206. path: this.shareData.path,
  207. imageUrl: '/static/invite-card.png'
  208. }
  209. }
  210. },
  211. onLoad(options) {
  212. this.memberId = options.memberId || ''
  213. this.loadChildren()
  214. this.loadTodoData()
  215. this.loadDimensionActivities()
  216. },
  217. methods: {
  218. goPage: function(url) {
  219. uni.navigateTo({ url: url })
  220. },
  221. loadDimensionActivities: function() {
  222. var self = this
  223. getActivityList({ dimensionCode: '', page: 1, size: 3 }).then(function(res) {
  224. if (res && res.code === 200) {
  225. var rawData = res.data && (Array.isArray(res.data) ? res.data : (res.data.data || res.data.records || []))
  226. self.dimensionActivities = Array.isArray(rawData) ? rawData.slice(0, 3) : []
  227. }
  228. }).catch(function() { self.dimensionActivities = [] })
  229. },
  230. goActivityDetail: function(act) {
  231. uni.navigateTo({ url: '/pages/activity/activity-detail/activity-detail?id=' + act.id })
  232. },
  233. goMoreActivities: function() {
  234. uni.navigateTo({ url: '/pages/activity/index' })
  235. },
  236. viewAllRecords: function() {
  237. // 滚动到档案区域或展开全部
  238. if (this.selectedChild) {
  239. uni.navigateTo({ url: '/pages/growth/detail?memberId=' + this.selectedChild.id })
  240. }
  241. },
  242. sourceTypeLabel: function(type) {
  243. var map = { 'manual': '手动', 'assessment': '测评', 'upload': '上传', 'supplement': '补充' }
  244. return map[type] || type
  245. },
  246. setFilter: function(type) {
  247. this.activeFilter = type
  248. },
  249. loadTodoData: function() {
  250. var self = this
  251. try {
  252. var api = require('../../utils/api.js')
  253. // 检查打卡状态
  254. if (api.getCheckinStats) {
  255. api.getCheckinStats().then(function(res) {
  256. if (res.code === 200 && res.data) {
  257. self.todayCheckedIn = !!(res.data.todayCheckedIn || res.data.checkedIn || (res.data.today && res.data.today.checkedIn))
  258. }
  259. }).catch(function() {})
  260. }
  261. // 待完成任务数
  262. if (api.getTodayTasks && self.children && self.children.length > 0) {
  263. var childId = self.selectedChild ? self.selectedChild.id : self.children[0].id
  264. api.getTodayTasks(childId).then(function(res) {
  265. if (res.code === 200) {
  266. self.pendingTasks = (res.data && res.data.length) || 0
  267. }
  268. }).catch(function() {})
  269. }
  270. // 进行中挑战
  271. if (api.getChallengeList) {
  272. api.getChallengeList({ status: 'active' }).then(function(res) {
  273. if (res.code === 200) {
  274. self.activeChallenges = (res.data && res.data.length) || 0
  275. }
  276. }).catch(function() {})
  277. }
  278. // 饮食记录数
  279. if (api.getMealLogs) {
  280. api.getMealLogs({ date: new Date().toISOString().slice(0, 10) }).then(function(res) {
  281. if (res.code === 200) {
  282. self.mealCount = (res.data && res.data.length) || 0
  283. }
  284. }).catch(function() {})
  285. }
  286. } catch (e) {
  287. console.error('加载待办数据失败', e)
  288. }
  289. },
  290. async loadChildren() {
  291. this.loading = true
  292. try {
  293. var res = await getChildren()
  294. if (res.code === 200) {
  295. this.children = res.data || []
  296. if (this.memberId && this.children.length > 0) {
  297. var matched = this.children.find(function(c) { return String(c.id) === String(this.memberId) }.bind(this))
  298. if (matched) {
  299. this.viewChildRecords(matched)
  300. }
  301. }
  302. }
  303. } catch (e) {
  304. console.error('加载孩子列表失败', e)
  305. } finally {
  306. this.loading = false
  307. }
  308. },
  309. async viewChildRecords(child) {
  310. this.selectedChild = child
  311. this.selectedChildName = child.nickname || child.name
  312. this.loading = true
  313. try {
  314. var res = await getChildRecords(child.id)
  315. if (res.code === 200) {
  316. this.records = res.data || []
  317. }
  318. } catch (e) {
  319. console.error('加载成长档案失败', e)
  320. } finally {
  321. this.loading = false
  322. }
  323. },
  324. viewDetail: function(record) {
  325. uni.navigateTo({
  326. url: '/pages/growth/detail?recordId=' + record.id
  327. })
  328. },
  329. createRecord: function() {
  330. uni.navigateTo({
  331. url: '/pages/growth/create?memberId=' + this.selectedChild.id + '&childName=' + encodeURIComponent(this.selectedChildName)
  332. })
  333. },
  334. formatDate: function(date) {
  335. if (!date) return ''
  336. return date.substring(0, 10)
  337. },
  338. async prepareGuideInvite() {
  339. try {
  340. var ui = uni.getStorageSync('userInfo') || {}
  341. if (!ui.familyId) {
  342. uni.showToast({ title: '请先创建家庭', icon: 'none' })
  343. return
  344. }
  345. var userInfo = ui
  346. var generateInviteCard = require('../../utils/api.js').generateInviteCard
  347. var res = await generateInviteCard('guide')
  348. var code = res.data.code
  349. this.shareData = {
  350. title: (userInfo && userInfo.nickname ? userInfo.nickname : '家长') + ' 邀请你成为成长规划师',
  351. path: '/pages/login/login?invite_code=' + code
  352. }
  353. uni.showToast({ title: '点击右上角转发给TA', icon: 'none' })
  354. } catch (e) {
  355. uni.showToast({ title: e.message || '生成邀请失败', icon: 'none' })
  356. }
  357. }
  358. }
  359. }
  360. </script>
  361. <style scoped>
  362. .container {
  363. background: #F8F8F8;
  364. min-height: 100vh;
  365. padding-bottom: 120rpx;
  366. }
  367. .section {
  368. margin: 20rpx 24rpx;
  369. }
  370. .section-header {
  371. display: flex;
  372. justify-content: space-between;
  373. align-items: center;
  374. margin-bottom: 16rpx;
  375. }
  376. .section-title {
  377. font-size: 30rpx;
  378. font-weight: bold;
  379. color: #333;
  380. }
  381. .section-more {
  382. font-size: 24rpx;
  383. color: #F97316;
  384. }
  385. /* 今日待办卡片 */
  386. .todo-card {
  387. background: #fff;
  388. border-radius: 20rpx;
  389. padding: 24rpx;
  390. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  391. }
  392. .todo-header {
  393. margin-bottom: 16rpx;
  394. }
  395. .todo-title {
  396. font-size: 28rpx;
  397. font-weight: bold;
  398. color: #333;
  399. }
  400. .todo-grid {
  401. display: flex;
  402. flex-wrap: wrap;
  403. }
  404. .todo-item {
  405. width: 50%;
  406. display: flex;
  407. align-items: center;
  408. padding: 10rpx 0;
  409. flex-wrap: wrap;
  410. }
  411. .todo-icon {
  412. font-size: 28rpx;
  413. margin-right: 8rpx;
  414. }
  415. .todo-label {
  416. font-size: 24rpx;
  417. color: #999;
  418. margin-right: 8rpx;
  419. }
  420. .todo-value {
  421. font-size: 28rpx;
  422. font-weight: bold;
  423. color: #333;
  424. }
  425. .text-success {
  426. color: #10B981;
  427. }
  428. .text-muted {
  429. color: #ccc;
  430. }
  431. /* 功能入口网格 3列 */
  432. .grid-3col {
  433. display: flex;
  434. flex-wrap: wrap;
  435. background: #fff;
  436. border-radius: 20rpx;
  437. padding: 8rpx 0;
  438. }
  439. .grid-item {
  440. width: 33.33%;
  441. display: flex;
  442. flex-direction: column;
  443. align-items: center;
  444. padding: 20rpx 0;
  445. }
  446. .grid-icon {
  447. width: 72rpx;
  448. height: 72rpx;
  449. border-radius: 18rpx;
  450. display: flex;
  451. align-items: center;
  452. justify-content: center;
  453. margin-bottom: 8rpx;
  454. }
  455. .grid-icon text {
  456. font-size: 32rpx;
  457. }
  458. .grid-item .grid-label {
  459. font-size: 24rpx;
  460. color: #666;
  461. }
  462. /* 孩子选择 */
  463. .children-list {
  464. margin-top: 8rpx;
  465. }
  466. .child-card {
  467. display: flex;
  468. align-items: center;
  469. background: #fff;
  470. border-radius: 20rpx;
  471. padding: 30rpx;
  472. margin-bottom: 20rpx;
  473. }
  474. .child-info {
  475. flex: 1;
  476. }
  477. .child-name {
  478. font-size: 32rpx;
  479. font-weight: bold;
  480. color: #333;
  481. display: block;
  482. }
  483. .child-age {
  484. font-size: 24rpx;
  485. color: #999;
  486. margin-top: 6rpx;
  487. display: block;
  488. }
  489. .arrow {
  490. width: 40rpx;
  491. }
  492. .arrow-icon {
  493. font-size: 40rpx;
  494. color: #ccc;
  495. }
  496. /* 记录筛选 */
  497. .records-section {
  498. margin-top: 16rpx;
  499. }
  500. .filter-tabs {
  501. display: flex;
  502. gap: 16rpx;
  503. margin-bottom: 20rpx;
  504. }
  505. .filter-tab {
  506. flex: 1;
  507. text-align: center;
  508. padding: 12rpx 0;
  509. border-radius: 20rpx;
  510. background: #fff;
  511. border: 1rpx solid #E0E0E0;
  512. }
  513. .tab-active {
  514. background: #667eea;
  515. border-color: #667eea;
  516. }
  517. .tab-text {
  518. font-size: 24rpx;
  519. color: #666;
  520. }
  521. .tab-active-text {
  522. color: #fff;
  523. }
  524. /* 记录卡片 */
  525. .record-card {
  526. background: #fff;
  527. border-radius: 16rpx;
  528. padding: 24rpx;
  529. margin-bottom: 16rpx;
  530. }
  531. .record-header {
  532. display: flex;
  533. justify-content: space-between;
  534. align-items: center;
  535. margin-bottom: 12rpx;
  536. }
  537. .record-title {
  538. font-size: 28rpx;
  539. color: #333;
  540. font-weight: bold;
  541. flex: 1;
  542. }
  543. .record-badges {
  544. display: flex;
  545. gap: 8rpx;
  546. flex-shrink: 0;
  547. }
  548. .record-source-tag {
  549. font-size: 20rpx;
  550. padding: 4rpx 10rpx;
  551. border-radius: 8rpx;
  552. background: #f0f0ff;
  553. color: #667eea;
  554. }
  555. .record-tag {
  556. font-size: 22rpx;
  557. padding: 4rpx 12rpx;
  558. border-radius: 20rpx;
  559. }
  560. .tag-completed {
  561. background: #e8f5e9;
  562. color: #4caf50;
  563. }
  564. .tag-pending {
  565. background: #fff3e0;
  566. color: #ff9800;
  567. }
  568. .record-scores {
  569. display: flex;
  570. gap: 20rpx;
  571. }
  572. .score-item {
  573. font-size: 24rpx;
  574. color: #666;
  575. }
  576. /* 空状态 */
  577. .empty-state {
  578. text-align: center;
  579. padding: 60rpx 0;
  580. }
  581. .empty-icon {
  582. font-size: 80rpx;
  583. display: block;
  584. margin-bottom: 20rpx;
  585. }
  586. .empty-text {
  587. font-size: 28rpx;
  588. color: #999;
  589. display: block;
  590. }
  591. .empty-hint {
  592. font-size: 24rpx;
  593. color: #ccc;
  594. margin-top: 10rpx;
  595. display: block;
  596. }
  597. /* 按钮 */
  598. .footer-btn {
  599. padding: 30rpx 0;
  600. }
  601. .btn-create {
  602. width: 100%;
  603. height: 88rpx;
  604. line-height: 88rpx;
  605. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  606. color: #fff;
  607. border-radius: 44rpx;
  608. font-size: 32rpx;
  609. font-weight: bold;
  610. text-align: center;
  611. }
  612. .btn-invite-guide {
  613. width: 100%;
  614. height: 88rpx;
  615. line-height: 88rpx;
  616. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  617. color: #fff;
  618. border-radius: 44rpx;
  619. font-size: 32rpx;
  620. font-weight: bold;
  621. text-align: center;
  622. }
  623. </style>