網(wǎng)站開發(fā)服務(wù)內(nèi)容企業(yè)vi設(shè)計說明
鶴壁市浩天電氣有限公司
2026/01/24 10:39:18
網(wǎng)站開發(fā)服務(wù)內(nèi)容,企業(yè)vi設(shè)計說明,深圳網(wǎng)頁設(shè)計興田德潤專業(yè),品牌創(chuàng)意型網(wǎng)站建設(shè)一、使用場景
在漢字學(xué)習、識字類項目中#xff0c;通常需要提前生成#xff1a;
漢字拼音#xff08;帶聲調(diào)#xff09;筆畫數(shù)筆畫類型#xff08;橫豎撇捺等#xff09;常見組詞
本文使用 Node.js cnchar 生成 JSON 數(shù)據(jù)#xff0c;供后端直接導(dǎo)入數(shù)據(jù)庫使用。二、安…一、使用場景在漢字學(xué)習、識字類項目中通常需要提前生成漢字拼音帶聲調(diào)筆畫數(shù)筆畫類型橫豎撇捺等常見組詞本文使用Node.js cnchar生成 JSON 數(shù)據(jù)供后端直接導(dǎo)入數(shù)據(jù)庫使用。二、安裝依賴npminstallcnchar cnchar-order cnchar-poly cnchar-words cnchar-voice三、生成腳本generate_char_data1.js// generate_char_data_for_execjs.js// Node ESM / execjs / cnchar// 生成拼音 / 筆畫數(shù) / 筆畫名 / 原始筆畫數(shù)據(jù)importcncharfromcnchar;importorderfromcnchar-order;importpolyfromcnchar-poly;importwordsfromcnchar-words;importvoicefromcnchar-voice;importfsfromfs;// // 1? 注冊插件// cnchar.use(order,poly,words,voice);// // 2? 獲取單字數(shù)據(jù)// functiongetCharacterData(char){try{// 拼音constspellcnchar.spell(char,tone);constpinyinArray.isArray(spell)?spell.join( / ):spell||;// 筆畫數(shù)conststrokeCountcnchar.stroke(char)||1;// 筆畫名稱標準conststrokeNameListcnchar.stroke(char,order,name);conststrokeNamesArray.isArray(strokeNameList)?strokeNameList.join(,):;// ? 原始筆畫detail 模式conststrokeDetailListcnchar.stroke(char,order,detail);conststrokesRawcnchar.stroke(char,order,shape)// 組詞constwordListcnchar.words(char);constwordsStrArray.isArray(wordList)?wordList.slice(0,8).join(,):;return{character:char,pinyin,stroke_count:strokeCount,stroke_names:strokeNames,strokes_raw:strokesRaw,// 新增字段words:wordsStr};}catch(err){return{character:char,pinyin:,stroke_count:1,stroke_names:,strokes_raw:[],words:};}}// // 3?Node 直接運行示例// if(process.argv[1]process.argv[1].includes(generate_char_data)){constchars[一,人,好,學(xué),你,我];constdatachars.map(getCharacterData);fs.writeFileSync(./char_data.json,JSON.stringify({generated_at:newDate().toISOString(),total:data.length,characters:data},null,2),utf-8);console.log( 已生成 char_data.json含原始筆畫);}// // 4? execjs 導(dǎo)出// export{getCharacterData};四、運行腳本nodegenerate_char_data1.js生成文件generated_characters.json五、生成結(jié)果示例{generated_at:2025-12-27T02:47:57.131Z,total:6,characters:[{character:一,pinyin:Yī,stroke_count:1,stroke_names:橫,strokes_raw:[[一]],words:八一,八一隊,不一,不一定,創(chuàng)一流,初一,單一,第一},{character:人,pinyin:Rén,stroke_count:2,stroke_names:撇,捺,strokes_raw:[[丿,?]],words:愛人,愛人民,保護人,被告人,北京人,本人,辯護人,別人},{character:好,pinyin:Hǎo,stroke_count:6,stroke_names:撇點,撇,橫,橫撇|橫鉤,豎鉤,橫,strokes_raw:[[,丿,一,?|乛,亅,一]],words:愛好,愛好者,辦好,備好,變好,不好,大好,打好},{character:學(xué),pinyin:Xué,stroke_count:8,stroke_names:點,點,撇,點2,橫撇|橫鉤,橫撇|橫鉤,豎鉤,橫,strokes_raw:[[丶,丶,丿,?,?|乛,?|乛,亅,一]],words:愛科學(xué),愛學(xué)習,辦學(xué),博學(xué),不科學(xué),才學(xué),輟學(xué),初學(xué)},{character:你,pinyin:Nǐ,stroke_count:7,stroke_names:撇,豎,撇,橫撇|橫鉤,豎鉤,撇,點,strokes_raw:[[丿,丨,丿,?|乛,亅,丿,丶]],words:你的,你好,迷你,你們,你我},{character:我,pinyin:Wǒ,stroke_count:7,stroke_names:撇,橫,豎鉤,提,斜鉤|臥鉤,撇,點,strokes_raw:[[丿,一,亅,?,?|?,丿,丶]],words:你我,忘我,我廠,我處,我方,我國,我局,我軍}]}六、注意事項重要stroke_count可靠stroke_names僅用于基礎(chǔ)展示教學(xué)級筆順 / 動畫建議前端使用HanziWriter不推薦在 Django / Java 中直接計算筆畫七、總結(jié)cnchar 適合數(shù)據(jù)預(yù)生成Node.js 非常適合做漢字數(shù)據(jù)工具腳本后端只負責存儲前端負責交互與動畫