relation-detail.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690
  1. <template>
  2. <view class="relation-detail-container">
  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. export default {
  104. data: function() {
  105. return {
  106. memberId: '',
  107. relation: null,
  108. loading: false,
  109. error: null,
  110. scoreCanvasContext: null,
  111. trendCanvasContext: null
  112. }
  113. },
  114. computed: {
  115. member1Color: function() {
  116. if (!this.relation || !this.relation.fromMemberRole) {
  117. return '#6B7280'
  118. }
  119. var colorMap = {
  120. 'parent': '#F97316',
  121. 'child': '#3B82F6',
  122. 'teacher': '#8B5CF6'
  123. }
  124. return colorMap[this.relation.fromMemberRole] || '#6B7280'
  125. },
  126. member2Color: function() {
  127. if (!this.relation || !this.relation.toMemberRole) {
  128. return '#6B7280'
  129. }
  130. var colorMap = {
  131. 'parent': '#F97316',
  132. 'child': '#3B82F6',
  133. 'teacher': '#8B5CF6'
  134. }
  135. return colorMap[this.relation.toMemberRole] || '#6B7280'
  136. },
  137. dimensions: function() {
  138. if (!this.relation || !this.relation.dimensions) {
  139. return []
  140. }
  141. var dimMap = {
  142. 'communication': { label: '沟通', description: '沟通频率与质量', color: '#10B981' },
  143. 'trust': { label: '信任', description: '相互信任程度', color: '#3B82F6' },
  144. 'understanding': { label: '理解', description: '相互理解程度', color: '#8B5CF6' },
  145. 'support': { label: '支持', description: '相互支持力度', color: '#F59E0B' },
  146. 'harmony': { label: '和谐', description: '关系和谐度', color: '#F97316' }
  147. }
  148. var result = []
  149. for (var key in this.relation.dimensions) {
  150. var value = this.relation.dimensions[key]
  151. var info = dimMap[key] || { label: key, description: '', color: '#6B7280' }
  152. result.push({
  153. type: key,
  154. label: info.label,
  155. description: info.description,
  156. value: value,
  157. color: info.color
  158. })
  159. }
  160. return result
  161. }
  162. },
  163. onLoad: function(options) {
  164. if (options && options.memberId) {
  165. this.memberId = options.memberId
  166. this.memberId2 = options.memberId2 || null
  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. if (!this.memberId) {
  182. this.error = '参数错误'
  183. this.loading = false
  184. return
  185. }
  186. var memberId2 = this.memberId2 || parseInt(this.memberId)
  187. this.loadCompatibility({ member1Id: parseInt(this.memberId), member2Id: parseInt(memberId2) })
  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.getWindowInfo().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.getWindowInfo().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. .loading-state, .error-state {
  385. display: flex;
  386. flex-direction: column;
  387. justify-content: center;
  388. align-items: center;
  389. padding: 80px 20px;
  390. text-align: center;
  391. }
  392. .loading-spinner {
  393. width: 40px;
  394. height: 40px;
  395. border: 4px solid #E5E7EB;
  396. border-top-color: #F97316;
  397. border-radius: 50%;
  398. animation: spin 1s linear infinite;
  399. margin-bottom: 16px;
  400. }
  401. @keyframes spin {
  402. to {
  403. transform: rotate(360deg);
  404. }
  405. }
  406. .retry-btn {
  407. margin-top: 16px;
  408. background: #F97316;
  409. color: #FFFFFF;
  410. border: none;
  411. padding: 10px 32px;
  412. border-radius: 20px;
  413. font-size: 14px;
  414. }
  415. .detail-content {
  416. padding: 16px;
  417. }
  418. .score-card {
  419. background: #FFFFFF;
  420. border-radius: 16px;
  421. padding: 32px 20px;
  422. margin-bottom: 16px;
  423. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  424. text-align: center;
  425. }
  426. .score-circle {
  427. position: relative;
  428. width: 180px;
  429. height: 180px;
  430. margin: 0 auto 16px;
  431. }
  432. .score-canvas {
  433. width: 180px;
  434. height: 180px;
  435. }
  436. .score-content {
  437. position: absolute;
  438. top: 50%;
  439. left: 50%;
  440. transform: translate(-50%, -50%);
  441. }
  442. .score-value {
  443. display: block;
  444. font-size: 48px;
  445. font-weight: bold;
  446. line-height: 1;
  447. }
  448. .score-label {
  449. display: block;
  450. font-size: 12px;
  451. color: #9CA3AF;
  452. margin-top: 8px;
  453. }
  454. .score-level {
  455. margin-top: 12px;
  456. }
  457. .level-text {
  458. font-size: 18px;
  459. font-weight: bold;
  460. color: #1F2937;
  461. }
  462. .score-good {
  463. color: #10B981;
  464. }
  465. .score-medium {
  466. color: #F59E0B;
  467. }
  468. .score-low {
  469. color: #EF4444;
  470. }
  471. .members-card, .dimensions-card, .trend-card, .advice-card {
  472. background: #FFFFFF;
  473. border-radius: 16px;
  474. padding: 20px;
  475. margin-bottom: 16px;
  476. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  477. }
  478. .card-header {
  479. margin-bottom: 16px;
  480. }
  481. .card-title {
  482. font-size: 16px;
  483. font-weight: bold;
  484. color: #1F2937;
  485. }
  486. .members-row {
  487. display: flex;
  488. align-items: center;
  489. justify-content: space-around;
  490. }
  491. .member-item {
  492. text-align: center;
  493. flex: 1;
  494. }
  495. .member-avatar {
  496. width: 56px;
  497. height: 56px;
  498. border-radius: 50%;
  499. display: flex;
  500. justify-content: center;
  501. align-items: center;
  502. margin: 0 auto 8px;
  503. }
  504. .member-avatar-text {
  505. color: #FFFFFF;
  506. font-size: 24px;
  507. font-weight: bold;
  508. }
  509. .member-name {
  510. display: block;
  511. font-size: 14px;
  512. font-weight: 500;
  513. color: #1F2937;
  514. }
  515. .member-role {
  516. display: block;
  517. font-size: 12px;
  518. color: #9CA3AF;
  519. margin-top: 2px;
  520. }
  521. .relation-icon {
  522. font-size: 24px;
  523. color: #D1D5DB;
  524. padding: 0 8px;
  525. }
  526. .dimension-list {
  527. margin-top: 16px;
  528. }
  529. .dimension-item {
  530. display: flex;
  531. align-items: center;
  532. margin-bottom: 16px;
  533. }
  534. .dim-info {
  535. width: 80px;
  536. }
  537. .dim-label {
  538. display: block;
  539. font-size: 14px;
  540. font-weight: 500;
  541. color: #1F2937;
  542. }
  543. .dim-desc {
  544. display: block;
  545. font-size: 12px;
  546. color: #9CA3AF;
  547. margin-top: 2px;
  548. }
  549. .dim-bar {
  550. flex: 1;
  551. height: 8px;
  552. background: #E5E7EB;
  553. border-radius: 4px;
  554. margin: 0 12px;
  555. overflow: hidden;
  556. }
  557. .dim-fill {
  558. height: 100%;
  559. border-radius: 4px;
  560. transition: width 0.3s ease;
  561. }
  562. .dim-value {
  563. width: 32px;
  564. text-align: right;
  565. font-size: 14px;
  566. font-weight: bold;
  567. color: #1F2937;
  568. }
  569. .trend-chart {
  570. height: 150px;
  571. }
  572. .trend-canvas {
  573. width: 100%;
  574. height: 100%;
  575. }
  576. .advice-content {
  577. padding: 12px;
  578. background: #FFF8F0;
  579. border-radius: 8px;
  580. }
  581. .advice-text {
  582. font-size: 14px;
  583. line-height: 1.6;
  584. color: #7C2D12;
  585. }
  586. .action-buttons {
  587. display: flex;
  588. flex-direction: column;
  589. gap: 12px;
  590. padding: 16px;
  591. }
  592. .action-btn {
  593. padding: 14px 24px;
  594. border-radius: 12px;
  595. font-size: 16px;
  596. border: none;
  597. }
  598. .action-btn.primary {
  599. background: linear-gradient(135deg, #F97316 0%, #FB923C 100%);
  600. color: #FFFFFF;
  601. }
  602. .action-btn.secondary {
  603. background: #FFFFFF;
  604. color: #F97316;
  605. border: 2px solid #F97316;
  606. }
  607. </style>