Skip to content

Commit

Permalink
feat(theme): hanzi 组件增加成语属性
Browse files Browse the repository at this point in the history
  • Loading branch information
FuckDoctors committed May 16, 2024
1 parent d3af2f6 commit 1a79835
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 5 deletions.
39 changes: 36 additions & 3 deletions docs/.vuepress/theme/components/hanzi/Hanzi.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<script setup>
import { onMounted, ref, shallowRef } from 'vue'
import { computed, onMounted, ref, shallowRef } from 'vue'
import cnchar from 'cnchar'
import draw from 'cnchar-draw'
import order from 'cnchar-order'
import radical from 'cnchar-radical'
import words from 'cnchar-words'
import voice from 'cnchar-voice'
import idiom from 'cnchar-idiom'
import {
CARD_WIDTH,
Expand Down Expand Up @@ -42,9 +43,15 @@ const props = defineProps({
return []
},
},
chengyu: {
type: Array,
default() {
return []
},
},
})
cnchar.use(draw, order, radical, words, voice)
cnchar.use(draw, order, radical, words, voice, idiom)
const printRef = ref(null)
const aniRef = ref(null)
Expand All @@ -55,6 +62,20 @@ const bushouRet = shallowRef([{}])
const bihuaCountRet = shallowRef([props.bihuashu])
const bihuaNameRet = shallowRef([props.bihua])
const zuciRet = shallowRef(props.zuci)
const chengyuRef = computed(() => {
if (props.chengyu.length > 0) {
return props.chengyu.slice(0, 5)
}
return (
cnchar
.idiom(props.zi)
// 过滤四字成语
.filter(item => item.length === 4)
// .sort((a, b) => a.length - b.length)
.slice(0, 5)
)
})
const speehTxt = ref([])
Expand Down Expand Up @@ -127,6 +148,11 @@ onMounted(() => {
speehTxt.value.push('组词')
speehTxt.value.push(...props.zuci)
}
if (chengyuRef.value.length > 0) {
speehTxt.value.push('成语')
speehTxt.value.push(...chengyuRef.value)
}
})
function handleVoice() {
Expand Down Expand Up @@ -238,7 +264,14 @@ function handleRead() {
:kong="TIAN_KONG"
/>
</div>
<div class="words-container">{{ zuciRet.join(' ') }}&nbsp;</div>
<div class="info words-container">
<span class="tag">组词</span>
<span class="content">{{ zuciRet.join(' ') }}</span>
</div>
<div class="info chengyu">
<span class="tag">成语</span>
<span class="content">{{ chengyuRef.join(' ') }}</span>
</div>
</div>
</div>
</div>
Expand Down
6 changes: 5 additions & 1 deletion docs/.vuepress/theme/components/hanzi/hanzi.css
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,12 @@
width: auto;
}

.words-container {
.info.words-container {
text-align: left;
display: block;
}
.info.chengyu {
display: block;
}

.hanzi-controls {
Expand Down
6 changes: 5 additions & 1 deletion docs/posts/edu/learn-hanzi.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,15 @@ head:

它是一个数组,用于指定汉字的组词。

### `成语`

它是一个数组,用于指定汉字的成语。

## 简单效果

<Hanzi zi="" :zuci="['春风', '春雨', '春天', '春日']" />
<Hanzi zi="" :bihua="['撇', '横撇', '捺', '点', '点']" />
<Hanzi zi="" pinyin="fēng" jiegou="独体字" :zuci="['风雨', '风云', '大风', '东风']" />
<Hanzi zi="" pinyin="fēng" jiegou="独体字" :zuci="['风雨', '风云', '大风', '东风']" :chengyu="['一帆风顺', '风口浪尖', '风云人物', '风吹云散']" />

## 查字

Expand Down

0 comments on commit 1a79835

Please sign in to comment.