1 | # zidian
|
2 | 汉字、词语、成语查询接口
|
3 |
|
4 | ### Demo <https://zidian.netnr.com>
|
5 |
|
6 | ### 引言
|
7 | - 数据来源于开源项目 <https://github.com/pwxcoo/chinese-xinhua>
|
8 | - 而该项目的数据是一个`JSON`文件,大小超出 `20M`,不利于页面加载使用,所以拆分了文件
|
9 | - 提取字、词、成语为数组,根据数组索引分页生成详情,具体请看 `build/parse.html` 的拆分脚本
|
10 |
|
11 | ### 使用
|
12 | 引入
|
13 | ```
|
14 | <script src="dist/zidian.js"></script>
|
15 | ```
|
16 |
|
17 | 汉字查询
|
18 | ```js
|
19 | zidian.equalWord(key)
|
20 |
|
21 | zidian.equalWord("爱").then(console.log)
|
22 | ```
|
23 |
|
24 | 词语查询
|
25 | ```js
|
26 | zidian.equalCi(key)
|
27 |
|
28 | zidian.equalCi("美丽").then(console.log)
|
29 | ```
|
30 |
|
31 | 成语查询
|
32 | ```js
|
33 | zidian.equalIdiom(key)
|
34 |
|
35 | zidian.equalIdiom("叶公好龙").then(console.log)
|
36 | ```
|
37 |
|
38 | 词语模糊搜索
|
39 | ```js
|
40 | zidian.likeCi(key)
|
41 |
|
42 | zidian.likeCi("美").then(console.log)
|
43 | ```
|
44 |
|
45 | 成语模糊搜索
|
46 | ```js
|
47 | zidian.likeIdiom(key)
|
48 |
|
49 | zidian.likeIdiom("三百").then(console.log)
|
50 | ```
|
51 |
|
52 | ### 说明
|
53 | - 接口查询返回一个 `Promise` 对象
|
54 | - 查询的接口会缓存到 `zidian.cache` 对象
|
55 | - 查询无记录时,返回 `null`
|
56 | - `zidian.config.host` 可配置请求源 |
\ | No newline at end of file |