index.vue 18 KB

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