Skip to content

Commit

Permalink
feat: web input method
Browse files Browse the repository at this point in the history
  • Loading branch information
yb6b committed Jun 25, 2024
1 parent 42ec6c7 commit 34bfd1e
Show file tree
Hide file tree
Showing 16 changed files with 2,159 additions and 1,393 deletions.
33 changes: 33 additions & 0 deletions components/ime/BaseGracefulCode.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<script setup lang="ts">
import FetchInput from "./FetchInput.vue"
import { ref, computed } from "vue"
import { ImeRule } from "./share";
const props = defineProps<{
/** 每个字的拆分数据,可以包含编码 */
chaifenJson: string
/** 字根数据的路径。如果省略,则chaifen里必须要有编码信息 */
zigenJson?: string
/** 方案的ID,用于保存localstorage */
id?: string
defaultPop?: boolean
}>()
const usePop = ref(props.defaultPop || false)
const rule: ImeRule = {
pop: 0,
len: 6,
cm1: ' ',
cm2: ';',
cm3: "'",
keys: 26,
autoCm: 2,
}
</script>

<template>
<FetchInput :zigenJson :chaifenJson :id :rule>
</FetchInput>
</template>
51 changes: 51 additions & 0 deletions components/ime/BaseGrandCode.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<script setup lang="ts">
import FetchInput from "./FetchInput.vue"
import { ref, computed } from "vue"
import { ImeRule } from "./share";
const props = defineProps<{
/** 每个字的拆分数据,可以包含编码 */
chaifenJson: string
/** 字根数据的路径。如果省略,则chaifen里必须要有编码信息 */
zigenJson?: string
/** 方案的ID,用于保存localstorage */
id?: string
defaultPop?: boolean
}>()
const usePop = ref(props.defaultPop || false)
const rule3: ImeRule = {
pop: 0,
len: 3,
cm1: ' ',
cm2: ';',
cm3: "'",
keys: 26,
autoCm: 4,
}
const rule42: ImeRule = {
pop: 2,
len: 3,
cm1: ' ',
cm2: ';',
cm3: "'",
keys: 26,
autoCm: 4,
}
const rule = computed(() => usePop.value ? rule42 : rule3)
</script>

<template>
<FetchInput :zigenJson :chaifenJson :id :rule>
<div class="form-control">
<label class="label cursor-pointer pt-0">
<input type="checkbox" class="checkbox checkbox-sm" style="border: currentColor 2px solid;"
v-model="usePop" />
<span>&nbsp;使用四二顶</span>
</label>
</div>
</FetchInput>
</template>
48 changes: 48 additions & 0 deletions components/ime/FetchInput.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<script setup lang="ts">
import * as utils from './share'
import { onMounted, shallowRef } from "vue";
import InputMethod from './InputMethod.vue'
/** 在线输入法,只打单字 */
const p = defineProps<{
/** 每个字的拆分数据,可以包含编码 */
chaifenJson: string
/** 字根数据的路径。如果省略,则chaifen里必须要有编码信息 */
zigenJson?: string
/** 方案的ID,用于保存localstorage */
id?: string
/** 方案的配置 */
rule: utils.ImeRule
}>()
const id = p.id || p.chaifenJson
const schemaData = shallowRef<utils.HanziCard[]>()
onMounted(async () => {
if (id in utils.cache) {
schemaData.value = utils.cache[id]
return
}
const chaifenJson: utils.HanziCard[] = await utils.fetchJsonWithCache(p.chaifenJson)
if (p.zigenJson) {
const zigenJson: utils.ZigenCard[] = await utils.fetchJsonWithCache(p.zigenJson)
const zigenMap = utils.makeMapFromArray(zigenJson)
for (const cf of chaifenJson) {
if (cf.key) continue
cf.key = [...cf.comp!].map(zg => zigenMap.get(zg)!.key).join('')
}
}
chaifenJson.sort(utils.sortFunc)
schemaData.value = chaifenJson
utils.cache[id] = chaifenJson
})
</script>

<template>
<div class="text-gray-600 text-center" v-if="!schemaData">加载中……</div>
<InputMethod v-else :id :rule :data="schemaData">
<slot></slot>
</InputMethod>
</template>
Loading

0 comments on commit 34bfd1e

Please sign in to comment.