diff --git a/numerology.db-shm b/numerology.db-shm index f21198d..6f33558 100644 Binary files a/numerology.db-shm and b/numerology.db-shm differ diff --git a/numerology.db-wal b/numerology.db-wal index 4e0cb07..7e1ea28 100644 Binary files a/numerology.db-wal and b/numerology.db-wal differ diff --git a/server/routes/analysis.cjs b/server/routes/analysis.cjs index 4233f11..09fb3f4 100644 --- a/server/routes/analysis.cjs +++ b/server/routes/analysis.cjs @@ -78,21 +78,19 @@ router.post('/bazi', authenticate, asyncHandler(async (req, res) => { // 易经分析接口 router.post('/yijing', authenticate, asyncHandler(async (req, res) => { - const { birth_data, question } = req.body; + const { question, user_id, divination_method } = req.body; // 输入验证 - if (!birth_data || !birth_data.name) { - throw new AppError('缺少必要参数:姓名', 400, 'MISSING_BIRTH_DATA'); + if (!question) { + throw new AppError('缺少必要参数:占卜问题', 400, 'MISSING_QUESTION'); } - const finalQuestion = question || '人生运势综合占卜'; - try { // 执行易经分析 const analysisResult = yijingAnalyzer.performYijingAnalysis({ - question: finalQuestion, - user_id: req.user.id, - birth_data: birth_data + question: question, + user_id: user_id || req.user.id, + divination_method: divination_method || 'time' }); // 保存到数据库 @@ -107,12 +105,12 @@ router.post('/yijing', authenticate, asyncHandler(async (req, res) => { const result = insertReading.run( req.user.id, 'yijing', - birth_data.name, - birth_data.birth_date || null, - birth_data.birth_time || null, - birth_data.birth_place || null, - birth_data.gender || null, - JSON.stringify({ question: finalQuestion, birth_data }), + '易经占卜用户', // 易经占卜不需要真实姓名 + null, // 不需要出生日期 + null, // 不需要出生时间 + null, // 不需要出生地点 + null, // 不需要性别 + JSON.stringify({ question, divination_method }), JSON.stringify(analysisResult), 'completed' ); diff --git a/server/services/yijingAnalyzer.cjs b/server/services/yijingAnalyzer.cjs index 0e7292d..bdb787c 100644 --- a/server/services/yijingAnalyzer.cjs +++ b/server/services/yijingAnalyzer.cjs @@ -1,20 +1,60 @@ -// 易经分析服务模块 -// 完全基于logic/yijing.txt的原始逻辑实现 +// 专业易经分析服务模块 +// 基于传统易学理论的完整实现 class YijingAnalyzer { constructor() { this.initializeHexagrams(); + this.initializeTrigramData(); + this.initializeNumerology(); } - // 易经分析主函数 + // 初始化八卦基础数据 + initializeTrigramData() { + this.TRIGRAMS = { + '乾': { binary: '111', nature: '天', attribute: '刚健', direction: '西北', season: '秋冬之交', family: '父', body: '头', animal: '马', element: '金' }, + '坤': { binary: '000', nature: '地', attribute: '柔顺', direction: '西南', season: '夏秋之交', family: '母', body: '腹', animal: '牛', element: '土' }, + '震': { binary: '001', nature: '雷', attribute: '动', direction: '东', season: '春', family: '长男', body: '足', animal: '龙', element: '木' }, + '巽': { binary: '011', nature: '风', attribute: '入', direction: '东南', season: '春夏之交', family: '长女', body: '股', animal: '鸡', element: '木' }, + '坎': { binary: '010', nature: '水', attribute: '陷', direction: '北', season: '冬', family: '中男', body: '耳', animal: '豕', element: '水' }, + '离': { binary: '101', nature: '火', attribute: '丽', direction: '南', season: '夏', family: '中女', body: '目', animal: '雉', element: '火' }, + '艮': { binary: '100', nature: '山', attribute: '止', direction: '东北', season: '冬春之交', family: '少男', body: '手', animal: '狗', element: '土' }, + '兑': { binary: '110', nature: '泽', attribute: '悦', direction: '西', season: '秋', family: '少女', body: '口', animal: '羊', element: '金' } + }; + } + + // 初始化象数理论 + initializeNumerology() { + this.NUMBERS = { + 1: { trigram: '乾', meaning: '天,创始,领导' }, + 2: { trigram: '兑', meaning: '泽,喜悦,交流' }, + 3: { trigram: '离', meaning: '火,光明,智慧' }, + 4: { trigram: '震', meaning: '雷,震动,行动' }, + 5: { trigram: '巽', meaning: '风,渗透,顺从' }, + 6: { trigram: '坎', meaning: '水,险难,智慧' }, + 7: { trigram: '艮', meaning: '山,静止,稳定' }, + 8: { trigram: '坤', meaning: '地,承载,包容' } + }; + } + + // 专业易经分析主函数 performYijingAnalysis(inputData) { try { - const { question, user_id, birth_data } = inputData; + const { question, user_id, birth_data, divination_method = 'time' } = inputData; const currentTime = new Date(); - const hexagramData = this.generateHexagram(currentTime, user_id); + + // 根据不同方法起卦 + const hexagramData = this.generateHexagramByMethod(divination_method, currentTime, user_id, question); const mainHexagramInfo = this.getHexagramInfo(hexagramData.mainHex); const changingHexagramInfo = this.getChangingHexagram(mainHexagramInfo, hexagramData.changingLines); - const changingLineAnalysis = this.analyzeChangingLines(mainHexagramInfo, hexagramData.changingLines); + + // 高级分析:互卦、错卦、综卦 + const advancedAnalysis = this.performAdvancedAnalysis(mainHexagramInfo, changingHexagramInfo); + + // 动态分析:基于问题类型和时间因素 + const dynamicAnalysis = this.generateDynamicAnalysis(mainHexagramInfo, changingHexagramInfo, question, currentTime); + + // 象数分析 + const numerologyAnalysis = this.performNumerologyAnalysis(hexagramData, currentTime); return { analysis_type: 'yijing', @@ -23,44 +63,40 @@ class YijingAnalyzer { divination_data: { question: question, divination_time: currentTime.toISOString(), - method: '梅花易数时间起卦法' + method: this.getMethodName(divination_method), + lunar_info: this.calculateLunarInfo(currentTime) }, hexagram_info: { main_hexagram: mainHexagramInfo.name, main_hexagram_symbol: mainHexagramInfo.symbol, + main_hexagram_number: mainHexagramInfo.number, + upper_trigram: mainHexagramInfo.upperTrigram, + lower_trigram: mainHexagramInfo.lowerTrigram, changing_hexagram: changingHexagramInfo ? changingHexagramInfo.name : '无', changing_hexagram_symbol: changingHexagramInfo ? changingHexagramInfo.symbol : '无', changing_lines: hexagramData.changingLines, - detailed_interpretation: `您得到的本卦是【${mainHexagramInfo.name}】,${mainHexagramInfo.judgment}` + hexagram_structure: this.analyzeHexagramStructure(mainHexagramInfo) } }, detailed_analysis: { hexagram_analysis: { - primary_meaning: `【${mainHexagramInfo.name}卦】 - ${mainHexagramInfo.meaning}`, + primary_meaning: `【${mainHexagramInfo.name}卦】第${mainHexagramInfo.number}卦 - ${mainHexagramInfo.meaning}`, judgment: `【彖传】曰:${mainHexagramInfo.judgment}`, - image: `【象传】曰:${mainHexagramInfo.image}` + image: `【象传】曰:${mainHexagramInfo.image}`, + trigram_analysis: this.analyzeTrigramCombination(mainHexagramInfo.upperTrigram, mainHexagramInfo.lowerTrigram), + five_elements: this.analyzeFiveElements(mainHexagramInfo) }, - changing_lines_analysis: changingLineAnalysis, - changing_hexagram_analysis: changingHexagramInfo ? { - name: `变卦为【${changingHexagramInfo.name}】`, - meaning: changingHexagramInfo.meaning, - transformation_insight: `从【${mainHexagramInfo.name}】到【${changingHexagramInfo.name}】的变化,预示着:${changingHexagramInfo.transformation || '事态将发生转变'}` - } : { - name: '无变卦', - meaning: '事态稳定,应以本卦为主要参考。', - transformation_insight: '没有动爻,表示当前状况将持续一段时间,应专注于当下。' - } - }, - life_guidance: { - overall_fortune: this.generateOverallFortune(mainHexagramInfo, changingHexagramInfo, question), - career_guidance: this.generateCareerAdvice(mainHexagramInfo, changingHexagramInfo), - relationship_guidance: this.generateRelationshipAdvice(mainHexagramInfo, changingHexagramInfo) + changing_lines_analysis: this.analyzeChangingLines(mainHexagramInfo, hexagramData.changingLines), + changing_hexagram_analysis: this.analyzeChangingHexagram(mainHexagramInfo, changingHexagramInfo), + advanced_analysis: advancedAnalysis, + numerology_analysis: numerologyAnalysis }, + dynamic_guidance: dynamicAnalysis, divination_wisdom: { - key_message: mainHexagramInfo.keyMessage || '保持平常心,顺势而为', - action_advice: mainHexagramInfo.actionAdvice || '谨慎行事,稳步前进', - warning: mainHexagramInfo.warning || '无特别警示', - philosophical_insight: `《易经》${mainHexagramInfo.name}卦的核心智慧在于:${mainHexagramInfo.philosophy || '顺应自然,把握时机'}` + key_message: this.generateKeyMessage(mainHexagramInfo, changingHexagramInfo, question), + action_advice: this.generateActionAdvice(mainHexagramInfo, changingHexagramInfo, currentTime), + timing_guidance: this.generateTimingGuidance(mainHexagramInfo, currentTime), + philosophical_insight: this.generatePhilosophicalInsight(mainHexagramInfo, changingHexagramInfo) } }; } catch (error) { @@ -69,8 +105,24 @@ class YijingAnalyzer { } } - // 生成卦象 - generateHexagram(currentTime, userId) { + // 根据不同方法生成卦象 + generateHexagramByMethod(method, currentTime, userId, question) { + switch (method) { + case 'time': + return this.generateHexagramByTime(currentTime, userId); + case 'plum_blossom': + return this.generateHexagramByPlumBlossom(currentTime, question); + case 'coin': + return this.generateHexagramByCoin(); + case 'number': + return this.generateHexagramByNumber(currentTime, userId); + default: + return this.generateHexagramByTime(currentTime, userId); + } + } + + // 梅花易数时间起卦法 + generateHexagramByTime(currentTime, userId) { const year = currentTime.getFullYear(); const month = currentTime.getMonth() + 1; const day = currentTime.getDate(); @@ -87,10 +139,99 @@ class YijingAnalyzer { return { mainHex: mainHexNumber, - changingLines: [changingLinePos] + changingLines: [changingLinePos], + method: '梅花易数时间起卦法', + upperTrigram: upperTrigramNum, + lowerTrigram: lowerTrigramNum }; } + // 梅花易数外应起卦法 + generateHexagramByPlumBlossom(currentTime, question) { + const questionLength = question ? question.length : 8; + const timeSum = currentTime.getHours() + currentTime.getMinutes(); + + const upperTrigramNum = (questionLength + timeSum) % 8 || 8; + const lowerTrigramNum = (questionLength * 2 + timeSum) % 8 || 8; + const changingLinePos = (questionLength + timeSum) % 6 + 1; + + const mainHexNumber = this.getHexagramNumber(upperTrigramNum, lowerTrigramNum); + + return { + mainHex: mainHexNumber, + changingLines: [changingLinePos], + method: '梅花易数外应起卦法', + upperTrigram: upperTrigramNum, + lowerTrigram: lowerTrigramNum + }; + } + + // 金钱卦起卦法(模拟) + generateHexagramByCoin() { + const lines = []; + const changingLines = []; + + for (let i = 0; i < 6; i++) { + // 模拟投掷三枚硬币 + const coin1 = Math.random() > 0.5 ? 3 : 2; // 正面3,反面2 + const coin2 = Math.random() > 0.5 ? 3 : 2; + const coin3 = Math.random() > 0.5 ? 3 : 2; + const sum = coin1 + coin2 + coin3; + + if (sum === 6) { // 老阴,变阳 + lines.push(0); + changingLines.push(i + 1); + } else if (sum === 7) { // 少阳 + lines.push(1); + } else if (sum === 8) { // 少阴 + lines.push(0); + } else if (sum === 9) { // 老阳,变阴 + lines.push(1); + changingLines.push(i + 1); + } + } + + const binary = lines.join(''); + const mainHexNumber = this.getHexagramByBinary(binary); + + return { + mainHex: mainHexNumber, + changingLines: changingLines, + method: '金钱卦起卦法', + binary: binary + }; + } + + // 数字起卦法 + generateHexagramByNumber(currentTime, userId) { + const timeNum = currentTime.getTime(); + const userNum = userId ? parseInt(String(userId).slice(-3)) || 123 : 123; + + const upperTrigramNum = (Math.floor(timeNum / 1000) + userNum) % 8 || 8; + const lowerTrigramNum = (Math.floor(timeNum / 100) + userNum * 2) % 8 || 8; + const changingLinePos = (timeNum + userNum) % 6 + 1; + + const mainHexNumber = this.getHexagramNumber(upperTrigramNum, lowerTrigramNum); + + return { + mainHex: mainHexNumber, + changingLines: [changingLinePos], + method: '数字起卦法', + upperTrigram: upperTrigramNum, + lowerTrigram: lowerTrigramNum + }; + } + + // 根据二进制获取卦象 + getHexagramByBinary(binary) { + for (const hexNum in this.ALL_HEXAGRAMS) { + if (this.ALL_HEXAGRAMS[hexNum].binary === binary) { + return parseInt(hexNum); + } + } + return 1; + } + // 获取卦象编号 getHexagramNumber(upper, lower) { const trigramMap = { @@ -115,39 +256,86 @@ class YijingAnalyzer { return this.ALL_HEXAGRAMS[hexNumber] || this.ALL_HEXAGRAMS[1]; } - // 分析动爻 + // 专业动爻分析 analyzeChangingLines(hexagramInfo, changingLines) { if (!changingLines || changingLines.length === 0) { return { method: '以本卦卦辞为断', analysis: `无动爻,应以【${hexagramInfo.name}】的整体卦辞为主要判断依据。`, - guidance: hexagramInfo.judgment + guidance: hexagramInfo.judgment, + interpretation: '静卦主静,事态稳定,当前状况将持续一段时间。应专注于当下,不宜有大的变动。' }; } - const linePos = changingLines[0]; - const lineIndex = linePos - 1; - const lineData = hexagramInfo.lines[lineIndex]; + const analyses = []; - if (!lineData) { - return { - method: '动爻分析异常', - analysis: '无法找到对应的爻辞信息。', - guidance: '' - }; - } - - const lineName = ['初', '二', '三', '四', '五', '上'][lineIndex] + (lineData.type === 'yang' ? '九' : '六'); + changingLines.forEach(linePos => { + const lineIndex = linePos - 1; + const lineData = hexagramInfo.lines[lineIndex]; + + if (lineData) { + const lineName = ['初', '二', '三', '四', '五', '上'][lineIndex] + (lineData.type === 'yang' ? '九' : '六'); + const linePosition = this.getLinePosition(lineIndex); + + analyses.push({ + line_position: `${lineName}(第${linePos}爻)`, + line_nature: lineData.type === 'yang' ? '阳爻' : '阴爻', + position_meaning: linePosition.meaning, + line_text: `【爻辞】曰:${lineData.text}`, + line_image: `【象传】曰:${lineData.image}`, + practical_guidance: this.generateLineGuidance(lineData, lineIndex, hexagramInfo) + }); + } + }); return { - method: '以动爻爻辞为断', - changing_line_position: `${lineName}(第${linePos}爻)`, - line_meaning: `【爻辞】曰:${lineData.text}`, - line_image_meaning: `【象传】对该爻的解释:${lineData.image}`, - guidance: `当前阶段的关键点在于理解和应对"${lineData.text}"所揭示的情况。` + method: changingLines.length === 1 ? '以动爻爻辞为断' : '以多爻变化综合判断', + changing_lines_count: changingLines.length, + detailed_analysis: analyses, + overall_guidance: this.generateChangingLinesGuidance(analyses, changingLines.length) }; } + // 获取爻位含义 + getLinePosition(lineIndex) { + const positions = [ + { name: '初爻', meaning: '事物的开始阶段,基础地位,需要谨慎起步' }, + { name: '二爻', meaning: '臣位,中正之位,适合辅助和配合' }, + { name: '三爻', meaning: '人位,多忧之位,需要特别小心' }, + { name: '四爻', meaning: '近君之位,接近成功,但需谨慎' }, + { name: '五爻', meaning: '君位,最尊贵的位置,主导地位' }, + { name: '上爻', meaning: '事物的终结阶段,物极必反' } + ]; + return positions[lineIndex] || { name: '未知', meaning: '位置不明' }; + } + + // 生成爻辞指导 + generateLineGuidance(lineData, lineIndex, hexagramInfo) { + const position = this.getLinePosition(lineIndex); + const baseGuidance = `在${position.name}的位置上,${lineData.text}的含义是:`; + + // 根据爻的阴阳和位置生成具体指导 + if (lineData.type === 'yang' && lineIndex % 2 === 0) { + return baseGuidance + '阳爻居阳位,得正,行动力强,但需要把握分寸。'; + } else if (lineData.type === 'yin' && lineIndex % 2 === 1) { + return baseGuidance + '阴爻居阴位,得正,柔顺有利,适合守静待时。'; + } else { + return baseGuidance + '爻位不正,需要调整策略,避免过于激进或消极。'; + } + } + + // 生成动爻综合指导 + generateChangingLinesGuidance(analyses, count) { + if (count === 1) { + return '单爻发动,变化明确,应重点关注该爻的指示。'; + } else if (count === 2) { + return '两爻发动,变化复杂,需要综合考虑两个方面的因素。'; + } else if (count >= 3) { + return '多爻发动,变化剧烈,事态复杂多变,需要格外谨慎。'; + } + return '变化情况需要仔细分析。'; + } + // 获取变卦 getChangingHexagram(originalHexInfo, changingLines) { if (!changingLines || changingLines.length === 0) { @@ -172,17 +360,537 @@ class YijingAnalyzer { return null; } - // 生成整体运势分析 - generateOverallFortune(mainHex, changeHex, question) { - let fortune = `针对您的问题"${question}",本卦为【${mainHex.name}】,指示了当前的基本状况:${mainHex.guidance}。`; + // 高级分析:互卦、错卦、综卦 + performAdvancedAnalysis(mainHex, changeHex) { + const interHex = this.getInterHexagram(mainHex); + const oppositeHex = this.getOppositeHexagram(mainHex); + const reverseHex = this.getReverseHexagram(mainHex); - if (changeHex) { - fortune += ` 动爻预示着变化,未来趋势可参考变卦【${changeHex.name}】:${changeHex.guidance}。`; + return { + inter_hexagram: { + name: interHex.name, + symbol: interHex.symbol, + meaning: interHex.meaning, + analysis: `互卦【${interHex.name}】揭示了事物的内在发展趋势和隐藏因素。${interHex.guidance}` + }, + opposite_hexagram: { + name: oppositeHex.name, + symbol: oppositeHex.symbol, + meaning: oppositeHex.meaning, + analysis: `错卦【${oppositeHex.name}】代表了相对立的状态和需要避免的方向。${oppositeHex.guidance}` + }, + reverse_hexagram: { + name: reverseHex.name, + symbol: reverseHex.symbol, + meaning: reverseHex.meaning, + analysis: `综卦【${reverseHex.name}】显示了事物的另一面和可能的转化方向。${reverseHex.guidance}` + }, + comprehensive_insight: this.generateComprehensiveInsight(mainHex, interHex, oppositeHex, reverseHex) + }; + } + + // 获取互卦 + getInterHexagram(hexInfo) { + const binary = hexInfo.binary; + // 互卦取2、3、4爻为下卦,3、4、5爻为上卦 + const lowerInter = binary.substring(3, 6); // 2、3、4爻 + const upperInter = binary.substring(2, 5); // 3、4、5爻 + const interBinary = upperInter + lowerInter; + + for (const hexNum in this.ALL_HEXAGRAMS) { + if (this.ALL_HEXAGRAMS[hexNum].binary === interBinary) { + return this.ALL_HEXAGRAMS[hexNum]; + } + } + return this.ALL_HEXAGRAMS[1]; // 默认返回乾卦 + } + + // 获取错卦(阴阳相反) + getOppositeHexagram(hexInfo) { + const binary = hexInfo.binary; + const oppositeBinary = binary.split('').map(bit => bit === '1' ? '0' : '1').join(''); + + for (const hexNum in this.ALL_HEXAGRAMS) { + if (this.ALL_HEXAGRAMS[hexNum].binary === oppositeBinary) { + return this.ALL_HEXAGRAMS[hexNum]; + } + } + return this.ALL_HEXAGRAMS[2]; // 默认返回坤卦 + } + + // 获取综卦(上下颠倒) + getReverseHexagram(hexInfo) { + const binary = hexInfo.binary; + const reverseBinary = binary.split('').reverse().join(''); + + for (const hexNum in this.ALL_HEXAGRAMS) { + if (this.ALL_HEXAGRAMS[hexNum].binary === reverseBinary) { + return this.ALL_HEXAGRAMS[hexNum]; + } + } + return hexInfo; // 如果没找到,返回原卦 + } + + // 生成综合洞察 + generateComprehensiveInsight(mainHex, interHex, oppositeHex, reverseHex) { + return `通过四卦分析:本卦【${mainHex.name}】显示当前状态,互卦【${interHex.name}】揭示内在动力,错卦【${oppositeHex.name}】提醒对立面,综卦【${reverseHex.name}】指示转化方向。综合来看,需要在${mainHex.meaning}的基础上,注意${interHex.meaning}的内在发展,避免${oppositeHex.meaning}的极端,向${reverseHex.meaning}的方向转化。`; + } + + // 动态分析:基于问题类型和时间因素 + generateDynamicAnalysis(mainHex, changeHex, question, currentTime) { + const questionType = this.analyzeQuestionType(question); + const timeFactors = this.analyzeTimeFactors(currentTime); + + return { + question_analysis: { + type: questionType.type, + focus: questionType.focus, + approach: questionType.approach + }, + time_analysis: timeFactors, + targeted_guidance: this.generateTargetedGuidance(mainHex, changeHex, questionType, timeFactors), + practical_advice: this.generatePracticalAdvice(mainHex, changeHex, questionType) + }; + } + + // 分析问题类型 + analyzeQuestionType(question) { + const lowerQuestion = question.toLowerCase(); + + if (lowerQuestion.includes('事业') || lowerQuestion.includes('工作') || lowerQuestion.includes('职业')) { + return { + type: '事业发展', + focus: '职场发展、事业规划、工作机会', + approach: '重点关注事业宫位和变化趋势' + }; + } else if (lowerQuestion.includes('感情') || lowerQuestion.includes('爱情') || lowerQuestion.includes('婚姻')) { + return { + type: '感情婚姻', + focus: '情感关系、婚姻状况、人际和谐', + approach: '重点关注感情因素和人际关系' + }; + } else if (lowerQuestion.includes('财运') || lowerQuestion.includes('投资') || lowerQuestion.includes('金钱')) { + return { + type: '财运投资', + focus: '财富积累、投资机会、经济状况', + approach: '重点关注财运变化和投资时机' + }; + } else if (lowerQuestion.includes('健康') || lowerQuestion.includes('身体')) { + return { + type: '健康养生', + focus: '身体状况、健康维护、疾病预防', + approach: '重点关注身体状态和养生方法' + }; } else { - fortune += ` 事态稳定,应专注于当前状况。`; + return { + type: '综合运势', + focus: '整体发展、综合状况、全面分析', + approach: '全面分析各个方面的发展趋势' + }; + } + } + + // 分析时间因素 + analyzeTimeFactors(currentTime) { + const month = currentTime.getMonth() + 1; + const season = this.getSeason(month); + const hour = currentTime.getHours(); + const timeOfDay = this.getTimeOfDay(hour); + + return { + season: season, + time_of_day: timeOfDay, + lunar_phase: this.getLunarPhase(currentTime), + energy_state: this.getEnergyState(season, timeOfDay) + }; + } + + // 获取季节 + getSeason(month) { + if (month >= 3 && month <= 5) return { name: '春季', energy: '生发之气', advice: '适合开始新事物' }; + if (month >= 6 && month <= 8) return { name: '夏季', energy: '旺盛之气', advice: '适合积极行动' }; + if (month >= 9 && month <= 11) return { name: '秋季', energy: '收敛之气', advice: '适合收获总结' }; + return { name: '冬季', energy: '潜藏之气', advice: '适合休养生息' }; + } + + // 获取时辰 + getTimeOfDay(hour) { + if (hour >= 5 && hour < 7) return { name: '卯时', energy: '日出东方', advice: '新的开始' }; + if (hour >= 7 && hour < 9) return { name: '辰时', energy: '朝阳初升', advice: '积极进取' }; + if (hour >= 9 && hour < 11) return { name: '巳时', energy: '阳气渐盛', advice: '努力工作' }; + if (hour >= 11 && hour < 13) return { name: '午时', energy: '阳气最盛', advice: '把握机会' }; + if (hour >= 13 && hour < 15) return { name: '未时', energy: '阳气渐衰', advice: '稳步前进' }; + if (hour >= 15 && hour < 17) return { name: '申时', energy: '阳气转阴', advice: '谨慎行事' }; + if (hour >= 17 && hour < 19) return { name: '酉时', energy: '日落西山', advice: '收敛锋芒' }; + if (hour >= 19 && hour < 21) return { name: '戌时', energy: '阴气渐盛', advice: '休息调整' }; + if (hour >= 21 && hour < 23) return { name: '亥时', energy: '夜深人静', advice: '内省思考' }; + if (hour >= 23 || hour < 1) return { name: '子时', energy: '阴极阳生', advice: '蓄势待发' }; + if (hour >= 1 && hour < 3) return { name: '丑时', energy: '阴气深重', advice: '静心养神' }; + return { name: '寅时', energy: '阳气初动', advice: '准备行动' }; + } + + // 象数分析 + performNumerologyAnalysis(hexagramData, currentTime) { + const upperNum = hexagramData.upperTrigram || 1; + const lowerNum = hexagramData.lowerTrigram || 1; + const totalNum = upperNum + lowerNum; + + return { + upper_trigram_number: { + number: upperNum, + meaning: this.NUMBERS[upperNum]?.meaning || '未知', + influence: '代表外在环境和表面现象' + }, + lower_trigram_number: { + number: lowerNum, + meaning: this.NUMBERS[lowerNum]?.meaning || '未知', + influence: '代表内在动机和根本原因' + }, + combined_energy: { + total: totalNum, + interpretation: this.interpretCombinedNumber(totalNum), + harmony: this.analyzeNumberHarmony(upperNum, lowerNum) + }, + time_resonance: this.analyzeTimeResonance(totalNum, currentTime) + }; + } + + // 解释组合数字 + interpretCombinedNumber(num) { + const interpretations = { + 2: '极简之数,需要积累', + 3: '生发之数,开始行动', + 4: '稳定之数,循序渐进', + 5: '变化之数,灵活应对', + 6: '和谐之数,平衡发展', + 7: '完善之数,精益求精', + 8: '丰盛之数,收获时机', + 9: '圆满之数,功德圆满', + 10: '完成之数,新的开始', + 11: '突破之数,创新变革', + 12: '循环之数,周而复始', + 13: '转化之数,质的飞跃', + 14: '调和之数,协调统一', + 15: '圆融之数,和谐共生', + 16: '极盛之数,物极必反' + }; + return interpretations[num] || '特殊之数,需要特别关注'; + } + + // 分析数字和谐度 + analyzeNumberHarmony(upper, lower) { + const diff = Math.abs(upper - lower); + if (diff === 0) return '完全和谐,内外一致'; + if (diff === 1) return '基本和谐,略有差异'; + if (diff === 2) return '适度张力,需要平衡'; + if (diff >= 3) return '较大差异,需要调和'; + return '需要进一步分析'; + } + + // 添加更多专业分析方法 + + // 获取起卦方法名称 + getMethodName(method) { + const methods = { + 'time': '梅花易数时间起卦法', + 'plum_blossom': '梅花易数外应起卦法', + 'coin': '金钱卦起卦法', + 'number': '数字起卦法' + }; + return methods[method] || '传统起卦法'; + } + + // 计算农历信息 + calculateLunarInfo(currentTime) { + // 简化的农历计算,实际应用中需要更精确的算法 + const year = currentTime.getFullYear(); + const month = currentTime.getMonth() + 1; + const day = currentTime.getDate(); + + return { + year: `${year}年`, + month: `${month}月`, + day: `${day}日`, + note: '农历信息需要专业历法计算' + }; + } + + // 分析卦象结构 + analyzeHexagramStructure(hexInfo) { + const upperTrigram = this.TRIGRAMS[hexInfo.upperTrigram]; + const lowerTrigram = this.TRIGRAMS[hexInfo.lowerTrigram]; + + return { + upper_trigram: { + name: hexInfo.upperTrigram, + nature: upperTrigram?.nature || '未知', + attribute: upperTrigram?.attribute || '未知', + element: upperTrigram?.element || '未知' + }, + lower_trigram: { + name: hexInfo.lowerTrigram, + nature: lowerTrigram?.nature || '未知', + attribute: lowerTrigram?.attribute || '未知', + element: lowerTrigram?.element || '未知' + }, + interaction: this.analyzeTrigramInteraction(upperTrigram, lowerTrigram) + }; + } + + // 分析八卦组合 + analyzeTrigramCombination(upperName, lowerName) { + const upper = this.TRIGRAMS[upperName]; + const lower = this.TRIGRAMS[lowerName]; + + if (!upper || !lower) { + return '八卦信息不完整,无法分析'; } - return fortune; + return `上卦${upperName}(${upper.nature})代表${upper.attribute},下卦${lowerName}(${lower.nature})代表${lower.attribute}。${upper.nature}在上,${lower.nature}在下,形成${upperName}${lowerName}的组合,象征着${this.getTrigramCombinationMeaning(upperName, lowerName)}。`; + } + + // 获取八卦组合含义 + getTrigramCombinationMeaning(upper, lower) { + const combinations = { + '乾乾': '天行健,自强不息的力量', + '坤坤': '地势坤,厚德载物的包容', + '乾坤': '天地定位,阴阳和谐', + '坤乾': '地天泰,通达顺畅', + '震巽': '雷风相薄,变化迅速', + '巽震': '风雷益,增益发展', + '坎离': '水火既济,阴阳调和', + '离坎': '火水未济,尚需努力' + }; + return combinations[upper + lower] || '特殊的能量组合,需要深入分析'; + } + + // 分析八卦相互作用 + analyzeTrigramInteraction(upper, lower) { + if (!upper || !lower) return '无法分析八卦相互作用'; + + const upperElement = upper.element; + const lowerElement = lower.element; + + return this.analyzeFiveElementsInteraction(upperElement, lowerElement); + } + + // 分析五行关系 + analyzeFiveElements(hexInfo) { + const upperTrigram = this.TRIGRAMS[hexInfo.upperTrigram]; + const lowerTrigram = this.TRIGRAMS[hexInfo.lowerTrigram]; + + if (!upperTrigram || !lowerTrigram) { + return '五行信息不完整'; + } + + const upperElement = upperTrigram.element; + const lowerElement = lowerTrigram.element; + + return { + upper_element: upperElement, + lower_element: lowerElement, + relationship: this.analyzeFiveElementsInteraction(upperElement, lowerElement), + balance: this.analyzeFiveElementsBalance(upperElement, lowerElement) + }; + } + + // 分析五行相互作用 + analyzeFiveElementsInteraction(element1, element2) { + const interactions = { + '金金': '同气相求,力量集中', + '金木': '金克木,需要调和', + '金水': '金生水,相生有利', + '金火': '火克金,存在冲突', + '金土': '土生金,得到支持', + '木木': '同气相求,生机勃勃', + '木水': '水生木,滋养成长', + '木火': '木生火,能量转化', + '木土': '木克土,需要平衡', + '水水': '同气相求,流动不息', + '水火': '水火不容,需要调和', + '水土': '土克水,存在阻碍', + '火火': '同气相求,热情高涨', + '火土': '火生土,稳固发展', + '土土': '同气相求,稳重厚实' + }; + + return interactions[element1 + element2] || interactions[element2 + element1] || '五行关系复杂,需要综合分析'; + } + + // 分析五行平衡 + analyzeFiveElementsBalance(element1, element2) { + if (element1 === element2) { + return '五行同类,力量集中,但可能缺乏变化'; + } + + const generative = ['金水', '水木', '木火', '火土', '土金']; + const destructive = ['金木', '木土', '土水', '水火', '火金']; + + const combination = element1 + element2; + const reverseCombination = element2 + element1; + + if (generative.includes(combination) || generative.includes(reverseCombination)) { + return '五行相生,和谐发展,有利于事物的成长'; + } else if (destructive.includes(combination) || destructive.includes(reverseCombination)) { + return '五行相克,存在冲突,需要化解或利用这种张力'; + } + + return '五行关系中性,需要根据具体情况分析'; + } + + // 分析变卦 + analyzeChangingHexagram(mainHex, changeHex) { + if (!changeHex) { + return { + name: '无变卦', + meaning: '事态稳定,应以本卦为主要参考', + transformation_insight: '没有动爻,表示当前状况将持续一段时间,应专注于当下,不宜有大的变动。', + guidance: '保持现状,稳步发展,等待时机成熟再做改变。' + }; + } + + return { + name: `变卦为【${changeHex.name}】`, + meaning: changeHex.meaning, + transformation_insight: `从【${mainHex.name}】到【${changeHex.name}】的变化,预示着${this.generateTransformationInsight(mainHex, changeHex)}`, + guidance: `变卦指示:${changeHex.guidance}`, + timing: this.analyzeTransformationTiming(mainHex, changeHex) + }; + } + + // 生成转化洞察 + generateTransformationInsight(mainHex, changeHex) { + const mainMeaning = mainHex.meaning; + const changeMeaning = changeHex.meaning; + + return `事态将从${mainMeaning}转向${changeMeaning},这是一个重要的转折点。需要适应这种变化,调整策略和心态。`; + } + + // 分析转化时机 + analyzeTransformationTiming(mainHex, changeHex) { + // 根据卦象的性质分析转化的快慢 + const fastChangingHexagrams = [1, 4, 16, 25, 34, 51]; // 乾、蒙、豫、无妄、大壮、震等 + const slowChangingHexagrams = [2, 15, 23, 52]; // 坤、谦、剥、艮等 + + if (fastChangingHexagrams.includes(changeHex.number)) { + return '变化将会比较迅速,需要及时应对'; + } else if (slowChangingHexagrams.includes(changeHex.number)) { + return '变化将会比较缓慢,有充分的准备时间'; + } + + return '变化的速度适中,需要保持关注'; + } + + // 生成关键信息 + generateKeyMessage(mainHex, changeHex, question) { + const baseMessage = mainHex.keyMessage || '顺应自然,把握时机'; + + if (changeHex) { + return `${baseMessage}。变化在即,${changeHex.keyMessage || '需要适应新的形势'}。`; + } + + return baseMessage; + } + + // 生成行动建议 + generateActionAdvice(mainHex, changeHex, currentTime) { + const season = this.getSeason(currentTime.getMonth() + 1); + const timeOfDay = this.getTimeOfDay(currentTime.getHours()); + + let advice = mainHex.actionAdvice || '谨慎行事,稳步前进'; + + // 结合时间因素 + advice += ` 当前正值${season.name},${season.advice}。`; + advice += ` 现在是${timeOfDay.name},${timeOfDay.advice}。`; + + if (changeHex) { + advice += ` 考虑到即将到来的变化,建议:${changeHex.actionAdvice || '做好准备,迎接转变'}。`; + } + + return advice; + } + + // 生成时机指导 + generateTimingGuidance(mainHex, currentTime) { + const hour = currentTime.getHours(); + const month = currentTime.getMonth() + 1; + + let guidance = '时机分析:'; + + // 根据时辰分析 + if (hour >= 5 && hour < 11) { + guidance += '上午时光,阳气上升,适合开始新的行动。'; + } else if (hour >= 11 && hour < 17) { + guidance += '下午时光,阳气鼎盛,适合推进重要事务。'; + } else { + guidance += '晚间时光,阴气渐盛,适合思考和规划。'; + } + + // 根据季节分析 + const season = this.getSeason(month); + guidance += ` ${season.name}${season.advice}。`; + + return guidance; + } + + // 生成哲学洞察 + generatePhilosophicalInsight(mainHex, changeHex) { + let insight = `《易经》${mainHex.name}卦的核心智慧在于:${mainHex.philosophy || '顺应自然规律,把握变化时机'}。`; + + if (changeHex) { + insight += ` 而变卦${changeHex.name}则提醒我们:${changeHex.philosophy || '变化是永恒的,适应是智慧的'}。`; + } + + insight += ' 《易经》告诉我们,万事万物都在变化之中,智者应该顺应这种变化,在变化中寻找机遇,在稳定中积蓄力量。'; + + return insight; + } + + // 获取月相(简化版) + getLunarPhase(currentTime) { + const day = currentTime.getDate(); + if (day <= 7) return { name: '新月', energy: '新的开始', advice: '适合播种和规划' }; + if (day <= 14) return { name: '上弦月', energy: '成长发展', advice: '适合努力和进取' }; + if (day <= 21) return { name: '满月', energy: '圆满充实', advice: '适合收获和庆祝' }; + return { name: '下弦月', energy: '反思总结', advice: '适合整理和准备' }; + } + + // 获取能量状态 + getEnergyState(season, timeOfDay) { + const seasonEnergy = season.energy; + const timeEnergy = timeOfDay.energy; + + return { + overall: `${seasonEnergy}与${timeEnergy}相结合`, + recommendation: `在${season.name}的${timeOfDay.name},${season.advice},同时${timeOfDay.advice}` + }; + } + + // 生成针对性指导 + generateTargetedGuidance(mainHex, changeHex, questionType, timeFactors) { + let guidance = `针对您关于${questionType.type}的问题,`; + guidance += `本卦【${mainHex.name}】在${questionType.focus}方面的指示是:${mainHex.guidance}。`; + + if (changeHex) { + guidance += ` 变卦【${changeHex.name}】预示着在${questionType.focus}方面将会有所转变。`; + } + + guidance += ` 结合当前的时间因素(${timeFactors.season.name},${timeFactors.time_of_day.name}),建议您${timeFactors.season.advice}。`; + + return guidance; + } + + // 生成实用建议 + generatePracticalAdvice(mainHex, changeHex, questionType) { + const adviceMap = { + '事业发展': this.generateCareerAdvice(mainHex, changeHex), + '感情婚姻': this.generateRelationshipAdvice(mainHex, changeHex), + '财运投资': this.generateFinancialAdvice(mainHex, changeHex), + '健康养生': this.generateHealthAdvice(mainHex, changeHex), + '综合运势': this.generateGeneralAdvice(mainHex, changeHex) + }; + + return adviceMap[questionType.type] || this.generateGeneralAdvice(mainHex, changeHex); } // 生成事业建议 @@ -207,6 +915,52 @@ class YijingAnalyzer { return advice; } + // 生成财运建议 + generateFinancialAdvice(mainHex, changeHex) { + let advice = `财运方面,本卦【${mainHex.name}】显示:"${mainHex.wealth || mainHex.guidance}"。`; + + if (changeHex) { + advice += ` 变卦【${changeHex.name}】预示财运可能向"${changeHex.wealth || changeHex.guidance}"的方向发展。`; + } + + return advice; + } + + // 生成健康建议 + generateHealthAdvice(mainHex, changeHex) { + let advice = `健康方面,本卦【${mainHex.name}】提醒:"${mainHex.health || mainHex.guidance}"。`; + + if (changeHex) { + advice += ` 变卦【${changeHex.name}】暗示健康状况可能朝"${changeHex.health || changeHex.guidance}"的方向变化。`; + } + + return advice; + } + + // 生成综合建议 + generateGeneralAdvice(mainHex, changeHex) { + let advice = `综合来看,本卦【${mainHex.name}】的总体指导是:"${mainHex.guidance}"。`; + + if (changeHex) { + advice += ` 变卦【${changeHex.name}】提示未来趋势:"${changeHex.guidance}"。`; + } + + return advice; + } + + // 分析时间共振 + analyzeTimeResonance(totalNum, currentTime) { + const hour = currentTime.getHours(); + const day = currentTime.getDate(); + const resonance = (totalNum + hour + day) % 8 + 1; + + return { + resonance_number: resonance, + meaning: this.NUMBERS[resonance]?.meaning || '未知', + interpretation: `当前时间与卦象数字的共振显示:${this.NUMBERS[resonance]?.meaning || '特殊的能量状态'}` + }; + } + // 初始化64卦数据 initializeHexagrams() { this.ALL_HEXAGRAMS = { diff --git a/src/components/AnalysisResultDisplay.tsx b/src/components/AnalysisResultDisplay.tsx index 814342b..14acd6b 100644 --- a/src/components/AnalysisResultDisplay.tsx +++ b/src/components/AnalysisResultDisplay.tsx @@ -1,6 +1,7 @@ import React from 'react'; import CompleteBaziAnalysis from './CompleteBaziAnalysis'; import CompleteZiweiAnalysis from './CompleteZiweiAnalysis'; +import CompleteYijingAnalysis from './CompleteYijingAnalysis'; import BaziAnalysisDisplay from './BaziAnalysisDisplay'; interface AnalysisResultDisplayProps { @@ -10,9 +11,19 @@ interface AnalysisResultDisplayProps { date: string; time: string; }; + question?: string; + userId?: string; + divinationMethod?: string; } -const AnalysisResultDisplay: React.FC = ({ analysisResult, analysisType, birthDate }) => { +const AnalysisResultDisplay: React.FC = ({ + analysisResult, + analysisType, + birthDate, + question, + userId, + divinationMethod +}) => { // 安全地获取数据的辅助函数 const safeGet = (obj: any, path: string, defaultValue: any = '暂无数据') => { const keys = path.split('.'); @@ -238,7 +249,32 @@ const AnalysisResultDisplay: React.FC = ({ analysisR // 渲染易经占卜分析 const renderYijingAnalysis = () => { - // 处理新的数据结构: { type: 'yijing', data: analysisResult } + // 如果有问题参数,使用新的 CompleteYijingAnalysis 组件 + if (question) { + return ( + + ); + } + + // 如果有分析结果但没有问题参数,尝试从结果中提取问题信息 + if (analysisResult && analysisResult.data) { + const basicInfo = analysisResult.data.basic_info; + if (basicInfo && basicInfo.divination_data) { + return ( + + ); + } + } + + // 回退到旧的渲染方式(向后兼容) const data = analysisResult?.data || analysisResult; return ( diff --git a/src/components/CompleteYijingAnalysis.tsx b/src/components/CompleteYijingAnalysis.tsx new file mode 100644 index 0000000..9d2f7b0 --- /dev/null +++ b/src/components/CompleteYijingAnalysis.tsx @@ -0,0 +1,736 @@ +import React, { useState, useEffect } from 'react'; +import { Calendar, Star, BookOpen, Sparkles, User, BarChart3, Zap, TrendingUp, Loader2, Clock, Target, Heart, DollarSign, Activity, Crown, Compass, Moon, Sun, Hexagon, Layers, Eye, Shuffle } from 'lucide-react'; +import { Card, CardContent, CardHeader, CardTitle } from './ui/Card'; +import { localApi } from '../lib/localApi'; + +interface CompleteYijingAnalysisProps { + question: string; + userId?: string; + divinationMethod?: string; +} + +const CompleteYijingAnalysis: React.FC = ({ + question, + userId = 'user123', + divinationMethod = 'time' +}) => { + const [isLoading, setIsLoading] = useState(true); + const [error, setError] = useState(null); + const [analysisData, setAnalysisData] = useState(null); + + // 卦象颜色配置 + const hexagramColors: { [key: string]: string } = { + '乾': 'bg-yellow-100 text-yellow-800 border-yellow-300', + '坤': 'bg-brown-100 text-brown-800 border-brown-300', + '震': 'bg-green-100 text-green-800 border-green-300', + '巽': 'bg-blue-100 text-blue-800 border-blue-300', + '坎': 'bg-indigo-100 text-indigo-800 border-indigo-300', + '离': 'bg-red-100 text-red-800 border-red-300', + '艮': 'bg-gray-100 text-gray-800 border-gray-300', + '兑': 'bg-purple-100 text-purple-800 border-purple-300' + }; + + // 五行颜色配置 + const elementColors: { [key: string]: string } = { + '金': '#fbbf24', // 金色 + '木': '#22c55e', // 绿色 + '水': '#3b82f6', // 蓝色 + '火': '#ef4444', // 红色 + '土': '#a3a3a3' // 灰色 + }; + + // 问题类型颜色配置 + const questionTypeColors: { [key: string]: string } = { + '事业发展': 'bg-blue-100 text-blue-800 border-blue-300', + '感情婚姻': 'bg-pink-100 text-pink-800 border-pink-300', + '财运投资': 'bg-green-100 text-green-800 border-green-300', + '健康养生': 'bg-orange-100 text-orange-800 border-orange-300', + '综合运势': 'bg-purple-100 text-purple-800 border-purple-300' + }; + + useEffect(() => { + const fetchAnalysisData = async () => { + try { + setIsLoading(true); + setError(null); + + const yijingData = { + question: question, + user_id: userId, + divination_method: divinationMethod + }; + + const yijingResponse = await localApi.analysis.yijing(yijingData); + + if (yijingResponse.error) { + throw new Error(yijingResponse.error.message || '易经分析失败'); + } + + const analysisResult = yijingResponse.data?.analysis; + if (!analysisResult) { + throw new Error('分析结果为空'); + } + + setAnalysisData(analysisResult); + } catch (err) { + console.error('获取分析数据出错:', err); + setError(err instanceof Error ? err.message : '分析数据获取失败,请稍后重试'); + } finally { + setIsLoading(false); + } + }; + + if (question) { + fetchAnalysisData(); + } + }, [question, userId, divinationMethod]); + + // 渲染加载状态 + if (isLoading) { + return ( +
+ + + +

正在进行专业易经占卜

+

请稍候,正在为您起卦分析...

+
+
+
+ ); + } + + // 渲染错误状态 + if (error) { + return ( +
+ + +
+

占卜失败

+

{error}

+ +
+
+
+ ); + } + + if (!analysisData) { + return ( +
+ + +
⚠️
+

数据获取异常

+

未能获取到完整的分析数据,请重新提交占卜

+
+
+
+ ); + } + + // 渲染卦象卡片 + const renderHexagramCard = (hexagram: any, title: string, isMain: boolean = false) => { + if (!hexagram) return null; + + return ( + + + + {title} + + + +
+
{hexagram.symbol || hexagram}
+
+ {hexagram.name || hexagram} +
+ {hexagram.number && ( +
第{hexagram.number}卦
+ )} +
+ {hexagram.meaning || '卦象含义'} +
+
+
+
+ ); + }; + + // 渲染八卦信息 + const renderTrigramInfo = (trigram: any, position: string) => { + if (!trigram) return null; + + return ( +
+

{position}

+
+
+ 卦名: + {trigram.name} +
+
+ 性质: + {trigram.nature} +
+
+ 属性: + {trigram.attribute} +
+
+ 五行: + + {trigram.element} + +
+
+
+ ); + }; + + // 渲染动爻分析 + const renderChangingLinesAnalysis = (analysis: any) => { + if (!analysis || !analysis.detailed_analysis) return null; + + return ( +
+
+

动爻分析方法

+

{analysis.method}

+

{analysis.overall_guidance}

+
+ + {analysis.detailed_analysis.map((line: any, index: number) => ( +
+
+
{line.line_position}
+ + {line.line_nature} + +
+
+
+ 位置含义: + {line.position_meaning} +
+
+ 爻辞: + {line.line_text} +
+
+ 象传: + {line.line_image} +
+
+ 实用指导: + {line.practical_guidance} +
+
+
+ ))} +
+ ); + }; + + return ( +
+
+ + {/* 标题和基本信息 */} + + + + + 易经占卜分析报告 + + +
+
+ + {analysisData.analysis_date} +
+
+ + {new Date(analysisData.basic_info.divination_data.divination_time).toLocaleString('zh-CN')} +
+
+
+ +
+ {/* 占卜信息 */} +
+

占卜信息

+
+
+

问题:{analysisData.basic_info.divination_data.question}

+

方法:{analysisData.basic_info.divination_data.method}

+
+
+

问题类型: + + {analysisData.dynamic_guidance.question_analysis.type} + +

+

关注重点:{analysisData.dynamic_guidance.question_analysis.focus}

+
+
+
+
+
+
+ + {/* 卦象信息 */} +
+ {/* 本卦 */} +
+

+ + 本卦 +

+ {renderHexagramCard({ + name: analysisData.basic_info.hexagram_info.main_hexagram, + symbol: analysisData.basic_info.hexagram_info.main_hexagram_symbol, + number: analysisData.basic_info.hexagram_info.main_hexagram_number, + meaning: analysisData.detailed_analysis.hexagram_analysis.primary_meaning.split(' - ')[1] + }, '本卦', true)} + + {/* 八卦结构 */} + + + + + 八卦结构 + + + +
+ {renderTrigramInfo(analysisData.basic_info.hexagram_info.hexagram_structure.upper_trigram, '上卦')} + {renderTrigramInfo(analysisData.basic_info.hexagram_info.hexagram_structure.lower_trigram, '下卦')} +
+
+
八卦组合分析
+

{analysisData.detailed_analysis.hexagram_analysis.trigram_analysis}

+
+
+
+
+ + {/* 变卦 */} +
+

+ + 变卦 +

+ {analysisData.basic_info.hexagram_info.changing_hexagram !== '无' ? ( + renderHexagramCard({ + name: analysisData.basic_info.hexagram_info.changing_hexagram, + symbol: analysisData.basic_info.hexagram_info.changing_hexagram_symbol, + meaning: analysisData.detailed_analysis.changing_hexagram_analysis.meaning + }, '变卦') + ) : ( + + +
🔒
+

无变卦

+

静卦主静,事态稳定

+
+
+ )} + + {/* 变化分析 */} + + + + + 变化分析 + + + +
+
+
转化洞察
+

{analysisData.detailed_analysis.changing_hexagram_analysis.transformation_insight}

+
+
+
变化指导
+

{analysisData.detailed_analysis.changing_hexagram_analysis.guidance}

+
+
+
时机把握
+

{analysisData.detailed_analysis.changing_hexagram_analysis.timing}

+
+
+
+
+
+
+ + {/* 卦辞象传 */} + + + + + 卦辞象传 + + + +
+
+

彖传(卦辞)

+

{analysisData.detailed_analysis.hexagram_analysis.judgment}

+
+
+

象传(卦象)

+

{analysisData.detailed_analysis.hexagram_analysis.image}

+
+
+
+
+ + {/* 动爻分析 */} + {analysisData.detailed_analysis.changing_lines_analysis && ( + + + + + 动爻分析 + +

动爻数量:{analysisData.detailed_analysis.changing_lines_analysis.changing_lines_count}爻

+
+ + {renderChangingLinesAnalysis(analysisData.detailed_analysis.changing_lines_analysis)} + +
+ )} + + {/* 高级分析 */} + {analysisData.detailed_analysis.advanced_analysis && ( + + + + + 高级分析 + +

互卦、错卦、综卦深度解析

+
+ +
+ {/* 互卦 */} +
+

+ 🔄 + 互卦 - {analysisData.detailed_analysis.advanced_analysis.inter_hexagram.name} +

+
+
{analysisData.detailed_analysis.advanced_analysis.inter_hexagram.symbol}
+
{analysisData.detailed_analysis.advanced_analysis.inter_hexagram.meaning}
+
+

{analysisData.detailed_analysis.advanced_analysis.inter_hexagram.analysis}

+
+ + {/* 错卦 */} +
+

+ + 错卦 - {analysisData.detailed_analysis.advanced_analysis.opposite_hexagram.name} +

+
+
{analysisData.detailed_analysis.advanced_analysis.opposite_hexagram.symbol}
+
{analysisData.detailed_analysis.advanced_analysis.opposite_hexagram.meaning}
+
+

{analysisData.detailed_analysis.advanced_analysis.opposite_hexagram.analysis}

+
+ + {/* 综卦 */} +
+

+ 🔀 + 综卦 - {analysisData.detailed_analysis.advanced_analysis.reverse_hexagram.name} +

+
+
{analysisData.detailed_analysis.advanced_analysis.reverse_hexagram.symbol}
+
{analysisData.detailed_analysis.advanced_analysis.reverse_hexagram.meaning}
+
+

{analysisData.detailed_analysis.advanced_analysis.reverse_hexagram.analysis}

+
+
+ + {/* 综合洞察 */} +
+

四卦综合洞察

+

{analysisData.detailed_analysis.advanced_analysis.comprehensive_insight}

+
+
+
+ )} + + {/* 象数分析 */} + {analysisData.detailed_analysis.numerology_analysis && ( + + + + + 象数分析 + +

八卦数理与时间共振分析

+
+ +
+
+

上卦数

+
{analysisData.detailed_analysis.numerology_analysis.upper_trigram_number.number}
+
{analysisData.detailed_analysis.numerology_analysis.upper_trigram_number.meaning}
+
{analysisData.detailed_analysis.numerology_analysis.upper_trigram_number.influence}
+
+ +
+

下卦数

+
{analysisData.detailed_analysis.numerology_analysis.lower_trigram_number.number}
+
{analysisData.detailed_analysis.numerology_analysis.lower_trigram_number.meaning}
+
{analysisData.detailed_analysis.numerology_analysis.lower_trigram_number.influence}
+
+ +
+

组合能量

+
{analysisData.detailed_analysis.numerology_analysis.combined_energy.total}
+
{analysisData.detailed_analysis.numerology_analysis.combined_energy.interpretation}
+
{analysisData.detailed_analysis.numerology_analysis.combined_energy.harmony}
+
+ +
+

时间共振

+
{analysisData.detailed_analysis.numerology_analysis.time_resonance.resonance_number}
+
{analysisData.detailed_analysis.numerology_analysis.time_resonance.meaning}
+
{analysisData.detailed_analysis.numerology_analysis.time_resonance.interpretation}
+
+
+
+
+ )} + + {/* 五行分析 */} + {analysisData.detailed_analysis.hexagram_analysis.five_elements && ( + + + + + 五行分析 + + + +
+
+
+

五行属性

+
+
+ 上卦五行: + + {analysisData.detailed_analysis.hexagram_analysis.five_elements.upper_element} + +
+
+ 下卦五行: + + {analysisData.detailed_analysis.hexagram_analysis.five_elements.lower_element} + +
+
+
+
+ +
+
+

五行关系

+
+
+ 相互作用: +

{analysisData.detailed_analysis.hexagram_analysis.five_elements.relationship}

+
+
+ 平衡状态: +

{analysisData.detailed_analysis.hexagram_analysis.five_elements.balance}

+
+
+
+
+
+
+
+ )} + + {/* 时间分析 */} + {analysisData.dynamic_guidance.time_analysis && ( + + + + + 时间分析 + +

天时地利人和的时机把握

+
+ +
+
+

+ 🌸 + 季节 +

+
{analysisData.dynamic_guidance.time_analysis.season.name}
+
{analysisData.dynamic_guidance.time_analysis.season.energy}
+
{analysisData.dynamic_guidance.time_analysis.season.advice}
+
+ +
+

+ + 时辰 +

+
{analysisData.dynamic_guidance.time_analysis.time_of_day.name}
+
{analysisData.dynamic_guidance.time_analysis.time_of_day.energy}
+
{analysisData.dynamic_guidance.time_analysis.time_of_day.advice}
+
+ +
+

+ + 月相 +

+
{analysisData.dynamic_guidance.time_analysis.lunar_phase.name}
+
{analysisData.dynamic_guidance.time_analysis.lunar_phase.energy}
+
{analysisData.dynamic_guidance.time_analysis.lunar_phase.advice}
+
+ +
+

+ + 能量状态 +

+
{analysisData.dynamic_guidance.time_analysis.energy_state.overall}
+
{analysisData.dynamic_guidance.time_analysis.energy_state.recommendation}
+
+
+
+
+ )} + + {/* 专业指导 */} +
+ {/* 针对性指导 */} + + + + + 针对性指导 + + + +
+
+

专业分析

+

{analysisData.dynamic_guidance.targeted_guidance}

+
+
+

实用建议

+

{analysisData.dynamic_guidance.practical_advice}

+
+
+
+
+ + {/* 易经智慧 */} + + + + + 易经智慧 + + + +
+
+

核心信息

+

{analysisData.divination_wisdom.key_message}

+
+
+

行动建议

+

{analysisData.divination_wisdom.action_advice}

+
+
+

时机把握

+

{analysisData.divination_wisdom.timing_guidance}

+
+
+
+
+
+ + {/* 哲学洞察 */} + + + + + 哲学洞察 + + + +
+

+ {analysisData.divination_wisdom.philosophical_insight} +

+
+
+
+ + {/* 免责声明 */} + + +

+ 本占卜分析基于传统易经理论,结合现代分析方法生成。 + 易经占卜是中华传统文化的重要组成部分,仅供参考,不可过分依赖。 + 人生的幸福需要通过自己的努力和智慧来创造。 +

+
+ 占卜时间:{new Date().toLocaleString('zh-CN')} +
+
+
+
+
+ ); +}; + +export default CompleteYijingAnalysis; \ No newline at end of file diff --git a/src/lib/localApi.ts b/src/lib/localApi.ts index abde37c..28dfcc3 100644 --- a/src/lib/localApi.ts +++ b/src/lib/localApi.ts @@ -195,10 +195,10 @@ class LocalApiClient { }, // 易经分析 - yijing: async (birthData: any, question?: string): Promise> => { + yijing: async (yijingData: any): Promise> => { return this.request<{ record_id: number; analysis: any }>('/analysis/yijing', { method: 'POST', - body: JSON.stringify({ birth_data: birthData, question }), + body: JSON.stringify(yijingData), }); }, diff --git a/src/pages/AnalysisPage.tsx b/src/pages/AnalysisPage.tsx index 790efb7..a4184ec 100644 --- a/src/pages/AnalysisPage.tsx +++ b/src/pages/AnalysisPage.tsx @@ -56,9 +56,17 @@ const AnalysisPage: React.FC = () => { const handleAnalysis = async () => { if (!user) return; - if (!formData.name || !formData.birth_date) { - toast.error('请填写姓名和出生日期'); - return; + // 根据分析类型验证必要参数 + if (analysisType === 'yijing') { + if (!formData.question) { + toast.error('请填写占卜问题'); + return; + } + } else { + if (!formData.name || !formData.birth_date) { + toast.error('请填写姓名和出生日期'); + return; + } } setLoading(true); @@ -84,7 +92,12 @@ const AnalysisPage: React.FC = () => { response = await localApi.analysis.ziwei(birthData); break; case 'yijing': - response = await localApi.analysis.yijing(birthData, formData.question); + const yijingData = { + question: formData.question, + user_id: user.id, + divination_method: 'time' + }; + response = await localApi.analysis.yijing(yijingData); break; default: throw new Error(`不支持的分析类型: ${analysisType}`); @@ -190,79 +203,87 @@ const AnalysisPage: React.FC = () => {

-
-
- setFormData(prev => ({ ...prev, name: e.target.value }))} - required - placeholder="请输入真实姓名" - /> - -
- - setFormData(prev => ({ ...prev, birth_date: e.target.value }))} - required - /> - -
- - setFormData(prev => ({ ...prev, birth_time: e.target.value }))} - placeholder="选填,但强烈建议填写" - /> - - - {analysisType === 'yijing' && ( + {analysisType === 'yijing' ? ( + // 易经占卜表单
setFormData(prev => ({ ...prev, question: e.target.value }))} - placeholder="请输入您希望占卜的具体问题(可选)" + placeholder="请输入您希望占卜的具体问题,如:我的事业发展如何?" + required /> +

+ 💡 提示:问题越具体,占卜结果越准确。可以询问事业、感情、财运、健康等方面的问题。 +

- )} - - {analysisType !== 'ziwei' && analysisType !== 'yijing' && ( -
-
- setFormData(prev => ({ ...prev, birth_place: e.target.value }))} - placeholder="如:北京市朝阳区(选填)" + ) : ( + // 八字和紫微表单 + <> +
+
+ setFormData(prev => ({ ...prev, name: e.target.value }))} + required + placeholder="请输入真实姓名" + /> + +
+ + setFormData(prev => ({ ...prev, birth_date: e.target.value }))} + required + /> + +
+ + setFormData(prev => ({ ...prev, birth_time: e.target.value }))} + placeholder="选填,但强烈建议填写" + /> +
+ + {analysisType !== 'ziwei' && ( +
+
+ setFormData(prev => ({ ...prev, birth_place: e.target.value }))} + placeholder="如:北京市朝阳区(选填)" + /> + +
+
+ )} + )}