增加18030修正版字库

master
yutent 2022-03-11 18:58:43 +08:00
parent 98bd1fd292
commit 1e925f6571
4 changed files with 1313 additions and 28 deletions

View File

@ -35,17 +35,19 @@
<div class="search"> <div class="search">
<section class="field flex alc"> <section class="field flex alc">
<wc-input placeholder="输入汉字或五笔编码查询" :duplex="filter.txt" @submit="search"></wc-input> <wc-input placeholder="输入汉字或五笔编码查询" :duplex="filter.text" @submit="search"></wc-input>
</section> </section>
<section class="field flex alc"> <section class="field flex alc">
<wc-radio-group :duplex="filter.table"> <wc-radio-group :duplex="filter.table" @change="search">
<wc-radio value="86">86版</wc-radio> <wc-radio value="86">86版</wc-radio>
<wc-radio value="18030" type="danger">18030版(86修正版)</wc-radio> <wc-radio value="18030" type="danger">18030版(86修正版)</wc-radio>
</wc-radio-group> </wc-radio-group>
</section> </section>
<wc-scroll>
<section class="field result">{{result}}</section> <section class="field result">{{result}}</section>
</wc-scroll>
</div> </div>
@ -63,7 +65,7 @@
<footer class="footer flex ac"> <footer class="footer flex ac">
<div class="wrapper flex asc"> <div class="wrapper flex asc">
<span>&copy;2022, Yutent™.</span> <span>&copy;2022, Yutent™.</span>
<span>Power By Anot.js, wcui</span> <span>Power by JavaScript</span>
</div> </div>
</footer> </footer>

View File

@ -13,9 +13,11 @@ import '//unpkg.yutent.top/@bytedo/wcui/dist/form/switch.js'
import fetch from '//unpkg.yutent.top/@bytedo/fetch/dist/index.js' import fetch from '//unpkg.yutent.top/@bytedo/fetch/dist/index.js'
import { Enum } from './lib/core.js' import { Enum } from './lib/core.js'
import FIXED_18030 from './lib/18030.js'
const WB_CODE_NAME = new Enum({ 1: '一级简码', 2: '二级简码', 3: '三级简码', 4: '四级简码' }) const WB_CODE_NAME = { 1: '一级简码', 2: '二级简码', 3: '三级简码', 4: '四级简码' }
const WB_TABLE = new Enum() const WB_TABLE = new Enum()
const WB_TABLE_18030 = new Enum(FIXED_18030)
Anot.hideProperty(WB_TABLE, 'length', 0) Anot.hideProperty(WB_TABLE, 'length', 0)
@ -26,7 +28,7 @@ Anot({
words: 0, words: 0,
result: '', result: '',
filter: { filter: {
txt: '', text: '',
table: '86' table: '86'
} }
}, },
@ -55,49 +57,76 @@ Anot({
methods: { methods: {
search() { search() {
var params = { ...this.filter } var { text, table } = this.filter
var reverse = false var reverse = false
var res var res, res18030
params.txt = params.txt.trim().toLowerCase() text = text.trim().toLowerCase()
reverse = /^[a-z]{1,4}$/.test(params.txt) if (!text) {
return
if (!reverse) {
params.txt = params.txt.replace(/[\sa-z]/g, '')
} }
if (reverse || params.txt.length === 1) { reverse = /^[a-z]{1,4}$/.test(text)
res = [WB_TABLE.get(params.txt)]
if (!reverse) {
text = text.replace(/[\sa-z]/g, '')
}
if (reverse || text.length === 1) {
res = [WB_TABLE.get(text)]
if (table === '18030') {
res18030 = [WB_TABLE_18030.get(text)]
}
} else { } else {
res = params.txt.split('').map(t => WB_TABLE.get(t)) res = text.split('').map(t => WB_TABLE.get(t))
if (table === '18030') {
res18030 = text.split('').map(t => WB_TABLE_18030.get(t))
}
} }
if (reverse) { if (reverse) {
text = text.toUpperCase()
// 反查时, 直接替换结果
if (res18030 && res18030.length) {
res = res18030
}
if (res[0]) { if (res[0]) {
res = `${params.txt} 】👉\t${res[0].join('\t\t')}` res = `${text} 】👉\t${res[0]
.map(
t =>
`${t}(${(res18030 && res18030.length ? WB_TABLE_18030.get(t) : WB_TABLE.get(t))
.join('、')
.toUpperCase()})`
)
.join('\t\t')}`
} else { } else {
res = `${ res = `${text} 】👉\t无结果, 请检查你的输入是否正确, 如果确认无误, 可以反馈缺失字库。`
params.txt
} 👉\t无结果, 请检查你的输入是否正确, 如果确认无误, 可以反馈缺失字库`
} }
} else { } else {
if (res18030 && res18030.length) {
res18030.forEach((it, i) => {
if (it) {
res[i] = it
}
})
}
res = res res = res
.map((it, i) => { .map((it, i) => {
if (it) { if (it) {
return `${params.txt[i]} 】👉\t${it return `${text[i]} 】👉\t${it
.map(t => `${WB_CODE_NAME.get(t.length)}: ${t.toUpperCase()}`) .map(t => `${WB_CODE_NAME[t.length]}: ${t.toUpperCase()}`)
.join('\t\t')}` .join('\t\t')}`
} else { } else {
return `${ return `${
params.txt[i] text[i]
} 👉\t无结果, 请检查你的输入是否正确, 如果确认无误, 可以反馈缺失字库` } 👉\t无结果, 请检查你的输入是否正确, 如果确认无误, 可以反馈缺失字库`
} }
}) })
.join('\n') .join('\n')
} }
this.result = `查询耗时: ${t1}ms\n查询结果: \n${res}` this.result = `查询结果: \n${res}`
} }
} }
}) })

1254
js/lib/18030.js Normal file

File diff suppressed because it is too large Load Diff

View File

@ -48,7 +48,6 @@ export class Enum {
} }
get(k) { get(k) {
console.log('>>>>', k)
if (this.#dict_k[k]) { if (this.#dict_k[k]) {
return this.#dict_k[k] return this.#dict_k[k]
} else if (this.#dict_v[k]) { } else if (this.#dict_v[k]) {
@ -56,9 +55,10 @@ export class Enum {
} }
} }
forEach(callback) { forEach(callback, forV) {
for (let k in this.#dict_k) { var dict = forV ? this.#dict_v : this.#dict_k
if (callback(k, this.#dict_k[k]) === false) { for (let k in dict) {
if (callback(k, dict[k]) === false) {
break break
} }
} }