From 1be928cad479e6bc9b854ea242d8d7a7c208b453 Mon Sep 17 00:00:00 2001 From: yanglbme Date: Sun, 29 Dec 2019 21:23:47 +0800 Subject: [PATCH] feat: quickly insert table MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 快速插入表格 --- assets/scripts/editor.js | 34 +++++++++++++++++++++++++++++++++- index.html | 25 +++++++++++++++++++++---- 2 files changed, 54 insertions(+), 5 deletions(-) diff --git a/assets/scripts/editor.js b/assets/scripts/editor.js index 6e57816..aba6a88 100644 --- a/assets/scripts/editor.js +++ b/assets/scripts/editor.js @@ -22,7 +22,12 @@ let app = new Vue({ { label: '活力橘', value: 'rgba(250, 81, 81, 1)', hex: '热情活泼' } ], showBox: true, - aboutDialogVisible: false + aboutDialogVisible: false, + dialogFormVisible: false, + form: { + rows: 1, + cols: 1 + } }; d.currentFont = d.builtinFonts[0].value; d.currentSize = d.sizeOption[1].value; @@ -196,6 +201,33 @@ let app = new Vue({ this.editor.focus(); }); }, + // 插入表格 + insertTable() { + const cursor = this.editor.getCursor(); + const rows = parseInt(this.form.rows); + const cols = parseInt(this.form.cols); + if (isNaN(rows) || isNaN(cols) || rows < 1 || cols < 1) { + this.$message({ + showClose: true, + message: '输入的行/列数无效,请重新输入', + type: 'error' + }); + return; + } + + let table = ''; + for (let i = 0; i < rows + 2; ++i) { + for (let j = 0; j < cols + 1; ++j) { + table += (j === 0 ? '|' : (i !== 1 ? ' |' : ' --- |')); + } + table += '\n'; + } + + this.editor.replaceSelection(`\n${table}\n`, cursor); + this.dialogFormVisible = false + this.refresh(); + + }, statusChanged() { this.refresh(); }, diff --git a/index.html b/index.html index f698de5..ce038c2 100644 --- a/index.html +++ b/index.html @@ -74,18 +74,22 @@ - +   - +   - +   + + +   + @@ -167,7 +171,20 @@ Gitee 仓库 - + + + + + + + + + + +