first commit
This commit is contained in:
commit
6bc4ef1c41
84 files changed
+13968
No files matched your search
@@ -0,0 +1,42 @@
|
||||
import { dict } from './dic.js'
|
||||
|
||||
let SimpleInputMethod = {
|
||||
dict: {}
|
||||
}
|
||||
|
||||
SimpleInputMethod.initDict = function() {
|
||||
this.dict.py2hz = dict;
|
||||
this.dict.py2hz2 = {};
|
||||
this.dict.py2hz2['i'] = 'i'; // i比较特殊,没有符合的汉字,所以特殊处理
|
||||
|
||||
for (let key in this.dict.py2hz) {
|
||||
let ch = key[0];
|
||||
if (!this.dict.py2hz2[ch]) {
|
||||
this.dict.py2hz2[ch] = this.dict.py2hz[key];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
SimpleInputMethod.getSingleHanzi = function(pinyin){
|
||||
return this.dict.py2hz2[pinyin] || this.dict.py2hz[pinyin] || '';
|
||||
}
|
||||
|
||||
SimpleInputMethod.getHanzi = function(pinyin) {
|
||||
let result = this.getSingleHanzi(pinyin);
|
||||
if (result) return [result.split(''), pinyin];
|
||||
|
||||
let temp = '';
|
||||
let start = Math.min(pinyin.length, 6);
|
||||
|
||||
for (let i = start; i >= 1; i--) {
|
||||
let str = pinyin.substr(0, i);
|
||||
let rs = this.getSingleHanzi(str);
|
||||
if (rs) return [rs.split(''), str];
|
||||
}
|
||||
|
||||
return [[], '']; // 理论上一般不会出现这种情况
|
||||
};
|
||||
|
||||
SimpleInputMethod.initDict();
|
||||
|
||||
export { SimpleInputMethod } //换成export default SimpleInputMethod;不能用
|
||||
Reference in new issue
Block a user