Files
36Wisdom/ui-src/src/components/RubyText.vue
T

55 lines
1.1 KiB
Vue

<template>
<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>
</view>
</view>
</template>
<script>
import { parsePinyin, zipText } from '../utils/pinyin.js'
export default {
name: 'RubyText',
props: {
text: { type: String, default: '' },
pinyin: { type: String, default: '' }, // 后端原始 JSON 字符串
show: { type: Boolean, default: true }, // 4-6 档显示,6-8 档可关
dark: { type: Boolean, default: false }
},
computed: {
pairs() {
return zipText(this.text, parsePinyin(this.pinyin))
}
}
}
</script>
<style scoped>
.ruby-wrap {
display: flex;
flex-wrap: wrap;
line-height: 1.9;
}
.ruby-unit {
display: flex;
flex-direction: column;
align-items: center;
margin: 0 2rpx;
}
.ruby-py {
font-size: 20rpx;
color: #ff6b35;
line-height: 1.3;
height: 28rpx;
}
.ruby-ch {
font-size: 32rpx;
line-height: 1.5;
}
.dark .ruby-ch {
color: #5b4636;
}
</style>