zodiac.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  1. <template>
  2. <view class="zodiac-page">
  3. <!-- 自定义导航栏 -->
  4. <view class="custom-nav">
  5. <view class="nav-left" @click="goBack">
  6. <text class="back-icon">←</text>
  7. </view>
  8. <view class="nav-title">生肖配对</view>
  9. <view class="nav-right"></view>
  10. </view>
  11. <!-- 生肖配对选择区域 -->
  12. <view class="zodiac-selection-section" v-if="!hasResult">
  13. <view class="selection-card">
  14. <view class="card-title">💕 生肖配对测试</view>
  15. <view class="card-subtitle">看看你们的缘分指数有多高</view>
  16. <!-- 我的生肖选择 -->
  17. <view class="zodiac-picker-wrapper">
  18. <view class="picker-label">我的生肖</view>
  19. <picker mode="selector" :range="zodiacNames" :value="myZodiacIndex" @change="onMyZodiacChange">
  20. <view class="zodiac-display">
  21. <text class="zodiac-emoji">{{ myZodiacEmoji }}</text>
  22. <text class="zodiac-text">{{ myZodiac || '请选择' }}</text>
  23. </view>
  24. </picker>
  25. </view>
  26. <!-- 对方生肖选择 -->
  27. <view class="zodiac-picker-wrapper">
  28. <view class="picker-label">TA的生肖</view>
  29. <picker mode="selector" :range="zodiacNames" :value="targetZodiacIndex" @change="onTargetZodiacChange">
  30. <view class="zodiac-display">
  31. <text class="zodiac-emoji">{{ targetZodiacEmoji }}</text>
  32. <text class="zodiac-text">{{ targetZodiac || '请选择' }}</text>
  33. </view>
  34. </picker>
  35. </view>
  36. <button class="submit-btn" @click="handleSubmit" :disabled="!myZodiac || !targetZodiac">
  37. 开始配对
  38. </button>
  39. </view>
  40. <!-- 装饰性生肖图标 -->
  41. <view class="zodiac-icons">
  42. <text class="zodiac-icon" v-for="(zodiac, index) in allZodiacs" :key="index">
  43. {{ zodiac.emoji }}
  44. </text>
  45. </view>
  46. </view>
  47. <!-- 配对结果 -->
  48. <view class="result-section" v-if="hasResult">
  49. <!-- 配对标题卡片 -->
  50. <view class="match-title-card">
  51. <view class="match-header">
  52. <view class="zodiac-pair">
  53. <text class="zodiac-emoji-large">{{ myZodiacEmoji }}</text>
  54. <text class="vs-text">💕</text>
  55. <text class="zodiac-emoji-large">{{ targetZodiacEmoji }}</text>
  56. </view>
  57. <view class="match-title">{{ myZodiac }} 💕 {{ targetZodiac }}</view>
  58. <view class="match-subtitle">{{ matchResult.title || '配对分析' }}</view>
  59. </view>
  60. </view>
  61. <!-- 配对分析 -->
  62. <view class="match-analysis-section" v-if="matchResult">
  63. <view class="section-title">💝 配对分析</view>
  64. <view class="analysis-card">
  65. <!-- 男性视角 -->
  66. <view class="perspective-item" v-if="matchResult.malePerspective">
  67. <view class="perspective-header">
  68. <text class="perspective-icon">👨</text>
  69. <text class="perspective-title">男生视角</text>
  70. </view>
  71. <text class="perspective-content">{{ matchResult.malePerspective }}</text>
  72. </view>
  73. <!-- 女性视角 -->
  74. <view class="perspective-item" v-if="matchResult.femalePerspective">
  75. <view class="perspective-header">
  76. <text class="perspective-icon">👩</text>
  77. <text class="perspective-title">女生视角</text>
  78. </view>
  79. <text class="perspective-content">{{ matchResult.femalePerspective }}</text>
  80. </view>
  81. <!-- 补充分析 -->
  82. <view class="perspective-item" v-if="matchResult.malePerspective2">
  83. <view class="perspective-header">
  84. <text class="perspective-icon">💭</text>
  85. <text class="perspective-title">深度分析</text>
  86. </view>
  87. <text class="perspective-content">{{ matchResult.malePerspective2 }}</text>
  88. </view>
  89. <view class="perspective-item" v-if="matchResult.femalePerspective2">
  90. <view class="perspective-header">
  91. <text class="perspective-icon">💖</text>
  92. <text class="perspective-title">感情建议</text>
  93. </view>
  94. <text class="perspective-content">{{ matchResult.femalePerspective2 }}</text>
  95. </view>
  96. </view>
  97. </view>
  98. <!-- 重新配对 -->
  99. <view class="retest-btn" @click="handleRetest">
  100. 重新配对
  101. </view>
  102. <!-- 数据来源说明 -->
  103. <view class="data-source" :class="{'api-source': isAPIData}">
  104. <text class="source-icon">{{ isAPIData ? '✓' : 'ℹ️' }}</text>
  105. <view class="source-content">
  106. <text class="source-text">数据来源:{{ dataSourceText }}</text>
  107. <text class="source-time">更新时间:{{ updateTime }}</text>
  108. </view>
  109. </view>
  110. <!-- 免责声明 -->
  111. <view class="disclaimer">
  112. <view class="disclaimer-title">⚠️ 免责声明</view>
  113. <view class="disclaimer-text">
  114. 本配对结果基于传统文化和民俗理论,仅供娱乐参考,不作为感情决策依据。
  115. 每个人的性格和缘分是多方面因素综合作用的结果,建议理性对待配对内容。
  116. 真正的幸福需要双方共同努力和经营。
  117. </view>
  118. </view>
  119. </view>
  120. <!-- 底部占位 -->
  121. <view class="bottom-placeholder"></view>
  122. </view>
  123. </template>
  124. <script>
  125. import zodiacUtil from '@/utils/zodiac.js'
  126. import zodiacEnhanced from '@/utils/zodiac-enhanced.js'
  127. export default {
  128. data() {
  129. return {
  130. // 生肖配对相关数据
  131. myZodiac: '',
  132. targetZodiac: '',
  133. myZodiacIndex: -1,
  134. targetZodiacIndex: -1,
  135. hasResult: false,
  136. matchResult: null,
  137. allZodiacs: [],
  138. updateTime: '',
  139. // 生肖名称列表
  140. zodiacNames: ['鼠', '牛', '虎', '兔', '龙', '蛇', '马', '羊', '猴', '鸡', '狗', '猪']
  141. }
  142. },
  143. computed: {
  144. // 我的生肖emoji
  145. myZodiacEmoji() {
  146. return this.myZodiac ? zodiacUtil.getZodiacEmoji(this.myZodiac) : '🔮'
  147. },
  148. // 对方生肖emoji
  149. targetZodiacEmoji() {
  150. return this.targetZodiac ? zodiacUtil.getZodiacEmoji(this.targetZodiac) : '🔮'
  151. },
  152. // 是否使用API数据
  153. isAPIData() {
  154. return this.matchResult?.source === 'tianapi'
  155. },
  156. // 数据来源文本
  157. dataSourceText() {
  158. if (this.isAPIData) {
  159. return '天行数据专业API'
  160. }
  161. return '传统生肖配对理论'
  162. }
  163. },
  164. onLoad() {
  165. this.initData()
  166. },
  167. methods: {
  168. initData() {
  169. // 设置更新时间
  170. const date = new Date()
  171. const year = date.getFullYear()
  172. const month = parseInt(date.getMonth() + 1)
  173. const day = parseInt(date.getDate())
  174. this.updateTime = `${year}年${month}月${day}日`
  175. // 加载所有生肖
  176. this.allZodiacs = zodiacUtil.ZODIACS.map(name => ({
  177. name,
  178. emoji: zodiacUtil.getZodiacEmoji(name)
  179. }))
  180. },
  181. // 我的生肖选择
  182. onMyZodiacChange(e) {
  183. const index = e.detail.value
  184. this.myZodiacIndex = index
  185. this.myZodiac = this.zodiacNames[index]
  186. console.log('选择我的生肖:', this.myZodiac)
  187. },
  188. // 对方生肖选择
  189. onTargetZodiacChange(e) {
  190. const index = e.detail.value
  191. this.targetZodiacIndex = index
  192. this.targetZodiac = this.zodiacNames[index]
  193. console.log('选择对方生肖:', this.targetZodiac)
  194. },
  195. // 提交配对
  196. async handleSubmit() {
  197. if (!this.myZodiac || !this.targetZodiac) {
  198. uni.showToast({
  199. title: '请选择双方生肖',
  200. icon: 'none'
  201. })
  202. return
  203. }
  204. // 显示加载中
  205. uni.showLoading({
  206. title: '配对分析中...',
  207. mask: true
  208. })
  209. try {
  210. console.log('🔍 开始生肖配对分析')
  211. console.log('我的生肖:', this.myZodiac, '对方生肖:', this.targetZodiac)
  212. // 调用天行数据配对API
  213. this.matchResult = await zodiacEnhanced.getZodiacMatch(this.myZodiac, this.targetZodiac)
  214. // 检查API结果并降级处理
  215. if (!this.matchResult) {
  216. console.log('📋 API返回null,使用本地配对数据')
  217. this.matchResult = this.getLocalMatchResult()
  218. // 显示友好提示
  219. uni.showToast({
  220. title: '使用本地配对数据',
  221. icon: 'none',
  222. duration: 1500
  223. })
  224. } else {
  225. console.log('✅ 使用API配对数据')
  226. }
  227. this.hasResult = true
  228. console.log('✅ 配对分析完成', {
  229. source: this.matchResult.source,
  230. dataFrom: this.matchResult.dataFrom || '未知来源'
  231. })
  232. // 保存到本地存储
  233. uni.setStorageSync('zodiacMatch', {
  234. myZodiac: this.myZodiac,
  235. targetZodiac: this.targetZodiac,
  236. result: this.matchResult,
  237. lastUpdate: new Date().getTime()
  238. })
  239. } catch (error) {
  240. console.error('❌ 配对分析过程异常:', error)
  241. // 兜底降级到本地数据
  242. this.matchResult = this.getLocalMatchResult()
  243. this.hasResult = true
  244. uni.showToast({
  245. title: '配对分析异常,使用本地数据',
  246. icon: 'none',
  247. duration: 2000
  248. })
  249. } finally {
  250. uni.hideLoading()
  251. }
  252. },
  253. // 本地配对结果(当API失败时使用)
  254. getLocalMatchResult() {
  255. const myInfo = zodiacUtil.getZodiacInfo(this.myZodiac)
  256. const targetInfo = zodiacUtil.getZodiacInfo(this.targetZodiac)
  257. // 简单的配对逻辑
  258. const isBestMatch = myInfo.compatibility.best.includes(this.targetZodiac)
  259. const isGoodMatch = myInfo.compatibility.good.includes(this.targetZodiac)
  260. let analysisText = ''
  261. if (isBestMatch) {
  262. analysisText = `${this.myZodiac}和${this.targetZodiac}是非常般配的一对!你们在性格上互补,能够互相理解和支持。`
  263. } else if (isGoodMatch) {
  264. analysisText = `${this.myZodiac}和${this.targetZodiac}是比较和谐的组合,虽然偶有小摩擦,但总体来说相处愉快。`
  265. } else {
  266. analysisText = `${this.myZodiac}和${this.targetZodiac}需要更多的理解和包容,通过沟通和努力可以建立美好关系。`
  267. }
  268. return {
  269. title: `${this.myZodiac}💕${this.targetZodiac}`,
  270. malePerspective: analysisText,
  271. femalePerspective: '感情需要双方共同经营,真诚和理解是最重要的。',
  272. malePerspective2: `${this.myZodiac}的特点是${myInfo.personality},建议在交往中发挥这些优势。`,
  273. femalePerspective2: `${this.targetZodiac}的特点是${targetInfo.personality},了解对方的性格有助于更好相处。`,
  274. source: 'local',
  275. dataFrom: '传统生肖配对理论',
  276. updateTime: new Date().toLocaleString('zh-CN')
  277. }
  278. },
  279. // 获取生肖emoji
  280. getZodiacEmoji(zodiacName) {
  281. return zodiacUtil.getZodiacEmoji(zodiacName)
  282. },
  283. // 重新配对
  284. handleRetest() {
  285. this.hasResult = false
  286. this.myZodiac = ''
  287. this.targetZodiac = ''
  288. this.myZodiacIndex = -1
  289. this.targetZodiacIndex = -1
  290. this.matchResult = null
  291. },
  292. // 返回
  293. goBack() {
  294. uni.navigateBack({
  295. delta: 1
  296. })
  297. }
  298. }
  299. }
  300. </script>
  301. <style lang="scss" scoped>
  302. .zodiac-page {
  303. min-height: 100vh;
  304. background: linear-gradient(180deg, #FFF9F9 0%, #FFFFFF 50%);
  305. padding-bottom: 40rpx;
  306. }
  307. /* 自定义导航栏 */
  308. .custom-nav {
  309. position: relative;
  310. display: flex;
  311. align-items: center;
  312. justify-content: space-between;
  313. height: 88rpx;
  314. padding: 0 30rpx;
  315. background-color: #FFFFFF;
  316. border-bottom: 1rpx solid #F0F0F0;
  317. .nav-left {
  318. width: 80rpx;
  319. .back-icon {
  320. font-size: 40rpx;
  321. color: #333333;
  322. }
  323. }
  324. .nav-title {
  325. position: absolute;
  326. left: 50%;
  327. transform: translateX(-50%);
  328. font-size: 34rpx;
  329. font-weight: 600;
  330. color: #333333;
  331. }
  332. .nav-right {
  333. width: 80rpx;
  334. }
  335. }
  336. /* 生肖选择区域 */
  337. .zodiac-selection-section {
  338. padding: 60rpx 30rpx;
  339. display: flex;
  340. flex-direction: column;
  341. align-items: center;
  342. .selection-card {
  343. width: 100%;
  344. background-color: #FFFFFF;
  345. border-radius: 30rpx;
  346. padding: 60rpx 40rpx;
  347. box-shadow: 0 8rpx 30rpx rgba(233, 30, 99, 0.1);
  348. text-align: center;
  349. .card-title {
  350. font-size: 40rpx;
  351. font-weight: bold;
  352. color: #333333;
  353. margin-bottom: 15rpx;
  354. }
  355. .card-subtitle {
  356. font-size: 26rpx;
  357. color: #999999;
  358. margin-bottom: 50rpx;
  359. }
  360. .zodiac-picker-wrapper {
  361. margin-bottom: 30rpx;
  362. text-align: left;
  363. .picker-label {
  364. font-size: 28rpx;
  365. color: #666666;
  366. margin-bottom: 15rpx;
  367. }
  368. .zodiac-display {
  369. display: flex;
  370. align-items: center;
  371. justify-content: center;
  372. background-color: #F8F8F8;
  373. border-radius: 20rpx;
  374. padding: 25rpx 30rpx;
  375. border: 2rpx solid #E91E63;
  376. transition: all 0.3s;
  377. .zodiac-emoji {
  378. font-size: 40rpx;
  379. margin-right: 15rpx;
  380. }
  381. .zodiac-text {
  382. font-size: 32rpx;
  383. color: #333333;
  384. font-weight: 500;
  385. }
  386. }
  387. &:active .zodiac-display {
  388. background-color: #FFE5EE;
  389. transform: scale(0.98);
  390. }
  391. }
  392. .submit-btn {
  393. width: 100%;
  394. height: 90rpx;
  395. background: linear-gradient(135deg, #E91E63 0%, #FF6B9D 100%);
  396. color: #FFFFFF;
  397. font-size: 32rpx;
  398. font-weight: 600;
  399. border-radius: 45rpx;
  400. border: none;
  401. box-shadow: 0 8rpx 20rpx rgba(233, 30, 99, 0.3);
  402. &:disabled {
  403. opacity: 0.5;
  404. }
  405. &:active:not(:disabled) {
  406. opacity: 0.9;
  407. }
  408. }
  409. }
  410. .zodiac-icons {
  411. display: flex;
  412. flex-wrap: wrap;
  413. justify-content: center;
  414. gap: 20rpx;
  415. margin-top: 50rpx;
  416. opacity: 0.3;
  417. .zodiac-icon {
  418. font-size: 48rpx;
  419. animation: float 3s ease-in-out infinite;
  420. &:nth-child(2n) {
  421. animation-delay: 0.5s;
  422. }
  423. &:nth-child(3n) {
  424. animation-delay: 1s;
  425. }
  426. }
  427. }
  428. }
  429. @keyframes float {
  430. 0%, 100% {
  431. transform: translateY(0);
  432. }
  433. 50% {
  434. transform: translateY(-10rpx);
  435. }
  436. }
  437. /* 结果区域 */
  438. .result-section {
  439. padding: 30rpx 25rpx 40rpx 25rpx;
  440. }
  441. /* 配对标题卡片 */
  442. .match-title-card {
  443. background: linear-gradient(135deg, #FF6B9D 0%, #FFA5C6 100%);
  444. border-radius: 32rpx;
  445. padding: 60rpx 40rpx;
  446. text-align: center;
  447. box-shadow: 0 12rpx 40rpx rgba(233, 30, 99, 0.25);
  448. margin-bottom: 40rpx;
  449. .match-header {
  450. text-align: center;
  451. .zodiac-pair {
  452. display: flex;
  453. align-items: center;
  454. justify-content: center;
  455. margin-bottom: 30rpx;
  456. .zodiac-emoji-large {
  457. font-size: 120rpx;
  458. }
  459. .vs-text {
  460. font-size: 70rpx;
  461. margin: 0 30rpx;
  462. }
  463. }
  464. .match-title {
  465. font-size: 42rpx;
  466. font-weight: bold;
  467. color: #FFFFFF;
  468. margin-bottom: 15rpx;
  469. letter-spacing: 2rpx;
  470. }
  471. .match-subtitle {
  472. font-size: 28rpx;
  473. color: rgba(255, 255, 255, 0.9);
  474. }
  475. }
  476. }
  477. /* 通用标题 */
  478. .section-title {
  479. font-size: 36rpx;
  480. font-weight: 600;
  481. color: #333333;
  482. margin-bottom: 25rpx;
  483. padding: 0 10rpx;
  484. display: flex;
  485. align-items: center;
  486. justify-content: flex-start;
  487. }
  488. /* 配对分析 */
  489. .match-analysis-section {
  490. margin-bottom: 40rpx;
  491. .analysis-card {
  492. background-color: #FFFFFF;
  493. border-radius: 24rpx;
  494. padding: 0;
  495. box-shadow: 0 6rpx 24rpx rgba(0, 0, 0, 0.08);
  496. overflow: hidden;
  497. .perspective-item {
  498. margin-bottom: 0;
  499. border-bottom: 1rpx solid #F5F5F5;
  500. &:last-child {
  501. border-bottom: none;
  502. }
  503. .perspective-header {
  504. display: flex;
  505. align-items: center;
  506. padding: 25rpx 30rpx 15rpx 30rpx;
  507. background: linear-gradient(135deg, #FFF9F9 0%, #FFFBFC 100%);
  508. .perspective-icon {
  509. font-size: 32rpx;
  510. margin-right: 15rpx;
  511. }
  512. .perspective-title {
  513. font-size: 30rpx;
  514. color: #E91E63;
  515. font-weight: 600;
  516. }
  517. }
  518. .perspective-content {
  519. font-size: 30rpx;
  520. color: #333333;
  521. line-height: 1.8;
  522. padding: 20rpx 30rpx 30rpx 30rpx;
  523. text-align: justify;
  524. background-color: #FFFFFF;
  525. }
  526. }
  527. }
  528. }
  529. /* 重新配对 */
  530. .retest-btn {
  531. text-align: center;
  532. padding: 30rpx 40rpx;
  533. font-size: 30rpx;
  534. color: #666666;
  535. background-color: #F8F8F8;
  536. border-radius: 25rpx;
  537. margin: 20rpx 20rpx 30rpx 20rpx;
  538. border: 2rpx solid #E0E0E0;
  539. &:active {
  540. color: #E91E63;
  541. background-color: #FFF0F5;
  542. border-color: #E91E63;
  543. }
  544. }
  545. /* 数据来源说明 */
  546. .data-source {
  547. display: flex;
  548. align-items: center;
  549. background-color: #E3F2FD;
  550. border-radius: 20rpx;
  551. padding: 25rpx 30rpx;
  552. margin-bottom: 30rpx;
  553. transition: all 0.3s;
  554. .source-icon {
  555. font-size: 32rpx;
  556. margin-right: 15rpx;
  557. }
  558. .source-content {
  559. flex: 1;
  560. display: flex;
  561. flex-direction: column;
  562. gap: 8rpx;
  563. .source-text {
  564. font-size: 28rpx;
  565. color: #1976D2;
  566. font-weight: 500;
  567. }
  568. .source-time {
  569. font-size: 24rpx;
  570. color: #64B5F6;
  571. }
  572. }
  573. // API数据特殊样式
  574. &.api-source {
  575. background: linear-gradient(135deg, #E8F5E9 0%, #C8E6C9 100%);
  576. border-left: 6rpx solid #4CAF50;
  577. .source-icon {
  578. color: #4CAF50;
  579. }
  580. .source-text {
  581. color: #2E7D32;
  582. }
  583. .source-time {
  584. color: #66BB6A;
  585. }
  586. }
  587. }
  588. /* 免责声明 */
  589. .disclaimer {
  590. background-color: #FFF3E0;
  591. border-radius: 20rpx;
  592. padding: 30rpx;
  593. border-left: 6rpx solid #FF9800;
  594. margin: 0 10rpx;
  595. .disclaimer-title {
  596. font-size: 30rpx;
  597. font-weight: 600;
  598. color: #F57C00;
  599. margin-bottom: 20rpx;
  600. }
  601. .disclaimer-text {
  602. font-size: 26rpx;
  603. color: #666666;
  604. line-height: 2.0;
  605. text-align: justify;
  606. }
  607. }
  608. /* 底部占位 */
  609. .bottom-placeholder {
  610. height: 60rpx;
  611. }
  612. </style>