duo-compatibility.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520
  1. <template>
  2. <view class="duo-container" :style="{ '--font-scale': fontScale }">
  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 { BrandColors } from '../../utils/brand-colors.js'
  143. import config from '../../config'
  144. import fontScaleMixin from '@/mixins/font-scale.js'
  145. export default {
  146. mixins: [fontScaleMixin],
  147. data() {
  148. return {
  149. loading: true,
  150. dataLoaded: false,
  151. memberId1: null,
  152. memberId2: null,
  153. name1: '',
  154. name2: '',
  155. overallScore: 0,
  156. data: {},
  157. activeTab: 'wuxing',
  158. tabs: [
  159. { key: 'bazi', label: '八字合盘' },
  160. { key: 'wuxing', label: '五行互补' },
  161. { key: 'zodiac', label: '生肖配对' },
  162. { key: 'lifenumber', label: '灵数关系' }
  163. ],
  164. dimensions: [],
  165. wuxingColors: {
  166. wood: BrandColors.success,
  167. fire: BrandColors.mind,
  168. earth: BrandColors.body,
  169. metal: BrandColors.wisdom,
  170. water: BrandColors.infoBlue
  171. },
  172. wuxingLabels: {
  173. wood: '木', fire: '火', earth: '土', metal: '金', water: '水'
  174. },
  175. zodiacNames: {
  176. rat: '鼠', ox: '牛', tiger: '虎', rabbit: '兔', dragon: '龙',
  177. snake: '蛇', horse: '马', sheep: '羊', monkey: '猴',
  178. rooster: '鸡', dog: '狗', pig: '猪'
  179. },
  180. wuxingElements: ['wood', 'fire', 'earth', 'metal', 'water']
  181. }
  182. },
  183. computed: {
  184. zodLabel1() {
  185. var z = this.data.zodiacCompatibility
  186. return z ? (this.zodiacNames[z.zodiac1] || z.zodiac1) : ''
  187. },
  188. zodLabel2() {
  189. var z = this.data.zodiacCompatibility
  190. return z ? (this.zodiacNames[z.zodiac2] || z.zodiac2) : ''
  191. },
  192. wuxingData() {
  193. var wc = this.data.wuxingComplementarity
  194. if (!wc || !wc.elementScores) return []
  195. var arr = []
  196. for (var i = 0; i < this.wuxingElements.length; i++) {
  197. var elem = this.wuxingElements[i]
  198. var es = wc.elementScores[elem]
  199. if (es === undefined) continue
  200. arr.push({
  201. element: elem,
  202. elementLabel: this.wuxingLabels[elem],
  203. color: this.wuxingColors[elem],
  204. v1: wc.member1Elements[elem] || 0,
  205. v2: wc.member2Elements[elem] || 0,
  206. score: es,
  207. description: this.wuxingDesc(elem, es)
  208. })
  209. }
  210. return arr.sort(function(a, b) { return b.score - a.score })
  211. }
  212. },
  213. onLoad(params) {
  214. this.memberId1 = params.memberId1
  215. this.memberId2 = params.memberId2
  216. this.loadData()
  217. },
  218. methods: {
  219. loadData() {
  220. var self = this
  221. uni.request({
  222. url: config.API_BASE_URL + '/api/mind/traditional/compatibility',
  223. method: 'POST',
  224. data: {
  225. memberId1: self.memberId1,
  226. memberId2: self.memberId2,
  227. memberType1: 'child',
  228. memberType2: 'child'
  229. },
  230. success: function(res) {
  231. self.loading = false
  232. if (res.data && res.data.code === 200 && res.data.data) {
  233. var d = res.data.data
  234. self.data = d
  235. self.overallScore = d.overallScore || 0
  236. self.name1 = d.memberName1 || '成员1'
  237. self.name2 = d.memberName2 || '成员2'
  238. self.buildDimensions(d)
  239. self.dataLoaded = true
  240. } else {
  241. self.dataLoaded = false
  242. }
  243. },
  244. fail: function() {
  245. self.loading = false
  246. self.dataLoaded = false
  247. }
  248. })
  249. },
  250. buildDimensions(d) {
  251. var dims = []
  252. if (d.zodiacCompatibility && d.zodiacCompatibility.score !== undefined) {
  253. dims.push({ key: 'zodiac', label: '生肖配对', score: d.zodiacCompatibility.score, color: BrandColors.violet })
  254. }
  255. if (d.wuxingComplementarity && d.wuxingComplementarity.score !== undefined) {
  256. dims.push({ key: 'wuxing', label: '五行互补', score: d.wuxingComplementarity.score, color: BrandColors.success })
  257. }
  258. if (d.wuxingComplementarity && d.wuxingComplementarity.bloodTypeScore !== undefined) {
  259. dims.push({ key: 'blood', label: '血型兼容', score: d.wuxingComplementarity.bloodTypeScore, color: BrandColors.mind })
  260. }
  261. if (d.lifeNumberRelationship && d.lifeNumberRelationship.score !== undefined) {
  262. dims.push({ key: 'lifenumber', label: '灵数关系', score: d.lifeNumberRelationship.score, color: BrandColors.wealth })
  263. }
  264. this.dimensions = dims
  265. },
  266. wuxingDesc(elem, score) {
  267. if (score >= 70) return '互补良好'
  268. if (score >= 50) return '较为平衡'
  269. return '有待加强'
  270. }
  271. }
  272. }
  273. </script>
  274. <style scoped lang="scss">
  275. .duo-container {
  276. min-height: 100vh;
  277. background: $facade-fill-warm-tint;
  278. padding-bottom: 40rpx;
  279. }
  280. .loading-state {
  281. display: flex;
  282. align-items: center;
  283. justify-content: center;
  284. padding: 120rpx 0;
  285. color: $facade-text-muted;
  286. font-size: calc(28rpx * var(--font-scale, 1));
  287. }
  288. .duo-header {
  289. background: linear-gradient(135deg, $facade-violet, $facade-violet-light);
  290. padding: 40rpx 32rpx;
  291. display: flex;
  292. align-items: center;
  293. justify-content: space-around;
  294. }
  295. .person-card {
  296. display: flex;
  297. flex-direction: column;
  298. align-items: center;
  299. }
  300. .person-avatar {
  301. width: 88rpx;
  302. height: 88rpx;
  303. border-radius: 50%;
  304. background: rgba(255,255,255,0.3);
  305. display: flex;
  306. align-items: center;
  307. justify-content: center;
  308. font-size: calc(36rpx * var(--font-scale, 1));
  309. font-weight: 700;
  310. color: $app-surface;
  311. text-align: center;
  312. line-height: 88rpx;
  313. }
  314. .person-name {
  315. font-size: calc(26rpx * var(--font-scale, 1));
  316. color: rgba(255,255,255,0.9);
  317. margin-top: 12rpx;
  318. }
  319. .compatibility-badge {
  320. display: flex;
  321. flex-direction: column;
  322. align-items: center;
  323. }
  324. .compatibility-score {
  325. font-size: calc($uni-font-size-4xl * var(--font-scale, 1));
  326. font-weight: $uni-font-weight-extra-heavy;
  327. color: $app-surface;
  328. line-height: 1;
  329. }
  330. .compatibility-label {
  331. font-size: calc(22rpx * var(--font-scale, 1));
  332. color: rgba(255,255,255,0.7);
  333. margin-top: 8rpx;
  334. }
  335. .dimension-summary {
  336. margin: 24rpx 32rpx;
  337. background: $app-surface;
  338. border-radius: 24rpx;
  339. padding: 24rpx 28rpx;
  340. display: flex;
  341. flex-direction: column;
  342. gap: 16rpx;
  343. }
  344. .dimension-item {
  345. display: flex;
  346. align-items: center;
  347. gap: 12rpx;
  348. }
  349. .dimension-label {
  350. font-size: calc(24rpx * var(--font-scale, 1));
  351. font-weight: 500;
  352. color: $facade-text-body;
  353. width: 96rpx;
  354. flex-shrink: 0;
  355. }
  356. .dimension-bar-track {
  357. flex: 1;
  358. height: 16rpx;
  359. background: $facade-fill;
  360. border-radius: 8rpx;
  361. overflow: hidden;
  362. }
  363. .dimension-bar-fill {
  364. height: 100%;
  365. border-radius: 8rpx;
  366. transition: width 0.3s;
  367. }
  368. .dimension-score {
  369. font-size: calc(24rpx * var(--font-scale, 1));
  370. font-weight: 600;
  371. color: $facade-text-strong;
  372. width: 56rpx;
  373. text-align: right;
  374. }
  375. .tab-bar {
  376. display: flex;
  377. margin: 0 32rpx;
  378. background: $app-surface;
  379. border-radius: 24rpx 24rpx 0 0;
  380. overflow: hidden;
  381. }
  382. .tab-item {
  383. flex: 1;
  384. padding: 20rpx 0;
  385. text-align: center;
  386. font-size: calc(26rpx * var(--font-scale, 1));
  387. color: $facade-text-muted;
  388. border-bottom: 4rpx solid transparent;
  389. }
  390. .tab-active {
  391. color: $facade-violet;
  392. border-bottom-color: $facade-violet;
  393. font-weight: 600;
  394. }
  395. .tab-content {
  396. margin: 0 32rpx;
  397. background: $app-surface;
  398. border-radius: 0 0 24rpx 24rpx;
  399. padding: 28rpx;
  400. }
  401. .info-card {
  402. padding: 20rpx;
  403. background: $facade-fill-ghost;
  404. border-radius: 16rpx;
  405. }
  406. .info-row {
  407. display: flex;
  408. justify-content: space-between;
  409. align-items: center;
  410. padding: 12rpx 0;
  411. border-bottom: 1rpx solid $facade-fill;
  412. }
  413. .info-row:last-child {
  414. border-bottom: none;
  415. }
  416. .info-label {
  417. font-size: calc(26rpx * var(--font-scale, 1));
  418. color: $facade-text-body;
  419. }
  420. .info-value {
  421. font-size: calc(26rpx * var(--font-scale, 1));
  422. color: $facade-text-strong;
  423. font-weight: 500;
  424. text-align: right;
  425. max-width: 60%;
  426. }
  427. .score-high {
  428. color: $status-success;
  429. font-weight: 700;
  430. font-size: calc(32rpx * var(--font-scale, 1));
  431. }
  432. .score-primary {
  433. color: $facade-violet;
  434. font-weight: 700;
  435. font-size: calc(32rpx * var(--font-scale, 1));
  436. }
  437. .wuxing-grid {
  438. display: grid;
  439. grid-template-columns: 1fr 1fr;
  440. gap: 16rpx;
  441. margin-bottom: 20rpx;
  442. }
  443. .wuxing-card {
  444. padding: 20rpx;
  445. border-radius: 16rpx;
  446. border: 2rpx solid;
  447. }
  448. .wuxing-card-elem {
  449. font-size: calc(28rpx * var(--font-scale, 1));
  450. font-weight: 700;
  451. margin-bottom: 12rpx;
  452. display: block;
  453. }
  454. .wuxing-card-bars {
  455. display: flex;
  456. flex-direction: column;
  457. gap: 8rpx;
  458. }
  459. .wuxing-bar-pair {
  460. display: flex;
  461. align-items: center;
  462. gap: 8rpx;
  463. }
  464. .wuxing-bar-label {
  465. font-size: calc(20rpx * var(--font-scale, 1));
  466. color: $facade-text-muted;
  467. width: 60rpx;
  468. overflow: hidden;
  469. text-overflow: ellipsis;
  470. white-space: nowrap;
  471. }
  472. .wuxing-bar-track-s {
  473. flex: 1;
  474. height: 12rpx;
  475. background: $facade-fill;
  476. border-radius: 8rpx;
  477. overflow: hidden;
  478. }
  479. .wuxing-bar-fill-s {
  480. height: 100%;
  481. border-radius: 8rpx;
  482. }
  483. .wuxing-bar-val {
  484. font-size: calc(20rpx * var(--font-scale, 1));
  485. color: $facade-text-body;
  486. width: 36rpx;
  487. text-align: right;
  488. }
  489. .wuxing-card-desc {
  490. font-size: calc(22rpx * var(--font-scale, 1));
  491. color: $facade-text-body;
  492. margin-top: 8rpx;
  493. display: block;
  494. }
  495. .empty-state {
  496. display: flex;
  497. align-items: center;
  498. justify-content: center;
  499. padding: 120rpx 0;
  500. color: $facade-text-muted;
  501. font-size: calc(28rpx * var(--font-scale, 1));
  502. }
  503. </style>