self-check-entry.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. <template>
  2. <view class="sce-page" :style="{ '--font-scale': fontScale }">
  3. <view v-if="loading" class="sce-loading">
  4. <text class="sce-loading-text">加载中...</text>
  5. </view>
  6. <template v-else>
  7. <!-- 总分横幅 -->
  8. <view class="sce-hero" :style="{ background: heroGradient }">
  9. <view class="sce-hero-inner">
  10. <text class="sce-hero-label">最近自检总分</text>
  11. <view class="sce-hero-score-row">
  12. <text class="sce-hero-score">{{ lastResult && lastResult.totalScore || 0 }}</text>
  13. <text class="sce-hero-total">/45</text>
  14. </view>
  15. <text class="sce-hero-date" v-if="lastResult && lastResult.createdAt">
  16. {{ formatCreatedDate(lastResult.createdAt) }}
  17. </text>
  18. </view>
  19. </view>
  20. <!-- 维度分数条 -->
  21. <!-- 自检简易说明 -->
  22. <view class="sce-card">
  23. <view class="sce-card-title">
  24. <text class="sce-card-title-text">自检简易说明</text>
  25. </view>
  26. <text class="sce-info-text">五维自检从「身·智·富·行·心」五个维度评估家庭状态,每维满分 9 分,总分 45 分。建议每 15 天完成一次自检,重点关注分数的变化趋势,而不是单次绝对值。</text>
  27. </view>
  28. <view class="sce-card" v-if="lastResult && lastResult.dimensions && lastResult.dimensions.length > 0">
  29. <view class="sce-card-title">
  30. <text class="sce-card-title-text">五维得分</text>
  31. </view>
  32. <view class="sce-dim-list">
  33. <view class="sce-dim-item" v-for="dim in lastResult.dimensions" :key="dim.dimension">
  34. <view class="sce-dim-head">
  35. <view class="sce-dim-label">
  36. <view class="sce-dim-dot" :style="{ background: dim.color }"></view>
  37. <text class="sce-dim-name">{{ dim.name }}</text>
  38. </view>
  39. <view class="sce-dim-score-wrap">
  40. <text class="sce-dim-score" :style="{ color: dim.color }">{{ dim.score }}</text>
  41. <text class="sce-dim-max">/9</text>
  42. </view>
  43. </view>
  44. <view class="sce-dim-bar">
  45. <view class="sce-dim-bar-fill" :style="{ width: (dim.score / 9 * 100) + '%', background: dim.color }"></view>
  46. </view>
  47. </view>
  48. </view>
  49. </view>
  50. <!-- 状态提示 -->
  51. <view class="sce-status" v-if="!canCheck && lastResult">
  52. <text class="sce-status-text">距下次自检还有 {{ daysLeft }} 天</text>
  53. </view>
  54. <view class="sce-status" v-else-if="canCheck && lastResult">
  55. <text class="sce-status-text">已满 15 天,可再次自检</text>
  56. </view>
  57. <!-- 趋势分析(P1-1) -->
  58. <view class="sce-trend" v-if="trendLoaded && (aiInsight || trendSummary)">
  59. <view class="sce-trend-header">
  60. <text class="sce-trend-title">📈 自检趋势</text>
  61. <text class="sce-trend-summary" v-if="trendSummary">{{ trendSummary }}</text>
  62. </view>
  63. <text class="sce-trend-insight" v-if="aiInsight">{{ aiInsight }}</text>
  64. <view class="sce-trend-loading" v-if="trendLoading">
  65. <text>AI 趋势分析中...</text>
  66. </view>
  67. </view>
  68. <!-- 按钮区域 -->
  69. <view class="sce-footer">
  70. <button v-if="canCheck && lastResult" class="sce-btn sce-btn-primary" @click="retake">
  71. 再次自检
  72. </button>
  73. <button v-if="canCheck && lastResult" class="sce-btn sce-btn-outline" @click="ignore">
  74. 忽略本次
  75. </button>
  76. <button v-if="!lastResult" class="sce-btn sce-btn-primary" @click="retake">
  77. 开始自检
  78. </button>
  79. <button v-if="!canCheck && lastResult" class="sce-btn sce-btn-disabled" disabled>
  80. {{ daysLeft }} 天后可再次自检
  81. </button>
  82. </view>
  83. </template>
  84. </view>
  85. </template>
  86. <script>
  87. import { getSelfCheckStatus, ignoreSelfCheck, getSelfCheckTrendAnalysis } from '@/utils/api'
  88. import { parseDate } from '@/utils/format.js'
  89. import fontScaleMixin from '@/mixins/font-scale.js'
  90. export default {
  91. mixins: [fontScaleMixin],
  92. data() {
  93. return {
  94. loading: true,
  95. lastResult: null,
  96. canCheck: false,
  97. daysLeft: 0,
  98. trendLoaded: false,
  99. trendLoading: false,
  100. aiInsight: '',
  101. trendSummary: ''
  102. }
  103. },
  104. computed: {
  105. heroGradient: function() {
  106. if (!this.lastResult || !this.lastResult.dimensions || this.lastResult.dimensions.length === 0) {
  107. return 'linear-gradient(135deg, #F97316, #FF8C42)'
  108. }
  109. var lowest = this.lastResult.dimensions.reduce(function(min, d) {
  110. return d.score < min.score ? d : min
  111. }, this.lastResult.dimensions[0])
  112. return 'linear-gradient(135deg, ' + lowest.color + ', ' + (lowest.color + 'bb') + ')'
  113. }
  114. },
  115. onLoad: function() {
  116. this.loadStatus()
  117. this.loadTrend()
  118. },
  119. methods: {
  120. loadStatus: function() {
  121. var self = this
  122. getSelfCheckStatus().then(function(res) {
  123. self.loading = false
  124. if (res.code === 200 && res.data) {
  125. self.lastResult = res.data.lastResult || null
  126. self.canCheck = res.data.canCheck
  127. self.daysLeft = res.data.daysLeft || 0
  128. } else {
  129. uni.showToast({ title: (res && res.message) || '加载失败', icon: 'none' })
  130. }
  131. }).catch(function() {
  132. self.loading = false
  133. uni.showToast({ title: '网络异常', icon: 'none' })
  134. })
  135. },
  136. retake: function() {
  137. uni.navigateTo({ url: '/pages/family/self-check?retake=1' })
  138. },
  139. ignore: function() {
  140. var self = this
  141. ignoreSelfCheck({ checkId: this.lastResult && this.lastResult.id }).then(function(res) {
  142. if (res.code === 200) {
  143. uni.showToast({ title: '已忽略,15 天后再次提醒', icon: 'none' })
  144. setTimeout(function() {
  145. uni.navigateBack()
  146. }, 800)
  147. } else {
  148. uni.showToast({ title: (res && res.message) || '操作失败', icon: 'none' })
  149. }
  150. }).catch(function() {
  151. uni.showToast({ title: '操作失败', icon: 'none' })
  152. })
  153. },
  154. formatCreatedDate: function(dateStr) {
  155. if (!dateStr) return ''
  156. var d = parseDate(dateStr)
  157. if (!d) return ''
  158. var pad = function(n) { return n < 10 ? '0' + n : '' + n }
  159. return d.getFullYear() + '-' + pad(d.getMonth() + 1) + '-' + pad(d.getDate())
  160. },
  161. loadTrend: function() {
  162. var self = this
  163. this.trendLoading = true
  164. getSelfCheckTrendAnalysis().then(function(res) {
  165. self.trendLoading = false
  166. self.trendLoaded = true
  167. if (res.code === 200 && res.data) {
  168. self.aiInsight = res.data.aiInsight || ''
  169. self.trendSummary = res.data.trendSummary || ''
  170. }
  171. }).catch(function() {
  172. self.trendLoading = false
  173. self.trendLoaded = true
  174. })
  175. }
  176. }
  177. }
  178. </script>
  179. <style scoped lang="scss">
  180. .sce-page {
  181. min-height: 100vh;
  182. background: $facade-fill-blue-ghost;
  183. padding: 24rpx $uni-space-page 120rpx;
  184. box-sizing: border-box;
  185. }
  186. .sce-loading {
  187. display: flex;
  188. justify-content: center;
  189. align-items: center;
  190. height: 50vh;
  191. }
  192. .sce-loading-text {
  193. font-size: calc(28rpx * var(--font-scale, 1));
  194. color: $facade-text-muted;
  195. }
  196. .sce-hero {
  197. background: linear-gradient(135deg, $brand-primary, $dim-body);
  198. border-radius: 24rpx;
  199. padding: 40rpx $uni-space-page;
  200. margin-bottom: 24rpx;
  201. box-shadow: 0 6rpx 20rpx rgba(249, 114, 22, 0.25);
  202. }
  203. .sce-hero-inner {
  204. display: flex;
  205. flex-direction: column;
  206. align-items: center;
  207. }
  208. .sce-hero-label {
  209. font-size: calc(26rpx * var(--font-scale, 1));
  210. color: rgba(255, 255, 255, 0.9);
  211. }
  212. .sce-hero-score-row {
  213. display: flex;
  214. align-items: baseline;
  215. margin-top: 10rpx;
  216. }
  217. .sce-hero-score {
  218. font-size: calc($uni-font-size-5xl * var(--font-scale, 1));
  219. font-weight: 700;
  220. color: $app-surface;
  221. }
  222. .sce-hero-total {
  223. font-size: calc(30rpx * var(--font-scale, 1));
  224. color: rgba(255, 255, 255, 0.7);
  225. margin-left: 6rpx;
  226. }
  227. .sce-hero-date {
  228. display: block;
  229. text-align: center;
  230. font-size: calc(22rpx * var(--font-scale, 1));
  231. color: rgba(255, 255, 255, 0.8);
  232. margin-top: 16rpx;
  233. }
  234. .sce-card {
  235. background: $app-surface;
  236. border-radius: 24rpx;
  237. padding: $uni-space-lg 26rpx;
  238. margin-bottom: 24rpx;
  239. box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.05);
  240. }
  241. .sce-card-title {
  242. margin-bottom: 24rpx;
  243. }
  244. .sce-card-title-text {
  245. font-size: calc(32rpx * var(--font-scale, 1));
  246. font-weight: 600;
  247. color: $facade-text-strong;
  248. }
  249. .sce-dim-list {
  250. display: flex;
  251. flex-direction: column;
  252. }
  253. .sce-dim-item {
  254. margin-bottom: 24rpx;
  255. }
  256. .sce-dim-item:last-child {
  257. margin-bottom: 0;
  258. }
  259. .sce-dim-head {
  260. display: flex;
  261. align-items: center;
  262. justify-content: space-between;
  263. }
  264. .sce-dim-label {
  265. display: flex;
  266. align-items: center;
  267. }
  268. .sce-dim-dot {
  269. width: 28rpx;
  270. height: 28rpx;
  271. border-radius: 50%;
  272. margin-right: 12rpx;
  273. }
  274. .sce-dim-name {
  275. font-size: calc(30rpx * var(--font-scale, 1));
  276. font-weight: 600;
  277. color: $facade-text-strong;
  278. }
  279. .sce-dim-score-wrap {
  280. display: flex;
  281. align-items: baseline;
  282. }
  283. .sce-dim-score {
  284. font-size: calc(40rpx * var(--font-scale, 1));
  285. font-weight: 700;
  286. }
  287. .sce-dim-max {
  288. font-size: calc(22rpx * var(--font-scale, 1));
  289. color: $facade-text-ghost-light;
  290. }
  291. .sce-dim-bar {
  292. height: 12rpx;
  293. background: $facade-fill;
  294. border-radius: 8rpx;
  295. margin-top: 14rpx;
  296. overflow: hidden;
  297. }
  298. .sce-dim-bar-fill {
  299. height: 100%;
  300. border-radius: 8rpx;
  301. transition: width 0.5s ease;
  302. }
  303. .sce-status {
  304. background: $uni-primary-pale;
  305. border-radius: 16rpx;
  306. padding: 24rpx 20rpx;
  307. margin-bottom: 24rpx;
  308. text-align: center;
  309. }
  310. .sce-status-text {
  311. font-size: calc(26rpx * var(--font-scale, 1));
  312. color: $mat-orange-strong;
  313. }
  314. .sce-footer {
  315. display: flex;
  316. flex-direction: row;
  317. gap: 20rpx;
  318. margin-top: 20rpx;
  319. }
  320. .sce-btn {
  321. flex: 1;
  322. height: 88rpx;
  323. line-height: 88rpx;
  324. font-size: calc(30rpx * var(--font-scale, 1));
  325. border-radius: 24rpx;
  326. text-align: center;
  327. border: none;
  328. margin-left: 0;
  329. margin-right: 0;
  330. }
  331. .sce-btn-primary {
  332. background: linear-gradient(135deg, $brand-primary, $dim-body);
  333. color: $app-surface;
  334. font-weight: 600;
  335. }
  336. .sce-btn-outline {
  337. background: $app-surface;
  338. color: $brand-primary;
  339. border: 2rpx solid $brand-primary;
  340. }
  341. .sce-btn-disabled {
  342. background: $facade-gray-200;
  343. color: $facade-text-muted;
  344. font-weight: 400;
  345. }
  346. .sce-trend {
  347. background: $app-surface;
  348. border-radius: 24rpx;
  349. padding: $uni-space-lg 26rpx;
  350. margin-bottom: 24rpx;
  351. box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.05);
  352. }
  353. .sce-trend-header {
  354. display: flex;
  355. align-items: center;
  356. justify-content: space-between;
  357. margin-bottom: 12rpx;
  358. }
  359. .sce-trend-title {
  360. font-size: calc(30rpx * var(--font-scale, 1));
  361. font-weight: 600;
  362. color: $facade-text-strong;
  363. }
  364. .sce-trend-summary {
  365. font-size: calc(24rpx * var(--font-scale, 1));
  366. color: $brand-primary;
  367. font-weight: 600;
  368. }
  369. .sce-trend-insight {
  370. display: block;
  371. font-size: calc(26rpx * var(--font-scale, 1));
  372. color: $facade-text-deep;
  373. line-height: 1.6;
  374. }
  375. .sce-info-text {
  376. display: block;
  377. font-size: calc(26rpx * var(--font-scale, 1));
  378. color: $facade-text-body;
  379. line-height: 1.6;
  380. }
  381. </style>