From 70d2bd50cd524ebb3c64345ce3c7e2598b71e5ac Mon Sep 17 00:00:00 2001 From: yoimiya-kokomi <592981798@qq.com> Date: Mon, 5 Sep 2022 11:32:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=A7=92=E8=89=B2=E5=9B=BE?= =?UTF-8?q?=E9=89=B4=E7=9A=84=E8=A7=92=E8=89=B2=E6=8F=8F=E8=BF=B0=E6=8D=A2?= =?UTF-8?q?=E8=A1=8C=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/Character.js | 6 +++- models/character-lib/CharMeta.js | 43 ++++++++++++++++++++++++++++ resources/wiki/character-talent.html | 2 +- resources/wiki/character-wiki.css | 2 +- resources/wiki/character-wiki.html | 2 +- resources/wiki/character-wiki.less | 2 +- 6 files changed, 52 insertions(+), 5 deletions(-) diff --git a/models/Character.js b/models/Character.js index d660e0c0..c5e1afd7 100644 --- a/models/Character.js +++ b/models/Character.js @@ -22,7 +22,7 @@ class Character extends Base { if (!this.isCustom) { let meta = getMeta(name) this.meta = meta - for (let key of 'abbr,title,star,allegiance,weapon,astro,cncv,jpcv,ver,desc,talentCons'.split(',')) { + for (let key of 'abbr,title,star,allegiance,weapon,astro,cncv,jpcv,ver,talentCons'.split(',')) { this[key] = meta[key] } this.elem = CharId.getElem(elem || meta.elem) || 'anemo' @@ -63,6 +63,10 @@ class Character extends Base { return CharId.getElemName(this.elem) } + get desc () { + return CharMeta.getDesc(this.meta.desc || '') + } + // 获取头像 get face () { return this.getImgs().face diff --git a/models/character-lib/CharMeta.js b/models/character-lib/CharMeta.js index 1ffbc2e0..08d6ed5b 100644 --- a/models/character-lib/CharMeta.js +++ b/models/character-lib/CharMeta.js @@ -91,6 +91,49 @@ const CharMeta = { }) }) return ret + }, + + getDesc (desc) { + desc = desc.replace(/。$/, '') + desc = desc.replace('
', ',') + desc = desc.replace(/[。,]/g, ',') + desc = desc.replace('——', ',——') + let len = desc.length + if (len < 25) { + return desc + } + if (/-/.test(desc)) { + let idx = desc.indexOf('—') + return [desc.substr(0, idx), desc.substr(idx, desc.length)].join('
') + } + desc = desc.split(',') + return CharMeta.getDescLine(desc) + }, + getDescLine (inputs) { + let lens = [] + let len = 0 + let descs = [] + for (let desc of inputs) { + if (len + desc.length < 56) { + lens.push(desc.length) + descs.push(desc) + len += desc.length + } else { + break + } + } + if (len <= 28) { + return descs.join(',') + } + let ret = [[], [], []] + let idx = 0 + for (let desc of descs) { + if (ret[idx].join(' ').length + desc.length > 28) { + idx++ + } + ret[idx].push(desc) + } + return ret[0].join(',') + '
' + ret[1].join(',') } } export default CharMeta diff --git a/resources/wiki/character-talent.html b/resources/wiki/character-talent.html index 307b7cbf..46136d24 100644 --- a/resources/wiki/character-talent.html +++ b/resources/wiki/character-talent.html @@ -19,7 +19,7 @@
{{title}}·{{name}}
-
{{desc}}
+
{{@desc}}
90级基础数据
diff --git a/resources/wiki/character-wiki.css b/resources/wiki/character-wiki.css index f7c4a21c..535c302f 100644 --- a/resources/wiki/character-wiki.css +++ b/resources/wiki/character-wiki.css @@ -28,7 +28,7 @@ body { height: 500px; } .char-desc { - padding-left: 240px; + padding-left: 220px; font-size: 14px; } .char-meta { diff --git a/resources/wiki/character-wiki.html b/resources/wiki/character-wiki.html index 20235ad5..9968d158 100644 --- a/resources/wiki/character-wiki.html +++ b/resources/wiki/character-wiki.html @@ -17,7 +17,7 @@
{{data.title}} · {{data.name}}
-
{{data.desc}}
+
{{@data.desc}}
diff --git a/resources/wiki/character-wiki.less b/resources/wiki/character-wiki.less index 6bbd0576..8f871f13 100644 --- a/resources/wiki/character-wiki.less +++ b/resources/wiki/character-wiki.less @@ -38,7 +38,7 @@ body { } .char-desc { - padding-left: 240px; + padding-left: 220px; font-size: 14px; }