relation-detail.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  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.memberId2 = options.memberId2 || null
  168. this.loadData()
  169. }
  170. },
  171. onReady: function() {
  172. if (!this.loading && this.relation) {
  173. this.drawScoreCanvas()
  174. this.drawTrendCanvas()
  175. }
  176. },
  177. methods: {
  178. ...mapActions('tianpan', ['loadCompatibility']),
  179. loadData: function() {
  180. this.loading = true
  181. this.error = null
  182. var familyId = uni.getStorageSync('familyId')
  183. if (!familyId || !this.memberId) {
  184. this.error = '参数错误'
  185. this.loading = false
  186. return
  187. }
  188. var memberId2 = this.memberId2 || parseInt(this.memberId)
  189. this.loadCompatibility({ member1Id: parseInt(this.memberId), member2Id: parseInt(memberId2) })
  190. .then(this.setRelationData)
  191. .catch(this.handleError)
  192. .finally(function() {
  193. this.loading = false
  194. }.bind(this))
  195. },
  196. setRelationData: function(data) {
  197. if (data) {
  198. this.relation = data
  199. this.$nextTick(function() {
  200. this.drawScoreCanvas()
  201. this.drawTrendCanvas()
  202. }.bind(this))
  203. }
  204. },
  205. handleError: function(e) {
  206. this.error = e.message || '加载失败'
  207. },
  208. drawScoreCanvas: function() {
  209. var query = uni.createSelectorQuery()
  210. query.select('#scoreCanvas')
  211. .fields({ node: true, size: true })
  212. .exec(this.onScoreCanvasReady)
  213. },
  214. onScoreCanvasReady: function(res) {
  215. if (!res || !res[0] || !res[0].node) {
  216. return
  217. }
  218. var ctx = res[0].node.getContext('2d')
  219. var dpr = uni.getSystemInfoSync().pixelRatio
  220. this.scoreCanvasContext = ctx
  221. this.scoreCanvasContext.scale(dpr, dpr)
  222. var w = res[0].width / dpr
  223. var h = res[0].height / dpr
  224. var cx = w / 2
  225. var cy = h / 2
  226. var r = Math.min(w, h) / 2 - 10
  227. // 清空画布
  228. ctx.clearRect(0, 0, w, h)
  229. // 绘制背景圆
  230. ctx.beginPath()
  231. ctx.arc(cx, cy, r, 0, Math.PI * 2)
  232. ctx.strokeStyle = '#E5E7EB'
  233. ctx.lineWidth = 20
  234. ctx.stroke()
  235. // 绘制进度圆
  236. var score = this.relation && this.relation.score ? this.relation.score : 0
  237. var startAngle = -Math.PI / 2
  238. var endAngle = startAngle + (score / 100) * Math.PI * 2
  239. ctx.beginPath()
  240. ctx.arc(cx, cy, r, startAngle, endAngle)
  241. ctx.strokeStyle = this.getScoreColor(score)
  242. ctx.lineWidth = 20
  243. ctx.lineCap = 'round'
  244. ctx.stroke()
  245. },
  246. drawTrendCanvas: function() {
  247. if (!this.relation || !this.relation.trend || this.relation.trend.length === 0) {
  248. return
  249. }
  250. var query = uni.createSelectorQuery()
  251. query.select('#trendCanvas')
  252. .fields({ node: true, size: true })
  253. .exec(this.onTrendCanvasReady)
  254. },
  255. onTrendCanvasReady: function(res) {
  256. if (!res || !res[0] || !res[0].node) {
  257. return
  258. }
  259. var ctx = res[0].node.getContext('2d')
  260. var dpr = uni.getSystemInfoSync().pixelRatio
  261. this.trendCanvasContext = ctx
  262. this.trendCanvasContext.scale(dpr, dpr)
  263. var w = res[0].width / dpr
  264. var h = res[0].height / dpr
  265. // 清空画布
  266. ctx.clearRect(0, 0, w, h)
  267. var trend = this.relation.trend
  268. var padding = 20
  269. var chartW = w - padding * 2
  270. var chartH = h - padding * 2
  271. // 绘制坐标轴
  272. ctx.beginPath()
  273. ctx.moveTo(padding, padding)
  274. ctx.lineTo(padding, h - padding)
  275. ctx.lineTo(w - padding, h - padding)
  276. ctx.strokeStyle = '#E5E7EB'
  277. ctx.lineWidth = 1
  278. ctx.stroke()
  279. // 绘制折线
  280. if (trend.length < 2) {
  281. return
  282. }
  283. var stepX = chartW / (trend.length - 1)
  284. var maxScore = 100
  285. ctx.beginPath()
  286. for (var i = 0; i < trend.length; i++) {
  287. var point = trend[i]
  288. var x = padding + i * stepX
  289. var y = h - padding - (point.score / maxScore) * chartH
  290. if (i === 0) {
  291. ctx.moveTo(x, y)
  292. } else {
  293. ctx.lineTo(x, y)
  294. }
  295. }
  296. ctx.strokeStyle = '#F97316'
  297. ctx.lineWidth = 2
  298. ctx.stroke()
  299. // 绘制数据点
  300. for (var j = 0; j < trend.length; j++) {
  301. var point2 = trend[j]
  302. var x2 = padding + j * stepX
  303. var y2 = h - padding - (point2.score / maxScore) * chartH
  304. ctx.beginPath()
  305. ctx.arc(x2, y2, 4, 0, Math.PI * 2)
  306. ctx.fillStyle = '#F97316'
  307. ctx.fill()
  308. }
  309. },
  310. getScoreColor: function(score) {
  311. if (!score) {
  312. return '#6B7280'
  313. }
  314. if (score >= 80) {
  315. return '#10B981'
  316. } else if (score >= 60) {
  317. return '#F59E0B'
  318. } else {
  319. return '#EF4444'
  320. }
  321. },
  322. getScoreClass: function(score) {
  323. if (!score) {
  324. return ''
  325. }
  326. if (score >= 80) {
  327. return 'score-good'
  328. } else if (score >= 60) {
  329. return 'score-medium'
  330. } else {
  331. return 'score-low'
  332. }
  333. },
  334. getScoreLevel: function(score) {
  335. if (!score) {
  336. return '未知'
  337. }
  338. if (score >= 90) {
  339. return '卓越'
  340. } else if (score >= 80) {
  341. return '优秀'
  342. } else if (score >= 70) {
  343. return '良好'
  344. } else if (score >= 60) {
  345. return '合格'
  346. } else {
  347. return '待改善'
  348. }
  349. },
  350. getRoleText: function(role) {
  351. var roleMap = {
  352. 'parent': '家长',
  353. 'child': '孩子',
  354. 'teacher': '规划师'
  355. }
  356. return roleMap[role] || role
  357. },
  358. goBack: function() {
  359. uni.navigateBack()
  360. },
  361. startQuestionnaire: function() {
  362. uni.navigateTo({
  363. url: '/pages/family/questionnaire?memberId=' + this.memberId
  364. })
  365. },
  366. viewInteractionLog: function() {
  367. uni.navigateTo({
  368. url: '/pages/family/interaction-log?memberId=' + this.memberId
  369. })
  370. }
  371. }
  372. }
  373. </script>
  374. <style>
  375. .relation-detail-container {
  376. min-height: 100vh;
  377. background: #F9FAFB;
  378. padding-bottom: 20px;
  379. }
  380. .custom-nav {
  381. background: linear-gradient(135deg, #F97316 0%, #FB923C 100%);
  382. padding: 44px 16px 16px;
  383. display: flex;
  384. align-items: center;
  385. }
  386. .nav-back {
  387. color: #FFFFFF;
  388. font-size: 14px;
  389. margin-right: 16px;
  390. }
  391. .nav-title {
  392. color: #FFFFFF;
  393. font-size: 18px;
  394. font-weight: bold;
  395. }
  396. .loading-state, .error-state {
  397. display: flex;
  398. flex-direction: column;
  399. justify-content: center;
  400. align-items: center;
  401. padding: 80px 20px;
  402. text-align: center;
  403. }
  404. .loading-spinner {
  405. width: 40px;
  406. height: 40px;
  407. border: 4px solid #E5E7EB;
  408. border-top-color: #F97316;
  409. border-radius: 50%;
  410. animation: spin 1s linear infinite;
  411. margin-bottom: 16px;
  412. }
  413. @keyframes spin {
  414. to {
  415. transform: rotate(360deg);
  416. }
  417. }
  418. .retry-btn {
  419. margin-top: 16px;
  420. background: #F97316;
  421. color: #FFFFFF;
  422. border: none;
  423. padding: 10px 32px;
  424. border-radius: 20px;
  425. font-size: 14px;
  426. }
  427. .detail-content {
  428. padding: 16px;
  429. }
  430. .score-card {
  431. background: #FFFFFF;
  432. border-radius: 16px;
  433. padding: 32px 20px;
  434. margin-bottom: 16px;
  435. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  436. text-align: center;
  437. }
  438. .score-circle {
  439. position: relative;
  440. width: 180px;
  441. height: 180px;
  442. margin: 0 auto 16px;
  443. }
  444. .score-canvas {
  445. width: 180px;
  446. height: 180px;
  447. }
  448. .score-content {
  449. position: absolute;
  450. top: 50%;
  451. left: 50%;
  452. transform: translate(-50%, -50%);
  453. }
  454. .score-value {
  455. display: block;
  456. font-size: 48px;
  457. font-weight: bold;
  458. line-height: 1;
  459. }
  460. .score-label {
  461. display: block;
  462. font-size: 12px;
  463. color: #9CA3AF;
  464. margin-top: 8px;
  465. }
  466. .score-level {
  467. margin-top: 12px;
  468. }
  469. .level-text {
  470. font-size: 18px;
  471. font-weight: bold;
  472. color: #1F2937;
  473. }
  474. .score-good {
  475. color: #10B981;
  476. }
  477. .score-medium {
  478. color: #F59E0B;
  479. }
  480. .score-low {
  481. color: #EF4444;
  482. }
  483. .members-card, .dimensions-card, .trend-card, .advice-card {
  484. background: #FFFFFF;
  485. border-radius: 16px;
  486. padding: 20px;
  487. margin-bottom: 16px;
  488. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  489. }
  490. .card-header {
  491. margin-bottom: 16px;
  492. }
  493. .card-title {
  494. font-size: 16px;
  495. font-weight: bold;
  496. color: #1F2937;
  497. }
  498. .members-row {
  499. display: flex;
  500. align-items: center;
  501. justify-content: space-around;
  502. }
  503. .member-item {
  504. text-align: center;
  505. flex: 1;
  506. }
  507. .member-avatar {
  508. width: 56px;
  509. height: 56px;
  510. border-radius: 50%;
  511. display: flex;
  512. justify-content: center;
  513. align-items: center;
  514. margin: 0 auto 8px;
  515. }
  516. .member-avatar-text {
  517. color: #FFFFFF;
  518. font-size: 24px;
  519. font-weight: bold;
  520. }
  521. .member-name {
  522. display: block;
  523. font-size: 14px;
  524. font-weight: 500;
  525. color: #1F2937;
  526. }
  527. .member-role {
  528. display: block;
  529. font-size: 12px;
  530. color: #9CA3AF;
  531. margin-top: 2px;
  532. }
  533. .relation-icon {
  534. font-size: 24px;
  535. color: #D1D5DB;
  536. padding: 0 8px;
  537. }
  538. .dimension-list {
  539. margin-top: 16px;
  540. }
  541. .dimension-item {
  542. display: flex;
  543. align-items: center;
  544. margin-bottom: 16px;
  545. }
  546. .dim-info {
  547. width: 80px;
  548. }
  549. .dim-label {
  550. display: block;
  551. font-size: 14px;
  552. font-weight: 500;
  553. color: #1F2937;
  554. }
  555. .dim-desc {
  556. display: block;
  557. font-size: 12px;
  558. color: #9CA3AF;
  559. margin-top: 2px;
  560. }
  561. .dim-bar {
  562. flex: 1;
  563. height: 8px;
  564. background: #E5E7EB;
  565. border-radius: 4px;
  566. margin: 0 12px;
  567. overflow: hidden;
  568. }
  569. .dim-fill {
  570. height: 100%;
  571. border-radius: 4px;
  572. transition: width 0.3s ease;
  573. }
  574. .dim-value {
  575. width: 32px;
  576. text-align: right;
  577. font-size: 14px;
  578. font-weight: bold;
  579. color: #1F2937;
  580. }
  581. .trend-chart {
  582. height: 150px;
  583. }
  584. .trend-canvas {
  585. width: 100%;
  586. height: 100%;
  587. }
  588. .advice-content {
  589. padding: 12px;
  590. background: #FFF8F0;
  591. border-radius: 8px;
  592. }
  593. .advice-text {
  594. font-size: 14px;
  595. line-height: 1.6;
  596. color: #7C2D12;
  597. }
  598. .action-buttons {
  599. display: flex;
  600. flex-direction: column;
  601. gap: 12px;
  602. padding: 16px;
  603. }
  604. .action-btn {
  605. padding: 14px 24px;
  606. border-radius: 12px;
  607. font-size: 16px;
  608. border: none;
  609. }
  610. .action-btn.primary {
  611. background: linear-gradient(135deg, #F97316 0%, #FB923C 100%);
  612. color: #FFFFFF;
  613. }
  614. .action-btn.secondary {
  615. background: #FFFFFF;
  616. color: #F97316;
  617. border: 2px solid #F97316;
  618. }
  619. </style>