relation-detail.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  1. <template>
  2. <view class="relation-detail-container" :style="{ '--font-scale': fontScale }">
  3. <!-- 自定义导航栏 -->
  4. <view class="custom-nav">
  5. <view class="nav-back" @click="goBack">‹ 返回</view>
  6. </view>
  7. <!-- 加载状态 -->
  8. <view class="loading-state" v-if="loading">
  9. <view class="loading-spinner"></view>
  10. <text>加载中...</text>
  11. </view>
  12. <!-- 错误状态 -->
  13. <view class="error-state" v-if="error && !loading">
  14. <text>{{ error }}</text>
  15. <button class="retry-btn" @click="loadData">重试</button>
  16. </view>
  17. <!-- 详情内容 -->
  18. <view class="detail-content" v-if="relation && !loading">
  19. <!-- 关系评分卡片 -->
  20. <view class="score-card">
  21. <view class="score-circle">
  22. <canvas id="scoreCanvas" class="score-canvas"></canvas>
  23. <view class="score-content">
  24. <text class="score-value" :class="!relation.score ? '' : (relation.score >= 80 ? 'score-good' : (relation.score >= 60 ? 'score-medium' : 'score-low'))">{{ relation.score }}</text>
  25. <text class="score-label">关系质量分</text>
  26. </view>
  27. </view>
  28. <view class="score-level">
  29. <text class="level-text">{{ getScoreLevel(relation.score) }}</text>
  30. </view>
  31. </view>
  32. <!-- 双方信息 -->
  33. <view class="members-card">
  34. <view class="card-header">
  35. <text class="card-title">关系双方</text>
  36. </view>
  37. <view class="members-row">
  38. <view class="member-item">
  39. <view class="member-avatar" :style="{ backgroundColor: member1Color }">
  40. <text class="member-avatar-text">{{ relation.fromMemberName ? relation.fromMemberName.charAt(0) : 'A' }}</text>
  41. </view>
  42. <text class="member-name">{{ relation.fromMemberName }}</text>
  43. <text class="member-role">{{ getRoleText(relation.fromMemberRole) }}</text>
  44. </view>
  45. <view class="relation-icon">
  46. <text>↔</text>
  47. </view>
  48. <view class="member-item">
  49. <view class="member-avatar" :style="{ backgroundColor: member2Color }">
  50. <text class="member-avatar-text">{{ relation.toMemberName ? relation.toMemberName.charAt(0) : 'B' }}</text>
  51. </view>
  52. <text class="member-name">{{ relation.toMemberName }}</text>
  53. <text class="member-role">{{ getRoleText(relation.toMemberRole) }}</text>
  54. </view>
  55. </view>
  56. </view>
  57. <!-- 维度分解 -->
  58. <view class="dimensions-card">
  59. <view class="card-header">
  60. <text class="card-title">维度分解</text>
  61. </view>
  62. <view class="dimension-list">
  63. <view class="dimension-item" v-for="dim in dimensions" :key="dim.type">
  64. <view class="dim-info">
  65. <text class="dim-label">{{ dim.label }}</text>
  66. <text class="dim-desc">{{ dim.description }}</text>
  67. </view>
  68. <view class="dim-bar">
  69. <view class="dim-fill" :style="{ width: dim.value + '%', backgroundColor: dim.color }"></view>
  70. </view>
  71. <text class="dim-value">{{ dim.value }}</text>
  72. </view>
  73. </view>
  74. </view>
  75. <!-- 关系趋势 -->
  76. <view class="trend-card" v-if="relation.trend && relation.trend.length > 0">
  77. <view class="card-header">
  78. <text class="card-title">关系趋势</text>
  79. </view>
  80. <view class="trend-chart">
  81. <canvas id="trendCanvas" class="trend-canvas"></canvas>
  82. </view>
  83. </view>
  84. <!-- 改进建议 -->
  85. <view class="advice-card" v-if="relation.advice">
  86. <view class="card-header">
  87. <text class="card-title">改进建议</text>
  88. </view>
  89. <view class="advice-content">
  90. <text class="advice-text">{{ relation.advice }}</text>
  91. </view>
  92. </view>
  93. <!-- 操作按钮 -->
  94. <view class="action-buttons">
  95. <button class="action-btn primary" @click="startQuestionnaire">填写关系问卷</button>
  96. <button class="action-btn secondary" @click="viewInteractionLog">查看互动记录</button>
  97. </view>
  98. </view>
  99. </view>
  100. </template>
  101. <script>
  102. import { mapActions } from 'vuex'
  103. import { BrandColors } from '../../utils/brand-colors.js'
  104. import fontScaleMixin from '@/mixins/font-scale.js'
  105. export default {
  106. mixins: [fontScaleMixin],
  107. data: function() {
  108. return {
  109. memberId: '',
  110. relation: null,
  111. loading: false,
  112. error: null,
  113. scoreCanvasContext: null,
  114. trendCanvasContext: null
  115. }
  116. },
  117. computed: {
  118. member1Color: function() {
  119. if (!this.relation || !this.relation.fromMemberRole) {
  120. return BrandColors.textSlate
  121. }
  122. var colorMap = {
  123. 'parent': BrandColors.primary,
  124. 'child': BrandColors.infoBlue,
  125. 'teacher': BrandColors.violet
  126. }
  127. return colorMap[this.relation.fromMemberRole] || BrandColors.textSlate
  128. },
  129. member2Color: function() {
  130. if (!this.relation || !this.relation.toMemberRole) {
  131. return BrandColors.textSlate
  132. }
  133. var colorMap = {
  134. 'parent': BrandColors.primary,
  135. 'child': BrandColors.infoBlue,
  136. 'teacher': BrandColors.violet
  137. }
  138. return colorMap[this.relation.toMemberRole] || BrandColors.textSlate
  139. },
  140. dimensions: function() {
  141. if (!this.relation || !this.relation.dimensions) {
  142. return []
  143. }
  144. var dimMap = {
  145. 'communication': { label: '沟通', description: '沟通频率与质量', color: BrandColors.success },
  146. 'trust': { label: '信任', description: '相互信任程度', color: BrandColors.infoBlue },
  147. 'understanding': { label: '理解', description: '相互理解程度', color: BrandColors.violet },
  148. 'support': { label: '支持', description: '相互支持力度', color: BrandColors.wealth },
  149. 'harmony': { label: '和谐', description: '关系和谐度', color: BrandColors.primary }
  150. }
  151. var result = []
  152. for (var key in this.relation.dimensions) {
  153. var value = this.relation.dimensions[key]
  154. var info = dimMap[key] || { label: key, description: '', color: BrandColors.textSlate }
  155. result.push({
  156. type: key,
  157. label: info.label,
  158. description: info.description,
  159. value: value,
  160. color: info.color
  161. })
  162. }
  163. return result
  164. }
  165. },
  166. onLoad: function(options) {
  167. if (options && options.memberId) {
  168. this.memberId = options.memberId
  169. this.memberId2 = options.memberId2 || null
  170. this.loadData()
  171. }
  172. },
  173. onReady: function() {
  174. if (!this.loading && this.relation) {
  175. this.drawScoreCanvas()
  176. this.drawTrendCanvas()
  177. }
  178. },
  179. methods: {
  180. ...mapActions('tianpan', ['loadCompatibility']),
  181. loadData: function() {
  182. this.loading = true
  183. this.error = null
  184. if (!this.memberId) {
  185. this.error = '参数错误'
  186. this.loading = false
  187. return
  188. }
  189. var memberId2 = this.memberId2 || parseInt(this.memberId)
  190. this.loadCompatibility({ member1Id: parseInt(this.memberId), member2Id: parseInt(memberId2) })
  191. .then(this.setRelationData)
  192. .catch(this.handleError)
  193. .finally(function() {
  194. this.loading = false
  195. }.bind(this))
  196. },
  197. setRelationData: function(data) {
  198. if (data) {
  199. this.relation = data
  200. this.$nextTick(function() {
  201. this.drawScoreCanvas()
  202. this.drawTrendCanvas()
  203. }.bind(this))
  204. }
  205. },
  206. handleError: function(e) {
  207. this.error = e.message || '加载失败'
  208. },
  209. drawScoreCanvas: function() {
  210. var query = uni.createSelectorQuery()
  211. query.select('#scoreCanvas')
  212. .fields({ node: true, size: true })
  213. .exec(this.onScoreCanvasReady)
  214. },
  215. onScoreCanvasReady: function(res) {
  216. if (!res || !res[0] || !res[0].node) {
  217. return
  218. }
  219. var ctx = res[0].node.getContext('2d')
  220. var dpr = uni.getWindowInfo().pixelRatio
  221. this.scoreCanvasContext = ctx
  222. this.scoreCanvasContext.scale(dpr, dpr)
  223. var w = res[0].width / dpr
  224. var h = res[0].height / dpr
  225. var cx = w / 2
  226. var cy = h / 2
  227. var r = Math.min(w, h) / 2 - 10
  228. // 清空画布
  229. ctx.clearRect(0, 0, w, h)
  230. // 绘制背景圆
  231. ctx.beginPath()
  232. ctx.arc(cx, cy, r, 0, Math.PI * 2)
  233. ctx.strokeStyle = BrandColors.gray200
  234. ctx.lineWidth = 20
  235. ctx.stroke()
  236. // 绘制进度圆
  237. var score = this.relation && this.relation.score ? this.relation.score : 0
  238. var startAngle = -Math.PI / 2
  239. var endAngle = startAngle + (score / 100) * Math.PI * 2
  240. ctx.beginPath()
  241. ctx.arc(cx, cy, r, startAngle, endAngle)
  242. ctx.strokeStyle = this.getScoreColor(score)
  243. ctx.lineWidth = 20
  244. ctx.lineCap = 'round'
  245. ctx.stroke()
  246. },
  247. drawTrendCanvas: function() {
  248. if (!this.relation || !this.relation.trend || this.relation.trend.length === 0) {
  249. return
  250. }
  251. var query = uni.createSelectorQuery()
  252. query.select('#trendCanvas')
  253. .fields({ node: true, size: true })
  254. .exec(this.onTrendCanvasReady)
  255. },
  256. onTrendCanvasReady: function(res) {
  257. if (!res || !res[0] || !res[0].node) {
  258. return
  259. }
  260. var ctx = res[0].node.getContext('2d')
  261. var dpr = uni.getWindowInfo().pixelRatio
  262. this.trendCanvasContext = ctx
  263. this.trendCanvasContext.scale(dpr, dpr)
  264. var w = res[0].width / dpr
  265. var h = res[0].height / dpr
  266. // 清空画布
  267. ctx.clearRect(0, 0, w, h)
  268. var trend = this.relation.trend
  269. var padding = 20
  270. var chartW = w - padding * 2
  271. var chartH = h - padding * 2
  272. // 绘制坐标轴
  273. ctx.beginPath()
  274. ctx.moveTo(padding, padding)
  275. ctx.lineTo(padding, h - padding)
  276. ctx.lineTo(w - padding, h - padding)
  277. ctx.strokeStyle = BrandColors.gray200
  278. ctx.lineWidth = 1
  279. ctx.stroke()
  280. // 绘制折线
  281. if (trend.length < 2) {
  282. return
  283. }
  284. var stepX = chartW / (trend.length - 1)
  285. var maxScore = 100
  286. ctx.beginPath()
  287. for (var i = 0; i < trend.length; i++) {
  288. var point = trend[i]
  289. var x = padding + i * stepX
  290. var y = h - padding - (point.score / maxScore) * chartH
  291. if (i === 0) {
  292. ctx.moveTo(x, y)
  293. } else {
  294. ctx.lineTo(x, y)
  295. }
  296. }
  297. ctx.strokeStyle = BrandColors.primary
  298. ctx.lineWidth = 2
  299. ctx.stroke()
  300. // 绘制数据点
  301. for (var j = 0; j < trend.length; j++) {
  302. var point2 = trend[j]
  303. var x2 = padding + j * stepX
  304. var y2 = h - padding - (point2.score / maxScore) * chartH
  305. ctx.beginPath()
  306. ctx.arc(x2, y2, 4, 0, Math.PI * 2)
  307. ctx.fillStyle = BrandColors.primary
  308. ctx.fill()
  309. }
  310. },
  311. getScoreColor: function(score) {
  312. if (!score) {
  313. return BrandColors.textSlate
  314. }
  315. if (score >= 80) {
  316. return BrandColors.success
  317. } else if (score >= 60) {
  318. return BrandColors.wealth
  319. } else {
  320. return BrandColors.danger
  321. }
  322. },
  323. getScoreClass: function(score) {
  324. if (!score) {
  325. return ''
  326. }
  327. if (score >= 80) {
  328. return 'score-good'
  329. } else if (score >= 60) {
  330. return 'score-medium'
  331. } else {
  332. return 'score-low'
  333. }
  334. },
  335. getScoreLevel: function(score) {
  336. if (!score) {
  337. return '未知'
  338. }
  339. if (score >= 90) {
  340. return '卓越'
  341. } else if (score >= 80) {
  342. return '优秀'
  343. } else if (score >= 70) {
  344. return '良好'
  345. } else if (score >= 60) {
  346. return '合格'
  347. } else {
  348. return '待改善'
  349. }
  350. },
  351. getRoleText: function(role) {
  352. var roleMap = {
  353. 'parent': '本人',
  354. 'child': '成员',
  355. 'teacher': '规划师'
  356. }
  357. return roleMap[role] || role
  358. },
  359. goBack: function() {
  360. uni.navigateBack()
  361. },
  362. startQuestionnaire: function() {
  363. uni.navigateTo({
  364. url: '/pages/family/questionnaire?memberId=' + this.memberId
  365. })
  366. },
  367. viewInteractionLog: function() {
  368. uni.navigateTo({
  369. url: '/pages/action-detail/interaction-log?memberId=' + this.memberId
  370. })
  371. }
  372. }
  373. }
  374. </script>
  375. <style lang="scss">
  376. // ===== 关系详情页专属色阶(单页专用;约定见 uni.scss §14)=====
  377. $c-rel-brown: $mat-orange-900; // 深棕文字(暖橙卡内)
  378. .relation-detail-container {
  379. min-height: 100vh;
  380. background: $facade-fill-gray-50;
  381. padding-bottom: 40rpx;
  382. }
  383. .custom-nav {
  384. background: linear-gradient(135deg, $brand-primary 0%, $brand-primary-light 100%);
  385. padding: 88rpx 32rpx 32rpx;
  386. display: flex;
  387. align-items: center;
  388. }
  389. .loading-state, .error-state {
  390. display: flex;
  391. flex-direction: column;
  392. justify-content: center;
  393. align-items: center;
  394. padding: 160rpx 40rpx;
  395. text-align: center;
  396. }
  397. .loading-spinner {
  398. width: 80rpx;
  399. height: 80rpx;
  400. border: 8rpx solid $facade-gray-200;
  401. border-top-color: $brand-primary;
  402. border-radius: 50%;
  403. animation: spin 1s linear infinite;
  404. margin-bottom: 32rpx;
  405. }
  406. @keyframes spin {
  407. to {
  408. transform: rotate(360deg);
  409. }
  410. }
  411. .retry-btn {
  412. margin-top: 32rpx;
  413. background: $brand-primary;
  414. color: $app-surface;
  415. border: none;
  416. padding: 20rpx 64rpx;
  417. border-radius: 24rpx;
  418. font-size: calc(28rpx * var(--font-scale, 1));
  419. }
  420. .detail-content {
  421. padding: 32rpx;
  422. }
  423. .score-card {
  424. background: $app-surface;
  425. border-radius: 24rpx;
  426. padding: 64rpx 40rpx;
  427. margin-bottom: 32rpx;
  428. box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.05);
  429. text-align: center;
  430. }
  431. .score-circle {
  432. position: relative;
  433. width: 360rpx;
  434. height: 360rpx;
  435. margin: 0 auto 32rpx;
  436. }
  437. .score-canvas {
  438. width: 360rpx;
  439. height: 360rpx;
  440. }
  441. .score-content {
  442. position: absolute;
  443. top: 50%;
  444. left: 50%;
  445. transform: translate(-50%, -50%);
  446. }
  447. .score-value {
  448. display: block;
  449. font-size: calc($uni-font-size-6xl * var(--font-scale, 1));
  450. font-weight: bold;
  451. line-height: 1;
  452. }
  453. .score-label {
  454. display: block;
  455. font-size: calc(24rpx * var(--font-scale, 1));
  456. color: $facade-text-gray-400;
  457. margin-top: 16rpx;
  458. }
  459. .score-level {
  460. margin-top: 24rpx;
  461. }
  462. .level-text {
  463. font-size: calc(36rpx * var(--font-scale, 1));
  464. font-weight: bold;
  465. color: $facade-text-gray-800;
  466. }
  467. .score-good {
  468. color: $status-success;
  469. }
  470. .score-medium {
  471. color: $dim-wealth;
  472. }
  473. .score-low {
  474. color: $status-danger;
  475. }
  476. .members-card, .dimensions-card, .trend-card, .advice-card {
  477. background: $app-surface;
  478. border-radius: 24rpx;
  479. padding: 40rpx;
  480. margin-bottom: 32rpx;
  481. box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.05);
  482. }
  483. .card-header {
  484. margin-bottom: 32rpx;
  485. }
  486. .card-title {
  487. font-size: calc(32rpx * var(--font-scale, 1));
  488. font-weight: bold;
  489. color: $facade-text-gray-800;
  490. }
  491. .members-row {
  492. display: flex;
  493. align-items: center;
  494. justify-content: space-around;
  495. }
  496. .member-item {
  497. text-align: center;
  498. flex: 1;
  499. }
  500. .member-avatar {
  501. width: 112rpx;
  502. height: 112rpx;
  503. border-radius: 50%;
  504. display: flex;
  505. justify-content: center;
  506. align-items: center;
  507. margin: 0 auto 16rpx;
  508. }
  509. .member-avatar-text {
  510. color: $app-surface;
  511. font-size: calc(48rpx * var(--font-scale, 1));
  512. font-weight: bold;
  513. }
  514. .member-name {
  515. display: block;
  516. font-size: calc(28rpx * var(--font-scale, 1));
  517. font-weight: 500;
  518. color: $facade-text-gray-800;
  519. }
  520. .member-role {
  521. display: block;
  522. font-size: calc(24rpx * var(--font-scale, 1));
  523. color: $facade-text-gray-400;
  524. margin-top: 4rpx;
  525. }
  526. .relation-icon {
  527. font-size: calc(48rpx * var(--font-scale, 1));
  528. color: $app-border-strong;
  529. padding: 0 16rpx;
  530. }
  531. .dimension-list {
  532. margin-top: 32rpx;
  533. }
  534. .dimension-item {
  535. display: flex;
  536. align-items: center;
  537. margin-bottom: 32rpx;
  538. }
  539. .dim-info {
  540. width: 160rpx;
  541. }
  542. .dim-label {
  543. display: block;
  544. font-size: calc(28rpx * var(--font-scale, 1));
  545. font-weight: 500;
  546. color: $facade-text-gray-800;
  547. }
  548. .dim-desc {
  549. display: block;
  550. font-size: calc(24rpx * var(--font-scale, 1));
  551. color: $facade-text-gray-400;
  552. margin-top: 4rpx;
  553. }
  554. .dim-bar {
  555. flex: 1;
  556. height: 16rpx;
  557. background: $facade-gray-200;
  558. border-radius: 8rpx;
  559. margin: 0 24rpx;
  560. overflow: hidden;
  561. }
  562. .dim-fill {
  563. height: 100%;
  564. border-radius: 8rpx;
  565. transition: width 0.3s ease;
  566. }
  567. .dim-value {
  568. width: 64rpx;
  569. text-align: right;
  570. font-size: calc(28rpx * var(--font-scale, 1));
  571. font-weight: bold;
  572. color: $facade-text-gray-800;
  573. }
  574. .trend-chart {
  575. height: 300rpx;
  576. }
  577. .trend-canvas {
  578. width: 100%;
  579. height: 100%;
  580. }
  581. .advice-content {
  582. padding: 24rpx;
  583. background: $dim-body-tint;
  584. border-radius: 16rpx;
  585. }
  586. .advice-text {
  587. font-size: calc(28rpx * var(--font-scale, 1));
  588. line-height: 1.6;
  589. color: $c-rel-brown;
  590. }
  591. .action-buttons {
  592. display: flex;
  593. flex-direction: column;
  594. gap: 24rpx;
  595. padding: 32rpx;
  596. }
  597. .action-btn {
  598. padding: 28rpx 48rpx;
  599. border-radius: 24rpx;
  600. font-size: calc(32rpx * var(--font-scale, 1));
  601. border: none;
  602. }
  603. .action-btn.primary {
  604. background: linear-gradient(135deg, $brand-primary 0%, $brand-primary-light 100%);
  605. color: $app-surface;
  606. }
  607. .action-btn.secondary {
  608. background: $app-surface;
  609. color: $brand-primary;
  610. border: 4rpx solid $brand-primary;
  611. }
  612. </style>