From 723d3624a589d84ba7c13ced2cc047ae00c14ed5 Mon Sep 17 00:00:00 2001 From: H1d3rOne Date: Sat, 7 Mar 2026 09:38:23 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=85=AB=E5=AD=97=E7=BB=93=E6=9E=9C?= =?UTF-8?q?=E9=A1=B5=E5=85=AC=E5=8E=86=E6=97=B6=E9=97=B4=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=EF=BC=8C=E5=8E=BB=E6=8E=89=E7=A7=92=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- xuan-deduct-uniapp/src/pages/bazi/result.vue | 266 ++++++++++++++++++- 1 file changed, 265 insertions(+), 1 deletion(-) diff --git a/xuan-deduct-uniapp/src/pages/bazi/result.vue b/xuan-deduct-uniapp/src/pages/bazi/result.vue index 91eb237..f8a4b5a 100644 --- a/xuan-deduct-uniapp/src/pages/bazi/result.vue +++ b/xuan-deduct-uniapp/src/pages/bazi/result.vue @@ -32,7 +32,7 @@ πŸ€– AIε‘½η†εˆ†ζž - {{ result.aiAnalysis }} + @@ -185,6 +185,9 @@ export default { } } } + if (time.includes('η§’')) { + return time.replace(/\d{2}η§’$/, '') + } return time.replace(/:\d{2}$/, '') } return '-' @@ -196,6 +199,14 @@ export default { 'ζ—₯柱': this.result.dayGanZhiShenSha || [], 'ζ—ΆζŸ±': this.result.hourGanZhiShenSha || [] } + }, + parsedAiAnalysis() { + if (!this.result.aiAnalysis) return [] + return this.parseMarkdown(this.result.aiAnalysis) + }, + markdownHtml() { + if (!this.result.aiAnalysis) return '' + return this.markdownToHtml(this.result.aiAnalysis) } }, onLoad() { @@ -210,6 +221,173 @@ export default { } }, methods: { + markdownToHtml(markdown) { + if (!markdown) return '' + + let html = markdown + + const lines = html.split('\n') + if (lines.length > 0) { + lines.shift() + html = lines.join('\n').trim() + } + + html = html.replace(/^### (.*$)/gim, '

$1

') + html = html.replace(/^## (.*$)/gim, '

$1

') + html = html.replace(/^# (.*$)/gim, '

$1

') + + html = html.replace(/\*\*(.+?)\*\*/g, '$1') + html = html.replace(/\*(.+?)\*/g, '$1') + html = html.replace(/`(.+?)`/g, '$1') + + html = html.replace(/^\s*[-β€’]\s(.+)$/gim, '
  • $1
  • ') + + html = html.replace(/(]*>.*<\/li>\n?)+/g, function(match) { + return '' + }) + + html = html.replace(/\n\n/g, '

    ') + html = html.replace(/\n/g, '
    ') + + if (!html.startsWith('<')) { + html = '

    ' + html + '

    ' + } + + return html + }, + parseMarkdown(text) { + if (!text) return [] + + const nodes = [] + const lines = text.split('\n') + let currentParagraph = [] + let listItems = [] + + lines.forEach((line) => { + line = line.trim() + + if (line === '') { + if (currentParagraph.length > 0) { + nodes.push({ + type: 'paragraph', + text: currentParagraph.join('\n') + }) + currentParagraph = [] + } + if (listItems.length > 0) { + nodes.push({ + type: 'list', + items: listItems + }) + listItems = [] + } + return + } + + if (line.startsWith('### ')) { + if (currentParagraph.length > 0) { + nodes.push({ + type: 'paragraph', + text: currentParagraph.join('\n') + }) + currentParagraph = [] + } + if (listItems.length > 0) { + nodes.push({ + type: 'list', + items: listItems + }) + listItems = [] + } + nodes.push({ + type: 'h3', + text: line.substring(4) + }) + } else if (line.startsWith('## ')) { + if (currentParagraph.length > 0) { + nodes.push({ + type: 'paragraph', + text: currentParagraph.join('\n') + }) + currentParagraph = [] + } + if (listItems.length > 0) { + nodes.push({ + type: 'list', + items: listItems + }) + listItems = [] + } + nodes.push({ + type: 'h2', + text: line.substring(3) + }) + } else if (line.startsWith('# ')) { + if (currentParagraph.length > 0) { + nodes.push({ + type: 'paragraph', + text: currentParagraph.join('\n') + }) + currentParagraph = [] + } + if (listItems.length > 0) { + nodes.push({ + type: 'list', + items: listItems + }) + listItems = [] + } + nodes.push({ + type: 'h1', + text: line.substring(2) + }) + } else if (line.startsWith('β€’ ') || line.startsWith('- ') || line.startsWith('* ')) { + if (currentParagraph.length > 0) { + nodes.push({ + type: 'paragraph', + text: currentParagraph.join('\n') + }) + currentParagraph = [] + } + listItems.push(line.substring(2)) + } else if (line.match(/^\d+\.\s/)) { + if (currentParagraph.length > 0) { + nodes.push({ + type: 'paragraph', + text: currentParagraph.join('\n') + }) + currentParagraph = [] + } + const text = line.replace(/^\d+\.\s/, '') + listItems.push(text) + } else { + if (listItems.length > 0) { + nodes.push({ + type: 'list', + items: listItems + }) + listItems = [] + } + currentParagraph.push(line) + } + }) + + if (currentParagraph.length > 0) { + nodes.push({ + type: 'paragraph', + text: currentParagraph.join('\n') + }) + } + + if (listItems.length > 0) { + nodes.push({ + type: 'list', + items: listItems + }) + } + + return nodes + }, getGan(index) { if (this.result.baZi && this.result.baZi[index]) { return this.result.baZi[index].charAt(0) @@ -630,4 +808,90 @@ page { font-size: 24rpx; color: #9CA3AF; } + +.markdown-content { + width: 100%; + font-size: 26rpx; + color: #374151; + line-height: 1.8; +} + +.markdown-content h1 { + font-size: 36rpx; + font-weight: bold; + color: #DC2626; + margin: 32rpx 0 20rpx 0; + padding: 16rpx 24rpx; + background: linear-gradient(135deg, #FEF2F2 0%, #FEE2E2 100%); + border-left: 6rpx solid #DC2626; + border-radius: 8rpx; +} + +.markdown-content h2 { + font-size: 32rpx; + font-weight: bold; + color: #B91C1C; + margin: 28rpx 0 16rpx 0; + padding: 12rpx 20rpx; + background: linear-gradient(90deg, #FFF7ED 0%, transparent 100%); + border-left: 4rpx solid #F59E0B; +} + +.markdown-content h3 { + font-size: 28rpx; + font-weight: 600; + color: #92400E; + margin: 24rpx 0 12rpx 0; + padding: 8rpx 16rpx; + border-bottom: 2rpx dashed #F59E0B; + display: inline-block; +} + +.markdown-content p { + margin: 16rpx 0; + text-align: justify; + text-indent: 2em; + color: #4B5563; + line-height: 2; +} + +.markdown-content strong { + font-weight: bold; + color: #DC2626; + background: linear-gradient(135deg, #FEF2F2 0%, transparent 100%); + padding: 2rpx 8rpx; + border-radius: 4rpx; +} + +.markdown-content em { + font-style: normal; + color: #7C3AED; + font-weight: 500; +} + +.markdown-content code { + font-family: "Courier New", monospace; + background: linear-gradient(135deg, #FEF3C7 0%, #FDE68A 100%); + padding: 4rpx 12rpx; + border-radius: 6rpx; + color: #92400E; + font-size: 24rpx; + border: 1rpx solid #F59E0B; + font-weight: 500; +} + +.markdown-content ul { + margin: 16rpx 0; + padding-left: 0; + list-style: none; +} + +.markdown-content li { + margin: 12rpx 0; + padding: 12rpx 16rpx 12rpx 24rpx; + background: linear-gradient(90deg, #F0FDF4 0%, transparent 100%); + border-left: 3rpx solid #10B981; + color: #374151; + line-height: 1.8; +}