From d717fd0804322f3b1f9f4b09d29ba77f3ac96156 Mon Sep 17 00:00:00 2001 From: yutent Date: Fri, 11 Mar 2022 16:23:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=A4=9A=E5=AD=97=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- css/index.css | 2 +- css/index.scss | 1 + js/index.js | 48 ++++++++++++++++++++++++++++++++++-------------- 3 files changed, 36 insertions(+), 15 deletions(-) diff --git a/css/index.css b/css/index.css index d274fd6..9b6fa7c 100644 --- a/css/index.css +++ b/css/index.css @@ -1 +1 @@ -body{line-height:1.5;font-size:14px;color:var(--color-dark-1)}a{color:inherit;text-decoration:none}wc-switch{cursor:pointer}.app{width:100%;height:100vh}.flex{display:flex}.flex.column{flex-direction:column}.flex.ac{justify-content:center}.flex.alc{align-items:center}.flex.acc{justify-content:center;align-items:center}.flex.asc{justify-content:space-between;align-items:center}.wrapper{width:1024px}.topbar{width:100%;height:64px;background:#fff;box-shadow:0 6px 12px rgba(0,0,0,.05)}.topbar .logo{font-size:24px;color:var(--color-red-1)}.topbar .logo span{font-size:14px}.topbar .navs{font-size:16px}.topbar .navs .nav{margin-left:32px;cursor:pointer;transition:color .2s linear}.topbar .navs .nav.active,.topbar .navs .nav:hover{text-decoration:underline;color:var(--color-red-1)}.main{flex:1}.main .table-info{width:100%;height:64px}.main .search{width:100%}.main .search .field{margin-top:16px}.main .search .field.result{line-height:2;word-wrap:break-word;white-space:pre-wrap}.main .search .field wc-input{flex:1}.footer{width:100%;height:64px;border-top:1px solid var(--color-plain-2)}@media screen and (max-width: 1024px){.topbar,.main{padding:0 16px}.footer .wrapper{flex-direction:column;align-items:center;justify-content:center}} \ No newline at end of file +body{line-height:1.5;font-size:14px;color:var(--color-dark-1)}a{color:inherit;text-decoration:none}wc-switch{cursor:pointer}.app{width:100%;height:100vh}.flex{display:flex}.flex.column{flex-direction:column}.flex.ac{justify-content:center}.flex.alc{align-items:center}.flex.acc{justify-content:center;align-items:center}.flex.asc{justify-content:space-between;align-items:center}.wrapper{width:1024px}.topbar{width:100%;height:64px;background:#fff;box-shadow:0 6px 12px rgba(0,0,0,.05)}.topbar .logo{font-size:24px;color:var(--color-red-1)}.topbar .logo span{font-size:14px}.topbar .navs{font-size:16px}.topbar .navs .nav{margin-left:32px;cursor:pointer;transition:color .2s linear}.topbar .navs .nav.active,.topbar .navs .nav:hover{text-decoration:underline;color:var(--color-red-1)}.main{flex:1}.main .table-info{width:100%;height:64px}.main .search{width:100%}.main .search .field{margin-top:16px}.main .search .field.result{line-height:2;font-family:Menlo;word-wrap:break-word;white-space:pre-wrap}.main .search .field wc-input{flex:1}.footer{width:100%;height:64px;border-top:1px solid var(--color-plain-2)}@media screen and (max-width: 1024px){.topbar,.main{padding:0 16px}.footer .wrapper{flex-direction:column;align-items:center;justify-content:center}} \ No newline at end of file diff --git a/css/index.scss b/css/index.scss index 3d8197e..cd80173 100644 --- a/css/index.scss +++ b/css/index.scss @@ -94,6 +94,7 @@ wc-switch { &.result { line-height: 2; + font-family: Menlo; word-wrap: break-word; white-space: pre-wrap; } diff --git a/js/index.js b/js/index.js index 688b54f..10b8356 100644 --- a/js/index.js +++ b/js/index.js @@ -66,21 +66,41 @@ Anot({ reverse = /^[a-z]{1,4}$/.test(params.txt) - res = WB_TABLE.get(params.txt) - - if (res) { - if (reverse) { - res = res.join('\t\t') - } else { - res = res.map(t => `${WB_CODE_NAME.get(t.length)}: ${t}`).join('\t\t') - } - - this.result = `查询结果: 【 ${params.txt} 】\n${res.toUpperCase()}` - } else { - this.result = `查询结果: 【 ${ - params.txt - } 】\n无结果, 请检查你的输入是否正确, 如果确认无误, 可以反馈缺失字库。` + if (!reverse) { + params.txt = params.txt.replace(/[\sa-z]/g, '') } + + if (params.txt.length > 1) { + res = params.txt.split('').map(t => WB_TABLE.get(t)) + } else { + res = [WB_TABLE.get(params.txt)] + } + + if (reverse) { + if (res[0]) { + res = `【 ${params.txt} 】👉\t${res[0].join('\t\t')}` + } else { + res = `【 ${ + params.txt + } 】👉\t无结果, 请检查你的输入是否正确, 如果确认无误, 可以反馈缺失字库。` + } + } else { + res = res + .map((it, i) => { + if (it) { + return `【 ${params.txt[i]} 】👉\t${it + .map(t => `${WB_CODE_NAME.get(t.length)}: ${t.toUpperCase()}`) + .join('\t\t')}` + } else { + return `【 ${ + params.txt[i] + } 】👉\t无结果, 请检查你的输入是否正确, 如果确认无误, 可以反馈缺失字库。` + } + }) + .join('\n') + } + + this.result = `查询结果: \n${res}` } } })