constellation.js 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254
  1. /**
  2. * 星座相关工具函数
  3. */
  4. import { TIANAPI_CONFIG } from '@/config/api-config.js'
  5. // 十二星座数据
  6. export const CONSTELLATIONS = [
  7. {
  8. name: '白羊座',
  9. emoji: '♈',
  10. period: '3.21-4.19',
  11. element: '火象',
  12. ruler: '火星',
  13. description: '热情勇敢的火象星座',
  14. traits: ['勇敢', '热情', '积极'],
  15. personality: '热情洋溢,勇敢直率,富有冒险精神',
  16. loveStyle: '主动热情,喜欢浪漫刺激的恋爱',
  17. luckyColor: '红色',
  18. luckyNumber: [1, 3, 9],
  19. compatibility: {
  20. best: ['狮子座', '射手座', '双子座'],
  21. good: ['水瓶座', '天秤座'],
  22. avoid: ['巨蟹座', '摩羯座']
  23. }
  24. },
  25. {
  26. name: '金牛座',
  27. emoji: '♉',
  28. period: '4.20-5.20',
  29. element: '土象',
  30. ruler: '金星',
  31. description: '稳重踏实的土象星座',
  32. traits: ['稳重', '务实', '固执'],
  33. personality: '踏实稳重,勤劳努力,值得信赖',
  34. loveStyle: '专一深情,默默付出',
  35. luckyColor: '绿色',
  36. luckyNumber: [2, 6, 18],
  37. compatibility: {
  38. best: ['处女座', '摩羯座', '巨蟹座'],
  39. good: ['双鱼座', '天蝎座'],
  40. avoid: ['狮子座', '水瓶座']
  41. }
  42. },
  43. {
  44. name: '双子座',
  45. emoji: '♊',
  46. period: '5.21-6.21',
  47. element: '风象',
  48. ruler: '水星',
  49. description: '机智灵活的风象星座',
  50. traits: ['机智', '多变', '好奇'],
  51. personality: '机智灵活,好奇心强,善于沟通交流',
  52. loveStyle: '喜欢有趣的恋爱关系,注重精神交流',
  53. luckyColor: '黄色',
  54. luckyNumber: [3, 5, 14],
  55. compatibility: {
  56. best: ['天秤座', '水瓶座', '白羊座'],
  57. good: ['狮子座', '射手座'],
  58. avoid: ['处女座', '双鱼座']
  59. }
  60. },
  61. {
  62. name: '巨蟹座',
  63. emoji: '♋',
  64. period: '6.22-7.22',
  65. element: '水象',
  66. ruler: '月亮',
  67. description: '温柔感性的水象星座',
  68. traits: ['温柔', '感性', '顾家'],
  69. personality: '温柔敏感,重视家庭和情感',
  70. loveStyle: '渴望稳定温馨的恋爱关系',
  71. luckyColor: '银色',
  72. luckyNumber: [2, 7, 11],
  73. compatibility: {
  74. best: ['天蝎座', '双鱼座', '金牛座'],
  75. good: ['处女座', '摩羯座'],
  76. avoid: ['白羊座', '天秤座']
  77. }
  78. },
  79. {
  80. name: '狮子座',
  81. emoji: '♌',
  82. period: '7.23-8.22',
  83. element: '火象',
  84. ruler: '太阳',
  85. description: '自信王者的火象星座',
  86. traits: ['自信', '大方', '领导'],
  87. personality: '自信大方,有王者风范',
  88. loveStyle: '在爱情中慷慨浪漫,喜欢被崇拜',
  89. luckyColor: '金色',
  90. luckyNumber: [1, 10, 19],
  91. compatibility: {
  92. best: ['白羊座', '射手座', '双子座'],
  93. good: ['天秤座', '水瓶座'],
  94. avoid: ['金牛座', '天蝎座']
  95. }
  96. },
  97. {
  98. name: '处女座',
  99. emoji: '♍',
  100. period: '8.23-9.22',
  101. element: '土象',
  102. ruler: '水星',
  103. description: '完美主义的土象星座',
  104. traits: ['完美', '细致', '挑剔'],
  105. personality: '追求完美,注重细节',
  106. loveStyle: '在感情中谨慎细心,默默关心',
  107. luckyColor: '蓝色',
  108. luckyNumber: [3, 6, 15],
  109. compatibility: {
  110. best: ['金牛座', '摩羯座', '巨蟹座'],
  111. good: ['天蝎座', '双鱼座'],
  112. avoid: ['双子座', '射手座']
  113. }
  114. },
  115. {
  116. name: '天秤座',
  117. emoji: '♎',
  118. period: '9.23-10.23',
  119. element: '风象',
  120. ruler: '金星',
  121. description: '优雅和谐的风象星座',
  122. traits: ['优雅', '和谐', '犹豫'],
  123. personality: '追求和谐平衡,有优雅的品味',
  124. loveStyle: '渴望和谐美好的爱情,重视精神契合',
  125. luckyColor: '粉色',
  126. luckyNumber: [6, 9, 24],
  127. compatibility: {
  128. best: ['双子座', '水瓶座', '狮子座'],
  129. good: ['白羊座', '射手座'],
  130. avoid: ['巨蟹座', '摩羯座']
  131. }
  132. },
  133. {
  134. name: '天蝎座',
  135. emoji: '♏',
  136. period: '10.24-11.22',
  137. element: '水象',
  138. ruler: '冥王星',
  139. description: '神秘深刻的水象星座',
  140. traits: ['神秘', '专注', '极端'],
  141. personality: '神秘深刻,意志坚强',
  142. loveStyle: '在感情中专一深情,爱恨分明',
  143. luckyColor: '深红色',
  144. luckyNumber: [4, 8, 13],
  145. compatibility: {
  146. best: ['巨蟹座', '双鱼座', '处女座'],
  147. good: ['金牛座', '摩羯座'],
  148. avoid: ['狮子座', '水瓶座']
  149. }
  150. },
  151. {
  152. name: '射手座',
  153. emoji: '♐',
  154. period: '11.23-12.21',
  155. element: '火象',
  156. ruler: '木星',
  157. description: '自由奔放的火象星座',
  158. traits: ['自由', '乐观', '直率'],
  159. personality: '自由奔放,乐观开朗',
  160. loveStyle: '在感情中追求自由和刺激',
  161. luckyColor: '紫色',
  162. luckyNumber: [3, 9, 21],
  163. compatibility: {
  164. best: ['白羊座', '狮子座', '水瓶座'],
  165. good: ['双子座', '天秤座'],
  166. avoid: ['处女座', '双鱼座']
  167. }
  168. },
  169. {
  170. name: '摩羯座',
  171. emoji: '♑',
  172. period: '12.22-1.19',
  173. element: '土象',
  174. ruler: '土星',
  175. description: '踏实上进的土象星座',
  176. traits: ['踏实', '上进', '保守'],
  177. personality: '踏实上进,有强烈的责任感',
  178. loveStyle: '在感情中谨慎稳重,注重长期发展',
  179. luckyColor: '棕色',
  180. luckyNumber: [8, 10, 26],
  181. compatibility: {
  182. best: ['金牛座', '处女座', '天蝎座'],
  183. good: ['巨蟹座', '双鱼座'],
  184. avoid: ['白羊座', '天秤座']
  185. }
  186. },
  187. {
  188. name: '水瓶座',
  189. emoji: '♒',
  190. period: '1.20-2.18',
  191. element: '风象',
  192. ruler: '天王星',
  193. description: '创新独立的风象星座',
  194. traits: ['创新', '独立', '理性'],
  195. personality: '独立创新,有人道主义精神',
  196. loveStyle: '在感情中追求精神层面的交流',
  197. luckyColor: '蓝紫色',
  198. luckyNumber: [4, 7, 22],
  199. compatibility: {
  200. best: ['双子座', '天秤座', '射手座'],
  201. good: ['白羊座', '狮子座'],
  202. avoid: ['金牛座', '天蝎座']
  203. }
  204. },
  205. {
  206. name: '双鱼座',
  207. emoji: '♓',
  208. period: '2.19-3.20',
  209. element: '水象',
  210. ruler: '海王星',
  211. description: '浪漫梦幻的水象星座',
  212. traits: ['浪漫', '梦幻', '敏感'],
  213. personality: '浪漫梦幻,富有同情心',
  214. loveStyle: '在感情中浪漫理想,渴望童话般的爱情',
  215. luckyColor: '海蓝色',
  216. luckyNumber: [5, 12, 29],
  217. compatibility: {
  218. best: ['巨蟹座', '天蝎座', '摩羯座'],
  219. good: ['金牛座', '处女座'],
  220. avoid: ['双子座', '射手座']
  221. }
  222. }
  223. ]
  224. /**
  225. * 根据星座名称获取星座信息
  226. * @param {String} constellationName 星座名称
  227. * @returns {Object} 星座信息对象
  228. */
  229. export function getConstellationInfo(constellationName) {
  230. return CONSTELLATIONS.find(c => c.name === constellationName) || null
  231. }
  232. /**
  233. * 根据星座名称获取星座emoji
  234. * @param {String} constellationName 星座名称
  235. * @returns {String} 星座emoji
  236. */
  237. export function getConstellationEmoji(constellationName) {
  238. const constellation = getConstellationInfo(constellationName)
  239. return constellation ? constellation.emoji : '⭐'
  240. }
  241. /**
  242. * 获取所有星座列表
  243. * @returns {Array} 星座列表
  244. */
  245. export function getAllConstellations() {
  246. return CONSTELLATIONS
  247. }
  248. /**
  249. * 调用天行数据API获取星座运势
  250. * @param {String} constellation 星座名称
  251. * @returns {Promise} API返回结果
  252. */
  253. export async function getConstellationFortuneFromAPI(constellation) {
  254. try {
  255. console.log('🔍 尝试调用天行数据星座运势API')
  256. console.log('星座:', constellation)
  257. console.log('API Key:', TIANAPI_CONFIG.API_KEY ? `${TIANAPI_CONFIG.API_KEY.slice(0, 8)}...` : '未配置')
  258. if (!TIANAPI_CONFIG.API_KEY) {
  259. console.log('⚠️ API Key未配置,使用本地数据')
  260. return null
  261. }
  262. // 检查是否为示例Key
  263. if (TIANAPI_CONFIG.API_KEY === '23e38be1fddb7c6aee4ea3e4294c6b4a') {
  264. console.log('⚠️ 检测到示例API Key,尝试调用(可能会失败)')
  265. console.log('💡 请到 https://www.tianapi.com 申请真实的API Key')
  266. }
  267. // 星座名称映射 (天行数据可能需要英文或特定格式)
  268. const constellationMap = {
  269. '白羊座': 'aries',
  270. '金牛座': 'taurus',
  271. '双子座': 'gemini',
  272. '巨蟹座': 'cancer',
  273. '狮子座': 'leo',
  274. '处女座': 'virgo',
  275. '天秤座': 'libra',
  276. '天蝎座': 'scorpio',
  277. '射手座': 'sagittarius',
  278. '摩羯座': 'capricorn',
  279. '水瓶座': 'aquarius',
  280. '双鱼座': 'pisces'
  281. }
  282. const englishName = constellationMap[constellation]
  283. if (!englishName) {
  284. console.log('❌ 星座名称映射失败:', constellation)
  285. return null
  286. }
  287. const url = `${TIANAPI_CONFIG.BASE_URL}${TIANAPI_CONFIG.ENDPOINTS.constellation}`
  288. const params = {
  289. key: TIANAPI_CONFIG.API_KEY,
  290. astro: englishName
  291. }
  292. console.log('📡 API请求地址:', url)
  293. console.log('📡 请求参数:', { ...params, key: params.key ? `${params.key.slice(0, 8)}...` : '未设置' })
  294. const response = await new Promise((resolve, reject) => {
  295. uni.request({
  296. url: url,
  297. data: params,
  298. method: 'GET',
  299. timeout: 10000,
  300. success: (res) => {
  301. console.log('📡 API响应状态:', res.statusCode)
  302. console.log('📡 API响应数据:', res.data)
  303. resolve(res)
  304. },
  305. fail: (err) => {
  306. console.error('📡 API请求失败:', err)
  307. reject(err)
  308. }
  309. })
  310. })
  311. console.log('✅ 请求完成,状态码:', response.statusCode)
  312. if (response.statusCode === 200 && response.data && response.data.code === 200) {
  313. const result = response.data.result
  314. if (result && result.list && result.list.length > 0) {
  315. console.log('✅ 成功获取API星座运势数据')
  316. // 解析天行数据API返回的格式
  317. const apiData = {}
  318. result.list.forEach(item => {
  319. switch(item.type) {
  320. case '综合指数':
  321. apiData.overall = parseInt(item.content) || 80
  322. break
  323. case '爱情指数':
  324. apiData.love = parseInt(item.content) || 75
  325. break
  326. case '事业指数':
  327. apiData.career = parseInt(item.content) || 78
  328. break
  329. case '财运指数':
  330. apiData.wealth = parseInt(item.content) || 72
  331. break
  332. case '健康指数':
  333. apiData.health = parseInt(item.content) || 80
  334. break
  335. case '今日概述':
  336. apiData.advice = item.content || '今天是美好的一天!'
  337. break
  338. }
  339. })
  340. return {
  341. overall: apiData.overall || 80,
  342. love: apiData.love || 75,
  343. career: apiData.career || 78,
  344. wealth: apiData.wealth || 72,
  345. health: apiData.health || 80,
  346. advice: apiData.advice || '今天是美好的一天,保持积极心态!',
  347. level: apiData.overall >= 90 ? '超棒' : apiData.overall >= 80 ? '极佳' : apiData.overall >= 70 ? '良好' : '一般',
  348. levelColor: apiData.overall >= 90 ? 'linear-gradient(135deg, #FF6B6B 0%, #FF8E53 100%)' :
  349. apiData.overall >= 80 ? 'linear-gradient(135deg, #4CAF50 0%, #81C784 100%)' :
  350. apiData.overall >= 70 ? 'linear-gradient(135deg, #2196F3 0%, #64B5F6 100%)' :
  351. 'linear-gradient(135deg, #9E9E9E 0%, #BDBDBD 100%)',
  352. source: 'tianapi',
  353. dataFrom: '天行数据专业API',
  354. updateTime: new Date().toLocaleString('zh-CN')
  355. }
  356. }
  357. }
  358. console.log('⚠️ API返回数据格式异常,使用本地数据')
  359. return null
  360. } catch (error) {
  361. console.error('❌ 星座运势API调用异常:', error)
  362. console.log('🔄 降级到本地数据')
  363. return null
  364. }
  365. }
  366. /**
  367. * 生成本地星座运势数据
  368. * @param {String} constellation 星座名称
  369. * @returns {Object} 运势数据
  370. */
  371. export function generateLocalConstellationFortune(constellation) {
  372. const constellationInfo = getConstellationInfo(constellation)
  373. if (!constellationInfo) {
  374. return null
  375. }
  376. // 生成随机分数
  377. const scores = {
  378. overall: Math.floor(Math.random() * 30) + 70,
  379. love: Math.floor(Math.random() * 40) + 60,
  380. career: Math.floor(Math.random() * 40) + 60,
  381. wealth: Math.floor(Math.random() * 40) + 60,
  382. health: Math.floor(Math.random() * 40) + 60
  383. }
  384. // 根据分数确定等级
  385. const levels = ['一般', '良好', '极佳', '超棒']
  386. const levelColors = [
  387. 'linear-gradient(135deg, #9E9E9E 0%, #BDBDBD 100%)',
  388. 'linear-gradient(135deg, #2196F3 0%, #64B5F6 100%)',
  389. 'linear-gradient(135deg, #4CAF50 0%, #81C784 100%)',
  390. 'linear-gradient(135deg, #FF6B6B 0%, #FF8E53 100%)'
  391. ]
  392. const levelIndex = Math.floor(scores.overall / 25)
  393. const level = levels[Math.min(levelIndex, levels.length - 1)]
  394. const levelColor = levelColors[Math.min(levelIndex, levelColors.length - 1)]
  395. // 根据星座特性生成建议
  396. const adviceTemplates = {
  397. '白羊座': [
  398. '今天是展现你勇敢本色的好时机,不要害怕迎接挑战!',
  399. '你的热情感染着周围的人,保持这种积极的能量。',
  400. '适合主动出击,在爱情或事业上都有不错的机会。'
  401. ],
  402. '金牛座': [
  403. '稳扎稳打是你的优势,今天坚持自己的节奏就好。',
  404. '财运不错,但要避免冲动消费,理性规划更重要。',
  405. '感情方面需要多一些耐心,真诚的付出会有回报。'
  406. ],
  407. '双子座': [
  408. '你的机智和幽默感今天特别受欢迎,多与人交流。',
  409. '适合学习新知识或尝试新事物,保持好奇心。',
  410. '在沟通中要注意表达的准确性,避免误解。'
  411. ],
  412. '巨蟹座': [
  413. '今天的直觉特别准确,相信自己的第一感觉。',
  414. '家庭和感情是你的能量源泉,多花时间陪伴亲人。',
  415. '情绪起伏较大时,找个安静的地方调整心情。'
  416. ],
  417. '狮子座': [
  418. '你的魅力今天格外闪耀,是展现自己的好时机。',
  419. '领导才能得到认可,但要注意倾听他人的意见。',
  420. '在感情中保持大方和真诚,会收获意想不到的惊喜。'
  421. ],
  422. '处女座': [
  423. '细致入微的工作态度为你赢得好评,继续保持。',
  424. '今天适合整理和规划,让生活更有条理。',
  425. '对自己不要过于苛刻,适当放松也很重要。'
  426. ],
  427. '天秤座': [
  428. '你的协调能力今天特别突出,可以化解不少矛盾。',
  429. '在美的事物上有不错的眼光,适合艺术相关活动。',
  430. '做决定时不要过于犹豫,相信自己的判断。'
  431. ],
  432. '天蝎座': [
  433. '你的洞察力今天特别敏锐,能看透事物的本质。',
  434. '在感情中要学会适度表达,不要把所有感受都埋在心里。',
  435. '专注力很强,适合处理复杂或需要深度思考的事务。'
  436. ],
  437. '射手座': [
  438. '自由和冒险的心情高涨,可以计划一次小旅行。',
  439. '乐观的态度感染着周围的人,继续传播正能量。',
  440. '在学习和探索新领域方面会有不错的收获。'
  441. ],
  442. '摩羯座': [
  443. '踏实的努力今天会看到成果,坚持就是胜利。',
  444. '在职场上的表现得到认可,但不要忘记劳逸结合。',
  445. '感情需要更多的浪漫元素,偶尔打破常规很有必要。'
  446. ],
  447. '水瓶座': [
  448. '创新的想法今天特别多,不妨记录下来慢慢实践。',
  449. '朋友圈中你是重要的智慧来源,多分享你的见解。',
  450. '在感情中要学会表达真实的感受,不要过于理性。'
  451. ],
  452. '双鱼座': [
  453. '艺术创作灵感爆发,可以尝试画画、写作或音乐。',
  454. '同情心让你成为朋友们的倾诉对象,但也要保护好自己。',
  455. '直觉和梦境可能给你重要的启示,多留意。'
  456. ]
  457. }
  458. const advice = adviceTemplates[constellation] || ['今天是美好的一天,保持积极心态!']
  459. const selectedAdvice = advice[Math.floor(Math.random() * advice.length)]
  460. return {
  461. constellation: constellation,
  462. date: new Date().toLocaleDateString('zh-CN'),
  463. overall: scores.overall,
  464. level: level,
  465. levelColor: levelColor,
  466. love: scores.love,
  467. career: scores.career,
  468. wealth: scores.wealth,
  469. health: scores.health,
  470. advice: selectedAdvice,
  471. luckyColor: constellationInfo.luckyColor,
  472. luckyNumber: constellationInfo.luckyNumber[Math.floor(Math.random() * constellationInfo.luckyNumber.length)],
  473. source: 'local',
  474. dataFrom: '星座占星学理论',
  475. updateTime: new Date().toLocaleString('zh-CN')
  476. }
  477. }
  478. /**
  479. * 获取星座运势(优先API,失败时使用本地数据)
  480. * @param {String} constellation 星座名称
  481. * @returns {Promise<Object>} 运势数据
  482. */
  483. export async function getConstellationFortune(constellation) {
  484. try {
  485. // 尝试获取API数据
  486. const apiResult = await getConstellationFortuneFromAPI(constellation)
  487. if (apiResult) {
  488. console.log('✅ 使用API星座运势数据')
  489. return apiResult
  490. }
  491. // API失败,使用本地数据
  492. console.log('🔄 使用本地星座运势数据')
  493. return generateLocalConstellationFortune(constellation)
  494. } catch (error) {
  495. console.error('❌ 获取星座运势异常:', error)
  496. // 异常情况下也使用本地数据
  497. return generateLocalConstellationFortune(constellation)
  498. }
  499. }
  500. /**
  501. * 生成星座匹配数据
  502. * @param {String} constellation 星座名称
  503. * @returns {Object} 匹配数据
  504. */
  505. export function generateConstellationMatch(constellation) {
  506. const constellationInfo = getConstellationInfo(constellation)
  507. if (!constellationInfo) {
  508. return { best: [], good: [] }
  509. }
  510. return {
  511. best: constellationInfo.compatibility.best.map(name => {
  512. const matchInfo = getConstellationInfo(name)
  513. return {
  514. name: name,
  515. emoji: matchInfo?.emoji || '⭐',
  516. score: Math.floor(Math.random() * 10) + 90
  517. }
  518. }),
  519. good: constellationInfo.compatibility.good.map(name => {
  520. const matchInfo = getConstellationInfo(name)
  521. return {
  522. name: name,
  523. emoji: matchInfo?.emoji || '⭐',
  524. score: Math.floor(Math.random() * 15) + 75
  525. }
  526. })
  527. }
  528. }
  529. /**
  530. * 调用天行数据API获取星座配对分析
  531. * @param {String} constellation1 第一个星座名称
  532. * @param {String} constellation2 第二个星座名称
  533. * @returns {Promise<Object>} API返回结果
  534. */
  535. export async function getConstellationMatchFromAPI(constellation1, constellation2) {
  536. try {
  537. console.log('🔍 尝试调用天行数据星座配对API')
  538. console.log('星座1:', constellation1, '星座2:', constellation2)
  539. console.log('API Key:', TIANAPI_CONFIG.API_KEY ? `${TIANAPI_CONFIG.API_KEY.slice(0, 8)}...` : '未配置')
  540. if (!TIANAPI_CONFIG.API_KEY) {
  541. console.log('⚠️ API Key未配置,使用本地数据')
  542. return null
  543. }
  544. // 检查是否为示例Key
  545. if (TIANAPI_CONFIG.API_KEY === '23e38be1fddb7c6aee4ea3e4294c6b4a') {
  546. console.log('⚠️ 检测到示例API Key,尝试调用(可能会失败)')
  547. console.log('💡 请到 https://www.tianapi.com 申请真实的API Key')
  548. }
  549. // 星座名称处理(去掉"座"字)
  550. const me = constellation1.replace('座', '')
  551. const he = constellation2.replace('座', '')
  552. const url = `${TIANAPI_CONFIG.BASE_URL}${TIANAPI_CONFIG.ENDPOINTS.constellationMatch}`
  553. const params = {
  554. key: TIANAPI_CONFIG.API_KEY,
  555. me: me,
  556. he: he
  557. }
  558. console.log('📡 API请求地址:', url)
  559. console.log('📡 请求参数:', { ...params, key: params.key ? `${params.key.slice(0, 8)}...` : '未设置' })
  560. const response = await new Promise((resolve, reject) => {
  561. uni.request({
  562. url: url,
  563. data: params,
  564. method: 'GET',
  565. timeout: 10000,
  566. success: (res) => {
  567. console.log('📡 API响应状态:', res.statusCode)
  568. console.log('📡 API响应数据:', res.data)
  569. resolve(res)
  570. },
  571. fail: (err) => {
  572. console.error('📡 API请求失败:', err)
  573. reject(err)
  574. }
  575. })
  576. })
  577. console.log('✅ 请求完成,状态码:', response.statusCode)
  578. if (response.statusCode === 200 && response.data && response.data.code === 200) {
  579. const result = response.data.result
  580. if (result && (result.title || result.content)) {
  581. console.log('✅ 成功获取API星座配对数据')
  582. // 解析天行数据API返回的格式
  583. return {
  584. title: result.title || `${constellation1}×${constellation2}`,
  585. grade: result.grade || '',
  586. content: result.content || '',
  587. source: 'tianapi',
  588. dataFrom: '天行数据专业API',
  589. updateTime: new Date().toLocaleString('zh-CN'),
  590. apiData: result
  591. }
  592. }
  593. }
  594. console.log('⚠️ API返回数据格式异常,使用本地数据')
  595. return null
  596. } catch (error) {
  597. console.error('❌ 星座配对API调用异常:', error)
  598. console.log('🔄 降级到本地数据')
  599. return null
  600. }
  601. }
  602. /**
  603. * 计算两个星座的详细配对分析(优先API,失败时使用本地数据)
  604. * @param {String} constellation1 第一个星座名称
  605. * @param {String} constellation2 第二个星座名称
  606. * @returns {Promise<Object>} 详细配对分析结果
  607. */
  608. export async function getDetailedConstellationMatch(constellation1, constellation2) {
  609. try {
  610. // 尝试获取API数据
  611. const apiResult = await getConstellationMatchFromAPI(constellation1, constellation2)
  612. if (apiResult) {
  613. console.log('✅ 使用API星座配对数据')
  614. // 将API数据转换为统一格式
  615. return convertAPIDataToStandardFormat(constellation1, constellation2, apiResult)
  616. }
  617. // API失败,使用本地数据
  618. console.log('🔄 使用本地星座配对数据')
  619. return getLocalConstellationMatch(constellation1, constellation2)
  620. } catch (error) {
  621. console.error('❌ 获取星座配对异常:', error)
  622. // 异常情况下也使用本地数据
  623. return getLocalConstellationMatch(constellation1, constellation2)
  624. }
  625. }
  626. /**
  627. * 将API数据转换为标准格式
  628. * @param {String} constellation1 第一个星座名称
  629. * @param {String} constellation2 第二个星座名称
  630. * @param {Object} apiResult API返回数据
  631. * @returns {Object} 标准格式的配对分析
  632. */
  633. function convertAPIDataToStandardFormat(constellation1, constellation2, apiResult) {
  634. const info1 = getConstellationInfo(constellation1)
  635. const info2 = getConstellationInfo(constellation2)
  636. // 从API的grade字段解析分数
  637. let totalScore = 75 // 默认分数
  638. if (apiResult.grade) {
  639. // 解析 "友情:★★ 爱情:★★★ 婚姻:★★ 亲情:★★" 格式
  640. const loveMatch = apiResult.grade.match(/爱情:(★+)/)
  641. if (loveMatch) {
  642. const stars = loveMatch[1].length
  643. totalScore = Math.min(50 + stars * 10, 100) // 1-5颗星对应60-100分
  644. }
  645. }
  646. // 确定等级和颜色
  647. let level, levelColor, scoreColor
  648. if (totalScore >= 90) {
  649. level = '天作之合'
  650. levelColor = 'linear-gradient(135deg, #FF6B9D 0%, #FFA5C6 100%)'
  651. scoreColor = 'linear-gradient(135deg, #FF6B9D 0%, #FFA5C6 100%)'
  652. } else if (totalScore >= 80) {
  653. level = '非常匹配'
  654. levelColor = 'linear-gradient(135deg, #4CAF50 0%, #81C784 100%)'
  655. scoreColor = 'linear-gradient(135deg, #4CAF50 0%, #81C784 100%)'
  656. } else if (totalScore >= 70) {
  657. level = '比较合适'
  658. levelColor = 'linear-gradient(135deg, #2196F3 0%, #64B5F6 100%)'
  659. scoreColor = 'linear-gradient(135deg, #2196F3 0%, #64B5F6 100%)'
  660. } else if (totalScore >= 60) {
  661. level = '需要努力'
  662. levelColor = 'linear-gradient(135deg, #FF9800 0%, #FFB74D 100%)'
  663. scoreColor = 'linear-gradient(135deg, #FF9800 0%, #FFB74D 100%)'
  664. } else {
  665. level = '挑战较大'
  666. levelColor = 'linear-gradient(135deg, #9E9E9E 0%, #BDBDBD 100%)'
  667. scoreColor = 'linear-gradient(135deg, #9E9E9E 0%, #BDBDBD 100%)'
  668. }
  669. // 生成本地分析作为补充
  670. const localAnalysis = generateConstellationAnalysis(info1, info2, { total: totalScore })
  671. return {
  672. constellation1: constellation1,
  673. constellation2: constellation2,
  674. totalScore: totalScore,
  675. level: level,
  676. levelColor: levelColor,
  677. scoreColor: scoreColor,
  678. title: apiResult.title || `${constellation1}×${constellation2}`,
  679. apiGrade: apiResult.grade || '',
  680. apiContent: apiResult.content || '',
  681. elementCompatibility: localAnalysis.elementCompatibility,
  682. personalityMatch: localAnalysis.personalityMatch,
  683. advantages: apiResult.content || localAnalysis.advantages,
  684. challenges: localAnalysis.challenges,
  685. suggestions: localAnalysis.suggestions,
  686. lovePrediction: localAnalysis.lovePrediction,
  687. source: 'tianapi',
  688. dataFrom: '天行数据专业API + 本地分析',
  689. updateTime: apiResult.updateTime
  690. }
  691. }
  692. /**
  693. * 获取本地星座配对分析
  694. * @param {String} constellation1 第一个星座名称
  695. * @param {String} constellation2 第二个星座名称
  696. * @returns {Object} 本地配对分析结果
  697. */
  698. function getLocalConstellationMatch(constellation1, constellation2) {
  699. const info1 = getConstellationInfo(constellation1)
  700. const info2 = getConstellationInfo(constellation2)
  701. if (!info1 || !info2) {
  702. return null
  703. }
  704. // 计算基础匹配度
  705. const compatibilityScore = calculateConstellationCompatibility(info1, info2)
  706. // 生成详细分析
  707. const analysis = generateConstellationAnalysis(info1, info2, compatibilityScore)
  708. return {
  709. constellation1: constellation1,
  710. constellation2: constellation2,
  711. totalScore: compatibilityScore.total,
  712. level: compatibilityScore.level,
  713. levelColor: compatibilityScore.levelColor,
  714. scoreColor: compatibilityScore.scoreColor,
  715. elementCompatibility: analysis.elementCompatibility,
  716. personalityMatch: analysis.personalityMatch,
  717. advantages: analysis.advantages,
  718. challenges: analysis.challenges,
  719. suggestions: analysis.suggestions,
  720. lovePrediction: analysis.lovePrediction,
  721. source: 'local',
  722. dataFrom: '星座占星学理论',
  723. updateTime: new Date().toLocaleString('zh-CN')
  724. }
  725. }
  726. /**
  727. * 计算星座配对得分
  728. * @param {Object} info1 第一个星座信息
  729. * @param {Object} info2 第二个星座信息
  730. * @returns {Object} 配对得分详情
  731. */
  732. function calculateConstellationCompatibility(info1, info2) {
  733. // 元素相容性得分 (30%)
  734. const elementScore = getElementCompatibilityScore(info1.element, info2.element)
  735. // 传统配对得分 (40%)
  736. const traditionalScore = getTraditionalMatchScore(info1, info2)
  737. // 性格互补得分 (30%)
  738. const personalityScore = getPersonalityCompatibilityScore(info1, info2)
  739. // 综合计算
  740. const total = Math.round(
  741. elementScore * 0.3 +
  742. traditionalScore * 0.4 +
  743. personalityScore * 0.3
  744. )
  745. // 确定等级和颜色
  746. let level, levelColor, scoreColor
  747. if (total >= 90) {
  748. level = '天作之合'
  749. levelColor = 'linear-gradient(135deg, #FF6B9D 0%, #FFA5C6 100%)'
  750. scoreColor = 'linear-gradient(135deg, #FF6B9D 0%, #FFA5C6 100%)'
  751. } else if (total >= 80) {
  752. level = '非常匹配'
  753. levelColor = 'linear-gradient(135deg, #4CAF50 0%, #81C784 100%)'
  754. scoreColor = 'linear-gradient(135deg, #4CAF50 0%, #81C784 100%)'
  755. } else if (total >= 70) {
  756. level = '比较合适'
  757. levelColor = 'linear-gradient(135deg, #2196F3 0%, #64B5F6 100%)'
  758. scoreColor = 'linear-gradient(135deg, #2196F3 0%, #64B5F6 100%)'
  759. } else if (total >= 60) {
  760. level = '需要努力'
  761. levelColor = 'linear-gradient(135deg, #FF9800 0%, #FFB74D 100%)'
  762. scoreColor = 'linear-gradient(135deg, #FF9800 0%, #FFB74D 100%)'
  763. } else {
  764. level = '挑战较大'
  765. levelColor = 'linear-gradient(135deg, #9E9E9E 0%, #BDBDBD 100%)'
  766. scoreColor = 'linear-gradient(135deg, #9E9E9E 0%, #BDBDBD 100%)'
  767. }
  768. return {
  769. total,
  770. level,
  771. levelColor,
  772. scoreColor,
  773. elementScore,
  774. traditionalScore,
  775. personalityScore
  776. }
  777. }
  778. /**
  779. * 获取元素相容性得分
  780. * @param {String} element1 第一个元素
  781. * @param {String} element2 第二个元素
  782. * @returns {Number} 相容性得分
  783. */
  784. function getElementCompatibilityScore(element1, element2) {
  785. const compatibilityMatrix = {
  786. '火象': { '火象': 85, '土象': 65, '风象': 90, '水象': 45 },
  787. '土象': { '火象': 65, '土象': 80, '风象': 55, '水象': 95 },
  788. '风象': { '火象': 90, '土象': 55, '风象': 75, '水象': 70 },
  789. '水象': { '火象': 45, '土象': 95, '风象': 70, '水象': 85 }
  790. }
  791. return compatibilityMatrix[element1]?.[element2] || 70
  792. }
  793. /**
  794. * 获取传统配对得分
  795. * @param {Object} info1 第一个星座信息
  796. * @param {Object} info2 第二个星座信息
  797. * @returns {Number} 传统配对得分
  798. */
  799. function getTraditionalMatchScore(info1, info2) {
  800. let score1 = 70, score2 = 70
  801. // 双向检查配对关系
  802. if (info1.compatibility.best.includes(info2.name)) score1 = 95
  803. else if (info1.compatibility.good.includes(info2.name)) score1 = 80
  804. else if (info1.compatibility.avoid.includes(info2.name)) score1 = 50
  805. if (info2.compatibility.best.includes(info1.name)) score2 = 95
  806. else if (info2.compatibility.good.includes(info1.name)) score2 = 80
  807. else if (info2.compatibility.avoid.includes(info1.name)) score2 = 50
  808. return Math.round((score1 + score2) / 2)
  809. }
  810. /**
  811. * 获取性格相容性得分
  812. * @param {Object} info1 第一个星座信息
  813. * @param {Object} info2 第二个星座信息
  814. * @returns {Number} 性格相容性得分
  815. */
  816. function getPersonalityCompatibilityScore(info1, info2) {
  817. // 检查共同特质
  818. const commonTraits = info1.traits.filter(trait => info2.traits.includes(trait))
  819. const commonTraitsScore = commonTraits.length * 15
  820. // 检查互补特质
  821. const complementaryPairs = [
  822. ['勇敢', '温柔'], ['热情', '稳重'], ['积极', '细致'],
  823. ['自信', '谦逊'], ['领导', '支持'], ['创新', '传统']
  824. ]
  825. let complementaryScore = 0
  826. complementaryPairs.forEach(pair => {
  827. if ((info1.traits.includes(pair[0]) && info2.traits.includes(pair[1])) ||
  828. (info1.traits.includes(pair[1]) && info2.traits.includes(pair[0]))) {
  829. complementaryScore += 10
  830. }
  831. })
  832. return Math.min(60 + commonTraitsScore + complementaryScore, 100)
  833. }
  834. /**
  835. * 生成星座配对分析
  836. * @param {Object} info1 第一个星座信息
  837. * @param {Object} info2 第二个星座信息
  838. * @param {Object} compatibilityScore 配对得分
  839. * @returns {Object} 配对分析
  840. */
  841. function generateConstellationAnalysis(info1, info2, compatibilityScore) {
  842. const element1 = info1.element
  843. const element2 = info2.element
  844. const totalScore = compatibilityScore.total
  845. // 元素相容性分析
  846. const elementCompatibility = getElementCompatibilityAnalysis(element1, element2)
  847. // 性格匹配分析
  848. const personalityMatch = getPersonalityMatchAnalysis(info1, info2)
  849. // 优势分析
  850. const advantages = generateAdvantagesAnalysis(info1, info2, element1, element2)
  851. // 挑战分析
  852. const challenges = generateChallengesAnalysis(info1, info2, element1, element2)
  853. // 建议分析
  854. const suggestions = generateSuggestionsAnalysis(info1, info2, totalScore)
  855. // 爱情预测
  856. const lovePrediction = generateLovePredictionData(totalScore)
  857. return {
  858. elementCompatibility,
  859. personalityMatch,
  860. advantages,
  861. challenges,
  862. suggestions,
  863. lovePrediction
  864. }
  865. }
  866. /**
  867. * 获取元素相容性分析
  868. * @param {String} element1 第一个元素
  869. * @param {String} element2 第二个元素
  870. * @returns {String} 元素相容性分析
  871. */
  872. function getElementCompatibilityAnalysis(element1, element2) {
  873. const analyses = {
  874. '火象火象': '同为火象星座,你们都充满激情和活力,能够互相理解对方的冲动和热情,但也要注意避免过度竞争。',
  875. '火象土象': '火象的激情与土象的稳重形成有趣的对比,火象能激发土象的活力,土象能稳定火象的冲动。',
  876. '火象风象': '火象与风象的结合如同火遇风,能够互相激发,创造出更大的能量和无限的可能性。',
  877. '火象水象': '火象与水象的组合充满戏剧性,虽然差异明显,但正是这种差异创造了独特的吸引力。',
  878. '土象土象': '同为土象星座,你们都追求稳定和安全感,能够建立坚实可靠的关系基础。',
  879. '土象风象': '土象的踏实与风象的灵活形成互补,需要相互学习和适应,找到平衡点。',
  880. '土象水象': '土象与水象的组合非常和谐,既有物质基础的稳定性又有情感上的丰富性。',
  881. '风象风象': '同为风象星座,你们都重视精神交流和智慧碰撞,有着无穷无尽的话题。',
  882. '风象水象': '风象的理性与水象的感性形成有趣的平衡,能够互相学习不同的思维方式。',
  883. '水象水象': '同为水象星座,你们情感丰富敏感,能够深度理解彼此的内心世界和情感需求。'
  884. }
  885. const key = element1 + element2
  886. return analyses[key] || analyses[element2 + element1] || '你们的元素组合有着独特的化学反应,值得深入探索。'
  887. }
  888. /**
  889. * 获取性格匹配分析
  890. * @param {Object} info1 第一个星座信息
  891. * @param {Object} info2 第二个星座信息
  892. * @returns {String} 性格匹配分析
  893. */
  894. function getPersonalityMatchAnalysis(info1, info2) {
  895. const commonTraits = info1.traits.filter(trait => info2.traits.includes(trait))
  896. if (commonTraits.length >= 2) {
  897. return `你们都具有${commonTraits.join('、')}的特质,在这些方面容易产生共鸣和理解。`
  898. } else if (commonTraits.length === 1) {
  899. return `你们共同的${commonTraits[0]}特质为关系奠定了基础,其他方面的差异则增加了吸引力。`
  900. } else {
  901. return '你们的性格特质各有特色,这种差异性能够让彼此学到很多新的东西。'
  902. }
  903. }
  904. /**
  905. * 生成优势分析
  906. * @param {Object} info1 第一个星座信息
  907. * @param {Object} info2 第二个星座信息
  908. * @param {String} element1 第一个元素
  909. * @param {String} element2 第二个元素
  910. * @returns {String} 优势分析
  911. */
  912. function generateAdvantagesAnalysis(info1, info2, element1, element2) {
  913. const advantages = []
  914. // 基于元素的优势
  915. if (element1 === element2) {
  916. advantages.push('属于同一元素,在价值观和生活节奏上有天然的默契')
  917. } else if (
  918. (element1 === '火象' && element2 === '风象') ||
  919. (element1 === '风象' && element2 === '火象')
  920. ) {
  921. advantages.push('火象与风象的组合充满创意和激情,能够互相激发潜能')
  922. } else if (
  923. (element1 === '土象' && element2 === '水象') ||
  924. (element1 === '水象' && element2 === '土象')
  925. ) {
  926. advantages.push('土象与水象的结合既稳定又温馨,能够建立深厚的情感纽带')
  927. }
  928. // 基于配对关系的优势
  929. if (info1.compatibility.best.includes(info2.name)) {
  930. advantages.push('从传统占星学角度来看,你们是理想的配对组合')
  931. } else if (info1.compatibility.good.includes(info2.name)) {
  932. advantages.push('你们的星座组合在传统上被认为是和谐的搭配')
  933. }
  934. // 基于特质的优势
  935. const commonTraits = info1.traits.filter(trait => info2.traits.includes(trait))
  936. if (commonTraits.length > 0) {
  937. advantages.push(`共同的${commonTraits.join('、')}特质让你们容易理解彼此`)
  938. }
  939. return advantages.length > 0 ? advantages.join(';') : '你们的组合有着独特的魅力和潜力。'
  940. }
  941. /**
  942. * 生成挑战分析
  943. * @param {Object} info1 第一个星座信息
  944. * @param {Object} info2 第二个星座信息
  945. * @param {String} element1 第一个元素
  946. * @param {String} element2 第二个元素
  947. * @returns {String} 挑战分析
  948. */
  949. function generateChallengesAnalysis(info1, info2, element1, element2) {
  950. const challenges = []
  951. // 基于元素的挑战
  952. if (
  953. (element1 === '火象' && element2 === '水象') ||
  954. (element1 === '水象' && element2 === '火象')
  955. ) {
  956. challenges.push('火象的直接与水象的含蓄可能造成沟通上的误解')
  957. } else if (
  958. (element1 === '土象' && element2 === '风象') ||
  959. (element1 === '风象' && element2 === '土象')
  960. ) {
  961. challenges.push('土象的稳重与风象的多变可能在生活节奏上产生分歧')
  962. }
  963. // 基于避免列表的挑战
  964. if (info1.compatibility.avoid.includes(info2.name)) {
  965. challenges.push('你们的性格差异较大,需要更多的理解和包容')
  966. }
  967. // 通用挑战
  968. challenges.push('任何关系都需要双方的努力和妥协,保持开放诚实的沟通')
  969. return challenges.join(';')
  970. }
  971. /**
  972. * 生成建议分析
  973. * @param {Object} info1 第一个星座信息
  974. * @param {Object} info2 第二个星座信息
  975. * @param {Number} totalScore 总分
  976. * @returns {String} 建议分析
  977. */
  978. function generateSuggestionsAnalysis(info1, info2, totalScore) {
  979. const suggestions = []
  980. if (totalScore >= 85) {
  981. suggestions.push('你们的匹配度很高,要珍惜这份难得的缘分')
  982. } else if (totalScore >= 70) {
  983. suggestions.push('通过深入了解和有效沟通,你们的关系会更加稳固')
  984. } else {
  985. suggestions.push('虽然面临一些挑战,但只要双方都愿意努力,完全可以克服')
  986. }
  987. suggestions.push(`理解${info1.name}的${info1.loveStyle}和${info2.name}的${info2.loveStyle},互相欣赏对方的爱情观`)
  988. suggestions.push('记住,星座只是参考,真正的感情需要用心去经营和维护')
  989. return suggestions.join(';')
  990. }
  991. /**
  992. * 生成爱情预测数据
  993. * @param {Number} totalScore 总分
  994. * @returns {Array} 爱情预测数据
  995. */
  996. function generateLovePredictionData(totalScore) {
  997. const baseScore = totalScore
  998. return [
  999. {
  1000. label: '初见印象',
  1001. icon: '👀',
  1002. value: Math.min(baseScore + Math.floor(Math.random() * 10) - 5, 100) + '%',
  1003. bgColor: 'linear-gradient(135deg, #FFB6C1 0%, #FFE4E1 100%)'
  1004. },
  1005. {
  1006. label: '恋爱甜蜜度',
  1007. icon: '🍯',
  1008. value: Math.min(baseScore + Math.floor(Math.random() * 15) - 7, 100) + '%',
  1009. bgColor: 'linear-gradient(135deg, #FF6B9D 0%, #FFA5C6 100%)'
  1010. },
  1011. {
  1012. label: '长期稳定性',
  1013. icon: '🏠',
  1014. value: Math.min(baseScore + Math.floor(Math.random() * 8) - 4, 100) + '%',
  1015. bgColor: 'linear-gradient(135deg, #4CAF50 0%, #81C784 100%)'
  1016. },
  1017. {
  1018. label: '婚姻契合度',
  1019. icon: '💍',
  1020. value: Math.min(baseScore + Math.floor(Math.random() * 12) - 6, 100) + '%',
  1021. bgColor: 'linear-gradient(135deg, #9C27B0 0%, #CE93D8 100%)'
  1022. }
  1023. ]
  1024. }
  1025. /**
  1026. * 生成幸运元素
  1027. * @param {String} constellation 星座名称
  1028. * @returns {Array} 幸运元素列表
  1029. */
  1030. export function generateLuckyElements(constellation) {
  1031. const constellationInfo = getConstellationInfo(constellation)
  1032. if (!constellationInfo) {
  1033. return []
  1034. }
  1035. const stones = ['紫水晶', '玫瑰石英', '黑曜石', '白水晶', '碧玺', '翡翠', '琥珀', '珍珠']
  1036. const directions = ['东', '南', '西', '北', '东南', '西南', '东北', '西北']
  1037. return [
  1038. {
  1039. label: '幸运色',
  1040. icon: '🎨',
  1041. value: constellationInfo.luckyColor,
  1042. bgColor: 'linear-gradient(135deg, #FFB6C1 0%, #FFE4E1 100%)'
  1043. },
  1044. {
  1045. label: '幸运数字',
  1046. icon: '🔢',
  1047. value: constellationInfo.luckyNumber[Math.floor(Math.random() * constellationInfo.luckyNumber.length)].toString(),
  1048. bgColor: 'linear-gradient(135deg, #9C27B0 0%, #CE93D8 100%)'
  1049. },
  1050. {
  1051. label: '幸运石',
  1052. icon: '💎',
  1053. value: stones[Math.floor(Math.random() * stones.length)],
  1054. bgColor: 'linear-gradient(135deg, #2196F3 0%, #64B5F6 100%)'
  1055. },
  1056. {
  1057. label: '幸运方位',
  1058. icon: '🧭',
  1059. value: directions[Math.floor(Math.random() * directions.length)],
  1060. bgColor: 'linear-gradient(135deg, #4CAF50 0%, #81C784 100%)'
  1061. }
  1062. ]
  1063. }
  1064. /**
  1065. * 生成星座特质详解
  1066. * @param {String} constellation 星座名称
  1067. * @returns {Array} 特质详解列表
  1068. */
  1069. export function generateConstellationTraits(constellation) {
  1070. const traitsData = {
  1071. '白羊座': [
  1072. { icon: '🔥', title: '性格特点', content: '热情洋溢,勇敢直率,富有冒险精神。喜欢挑战,敢于开拓新领域,是天生的领导者。' },
  1073. { icon: '💕', title: '爱情观', content: '在爱情中主动热情,喜欢浪漫刺激的恋爱。一旦爱上就会全力以赴,但也容易因冲动而受伤。' },
  1074. { icon: '💼', title: '事业运', content: '适合需要创新和领导能力的工作。在竞争激烈的环境中能发挥优势,但需要学会耐心和坚持。' }
  1075. ],
  1076. '金牛座': [
  1077. { icon: '🏔️', title: '性格特点', content: '稳重踏实,有强烈的责任感。注重物质安全,喜欢稳定的生活环境,做事有始有终。' },
  1078. { icon: '💕', title: '爱情观', content: '在感情中忠诚专一,注重长期稳定的关系。虽然慢热,但一旦确定关系就会全心投入。' },
  1079. { icon: '💼', title: '事业运', content: '适合需要耐心和专业技能的工作。在金融、艺术、美食等领域有天赋,能够长期积累成就。' }
  1080. ],
  1081. '双子座': [
  1082. { icon: '🌪️', title: '性格特点', content: '机智灵活,好奇心强,善于沟通交流。思维活跃,适应能力强,但有时显得不够专一。' },
  1083. { icon: '💕', title: '爱情观', content: '喜欢有趣的恋爱关系,注重精神层面的交流。需要对方能跟上自己的思维节奏。' },
  1084. { icon: '💼', title: '事业运', content: '适合需要沟通协调的工作。在媒体、教育、销售等领域能发挥优势,但需要避免三心二意。' }
  1085. ],
  1086. '巨蟹座': [
  1087. { icon: '🏠', title: '性格特点', content: '温柔敏感,重视家庭和情感。有强烈的保护欲,善于照顾他人,但有时过于敏感多疑。' },
  1088. { icon: '💕', title: '爱情观', content: '渴望稳定温馨的恋爱关系,会为爱人付出一切。但容易因为缺乏安全感而多疑。' },
  1089. { icon: '💼', title: '事业运', content: '适合与人打交道的服务性工作。在医疗、教育、餐饮等领域有天赋,能给人温暖感受。' }
  1090. ],
  1091. '狮子座': [
  1092. { icon: '👑', title: '性格特点', content: '自信大方,有王者风范。喜欢成为焦点,慷慨大度,但有时过于骄傲,需要别人的赞美。' },
  1093. { icon: '💕', title: '爱情观', content: '在爱情中慷慨浪漫,喜欢被崇拜的感觉。会为爱人创造浪漫惊喜,但也需要对方的认可。' },
  1094. { icon: '💼', title: '事业运', content: '适合需要展现个人魅力的工作。在娱乐、艺术、管理等领域能发光发热,是天生的明星。' }
  1095. ],
  1096. '处女座': [
  1097. { icon: '🔍', title: '性格特点', content: '追求完美,注重细节。做事认真负责,有强烈的服务精神,但有时过于挑剔苛求。' },
  1098. { icon: '💕', title: '爱情观', content: '在感情中谨慎细心,会默默关心对方的每个细节。虽然不善表达,但爱意深藏。' },
  1099. { icon: '💼', title: '事业运', content: '适合需要精确性和专业性的工作。在医疗、会计、研究等领域有优势,能做到精益求精。' }
  1100. ],
  1101. '天秤座': [
  1102. { icon: '⚖️', title: '性格特点', content: '追求和谐平衡,有优雅的品味。善于调解矛盾,但有时过于犹豫不决,难以做出选择。' },
  1103. { icon: '💕', title: '爱情观', content: '渴望和谐美好的爱情,重视精神契合。在感情中善于妥协,但有时缺乏主见。' },
  1104. { icon: '💼', title: '事业运', content: '适合需要审美和协调能力的工作。在设计、法律、外交等领域有天赋,能营造和谐氛围。' }
  1105. ],
  1106. '天蝎座': [
  1107. { icon: '🦂', title: '性格特点', content: '神秘深刻,意志坚强。有强烈的直觉力,善于洞察他人内心,但有时过于极端和报复心重。' },
  1108. { icon: '💕', title: '爱情观', content: '在感情中专一深情,爱恨分明。一旦爱上就会全身心投入,但也容易因嫉妒而痛苦。' },
  1109. { icon: '💼', title: '事业运', content: '适合需要深度研究和洞察力的工作。在心理学、侦探、投资等领域有优势,能发现他人忽略的细节。' }
  1110. ],
  1111. '射手座': [
  1112. { icon: '🏹', title: '性格特点', content: '自由奔放,乐观开朗。热爱冒险和旅行,有哲学思维,但有时过于直率,缺乏耐心。' },
  1113. { icon: '💕', title: '爱情观', content: '在感情中追求自由和刺激,不喜欢被束缚。需要有共同兴趣和理想的伴侣。' },
  1114. { icon: '💼', title: '事业运', content: '适合需要创新和自由度的工作。在旅游、教育、出版等领域有优势,能带来新鲜活力。' }
  1115. ],
  1116. '摩羯座': [
  1117. { icon: '🏔️', title: '性格特点', content: '踏实上进,有强烈的责任感。目标明确,善于规划,但有时过于严肃,缺乏幽默感。' },
  1118. { icon: '💕', title: '爱情观', content: '在感情中谨慎稳重,注重长期发展。虽然表达含蓄,但会通过实际行动证明爱意。' },
  1119. { icon: '💼', title: '事业运', content: '适合需要长期规划和管理能力的工作。在企业管理、建筑、政府等领域有优势,能稳步上升。' }
  1120. ],
  1121. '水瓶座': [
  1122. { icon: '🌊', title: '性格特点', content: '独立创新,有人道主义精神。思维前卫,善于发现新事物,但有时过于理性,显得冷漠。' },
  1123. { icon: '💕', title: '爱情观', content: '在感情中追求精神层面的交流,注重友谊基础。需要理解和支持自己理想的伴侣。' },
  1124. { icon: '💼', title: '事业运', content: '适合需要创新思维的工作。在科技、公益、新媒体等领域有优势,能引领时代潮流。' }
  1125. ],
  1126. '双鱼座': [
  1127. { icon: '🌙', title: '性格特点', content: '浪漫梦幻,富有同情心。想象力丰富,艺术天赋高,但有时过于敏感,容易逃避现实。' },
  1128. { icon: '💕', title: '爱情观', content: '在感情中浪漫理想,渴望童话般的爱情。容易为爱牺牲,但也容易受伤。' },
  1129. { icon: '💼', title: '事业运', content: '适合需要创意和同情心的工作。在艺术、医疗、慈善等领域有优势,能给人带来温暖。' }
  1130. ]
  1131. }
  1132. return traitsData[constellation] || []
  1133. }
  1134. export default {
  1135. CONSTELLATIONS,
  1136. getConstellationInfo,
  1137. getConstellationEmoji,
  1138. getAllConstellations,
  1139. getConstellationFortune,
  1140. generateConstellationMatch,
  1141. generateLuckyElements,
  1142. generateConstellationTraits,
  1143. getDetailedConstellationMatch,
  1144. getConstellationMatchFromAPI
  1145. }