Skip to content

Commit

Permalink
fix: vv9-26 chaifen
Browse files Browse the repository at this point in the history
  • Loading branch information
yb6b committed Mar 21, 2024
1 parent 4d0eded commit 3d3ce0c
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 42 deletions.
7 changes: 0 additions & 7 deletions components/Anki.vue

This file was deleted.

20 changes: 10 additions & 10 deletions components/search/FetchSearch.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<script setup lang="ts">
import { onMounted, shallowRef, provide } from "vue";
import Search from "./Search.vue";
import { cache } from "./share";
import { cache, ChaiCard, ZigenCard } from "./share";
import { fetchJsonWithCache } from "../train/share";
const p = defineProps<{
/** 汉字到拆分表的JSON文件名 */
/** 汉字信息的JSON文件的名字 */
hanziJson: string
/** 字根到按键的JSON文件名 */
/** 字根信息的JSON文件的名字 */
compJson?: string
/** 字根字体的class名字 */
compFont?: string
Expand All @@ -21,8 +21,8 @@ provide('font', p.compFont)
// 一丨丿丶乙
provide('high', p.id.includes('easy') ? '' : '⼀⼂⺂⼁⼃')
const schemaData = shallowRef<{
compDict: Record<string, string>,
hanziDict: Record<string, string | Array<string>>
compDict: Record<string, ZigenCard>,
hanziDict: Record<string, ChaiCard>
}>()
onMounted(async () => {
Expand All @@ -31,11 +31,11 @@ onMounted(async () => {
schemaData.value = cache[p.id]
return
}
const hanziJson = await fetchJsonWithCache(p.hanziJson)
const compJson = p.compJson && await fetchJsonWithCache(p.compJson)
const hanziJson = await fetchJsonWithCache(p.hanziJson) as ChaiCard[]
const compJson = p.compJson ? (await fetchJsonWithCache(p.compJson) as ZigenCard[]) : []
const result = {
compDict: Object.fromEntries(compJson.map(v => [v.name, v.key])),
hanziDict: Object.fromEntries(hanziJson.map(v => [v.name, v.comp])),
compDict: Object.fromEntries(compJson.map(v => [v.name, v])),
hanziDict: Object.fromEntries(hanziJson.map(v => [v.name, v])),
}
cache[p.id] = result
schemaData.value = result
Expand All @@ -44,5 +44,5 @@ onMounted(async () => {

<template>
<div class="text-gray-600" v-if="!schemaData">正在加载拆分数据……</div>
<Search v-else :hanziDict="schemaData.hanziDict" :compDict="schemaData.compDict" />
<Search v-else :hanziDict="schemaData.hanziDict" :compDict="schemaData.compDict" :dasm />
</template>
13 changes: 7 additions & 6 deletions components/search/Search.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { watchThrottled, useUrlSearchParams } from "@vueuse/core";
import SearchAsync from "./SearchAsync.vue";
import SearchHanzi from "./SearchHanzi.vue";
import SearchHelp from "./SearchHelp.vue";
import { type Result } from "./share";
import type { Result, ChaiCard, ZigenCard } from "./share";
const p = defineProps<{
/** 汉字到拆分表的映射 */
hanziDict: Record<string, string | Array<string>>
hanziDict: Record<string, ChaiCard>
/** 字根到按键的映射 */
compDict?: Record<string, string>
compDict?: Record<string, ZigenCard>
/** 自定义字根转编码时的规则 */
dasm?: (comp: string[], compDict: Record<string, string>) => string
}>()
Expand Down Expand Up @@ -38,9 +38,10 @@ watchThrottled(userInput, () => {
const textToResult = (text: string): Result => [...text]
.filter(z => z in p.hanziDict)
.map(zi => {
const comps = [...p.hanziDict[zi]]
const keys = p.dasm ? [...p.dasm(comps, p.compDict)] : comps.map(c => p.compDict[c])
return [zi, comps, keys] as const
const data = p.hanziDict[zi]
const comps = [...data.comp]
const keys = 'key' in data ? [...data.key] : comps.map(c => p.compDict[c].key)
return [zi, comps, keys]
})
function searchHanziHandler() {
Expand Down
3 changes: 2 additions & 1 deletion components/search/share.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export { type ZigenCard, type ChaiCard, fetchJsonWithCache } from '../train/share'
export let cache: Record<string, object> = {}
export type Result = (readonly [zi: string, comps: string[], keys: string[]])[]
export type Result = [zi: string, comps: string[], keys: string[]][]
6 changes: 4 additions & 2 deletions components/train/HanziTrain.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ const p = defineProps<{
zigenJson?: string,
/** 字根的字体CSS名称 */
fontClass?: string
/** 自定义字根转编码时的规则 */
dasm?: (comp: string[], compDict: Record<string, string>) => string
}>()
provide("font", p.fontClass)
Expand Down Expand Up @@ -42,7 +44,7 @@ onMounted(async () => {
if (p.zigenJson) {
const zigenCard = await fetchJsonWithCache(p.zigenJson) as ZigenCard[]
const zigenKeyMap = new Map(zigenCard.map(v => [v.name, v.key]))
const zigenKeyMap = Object.fromEntries(zigenCard.map(v => [v.name, v.key]))
for (const e of chaifenCards) {
if (e.key) continue
Expand All @@ -52,7 +54,7 @@ onMounted(async () => {
throw new Error(msg)
}
e.key = [...e.comp].map(gen => zigenKeyMap.get(gen) || '').join('')
e.key = p.dasm ? p.dasm([...e.comp], zigenKeyMap) : [...e.comp].map(gen => zigenKeyMap[gen] || '').join('')
}
}
Expand Down
2 changes: 1 addition & 1 deletion components/train/TrainCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ watch(progress, async (newV, oldV) => {
</div>
<div :class="['text-center', { 'opacity-0': !isFirstLearn }]">答案是 <b class="font-mono">{{ card.key
}}</b>
<span :class="[fontClass]" v-if="'comp' in card">({{ card.comp }})</span>
<span :class="['kaiti-font', fontClass]" v-if="'comp' in card">({{ card.comp }})</span>
</div>
</slot>
</template>
Expand Down
9 changes: 7 additions & 2 deletions components/train/anki/TrainAnki.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ watch(progress, async (newV, oldV) => {
}
})
const cusRestart = () => {
if (!confirm(`重置进度需要清空数据,无法撤回,您确定继续吗?`)) return;
restart()
}
</script>

<template>
Expand All @@ -81,7 +86,7 @@ watch(progress, async (newV, oldV) => {
:class="['input w-half max-w-xs input-bordered text-center input-sm dark:bg-slate-800 bg-white', { 'input-error': !isCorrect }]" />
</div>
<div :class="['text-center', { 'opacity-0': isCorrect }]">答案是 <b class="font-mono">{{ card.key }}</b>
<span :class="[fontClass]" v-if="'comp' in card">({{ card.comp }})</span>
<span :class="['kaiti-font', fontClass]" v-if="'comp' in card">({{ card.comp }})</span>
</div>
</template>

Expand All @@ -97,6 +102,6 @@ watch(progress, async (newV, oldV) => {

<div class="text-gray-500 flex justify-between">
<div class="text-gray-500">训练进度: {{ progress.meet }} / {{ cards.length }}</div>
<button class="btn btn-ghost btn-sm font-light" @click="_ => restart()">restart</button>
<button class="btn btn-ghost btn-sm font-light" @click=" cusRestart()">restart</button>
</div>
</template>
4 changes: 2 additions & 2 deletions src/easy-code/search.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
aside: false
---
<script setup>
import Search from "@/search/FetchSearch.vue"
import Search from "@/search/FetchSearch.vue"
</script>

# 易码拆分反查

<Search hanziJson="/easy-code/chaifen.json" compJson="/easy-code/zigen.json" compFont="outi-font" id="easy-code"/>
<Search hanziJson="/easy-code/chaifen.json" compJson="/easy-code/zigen.json" compFont="outi-font" id="easy-code" />
9 changes: 1 addition & 8 deletions src/graceful-code/vv9-26/search.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,8 @@ aside: false
---
<script setup>
import Search from "@/search/FetchSearch.vue"
const s5 = new Set("ノㄋ丨一丶")
const dasm = (comp, compDict) => {
const tmp = comp.map((v) => compDict[v])
if (s5.has(tmp[0])) tmp[0] = 'j'
if (s5.has(tmp[1])) tmp[1] = 'j'
return tmp.join('')
}
</script>

# 逸码VV9 · 26键 拆分反查

<Search hanziJson="/vv9-26/chaifen.json" compJson="/vv9-26/zigen.json" compFont="kaiti-font" id="vv9-26" :dasm />
<Search hanziJson="/vv9-26/chaifen.json" compJson="/vv9-26/zigen.json" id="vv9-26" />
2 changes: 1 addition & 1 deletion src/graceful-code/vv9-26/zi.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
aside: false
---
<script setup>
import Train from "@/train/HanziTrain.vue"
import Train from "@/train/HanziTrain.vue"
</script>
# 逸码 VV9 · 26键 常用 1000 字练习

Expand Down
2 changes: 1 addition & 1 deletion src/graceful-code/vv9-26/zi2.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
aside: false
---
<script setup>
import Train from "@/train/HanziTrain.vue"
import Train from "@/train/HanziTrain.vue"
</script>
# 逸码 VV9 · 26键 常用 1000~2000 字练习

Expand Down
2 changes: 1 addition & 1 deletion src/public/vv9-26/chaifen.json

Large diffs are not rendered by default.

0 comments on commit 3d3ce0c

Please sign in to comment.