From 64c06a8a5d65f64771a0bec47432bb68fa84f287 Mon Sep 17 00:00:00 2001 From: yanglbme Date: Mon, 6 Jan 2020 15:40:30 +0800 Subject: [PATCH] fix: update font size options MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复字体大小错误 --- assets/scripts/editor.js | 9 +++++++-- assets/scripts/util.js | 16 +++++++++++++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/assets/scripts/editor.js b/assets/scripts/editor.js index 3e67979..f91ffaf 100644 --- a/assets/scripts/editor.js +++ b/assets/scripts/editor.js @@ -136,6 +136,7 @@ let app = new Vue({ this.wxRenderer.setOptions({ fonts: fonts }); + this.currentFont = fonts; this.refresh(); }, sizeChanged(size) { @@ -146,18 +147,22 @@ let app = new Vue({ this.wxRenderer.setOptions({ theme: theme }); + this.currentSize = size; this.refresh(); }, colorChanged(color) { - let theme = setColor(color); + let theme = setFontSize(this.currentSize.replace('px', '')); + theme = setColorWithCustomTemplate(theme, color); this.wxRenderer.setOptions({ theme: theme }); + this.currentColor = color; this.refresh(); }, cssChanged() { let json = css2json(this.cssEditor.getValue(0)); - let theme = customCssWithTemplate(json, this.currentColor); + let theme = setFontSize(this.currentSize.replace('px', '')); + theme = customCssWithTemplate(json, this.currentColor, theme); this.wxRenderer.setOptions({ theme: theme }); diff --git a/assets/scripts/util.js b/assets/scripts/util.js index 86e3ba4..3aeb198 100644 --- a/assets/scripts/util.js +++ b/assets/scripts/util.js @@ -11,6 +11,17 @@ function setColorWithTemplate(template) { }; } + +let setColorWithCustomTemplate = function setColorWithCustomTemplate(template, color) { + let custom_theme = JSON.parse(JSON.stringify(template)); + custom_theme.block.h1['border-bottom'] = `2px solid ${color}`; + custom_theme.block.h2['background'] = color; + custom_theme.block.h3['border-left'] = `3px solid ${color}`; + custom_theme.block.h4['color'] = color; + custom_theme.inline.strong['color'] = color; + return custom_theme; +} + // 设置自定义字体大小 function setFontSizeWithTemplate(template) { return function (fontSize) { @@ -21,14 +32,13 @@ function setFontSizeWithTemplate(template) { custom_theme.block.h4['font-size'] = `${fontSize}px`; return custom_theme; } - } let setColor = setColorWithTemplate(default_theme); let setFontSize = setFontSizeWithTemplate(default_theme); -function customCssWithTemplate(jsonString, color) { - let custom_theme = JSON.parse(JSON.stringify(default_theme)); +function customCssWithTemplate(jsonString, color, theme) { + let custom_theme = JSON.parse(JSON.stringify(theme)); // block custom_theme.block.h1['border-bottom'] = `2px solid ${color}`; custom_theme.block.h2['background'] = color;