feat: 前端剧本解析 parseScript + RubyText 逐字高亮 highlight prop
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
<view class="ruby-wrap" :class="{ dark: dark }">
|
||||
<view v-for="(ch, i) in pairs" :key="i" class="ruby-unit">
|
||||
<text v-if="ch.p && show" class="ruby-py">{{ ch.p }}</text>
|
||||
<text class="ruby-ch">{{ ch.c }}</text>
|
||||
<text class="ruby-ch" :class="{ 'ruby-hl': highlight >= 0 && i < highlight, 'ruby-cur': i === highlight }">{{ ch.c }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
@@ -16,7 +16,8 @@ export default {
|
||||
text: { type: String, default: '' },
|
||||
pinyin: { type: String, default: '' }, // 后端原始 JSON 字符串
|
||||
show: { type: Boolean, default: true }, // 4-6 档显示,6-8 档可关
|
||||
dark: { type: Boolean, default: false }
|
||||
dark: { type: Boolean, default: false },
|
||||
highlight: { type: Number, default: -1 } // >=0 逐字高亮到该下标;-1 不启用
|
||||
},
|
||||
computed: {
|
||||
pairs() {
|
||||
@@ -51,4 +52,7 @@ export default {
|
||||
.dark .ruby-ch {
|
||||
color: #5b4636;
|
||||
}
|
||||
.ruby-hl { color: #ff6b35; font-weight: 700; }
|
||||
.ruby-cur { color: #ff6b35; font-weight: 800; animation: cur-pop 0.3s ease; }
|
||||
@keyframes cur-pop { 0% { transform: scale(1.35); } 100% { transform: scale(1.15); } }
|
||||
</style>
|
||||
|
||||
@@ -27,3 +27,14 @@ export function entryProps(entry) {
|
||||
export function entryCharacter(entry) {
|
||||
return entry && entry.character ? entry.character : null
|
||||
}
|
||||
|
||||
// parseScript 解析节点剧本(JSON 台词流),非法/为空返回 null(调用方回退 v1 呈现)
|
||||
export function parseScript(raw) {
|
||||
if (!raw) return null
|
||||
try {
|
||||
const arr = JSON.parse(raw)
|
||||
return Array.isArray(arr) && arr.length > 0 ? arr : null
|
||||
} catch (e) {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user