duo-compatibility.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  1. <template>
  2. <view class="duo-container">
  3. <view class="loading-state" v-if="loading">
  4. <text>加载中...</text>
  5. </view>
  6. <template v-if="!loading && dataLoaded">
  7. <!-- 双人头像区 -->
  8. <view class="duo-header">
  9. <view class="person-card">
  10. <view class="person-avatar">{{ name1.charAt(0) }}</view>
  11. <text class="person-name">{{ name1 }}</text>
  12. </view>
  13. <view class="compatibility-badge">
  14. <text class="compatibility-score">{{ overallScore }}</text>
  15. <text class="compatibility-label">兼容分</text>
  16. </view>
  17. <view class="person-card">
  18. <view class="person-avatar">{{ name2.charAt(0) }}</view>
  19. <text class="person-name">{{ name2 }}</text>
  20. </view>
  21. </view>
  22. <!-- 维度评分条 -->
  23. <view class="dimension-summary">
  24. <view class="dimension-item" v-for="dim in dimensions" :key="dim.key" @click="activeTab = dim.key">
  25. <text class="dimension-label">{{ dim.label }}</text>
  26. <view class="dimension-bar-track">
  27. <view class="dimension-bar-fill" :style="{ width: dim.score + '%', background: dim.color }"></view>
  28. </view>
  29. <text class="dimension-score">{{ dim.score }}</text>
  30. </view>
  31. </view>
  32. <!-- Tab 切换 -->
  33. <view class="tab-bar">
  34. <view
  35. class="tab-item"
  36. v-for="tab in tabs"
  37. :key="tab.key"
  38. :class="activeTab === tab.key ? 'tab-active' : ''"
  39. @click="activeTab = tab.key">
  40. <text>{{ tab.label }}</text>
  41. </view>
  42. </view>
  43. <!-- 八字合盘 Tab -->
  44. <view class="tab-content" v-if="activeTab === 'zodiac'">
  45. <view class="info-card">
  46. <view class="info-row" v-if="data.baziPairingSummary">
  47. <text class="info-label">合盘摘要</text>
  48. <text class="info-value">{{ data.baziPairingSummary }}</text>
  49. </view>
  50. </view>
  51. </view>
  52. <!-- 五行互补 Tab -->
  53. <view class="tab-content" v-if="activeTab === 'wuxing'">
  54. <view class="wuxing-grid">
  55. <view
  56. class="wuxing-card"
  57. v-for="wx in wuxingData"
  58. :key="wx.element"
  59. :style="{ background: wx.color + '18', borderColor: wx.color }">
  60. <text class="wuxing-card-elem">{{ wx.elementLabel }}</text>
  61. <view class="wuxing-card-bars">
  62. <view class="wuxing-bar-pair">
  63. <text class="wuxing-bar-label">{{ name1 }}</text>
  64. <view class="wuxing-bar-track-s">
  65. <view class="wuxing-bar-fill-s" :style="{ width: wx.v1 + '%', background: wx.color }"></view>
  66. </view>
  67. <text class="wuxing-bar-val">{{ wx.v1 }}</text>
  68. </view>
  69. <view class="wuxing-bar-pair">
  70. <text class="wuxing-bar-label">{{ name2 }}</text>
  71. <view class="wuxing-bar-track-s">
  72. <view class="wuxing-bar-fill-s" :style="{ width: wx.v2 + '%', background: wx.color }"></view>
  73. </view>
  74. <text class="wuxing-bar-val">{{ wx.v2 }}</text>
  75. </view>
  76. </view>
  77. <text class="wuxing-card-desc">{{ wx.description }}</text>
  78. </view>
  79. </view>
  80. <view class="info-card" v-if="data.wuxingComplementarity">
  81. <text class="info-label">五行互补分析</text>
  82. <text class="info-value" style="margin-top:12rpx">{{ data.wuxingComplementarity.analysis }}</text>
  83. </view>
  84. </view>
  85. <!-- 生肖配对 Tab -->
  86. <view class="tab-content" v-if="activeTab === 'zodiac'">
  87. <view class="info-card" v-if="data.zodiacCompatibility">
  88. <view class="info-row">
  89. <text class="info-label">生肖配对</text>
  90. <text class="info-value">{{ zodLabel1 }} & {{ zodLabel2 }}</text>
  91. </view>
  92. <view class="info-row" v-if="data.zodiacCompatibility.affinityType">
  93. <text class="info-label">配对关系</text>
  94. <text class="info-value">{{ data.zodiacCompatibility.affinityType }}</text>
  95. </view>
  96. <view class="info-row" v-if="data.zodiacCompatibility.description">
  97. <text class="info-label">详解</text>
  98. <text class="info-value">{{ data.zodiacCompatibility.description }}</text>
  99. </view>
  100. <view class="info-row">
  101. <text class="info-label">得分</text>
  102. <text class="info-value score-high">{{ data.zodiacCompatibility.score }}</text>
  103. </view>
  104. </view>
  105. </view>
  106. <!-- 灵数关系 Tab -->
  107. <view class="tab-content" v-if="activeTab === 'lifenumber'">
  108. <view class="info-card" v-if="data.lifeNumberRelationship">
  109. <view class="info-row">
  110. <text class="info-label">{{ name1 }} 灵数</text>
  111. <text class="info-value">{{ data.lifeNumberRelationship.lifeNumber1 }}</text>
  112. </view>
  113. <view class="info-row">
  114. <text class="info-label">{{ name2 }} 灵数</text>
  115. <text class="info-value">{{ data.lifeNumberRelationship.lifeNumber2 }}</text>
  116. </view>
  117. <view class="info-row">
  118. <text class="info-label">关系数</text>
  119. <text class="info-value score-primary">{{ data.lifeNumberRelationship.relationshipNumber }}</text>
  120. </view>
  121. <view class="info-row" v-if="data.lifeNumberRelationship.relationshipType">
  122. <text class="info-label">关系类型</text>
  123. <text class="info-value">{{ data.lifeNumberRelationship.relationshipType }}</text>
  124. </view>
  125. <view class="info-row" v-if="data.lifeNumberRelationship.description">
  126. <text class="info-label">详解</text>
  127. <text class="info-value">{{ data.lifeNumberRelationship.description }}</text>
  128. </view>
  129. <view class="info-row">
  130. <text class="info-label">得分</text>
  131. <text class="info-value score-high">{{ data.lifeNumberRelationship.score }}</text>
  132. </view>
  133. </view>
  134. </view>
  135. </template>
  136. <view class="empty-state" v-if="!loading && !dataLoaded">
  137. <text>暂无兼容数据</text>
  138. </view>
  139. </view>
  140. </template>
  141. <script>
  142. import config from '../../config'
  143. export default {
  144. data() {
  145. return {
  146. loading: true,
  147. dataLoaded: false,
  148. memberId1: null,
  149. memberId2: null,
  150. name1: '',
  151. name2: '',
  152. overallScore: 0,
  153. data: {},
  154. activeTab: 'wuxing',
  155. tabs: [
  156. { key: 'bazi', label: '八字合盘' },
  157. { key: 'wuxing', label: '五行互补' },
  158. { key: 'zodiac', label: '生肖配对' },
  159. { key: 'lifenumber', label: '灵数关系' }
  160. ],
  161. dimensions: [],
  162. wuxingColors: {
  163. wood: '#10B981',
  164. fire: '#FF6B9D',
  165. earth: '#FF8C42',
  166. metal: '#6366F1',
  167. water: '#3B82F6'
  168. },
  169. wuxingLabels: {
  170. wood: '木', fire: '火', earth: '土', metal: '金', water: '水'
  171. },
  172. zodiacNames: {
  173. rat: '鼠', ox: '牛', tiger: '虎', rabbit: '兔', dragon: '龙',
  174. snake: '蛇', horse: '马', sheep: '羊', monkey: '猴',
  175. rooster: '鸡', dog: '狗', pig: '猪'
  176. },
  177. wuxingElements: ['wood', 'fire', 'earth', 'metal', 'water']
  178. }
  179. },
  180. computed: {
  181. zodLabel1() {
  182. var z = this.data.zodiacCompatibility
  183. return z ? (this.zodiacNames[z.zodiac1] || z.zodiac1) : ''
  184. },
  185. zodLabel2() {
  186. var z = this.data.zodiacCompatibility
  187. return z ? (this.zodiacNames[z.zodiac2] || z.zodiac2) : ''
  188. },
  189. wuxingData() {
  190. var wc = this.data.wuxingComplementarity
  191. if (!wc || !wc.elementScores) return []
  192. var arr = []
  193. for (var i = 0; i < this.wuxingElements.length; i++) {
  194. var elem = this.wuxingElements[i]
  195. var es = wc.elementScores[elem]
  196. if (es === undefined) continue
  197. arr.push({
  198. element: elem,
  199. elementLabel: this.wuxingLabels[elem],
  200. color: this.wuxingColors[elem],
  201. v1: wc.member1Elements[elem] || 0,
  202. v2: wc.member2Elements[elem] || 0,
  203. score: es,
  204. description: this.wuxingDesc(elem, es)
  205. })
  206. }
  207. return arr.sort(function(a, b) { return b.score - a.score })
  208. }
  209. },
  210. onLoad(params) {
  211. this.memberId1 = params.memberId1
  212. this.memberId2 = params.memberId2
  213. this.loadData()
  214. },
  215. methods: {
  216. loadData() {
  217. var self = this
  218. uni.request({
  219. url: config.API_BASE_URL + '/api/mind/traditional/compatibility',
  220. method: 'POST',
  221. data: {
  222. memberId1: self.memberId1,
  223. memberId2: self.memberId2,
  224. memberType1: 'child',
  225. memberType2: 'child'
  226. },
  227. success: function(res) {
  228. self.loading = false
  229. if (res.data && res.data.code === 200 && res.data.data) {
  230. var d = res.data.data
  231. self.data = d
  232. self.overallScore = d.overallScore || 0
  233. self.name1 = d.memberName1 || '成员1'
  234. self.name2 = d.memberName2 || '成员2'
  235. self.buildDimensions(d)
  236. self.dataLoaded = true
  237. } else {
  238. self.dataLoaded = false
  239. }
  240. },
  241. fail: function() {
  242. self.loading = false
  243. self.dataLoaded = false
  244. }
  245. })
  246. },
  247. buildDimensions(d) {
  248. var dims = []
  249. if (d.zodiacCompatibility && d.zodiacCompatibility.score !== undefined) {
  250. dims.push({ key: 'zodiac', label: '生肖配对', score: d.zodiacCompatibility.score, color: '#8B5CF6' })
  251. }
  252. if (d.wuxingComplementarity && d.wuxingComplementarity.score !== undefined) {
  253. dims.push({ key: 'wuxing', label: '五行互补', score: d.wuxingComplementarity.score, color: '#10B981' })
  254. }
  255. if (d.wuxingComplementarity && d.wuxingComplementarity.bloodTypeScore !== undefined) {
  256. dims.push({ key: 'blood', label: '血型兼容', score: d.wuxingComplementarity.bloodTypeScore, color: '#FF6B9D' })
  257. }
  258. if (d.lifeNumberRelationship && d.lifeNumberRelationship.score !== undefined) {
  259. dims.push({ key: 'lifenumber', label: '灵数关系', score: d.lifeNumberRelationship.score, color: '#F59E0B' })
  260. }
  261. this.dimensions = dims
  262. },
  263. wuxingDesc(elem, score) {
  264. if (score >= 70) return '互补良好'
  265. if (score >= 50) return '较为平衡'
  266. return '有待加强'
  267. }
  268. }
  269. }
  270. </script>
  271. <style scoped>
  272. .duo-container {
  273. min-height: 100vh;
  274. background: #F8F6F0;
  275. padding-bottom: 40rpx;
  276. }
  277. .loading-state {
  278. display: flex;
  279. align-items: center;
  280. justify-content: center;
  281. padding: 120rpx 0;
  282. color: #999;
  283. font-size: 28rpx;
  284. }
  285. .duo-header {
  286. background: linear-gradient(135deg, #8B5CF6, #A78BFA);
  287. padding: 40rpx 32rpx;
  288. display: flex;
  289. align-items: center;
  290. justify-content: space-around;
  291. }
  292. .person-card {
  293. display: flex;
  294. flex-direction: column;
  295. align-items: center;
  296. }
  297. .person-avatar {
  298. width: 88rpx;
  299. height: 88rpx;
  300. border-radius: 50%;
  301. background: rgba(255,255,255,0.3);
  302. display: flex;
  303. align-items: center;
  304. justify-content: center;
  305. font-size: 36rpx;
  306. font-weight: 700;
  307. color: #fff;
  308. text-align: center;
  309. line-height: 88rpx;
  310. }
  311. .person-name {
  312. font-size: 26rpx;
  313. color: rgba(255,255,255,0.9);
  314. margin-top: 12rpx;
  315. }
  316. .compatibility-badge {
  317. display: flex;
  318. flex-direction: column;
  319. align-items: center;
  320. }
  321. .compatibility-score {
  322. font-size: 64rpx;
  323. font-weight: 800;
  324. color: #fff;
  325. line-height: 1;
  326. }
  327. .compatibility-label {
  328. font-size: 22rpx;
  329. color: rgba(255,255,255,0.7);
  330. margin-top: 8rpx;
  331. }
  332. .dimension-summary {
  333. margin: 24rpx 32rpx;
  334. background: #fff;
  335. border-radius: 20rpx;
  336. padding: 24rpx 28rpx;
  337. display: flex;
  338. flex-direction: column;
  339. gap: 16rpx;
  340. }
  341. .dimension-item {
  342. display: flex;
  343. align-items: center;
  344. gap: 12rpx;
  345. }
  346. .dimension-label {
  347. font-size: 24rpx;
  348. font-weight: 500;
  349. color: #666;
  350. width: 96rpx;
  351. flex-shrink: 0;
  352. }
  353. .dimension-bar-track {
  354. flex: 1;
  355. height: 16rpx;
  356. background: #F0F0F0;
  357. border-radius: 8rpx;
  358. overflow: hidden;
  359. }
  360. .dimension-bar-fill {
  361. height: 100%;
  362. border-radius: 8rpx;
  363. transition: width 0.3s;
  364. }
  365. .dimension-score {
  366. font-size: 24rpx;
  367. font-weight: 600;
  368. color: #333;
  369. width: 56rpx;
  370. text-align: right;
  371. }
  372. .tab-bar {
  373. display: flex;
  374. margin: 0 32rpx;
  375. background: #fff;
  376. border-radius: 20rpx 20rpx 0 0;
  377. overflow: hidden;
  378. }
  379. .tab-item {
  380. flex: 1;
  381. padding: 20rpx 0;
  382. text-align: center;
  383. font-size: 26rpx;
  384. color: #999;
  385. border-bottom: 4rpx solid transparent;
  386. }
  387. .tab-active {
  388. color: #8B5CF6;
  389. border-bottom-color: #8B5CF6;
  390. font-weight: 600;
  391. }
  392. .tab-content {
  393. margin: 0 32rpx;
  394. background: #fff;
  395. border-radius: 0 0 20rpx 20rpx;
  396. padding: 28rpx;
  397. }
  398. .info-card {
  399. padding: 20rpx;
  400. background: #FAFAFA;
  401. border-radius: 16rpx;
  402. }
  403. .info-row {
  404. display: flex;
  405. justify-content: space-between;
  406. align-items: center;
  407. padding: 12rpx 0;
  408. border-bottom: 1rpx solid #F0F0F0;
  409. }
  410. .info-row:last-child {
  411. border-bottom: none;
  412. }
  413. .info-label {
  414. font-size: 26rpx;
  415. color: #666;
  416. }
  417. .info-value {
  418. font-size: 26rpx;
  419. color: #333;
  420. font-weight: 500;
  421. text-align: right;
  422. max-width: 60%;
  423. }
  424. .score-high {
  425. color: #10B981;
  426. font-weight: 700;
  427. font-size: 32rpx;
  428. }
  429. .score-primary {
  430. color: #8B5CF6;
  431. font-weight: 700;
  432. font-size: 32rpx;
  433. }
  434. .wuxing-grid {
  435. display: grid;
  436. grid-template-columns: 1fr 1fr;
  437. gap: 16rpx;
  438. margin-bottom: 20rpx;
  439. }
  440. .wuxing-card {
  441. padding: 20rpx;
  442. border-radius: 16rpx;
  443. border: 2rpx solid;
  444. }
  445. .wuxing-card-elem {
  446. font-size: 28rpx;
  447. font-weight: 700;
  448. margin-bottom: 12rpx;
  449. display: block;
  450. }
  451. .wuxing-card-bars {
  452. display: flex;
  453. flex-direction: column;
  454. gap: 8rpx;
  455. }
  456. .wuxing-bar-pair {
  457. display: flex;
  458. align-items: center;
  459. gap: 8rpx;
  460. }
  461. .wuxing-bar-label {
  462. font-size: 20rpx;
  463. color: #999;
  464. width: 60rpx;
  465. overflow: hidden;
  466. text-overflow: ellipsis;
  467. white-space: nowrap;
  468. }
  469. .wuxing-bar-track-s {
  470. flex: 1;
  471. height: 12rpx;
  472. background: #F0F0F0;
  473. border-radius: 6rpx;
  474. overflow: hidden;
  475. }
  476. .wuxing-bar-fill-s {
  477. height: 100%;
  478. border-radius: 6rpx;
  479. }
  480. .wuxing-bar-val {
  481. font-size: 20rpx;
  482. color: #666;
  483. width: 36rpx;
  484. text-align: right;
  485. }
  486. .wuxing-card-desc {
  487. font-size: 22rpx;
  488. color: #666;
  489. margin-top: 8rpx;
  490. display: block;
  491. }
  492. .empty-state {
  493. display: flex;
  494. align-items: center;
  495. justify-content: center;
  496. padding: 120rpx 0;
  497. color: #999;
  498. font-size: 28rpx;
  499. }
  500. </style>