zodiac.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  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: uni.getStorageSync("userInfo").animal,
  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. },
  187. // 对方生肖选择
  188. onTargetZodiacChange(e) {
  189. const index = e.detail.value
  190. this.targetZodiacIndex = index
  191. this.targetZodiac = this.zodiacNames[index]
  192. },
  193. // 提交配对
  194. async handleSubmit() {
  195. if (!this.myZodiac || !this.targetZodiac) {
  196. uni.showToast({
  197. title: '请选择双方生肖',
  198. icon: 'none'
  199. })
  200. return
  201. }
  202. // 显示加载中
  203. uni.showLoading({
  204. title: '配对分析中...',
  205. mask: true
  206. })
  207. try {
  208. // 调用天行数据配对API
  209. this.matchResult = await zodiacEnhanced.getZodiacMatch(this.myZodiac, this.targetZodiac)
  210. // 检查API结果并降级处理
  211. if (!this.matchResult) {
  212. this.matchResult = this.getLocalMatchResult()
  213. // 显示友好提示
  214. uni.showToast({
  215. title: '使用本地配对数据',
  216. icon: 'none',
  217. duration: 1500
  218. })
  219. }
  220. this.hasResult = true
  221. // 保存到本地存储
  222. uni.setStorageSync('zodiacMatch', {
  223. myZodiac: this.myZodiac,
  224. targetZodiac: this.targetZodiac,
  225. result: this.matchResult,
  226. lastUpdate: new Date().getTime()
  227. })
  228. } catch (error) {
  229. // 兜底降级到本地数据
  230. this.matchResult = this.getLocalMatchResult()
  231. this.hasResult = true
  232. uni.showToast({
  233. title: '配对分析异常,使用本地数据',
  234. icon: 'none',
  235. duration: 2000
  236. })
  237. } finally {
  238. uni.hideLoading()
  239. }
  240. },
  241. // 本地配对结果(当API失败时使用)
  242. getLocalMatchResult() {
  243. const myInfo = zodiacUtil.getZodiacInfo(this.myZodiac)
  244. const targetInfo = zodiacUtil.getZodiacInfo(this.targetZodiac)
  245. // 简单的配对逻辑
  246. const isBestMatch = myInfo.compatibility.best.includes(this.targetZodiac)
  247. const isGoodMatch = myInfo.compatibility.good.includes(this.targetZodiac)
  248. let analysisText = ''
  249. if (isBestMatch) {
  250. analysisText = `${this.myZodiac}和${this.targetZodiac}是非常般配的一对!你们在性格上互补,能够互相理解和支持。`
  251. } else if (isGoodMatch) {
  252. analysisText = `${this.myZodiac}和${this.targetZodiac}是比较和谐的组合,虽然偶有小摩擦,但总体来说相处愉快。`
  253. } else {
  254. analysisText = `${this.myZodiac}和${this.targetZodiac}需要更多的理解和包容,通过沟通和努力可以建立美好关系。`
  255. }
  256. return {
  257. title: `${this.myZodiac}💕${this.targetZodiac}`,
  258. malePerspective: analysisText,
  259. femalePerspective: '感情需要双方共同经营,真诚和理解是最重要的。',
  260. malePerspective2: `${this.myZodiac}的特点是${myInfo.personality},建议在交往中发挥这些优势。`,
  261. femalePerspective2: `${this.targetZodiac}的特点是${targetInfo.personality},了解对方的性格有助于更好相处。`,
  262. source: 'local',
  263. dataFrom: '传统生肖配对理论',
  264. updateTime: new Date().toLocaleString('zh-CN')
  265. }
  266. },
  267. // 获取生肖emoji
  268. getZodiacEmoji(zodiacName) {
  269. return zodiacUtil.getZodiacEmoji(zodiacName)
  270. },
  271. // 重新配对
  272. handleRetest() {
  273. this.hasResult = false
  274. this.myZodiac = ''
  275. this.targetZodiac = ''
  276. this.myZodiacIndex = -1
  277. this.targetZodiacIndex = -1
  278. this.matchResult = null
  279. },
  280. // 返回
  281. goBack() {
  282. uni.navigateBack({
  283. delta: 1
  284. })
  285. }
  286. }
  287. }
  288. </script>
  289. <style lang="scss" scoped>
  290. .zodiac-page {
  291. min-height: 100vh;
  292. background: linear-gradient(180deg, #FFF9F9 0%, #FFFFFF 50%);
  293. padding-bottom: 40rpx;
  294. }
  295. /* 自定义导航栏 */
  296. .custom-nav {
  297. position: relative;
  298. display: flex;
  299. align-items: center;
  300. justify-content: space-between;
  301. height: 88rpx;
  302. padding: 0 30rpx;
  303. background-color: #FFFFFF;
  304. border-bottom: 1rpx solid #F0F0F0;
  305. .nav-left {
  306. width: 80rpx;
  307. .back-icon {
  308. font-size: 40rpx;
  309. color: #333333;
  310. }
  311. }
  312. .nav-title {
  313. position: absolute;
  314. left: 50%;
  315. transform: translateX(-50%);
  316. font-size: 34rpx;
  317. font-weight: 600;
  318. color: #333333;
  319. }
  320. .nav-right {
  321. width: 80rpx;
  322. }
  323. }
  324. /* 生肖选择区域 */
  325. .zodiac-selection-section {
  326. padding: 60rpx 30rpx;
  327. display: flex;
  328. flex-direction: column;
  329. align-items: center;
  330. .selection-card {
  331. width: 100%;
  332. background-color: #FFFFFF;
  333. border-radius: 30rpx;
  334. padding: 60rpx 40rpx;
  335. box-shadow: 0 8rpx 30rpx rgba(233, 30, 99, 0.1);
  336. text-align: center;
  337. .card-title {
  338. font-size: 40rpx;
  339. font-weight: bold;
  340. color: #333333;
  341. margin-bottom: 15rpx;
  342. }
  343. .card-subtitle {
  344. font-size: 26rpx;
  345. color: #999999;
  346. margin-bottom: 50rpx;
  347. }
  348. .zodiac-picker-wrapper {
  349. margin-bottom: 30rpx;
  350. text-align: left;
  351. .picker-label {
  352. font-size: 28rpx;
  353. color: #666666;
  354. margin-bottom: 15rpx;
  355. }
  356. .zodiac-display {
  357. display: flex;
  358. align-items: center;
  359. justify-content: center;
  360. background-color: #F8F8F8;
  361. border-radius: 20rpx;
  362. padding: 25rpx 30rpx;
  363. border: 2rpx solid #E91E63;
  364. transition: all 0.3s;
  365. .zodiac-emoji {
  366. font-size: 40rpx;
  367. margin-right: 15rpx;
  368. }
  369. .zodiac-text {
  370. font-size: 32rpx;
  371. color: #333333;
  372. font-weight: 500;
  373. }
  374. }
  375. &:active .zodiac-display {
  376. background-color: #FFE5EE;
  377. transform: scale(0.98);
  378. }
  379. }
  380. .submit-btn {
  381. width: 100%;
  382. height: 90rpx;
  383. background: linear-gradient(135deg, #E91E63 0%, #FF6B9D 100%);
  384. color: #FFFFFF;
  385. font-size: 32rpx;
  386. font-weight: 600;
  387. border-radius: 45rpx;
  388. border: none;
  389. box-shadow: 0 8rpx 20rpx rgba(233, 30, 99, 0.3);
  390. &:disabled {
  391. opacity: 0.5;
  392. }
  393. &:active:not(:disabled) {
  394. opacity: 0.9;
  395. }
  396. }
  397. }
  398. .zodiac-icons {
  399. display: flex;
  400. flex-wrap: wrap;
  401. justify-content: center;
  402. gap: 20rpx;
  403. margin-top: 50rpx;
  404. opacity: 0.3;
  405. .zodiac-icon {
  406. font-size: 48rpx;
  407. animation: float 3s ease-in-out infinite;
  408. &:nth-child(2n) {
  409. animation-delay: 0.5s;
  410. }
  411. &:nth-child(3n) {
  412. animation-delay: 1s;
  413. }
  414. }
  415. }
  416. }
  417. @keyframes float {
  418. 0%, 100% {
  419. transform: translateY(0);
  420. }
  421. 50% {
  422. transform: translateY(-10rpx);
  423. }
  424. }
  425. /* 结果区域 */
  426. .result-section {
  427. padding: 30rpx 25rpx 40rpx 25rpx;
  428. }
  429. /* 配对标题卡片 */
  430. .match-title-card {
  431. background: linear-gradient(135deg, #FF6B9D 0%, #FFA5C6 100%);
  432. border-radius: 32rpx;
  433. padding: 60rpx 40rpx;
  434. text-align: center;
  435. box-shadow: 0 12rpx 40rpx rgba(233, 30, 99, 0.25);
  436. margin-bottom: 40rpx;
  437. .match-header {
  438. text-align: center;
  439. .zodiac-pair {
  440. display: flex;
  441. align-items: center;
  442. justify-content: center;
  443. margin-bottom: 30rpx;
  444. .zodiac-emoji-large {
  445. font-size: 120rpx;
  446. }
  447. .vs-text {
  448. font-size: 70rpx;
  449. margin: 0 30rpx;
  450. }
  451. }
  452. .match-title {
  453. font-size: 42rpx;
  454. font-weight: bold;
  455. color: #FFFFFF;
  456. margin-bottom: 15rpx;
  457. letter-spacing: 2rpx;
  458. }
  459. .match-subtitle {
  460. font-size: 28rpx;
  461. color: rgba(255, 255, 255, 0.9);
  462. }
  463. }
  464. }
  465. /* 通用标题 */
  466. .section-title {
  467. font-size: 36rpx;
  468. font-weight: 600;
  469. color: #333333;
  470. margin-bottom: 25rpx;
  471. padding: 0 10rpx;
  472. display: flex;
  473. align-items: center;
  474. justify-content: flex-start;
  475. }
  476. /* 配对分析 */
  477. .match-analysis-section {
  478. margin-bottom: 40rpx;
  479. .analysis-card {
  480. background-color: #FFFFFF;
  481. border-radius: 24rpx;
  482. padding: 0;
  483. box-shadow: 0 6rpx 24rpx rgba(0, 0, 0, 0.08);
  484. overflow: hidden;
  485. .perspective-item {
  486. margin-bottom: 0;
  487. border-bottom: 1rpx solid #F5F5F5;
  488. &:last-child {
  489. border-bottom: none;
  490. }
  491. .perspective-header {
  492. display: flex;
  493. align-items: center;
  494. padding: 25rpx 30rpx 15rpx 30rpx;
  495. background: linear-gradient(135deg, #FFF9F9 0%, #FFFBFC 100%);
  496. .perspective-icon {
  497. font-size: 32rpx;
  498. margin-right: 15rpx;
  499. }
  500. .perspective-title {
  501. font-size: 30rpx;
  502. color: #E91E63;
  503. font-weight: 600;
  504. }
  505. }
  506. .perspective-content {
  507. font-size: 30rpx;
  508. color: #333333;
  509. line-height: 1.8;
  510. padding: 20rpx 30rpx 30rpx 30rpx;
  511. text-align: justify;
  512. background-color: #FFFFFF;
  513. }
  514. }
  515. }
  516. }
  517. /* 重新配对 */
  518. .retest-btn {
  519. text-align: center;
  520. padding: 30rpx 40rpx;
  521. font-size: 30rpx;
  522. color: #666666;
  523. background-color: #F8F8F8;
  524. border-radius: 25rpx;
  525. margin: 20rpx 20rpx 30rpx 20rpx;
  526. border: 2rpx solid #E0E0E0;
  527. &:active {
  528. color: #E91E63;
  529. background-color: #FFF0F5;
  530. border-color: #E91E63;
  531. }
  532. }
  533. /* 数据来源说明 */
  534. .data-source {
  535. display: flex;
  536. align-items: center;
  537. background-color: #E3F2FD;
  538. border-radius: 20rpx;
  539. padding: 25rpx 30rpx;
  540. margin-bottom: 30rpx;
  541. transition: all 0.3s;
  542. .source-icon {
  543. font-size: 32rpx;
  544. margin-right: 15rpx;
  545. }
  546. .source-content {
  547. flex: 1;
  548. display: flex;
  549. flex-direction: column;
  550. gap: 8rpx;
  551. .source-text {
  552. font-size: 28rpx;
  553. color: #1976D2;
  554. font-weight: 500;
  555. }
  556. .source-time {
  557. font-size: 24rpx;
  558. color: #64B5F6;
  559. }
  560. }
  561. // API数据特殊样式
  562. &.api-source {
  563. background: linear-gradient(135deg, #E8F5E9 0%, #C8E6C9 100%);
  564. border-left: 6rpx solid #4CAF50;
  565. .source-icon {
  566. color: #4CAF50;
  567. }
  568. .source-text {
  569. color: #2E7D32;
  570. }
  571. .source-time {
  572. color: #66BB6A;
  573. }
  574. }
  575. }
  576. /* 免责声明 */
  577. .disclaimer {
  578. background-color: #FFF3E0;
  579. border-radius: 20rpx;
  580. padding: 30rpx;
  581. border-left: 6rpx solid #FF9800;
  582. margin: 0 10rpx;
  583. .disclaimer-title {
  584. font-size: 30rpx;
  585. font-weight: 600;
  586. color: #F57C00;
  587. margin-bottom: 20rpx;
  588. }
  589. .disclaimer-text {
  590. font-size: 26rpx;
  591. color: #666666;
  592. line-height: 2.0;
  593. text-align: justify;
  594. }
  595. }
  596. /* 底部占位 */
  597. .bottom-placeholder {
  598. height: 60rpx;
  599. }
  600. </style>