index.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683
  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. return this.$store.getters.hasFamily
  193. },
  194. filteredRecords: function() {
  195. if (this.activeFilter === 'all') return this.records
  196. var filter = this.activeFilter
  197. return this.records.filter(function(r) { return r.sourceType === filter })
  198. }
  199. },
  200. onShareAppMessage() {
  201. if (this.shareData) {
  202. return {
  203. title: this.shareData.title,
  204. path: this.shareData.path,
  205. imageUrl: '/static/invite-card.png'
  206. }
  207. }
  208. },
  209. onLoad(options) {
  210. this.memberId = options.memberId || ''
  211. this.loadChildren()
  212. this.loadTodoData()
  213. this.loadDimensionActivities()
  214. },
  215. methods: {
  216. goPage: function(url) {
  217. uni.navigateTo({ url: url })
  218. },
  219. loadDimensionActivities: function() {
  220. var self = this
  221. getActivityList({ dimensionCode: '', page: 1, size: 3 }).then(function(res) {
  222. if (res && res.code === 200) {
  223. var rawData = res.data && (Array.isArray(res.data) ? res.data : (res.data.data || res.data.records || []))
  224. self.dimensionActivities = Array.isArray(rawData) ? rawData.slice(0, 3) : []
  225. }
  226. }).catch(function() { self.dimensionActivities = [] })
  227. },
  228. goActivityDetail: function(act) {
  229. uni.navigateTo({ url: '/pages/activity/activity-detail/activity-detail?id=' + act.id })
  230. },
  231. goMoreActivities: function() {
  232. uni.navigateTo({ url: '/pages/activity/index' })
  233. },
  234. viewAllRecords: function() {
  235. // 滚动到档案区域或展开全部
  236. if (this.selectedChild) {
  237. uni.navigateTo({ url: '/pages/growth/detail?memberId=' + this.selectedChild.id })
  238. }
  239. },
  240. sourceTypeLabel: function(type) {
  241. var map = { 'manual': '手动', 'assessment': '测评', 'upload': '上传', 'supplement': '补充' }
  242. return map[type] || type
  243. },
  244. setFilter: function(type) {
  245. this.activeFilter = type
  246. },
  247. loadTodoData: function() {
  248. var self = this
  249. try {
  250. var api = require('../../utils/api.js')
  251. // 检查打卡状态
  252. if (api.getCheckinStats) {
  253. api.getCheckinStats().then(function(res) {
  254. if (res.code === 200 && res.data) {
  255. self.todayCheckedIn = !!(res.data.todayCheckedIn || res.data.checkedIn || (res.data.today && res.data.today.checkedIn))
  256. }
  257. }).catch(function() {})
  258. }
  259. // 待完成任务数
  260. if (api.getTodayTasks && self.children && self.children.length > 0) {
  261. var childId = self.selectedChild ? self.selectedChild.id : self.children[0].id
  262. api.getTodayTasks(childId).then(function(res) {
  263. if (res.code === 200) {
  264. self.pendingTasks = (res.data && res.data.length) || 0
  265. }
  266. }).catch(function() {})
  267. }
  268. // 进行中挑战
  269. if (api.getChallengeList) {
  270. api.getChallengeList({ status: 'active' }).then(function(res) {
  271. if (res.code === 200) {
  272. self.activeChallenges = (res.data && res.data.length) || 0
  273. }
  274. }).catch(function() {})
  275. }
  276. // 饮食记录数
  277. if (api.getMealLogs) {
  278. api.getMealLogs({ date: new Date().toISOString().slice(0, 10) }).then(function(res) {
  279. if (res.code === 200) {
  280. self.mealCount = (res.data && res.data.length) || 0
  281. }
  282. }).catch(function() {})
  283. }
  284. } catch (e) {
  285. console.error('加载待办数据失败', e)
  286. }
  287. },
  288. async loadChildren() {
  289. this.loading = true
  290. try {
  291. var res = await getChildren()
  292. if (res.code === 200) {
  293. this.children = res.data || []
  294. if (this.memberId && this.children.length > 0) {
  295. var matched = this.children.find(function(c) { return String(c.id) === String(this.memberId) }.bind(this))
  296. if (matched) {
  297. this.viewChildRecords(matched)
  298. }
  299. }
  300. }
  301. } catch (e) {
  302. console.error('加载孩子列表失败', e)
  303. } finally {
  304. this.loading = false
  305. }
  306. },
  307. async viewChildRecords(child) {
  308. this.selectedChild = child
  309. this.selectedChildName = child.nickname || child.name
  310. this.loading = true
  311. try {
  312. var res = await getChildRecords(child.id)
  313. if (res.code === 200) {
  314. this.records = res.data || []
  315. }
  316. } catch (e) {
  317. console.error('加载成长档案失败', e)
  318. } finally {
  319. this.loading = false
  320. }
  321. },
  322. viewDetail: function(record) {
  323. uni.navigateTo({
  324. url: '/pages/growth/detail?recordId=' + record.id
  325. })
  326. },
  327. createRecord: function() {
  328. uni.navigateTo({
  329. url: '/pages/growth/create?memberId=' + this.selectedChild.id + '&childName=' + encodeURIComponent(this.selectedChildName)
  330. })
  331. },
  332. formatDate: function(date) {
  333. if (!date) return ''
  334. return date.substring(0, 10)
  335. },
  336. async prepareGuideInvite() {
  337. try {
  338. var ui = uni.getStorageSync('userInfo') || {}
  339. if (!ui.familyId) {
  340. uni.showToast({ title: '请先创建家庭', icon: 'none' })
  341. return
  342. }
  343. var userInfo = ui
  344. var generateInviteCard = require('../../utils/api.js').generateInviteCard
  345. var res = await generateInviteCard('guide')
  346. var code = res.data.code
  347. this.shareData = {
  348. title: (userInfo && userInfo.nickname ? userInfo.nickname : '家长') + ' 邀请你成为成长规划师',
  349. path: '/pages/login/login?invite_code=' + code
  350. }
  351. uni.showToast({ title: '点击右上角转发给TA', icon: 'none' })
  352. } catch (e) {
  353. uni.showToast({ title: e.message || '生成邀请失败', icon: 'none' })
  354. }
  355. }
  356. }
  357. }
  358. </script>
  359. <style scoped>
  360. .container {
  361. background: #F8F8F8;
  362. min-height: 100vh;
  363. padding-bottom: 120rpx;
  364. }
  365. .section {
  366. margin: 20rpx 24rpx;
  367. }
  368. .section-header {
  369. display: flex;
  370. justify-content: space-between;
  371. align-items: center;
  372. margin-bottom: 16rpx;
  373. }
  374. .section-title {
  375. font-size: 30rpx;
  376. font-weight: bold;
  377. color: #333;
  378. }
  379. .section-more {
  380. font-size: 24rpx;
  381. color: #F97316;
  382. }
  383. /* 今日待办卡片 */
  384. .todo-card {
  385. background: #fff;
  386. border-radius: 20rpx;
  387. padding: 24rpx;
  388. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  389. }
  390. .todo-header {
  391. margin-bottom: 16rpx;
  392. }
  393. .todo-title {
  394. font-size: 28rpx;
  395. font-weight: bold;
  396. color: #333;
  397. }
  398. .todo-grid {
  399. display: flex;
  400. flex-wrap: wrap;
  401. }
  402. .todo-item {
  403. width: 50%;
  404. display: flex;
  405. align-items: center;
  406. padding: 10rpx 0;
  407. flex-wrap: wrap;
  408. }
  409. .todo-icon {
  410. font-size: 28rpx;
  411. margin-right: 8rpx;
  412. }
  413. .todo-label {
  414. font-size: 24rpx;
  415. color: #999;
  416. margin-right: 8rpx;
  417. }
  418. .todo-value {
  419. font-size: 28rpx;
  420. font-weight: bold;
  421. color: #333;
  422. }
  423. .text-success {
  424. color: #10B981;
  425. }
  426. .text-muted {
  427. color: #ccc;
  428. }
  429. /* 功能入口网格 3列 */
  430. .grid-3col {
  431. display: flex;
  432. flex-wrap: wrap;
  433. background: #fff;
  434. border-radius: 20rpx;
  435. padding: 8rpx 0;
  436. }
  437. .grid-item {
  438. width: 33.33%;
  439. display: flex;
  440. flex-direction: column;
  441. align-items: center;
  442. padding: 20rpx 0;
  443. }
  444. .grid-icon {
  445. width: 72rpx;
  446. height: 72rpx;
  447. border-radius: 18rpx;
  448. display: flex;
  449. align-items: center;
  450. justify-content: center;
  451. margin-bottom: 8rpx;
  452. }
  453. .grid-icon text {
  454. font-size: 32rpx;
  455. }
  456. .grid-item .grid-label {
  457. font-size: 24rpx;
  458. color: #666;
  459. }
  460. /* 孩子选择 */
  461. .children-list {
  462. margin-top: 8rpx;
  463. }
  464. .child-card {
  465. display: flex;
  466. align-items: center;
  467. background: #fff;
  468. border-radius: 20rpx;
  469. padding: 30rpx;
  470. margin-bottom: 20rpx;
  471. }
  472. .child-info {
  473. flex: 1;
  474. }
  475. .child-name {
  476. font-size: 32rpx;
  477. font-weight: bold;
  478. color: #333;
  479. display: block;
  480. }
  481. .child-age {
  482. font-size: 24rpx;
  483. color: #999;
  484. margin-top: 6rpx;
  485. display: block;
  486. }
  487. .arrow {
  488. width: 40rpx;
  489. }
  490. .arrow-icon {
  491. font-size: 40rpx;
  492. color: #ccc;
  493. }
  494. /* 记录筛选 */
  495. .records-section {
  496. margin-top: 16rpx;
  497. }
  498. .filter-tabs {
  499. display: flex;
  500. gap: 16rpx;
  501. margin-bottom: 20rpx;
  502. }
  503. .filter-tab {
  504. flex: 1;
  505. text-align: center;
  506. padding: 12rpx 0;
  507. border-radius: 20rpx;
  508. background: #fff;
  509. border: 1rpx solid #E0E0E0;
  510. }
  511. .tab-active {
  512. background: #667eea;
  513. border-color: #667eea;
  514. }
  515. .tab-text {
  516. font-size: 24rpx;
  517. color: #666;
  518. }
  519. .tab-active-text {
  520. color: #fff;
  521. }
  522. /* 记录卡片 */
  523. .record-card {
  524. background: #fff;
  525. border-radius: 16rpx;
  526. padding: 24rpx;
  527. margin-bottom: 16rpx;
  528. }
  529. .record-header {
  530. display: flex;
  531. justify-content: space-between;
  532. align-items: center;
  533. margin-bottom: 12rpx;
  534. }
  535. .record-title {
  536. font-size: 28rpx;
  537. color: #333;
  538. font-weight: bold;
  539. flex: 1;
  540. }
  541. .record-badges {
  542. display: flex;
  543. gap: 8rpx;
  544. flex-shrink: 0;
  545. }
  546. .record-source-tag {
  547. font-size: 20rpx;
  548. padding: 4rpx 10rpx;
  549. border-radius: 8rpx;
  550. background: #f0f0ff;
  551. color: #667eea;
  552. }
  553. .record-tag {
  554. font-size: 22rpx;
  555. padding: 4rpx 12rpx;
  556. border-radius: 20rpx;
  557. }
  558. .tag-completed {
  559. background: #e8f5e9;
  560. color: #4caf50;
  561. }
  562. .tag-pending {
  563. background: #fff3e0;
  564. color: #ff9800;
  565. }
  566. .record-scores {
  567. display: flex;
  568. gap: 20rpx;
  569. }
  570. .score-item {
  571. font-size: 24rpx;
  572. color: #666;
  573. }
  574. /* 空状态 */
  575. .empty-state {
  576. text-align: center;
  577. padding: 60rpx 0;
  578. }
  579. .empty-icon {
  580. font-size: 80rpx;
  581. display: block;
  582. margin-bottom: 20rpx;
  583. }
  584. .empty-text {
  585. font-size: 28rpx;
  586. color: #999;
  587. display: block;
  588. }
  589. .empty-hint {
  590. font-size: 24rpx;
  591. color: #ccc;
  592. margin-top: 10rpx;
  593. display: block;
  594. }
  595. /* 按钮 */
  596. .footer-btn {
  597. padding: 30rpx 0;
  598. }
  599. .btn-create {
  600. width: 100%;
  601. height: 88rpx;
  602. line-height: 88rpx;
  603. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  604. color: #fff;
  605. border-radius: 44rpx;
  606. font-size: 32rpx;
  607. font-weight: bold;
  608. text-align: center;
  609. }
  610. .btn-invite-guide {
  611. width: 100%;
  612. height: 88rpx;
  613. line-height: 88rpx;
  614. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  615. color: #fff;
  616. border-radius: 44rpx;
  617. font-size: 32rpx;
  618. font-weight: bold;
  619. text-align: center;
  620. }
  621. </style>