zodiac.vue 17 KB

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