relation-detail.vue 16 KB

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