Skip to content

Commit

Permalink
添加自定义主码表功能,搜索显示码表自定义名
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleBing committed Jul 30, 2024
1 parent f459229 commit 7d96504
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 28 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## v1.27 `2024-07-30`
## v1.28 `2024-07-30`
- 优化暗黑模式下词条分组分配的显示
- 暗黑模式下 分组上下移动样式优化
- 添加调换两个词条顺序时调换两个词的权重
Expand Down
2 changes: 1 addition & 1 deletion assets/scss/_searchbar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ select{
position: absolute;
z-index: 9999;
top: 30px;
width: 400px;
max-width: 600px;
left: 0;
background-color: white;
@include border-radius($radius);
Expand Down
2 changes: 1 addition & 1 deletion assets/scss/wubi.css
Original file line number Diff line number Diff line change
Expand Up @@ -1264,7 +1264,7 @@ select option {
position: absolute;
z-index: 9999;
top: 30px;
width: 400px;
max-width: 600px;
left: 0;
background-color: white;
-webkit-border-radius: 3px;
Expand Down
18 changes: 15 additions & 3 deletions js/Dict.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ const EOL = '\n'


class Dict {
constructor(fileContent, fileName, filePath, header, ) {
/**
* @param fileContent 词库内容
* @param fileName
* @param filePath
* @param isForceProcessInUngroupMode 按照非分组模式读取词库
*/
constructor(fileContent, fileName, filePath, isForceProcessInUngroupMode) {
this.dictTypeName = 'Dict'
this.filePath = filePath // 文件路径
this.fileName = fileName // 文件名字
Expand All @@ -20,7 +26,6 @@ class Dict {
this.dictSetExceptCharacter = new Set() // 所有词组的 set



let indexEndOfHeader = fileContent.indexOf('...')
if (indexEndOfHeader < 0){
console.log('文件格式错误,没有 ... 这一行')
Expand All @@ -29,7 +34,14 @@ class Dict {
this.header = fileContent.substring(0, this.indexEndOfHeader)
this.isGroupMode = this.header.includes('dict_grouped: true') // 根据有没有这一段文字进行判断,是否为分组形式的码表
let body = fileContent.substring(this.indexEndOfHeader)
this.wordsOrigin = this.isGroupMode? this.getDictWordsInGroupMode(body): this.getDictWordsInNormalMode(body)

if (isForceProcessInUngroupMode) {
this.wordsOrigin = this.getDictWordsInNormalMode(body)
} else if (this.isGroupMode) {
this.wordsOrigin = this.getDictWordsInGroupMode(body)
} else {
this.wordsOrigin = this.getDictWordsInNormalMode(body)
}
// console.log('处理后的词条:',this.wordsOrigin)
}
}
Expand Down
5 changes: 3 additions & 2 deletions js/Global.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const CONFIG_FILE_PATH = 'wubi-dict-editor' // 配置文件存放的目录

const DEFAULT_CONFIG = {
initFileName: 'wubi86_jidian_user.dict.yaml' , // 初始文件信息
baseURL: 'http://kylebing.cn/portal/', // BASE_URL
baseURL: 'http://kylebing.cn/portal/', // BASE_URL
autoDeployOnAdd: false , // 添词后 是否自动部署
autoDeployOnDelete: false , // 删词后 是否自动部署
autoDeployOnEdit: false , // 编辑词条后 是否自动部署
Expand All @@ -27,7 +27,8 @@ const DEFAULT_CONFIG = {
hasSetDictMap: false , // 是否已经设置字典码表文件
isToolPanelShowing: true, // index.html 工具面板是否展开
fileNameList: [], // 匹配文件名,显示自定义码表文件的名字
// [{ "name": "luna_pinyin.sogou", "path": "luna_pinyin.sogou.dict.yaml" }]
// [{ "name": "luna_pinyin.sogou", "path": "luna_pinyin.sogou.dict.yaml" }]
mainDictFileName: 'wubi86_jidian.dict.yaml', // 主词库文件名 v1.28
}

const SYNC_MAX_WORD_COUNT = 40000
Expand Down
3 changes: 2 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ function createMainWindow() {

// 监听载入主文件内容的请求
ipcMain.on('loadMainDict', event => {
let mainDictFileName = 'wubi86_jidian.dict.yaml'
let config = readConfigFile()
let mainDictFileName = config.mainDictFileName || DEFAULT_CONFIG.mainDictFileName
fs.readFile(path.join(getRimeConfigDir(), mainDictFileName), {encoding: 'utf-8'}, (err, res) => {
if (err) {
console.log(err)
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "wubi-dict-editor",
"version": "1.2.7",
"version": "1.2.8",
"private": true,
"author": {
"name": "KyleBing",
"email": "[email protected]"
},
"date": "2024-06-13",
"date": "2024-07-30",
"dateInit": "2021-07-24",
"description": "五笔码表管理工具",
"main": "main.js",
Expand Down Expand Up @@ -34,7 +34,7 @@
"config": {
"forge": {
"packagerConfig": {
"appVersion": "1.2.7",
"appVersion": "1.2.8",
"name": "五笔码表助手",
"appCopyright": "[email protected]",
"icon": "./assets/img/appIcon/appicon",
Expand Down
13 changes: 8 additions & 5 deletions view/config/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ const app = {
ipcRenderer.on('ConfigWindow:ResponseConfigFile', (event, config) => {
console.log('获取配置成功')
this.config = config

// v1.27 添加 mainDictFileName 字段
if (!config.hasOwnProperty('mainDictFileName')) this.$set(this.config, 'mainDictFileName', 'wubi86_jidian.dict.yaml')

// v1.15 添加 rimeExecDir 字段
if (config.hasOwnProperty('rimeExecDir')){
if (!config.hasOwnProperty('rimeExecDir')) this.$set(this.config, 'rimeExecDir', '')

} else {
this.$set(this.config, 'rimeExecDir', '')
}
this.userInfo.email = config.userInfo && config.userInfo.email

// after config is loaded, then request for fileList
ipcRenderer.send('requestFileList')
})
Expand Down Expand Up @@ -125,6 +125,9 @@ const app = {
setInitFile(file){
this.config.initFileName = file.path
},
setMainDictFile(file){
this.config.mainDictFileName = file.path
},
setDictMap(){
ipcRenderer.send('ConfigWindow:SetDictMapFile')
},
Expand Down
36 changes: 28 additions & 8 deletions view/config/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,29 @@ <h3>3. 自动部署</h3>
</div>
</section>

<section v-if="config && config.fileNameList">
<div class="section-title">
<h3>4. 指定主码表文件</h3>
<div class="desc">自定义指定你的主码表文件,在搜索词条展示已存在词条时有用。设置完成后重启程序后生效。</div>
</div>
<div class="section-content">
<div class="config-file-list">
<div @click="setMainDictFile(file)"
:class="['config-file-list-item', {active: file.path === config.mainDictFileName}]"
v-for="(file, index) in config.fileNameList"
:key="index"
v-if="config.fileNameList"
>
<div class="name">{{file.name}}</div>
<div class="path">{{file.path}}</div>
</div>
</div>
</div>
</section>

<section>
<div class="section-title">
<h3>4. 回车动作</h3>
<h3>5. 回车动作</h3>
<div class="desc">定义搜索框中按回车键的动作</div>
</div>
<div class="section-content">
Expand Down Expand Up @@ -108,7 +128,7 @@ <h3>4. 回车动作</h3>

<section>
<div class="section-title">
<h3>5. 搜索</h3>
<h3>6. 搜索</h3>
<div class="desc">搜索匹配的内容</div>
</div>
<div class="section-content">
Expand Down Expand Up @@ -155,7 +175,7 @@ <h3>5. 搜索</h3>

<section>
<div class="section-title">
<h3>6. 选取输入法配置文件目录</h3>
<h3>7. 选取输入法配置文件目录</h3>
<div class="desc">工具自动读取的输入法配置文件目录</div>
</div>
<div class="section-content">
Expand All @@ -169,7 +189,7 @@ <h3>6. 选取输入法配置文件目录</h3>

<section>
<div class="section-title">
<h3>7. 选取输入法程序目录 ( 适用于 Windows )</h3>
<h3>8. 选取输入法程序目录 ( 适用于 Windows )</h3>
<div class="desc">程序安装在了什么位置,用于自动部署</div>
</div>
<div class="section-content">
Expand All @@ -182,7 +202,7 @@ <h3>7. 选取输入法程序目录 ( 适用于 Windows )</h3>
</section>
<section>
<div class="section-title">
<h3>8. 选择参考码表</h3>
<h3>9. 选择参考码表</h3>
<div class="desc">添加新词时、批量生成编码时,使用的码表,格式:前词后码,tab 分隔。</div>
<div class="desc">正常的 Rime 码表文件都能正常使用,有多字也无所谓,程序会自动只选取单字部分使用。</div>
<div class="desc">默认情况下,程序使用 wubi86_jidian.dict.yaml 这个文件作为参考码表。</div>
Expand All @@ -198,7 +218,7 @@ <h3>8. 选择参考码表</h3>

<section>
<div class="section-title">
<h3>9. 主题</h3>
<h3>10. 主题</h3>
<div class="desc">切换主题</div>
</div>
<div class="section-content">
Expand Down Expand Up @@ -236,7 +256,7 @@ <h3>9. 主题</h3>

<section>
<div class="section-title">
<h3>10. 请求地址</h3>
<h3>11. 请求地址</h3>
<div class="desc">数据交互的线上地址</div>
</div>
<div class="section-content">
Expand All @@ -251,7 +271,7 @@ <h3>10. 请求地址</h3>

<section>
<div class="section-title">
<h3>11. 同步</h3>
<h3>12. 同步</h3>
<div class="desc">同步用户词库,账号请前往 <a target="_blank" href="http://kylebing.cn/diary">http://kylebing.cn/diary</a> 注册</div>
</div>
<div class="section-content">
Expand Down
11 changes: 9 additions & 2 deletions view/index/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ const app = {

// 载入主码表
ipcRenderer.on('setMainDict', (event, filename, res) => {
this.dictMain = new Dict(res, filename)
this.dictMain = new Dict(res, filename, '', true)
console.log('主码表词条数量:', this.dictMain.wordsOrigin.length)
})

// 配置文件保存后,向主窗口更新配置文件内容
Expand Down Expand Up @@ -247,6 +248,11 @@ const app = {
// 当前载入的是否为 主 码表
isInMainDict(){
return this.dict.fileName === 'wubi86_jidian.dict.yaml'
},
// 文件名字列表
fileNameListMap(){
// [{ "name": "luna_pinyin.sogou", "path": "luna_pinyin.sogou.dict.yaml" }]
return new Map(this.config.fileNameList.map(item => [item.path, item.name]))
}
},
methods: {
Expand Down Expand Up @@ -1223,8 +1229,9 @@ const app = {
this.code = newValue.replaceAll(/[^A-Za-z ]/g, '') // input.code 只允许输入字母
// 主码表中的词
let wordsMainDictRedundancy = this.dictMain.wordsOrigin.filter(item => item.code === newValue)

wordsMainDictRedundancy = wordsMainDictRedundancy.map(item => {
item.origin = '主码表' // 标记主码表来源
item.origin = this.fileNameListMap.get(this.config.mainDictFileName) // 标记主码表来源
return item
})

Expand Down
2 changes: 1 addition & 1 deletion view/tool/Tool.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ const app = {

// 载入主码表
ipcRenderer.on('ToolWindow:setMainDict', (event, filename, res) => {
this.dictMain = new Dict(res, filename)
this.dictMain = new Dict(res, filename, '', true)
console.log('dictMain载入完成,包含词条:',this.dictMain.dictSetExceptCharacter.size)
})

Expand Down

0 comments on commit 7d96504

Please sign in to comment.