feat(mini-program): 剧本卡片支持 Markdown 渲染

实现内容:
- 扩展 Markdown 组件支持三级标题 (###) 和粗体 (**text**)
- ScriptView.vue 卡片摘要使用 Markdown 组件渲染
- 新增 ScriptDetailView.vue 剧本详情页,展示完整 Markdown 内容
- 点击卡片可跳转查看详情,"路径映射"按钮使用@click.stop 避免事件冒泡

修改文件:
- components/Markdown.vue: 添加 h3 标题、粗体解析和样式
- pages/main/ScriptView.vue: 导入 Markdown 组件,修改摘要渲染方式,添加跳转逻辑
- pages/main/ScriptDetailView.vue: 新建详情页,展示剧本完整内容
- pages.json: 注册 ScriptDetailView 页面

解决 issues: 小程序"创造未来"页面剧本内容以纯文本显示,
            无法正确渲染 Markdown 格式(标题、列表、粗体等)
This commit is contained in:
2026-04-07 21:28:44 +08:00
parent 42d7bb3cb5
commit 86b3fa8f84
4 changed files with 486 additions and 80 deletions
+190 -75
View File
@@ -2,7 +2,7 @@
<view class="script-view">
<text class="page-title font-serif">剧本生成器</text>
<view class="section-card glass-card">
<view class="section-card glass-card-gold">
<view class="section-header">
<text class="section-title">我的基础人设</text>
<text class="section-hint">可自由修改</text>
@@ -36,6 +36,24 @@
placeholder="如:巅峰重现、治愈之旅、赛博觉醒..."
v-model="scriptConfig.theme"
/>
<!-- 灵感气泡 -->
<view class="hint-container">
<view class="hint-header">
<text class="hint-icon"></text>
<text class="hint-label">灵感气泡</text>
</view>
<view class="hint-list">
<view
v-for="(hint, index) in scriptHints"
:key="index"
class="hint-chip"
:style="{ animationDelay: index * 0.1 + 's' }"
@click="addHint(hint)"
>
<text>{{ hint }}</text>
</view>
</view>
</view>
</view>
<view class="input-group">
@@ -127,17 +145,20 @@
:key="script.id"
class="script-card glass-card"
:class="{ selected: script.isSelected }"
@click="viewScriptDetail(script)"
>
<view class="script-header">
<text class="script-title">{{ script.title }}</text>
<text class="script-persona">{{ script.theme || '追光者' }}</text>
</view>
<text class="script-summary" lines="3">{{ getScriptSummary(script) }}</text>
<view class="script-summary">
<Markdown :content="getScriptSummary(script)" />
</view>
<view class="script-footer">
<text class="script-style">{{ script.style || '风格' }}</text>
<button class="select-btn" @click="selectScript(script.id)">
<button class="select-btn" @click.stop="selectScript(script.id)">
路径映射
</button>
</view>
@@ -159,6 +180,7 @@
<script setup>
import { ref, computed, reactive, onMounted } from 'vue'
import { useAppStore } from '../../stores/app.js'
import Markdown from '../../components/Markdown.vue'
const store = useAppStore()
@@ -168,6 +190,7 @@ const npcRoleOptions = ['伙伴', '宿敌', '导师', '挚爱', '下属', '路
const npcRelationOptions = ['信任', '对立', '暧昧', '敬畏', '背叛', '守护']
const scriptStyles = ['爽文', '治愈', '热血', '玄幻', '职场', '赛博']
const scriptLengths = ['短篇', '中篇', '长篇', '史诗']
const scriptHints = ['觉醒时刻', '命运转折', '自我救赎', '巅峰重现', '治愈之旅', '星际穿越', '破茧成蝶', '时光倒流']
const registrationData = computed(() => store.registrationData || {})
const scripts = computed(() => store.scripts || [])
@@ -232,6 +255,14 @@ const removeNpc = (index) => {
customNpcs.value.splice(index, 1)
}
const addHint = (hint) => {
if (scriptConfig.theme) {
scriptConfig.theme += ' · ' + hint
} else {
scriptConfig.theme = hint
}
}
const generateScript = async () => {
if (!scriptConfig.theme || isGenerating.value) return
@@ -256,9 +287,31 @@ const selectScript = async (id) => {
uni.$emit('switchTab', 'path')
}
const viewScriptDetail = (script) => {
uni.navigateTo({
url: `/pages/main/ScriptDetailView?id=${script.id}`
})
}
const getScriptSummary = (script) => {
const text = script.summary || script.content || ''
return text.replace(/\s+/g, ' ').trim()
// 优先使用 summary 字段
if (script.summary) {
return script.summary
}
// 从 fullContent 提取前 200 字符
const fullContent = script.plotJson?.fullContent || ''
if (fullContent) {
// 提取内容,去掉 Markdown 符号
return fullContent
.split('\n')
.filter(line => line.trim())
.slice(0, 5) // 取前 5 行
.join('\n')
.slice(0, 200) + '...'
}
return '暂无摘要'
}
onMounted(async () => {
@@ -274,35 +327,36 @@ onMounted(async () => {
flex-direction: column;
gap: 20rpx;
min-height: 100%;
font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}
.page-title {
font-size: 32rpx;
font-size: 36rpx;
font-weight: 300;
color: rgba(255, 255, 255, 0.9);
letter-spacing: 4rpx;
font-family: 'Cinzel', 'Inter', serif;
}
/* 人设卡片 - 金色玻璃态 */
.section-card {
padding: 32rpx; /* 20rpx → 32rpx */
border-radius: 40rpx; /* 28rpx → 40rpx */
/* 金色玻璃态背景 */
padding: 32rpx;
border-radius: 40rpx;
background: linear-gradient(135deg, rgba(168, 85, 247, 0.15), rgba(232, 121, 249, 0.1));
border: 1px solid rgba(168, 85, 247, 0.3);
box-shadow: inset 0 0 30rpx rgba(168, 85, 247, 0.08), 0 4rpx 20rpx rgba(168, 85, 247, 0.1);
transition: all 0.3s ease;
margin-bottom: 32rpx; /* 新增 */
margin-bottom: 32rpx;
}
.section-card:active {
transform: scale(0.98);
box-shadow: inset 0 0 20rpx rgba(168, 85, 247, 0.1), 0 2rpx 12rpx rgba(168, 85, 247, 0.05);
box-shadow: inset 0 0 20rpx rgba(168, 85, 247, 0.05), 0 2rpx 12rpx rgba(168, 85, 247, 0.05);
}
.glass-card-main {
padding: 32rpx; /* 24rpx → 32rpx */
border-radius: 40rpx; /* 56rpx → 40rpx (统一标准) */
padding: 32rpx;
border-radius: 40rpx;
}
.section-header {
@@ -313,7 +367,7 @@ onMounted(async () => {
}
.section-title {
font-size: 20rpx; /* 17rpx → 20rpx */
font-size: 20rpx;
color: rgba(192, 132, 252, 0.6);
font-weight: 600;
letter-spacing: 3rpx;
@@ -321,7 +375,7 @@ onMounted(async () => {
}
.section-hint {
font-size: 15rpx; /* 13rpx → 15rpx */
font-size: 15rpx;
color: rgba(255, 255, 255, 0.35);
font-style: italic;
}
@@ -329,18 +383,18 @@ onMounted(async () => {
.profile-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 24rpx; /* 10rpx → 24rpx */
gap: 24rpx;
}
.glass-input, .glass-picker {
width: 100%;
height: 88rpx; /* 64rpx → 88rpx */
height: 88rpx;
background: rgba(255, 255, 255, 0.05);
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 32rpx; /* 20rpx → 32rpx */
padding: 0 24rpx; /* 16rpx → 24rpx */
border-radius: 32rpx;
padding: 0 24rpx;
color: rgba(255, 255, 255, 0.9);
font-size: 28rpx; /* 18rpx → 28rpx */
font-size: 28rpx;
box-sizing: border-box;
}
@@ -349,12 +403,12 @@ onMounted(async () => {
}
.theme-input {
height: 88rpx; /* 72rpx → 88rpx */
font-size: 28rpx; /* 19rpx → 28rpx */
height: 88rpx;
font-size: 28rpx;
}
.picker-value {
line-height: 88rpx; /* 64rpx → 88rpx */
line-height: 88rpx;
color: rgba(255, 255, 255, 0.9);
}
@@ -362,14 +416,82 @@ onMounted(async () => {
margin-bottom: 24rpx;
}
/* 灵感气泡容器 */
.hint-container {
margin-top: 16rpx;
padding: 24rpx;
background: rgba(168, 85, 247, 0.08);
border: 1px solid rgba(168, 85, 247, 0.15);
border-radius: 32rpx;
box-shadow: inset 0 0 20rpx rgba(168, 85, 247, 0.05);
}
.hint-header {
display: flex;
align-items: center;
gap: 8rpx;
margin-bottom: 16rpx;
}
.hint-icon {
font-size: 24rpx;
filter: drop-shadow(0 0 8rpx rgba(192, 132, 252, 0.6));
}
.hint-label {
font-size: 18rpx;
color: rgba(192, 132, 252, 0.8);
font-weight: 600;
letter-spacing: 4rpx;
text-transform: uppercase;
}
.hint-list {
display: flex;
flex-wrap: wrap;
gap: 12rpx;
}
.hint-chip {
padding: 10rpx 20rpx;
background: rgba(255, 255, 255, 0.05);
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 24rpx;
font-size: 20rpx;
color: rgba(243, 232, 255, 0.8);
box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.2);
backdrop-filter: blur(8rpx);
transition: all 0.2s ease;
animation: bubble-float 5s ease-in-out infinite;
}
.hint-chip:active {
background: rgba(168, 85, 247, 0.25);
border-color: rgba(168, 85, 247, 0.5);
transform: scale(0.95);
box-shadow: 0 8rpx 15rpx rgba(168, 85, 247, 0.3);
}
@keyframes bubble-float {
0%, 100% {
transform: translateY(0) rotate(0deg);
}
33% {
transform: translateY(-4rpx) rotate(1deg);
}
66% {
transform: translateY(2rpx) rotate(-1deg);
}
}
.label {
display: block;
font-size: 20rpx; /* 17rpx → 20rpx */
font-size: 20rpx;
color: rgba(192, 132, 252, 0.6);
font-weight: 600;
letter-spacing: 3rpx;
text-transform: uppercase;
margin-bottom: 12rpx; /* 10rpx → 12rpx */
margin-bottom: 12rpx;
}
.npc-header {
@@ -398,7 +520,7 @@ onMounted(async () => {
.npc-form {
display: grid;
grid-template-columns: 1fr 1fr; /* 3 列 → 2 列 */
grid-template-columns: 1fr 1fr;
gap: 16rpx;
}
@@ -408,81 +530,81 @@ onMounted(async () => {
}
.npc-input, .npc-picker {
height: 88rpx; /* 60rpx → 88rpx */
padding: 0 24rpx; /* 14rpx → 24rpx */
font-size: 28rpx; /* 17rpx → 28rpx */
height: 88rpx;
padding: 0 24rpx;
font-size: 28rpx;
}
.npc-picker .picker-value {
line-height: 88rpx; /* 60rpx → 88rpx */
font-size: 28rpx; /* 17rpx → 28rpx */
line-height: 88rpx;
font-size: 28rpx;
}
.glass-textarea {
width: 100%;
height: 120rpx; /* 88rpx → 120rpx */
height: 120rpx;
background: rgba(255, 255, 255, 0.05);
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 32rpx; /* 20rpx → 32rpx */
padding: 20rpx; /* 14rpx → 20rpx */
border-radius: 32rpx;
padding: 20rpx;
color: rgba(255, 255, 255, 0.9);
font-size: 24rpx; /* 17rpx → 24rpx */
font-size: 24rpx;
box-sizing: border-box;
}
.npc-list {
display: flex;
flex-wrap: wrap;
gap: 16rpx; /* 10rpx → 16rpx */
gap: 16rpx;
}
.npc-tag {
background: rgba(168, 85, 247, 0.1);
border: 1px solid rgba(168, 85, 247, 0.3);
border-radius: 24rpx; /* 20rpx → 24rpx */
padding: 10rpx 20rpx; /* 6rpx 16rpx → 10rpx 20rpx */
font-size: 20rpx; /* 18rpx → 20rpx */
border-radius: 24rpx;
padding: 10rpx 20rpx;
font-size: 20rpx;
color: rgba(243, 232, 255, 0.8);
display: flex;
align-items: center;
gap: 8rpx; /* 6rpx → 8rpx */
gap: 8rpx;
}
.delete-btn {
color: rgba(255, 255, 255, 0.4);
font-size: 24rpx; /* 20rpx → 24rpx */
padding: 0 4rpx; /* 0 2rpx → 0 4rpx */
font-size: 24rpx;
padding: 0 4rpx;
}
.params-section {
margin-bottom: 32rpx; /* 24rpx → 32rpx */
margin-bottom: 32rpx;
}
.param-section-label {
display: block;
font-size: 20rpx; /* 17rpx → 20rpx */
font-size: 20rpx;
color: rgba(192, 132, 252, 0.6);
font-weight: 600;
letter-spacing: 3rpx;
text-transform: uppercase;
margin-bottom: 16rpx; /* 12rpx → 16rpx */
margin-bottom: 16rpx;
}
.params-container {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 24rpx; /* 16rpx → 24rpx */
gap: 24rpx;
}
.param-group {
display: flex;
flex-direction: column;
gap: 12rpx; /* 8rpx → 12rpx */
gap: 12rpx;
min-width: 0;
}
.param-sublabel {
font-size: 17rpx; /* 15rpx → 17rpx */
font-size: 17rpx;
color: rgba(255, 255, 255, 0.4);
margin-left: 4rpx;
}
@@ -490,17 +612,18 @@ onMounted(async () => {
.param-options {
display: flex;
flex-wrap: wrap;
gap: 10rpx; /* 6rpx → 10rpx */
gap: 10rpx;
}
.param-option {
padding: 12rpx 20rpx; /* 6rpx 12rpx → 12rpx 20rpx */
padding: 12rpx 20rpx;
background: rgba(255, 255, 255, 0.05);
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 20rpx; /* 18rpx → 20rpx */
font-size: 20rpx; /* 17rpx → 20rpx */
border-radius: 20rpx;
font-size: 20rpx;
color: rgba(255, 255, 255, 0.4);
white-space: nowrap;
transition: all 0.2s ease;
}
.param-option.active {
@@ -513,23 +636,22 @@ onMounted(async () => {
.generate-btn {
width: 100%;
height: 96rpx; /* 80rpx → 96rpx */
border-radius: 40rpx; /* 28rpx → 40rpx */
height: 96rpx;
border-radius: 40rpx;
box-shadow: 0 8rpx 32rpx rgba(168, 85, 247, 0.3);
margin-top: 24rpx; /* 8rpx → 24rpx */
margin-top: 24rpx;
}
.scripts-list {
display: flex;
flex-direction: column;
gap: 24rpx; /* 16rpx → 24rpx */
gap: 24rpx;
}
.script-card {
padding: 32rpx; /* 20rpx → 32rpx */
padding: 32rpx;
border-left: 3rpx solid transparent;
border-radius: 40rpx; /* 28rpx → 40rpx */
/* Crown 图标装饰 */
border-radius: 40rpx;
position: relative;
}
@@ -550,30 +672,30 @@ onMounted(async () => {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 14rpx; /* 10rpx → 14rpx */
margin-bottom: 14rpx;
}
.script-title {
font-size: 32rpx; /* 26rpx → 32rpx */
font-size: 32rpx;
font-weight: 500;
color: rgba(255, 255, 255, 0.9);
}
.script-persona {
font-size: 17rpx; /* 15rpx → 17rpx */
font-size: 17rpx;
color: rgba(168, 85, 247, 0.6);
background: rgba(168, 85, 247, 0.1);
padding: 6rpx 12rpx; /* 5rpx 10rpx → 6rpx 12rpx */
border-radius: 12rpx; /* 10rpx → 12rpx */
padding: 6rpx 12rpx;
border-radius: 12rpx;
border: 1px solid rgba(168, 85, 247, 0.2);
}
.script-summary {
display: block;
font-size: 24rpx; /* 20rpx → 24rpx */
font-size: 24rpx;
color: rgba(255, 255, 255, 0.5);
line-height: 1.5;
margin-bottom: 16rpx; /* 14rpx → 16rpx */
margin-bottom: 16rpx;
}
.script-footer {
@@ -583,12 +705,12 @@ onMounted(async () => {
}
.script-style {
font-size: 18rpx; /* 16rpx → 18rpx */
font-size: 18rpx;
color: #C084FC;
}
.select-btn {
font-size: 20rpx; /* 18rpx → 20rpx */
font-size: 20rpx;
color: #C084FC;
font-weight: 600;
background: transparent;
@@ -682,13 +804,6 @@ onMounted(async () => {
50% { opacity: 1; }
}
.generating-text {
font-size: 20rpx;
color: rgba(192, 132, 252, 0.6);
font-style: italic;
letter-spacing: 2rpx;
}
/* 超小屏幕适配 - 375px 断点 */
@media (max-width: 375px) {
.params-container {