feat: update animation and default color theme

更新动画文件和默认颜色主题
This commit is contained in:
yanglbme 2019-12-25 21:56:35 +08:00
parent 715d035355
commit b5d11dbc97
4 changed files with 66 additions and 73 deletions

View File

@ -82,7 +82,6 @@ section {
align-items: center; align-items: center;
justify-content: center; justify-content: center;
display: flex; display: flex;
/* height: 100%; */
overflow: scroll; overflow: scroll;
} }

View File

@ -8,14 +8,8 @@ let app = new Vue({
editor: null, editor: null,
cssEditor: null, cssEditor: null,
builtinFonts: [ builtinFonts: [
{ { label: '无衬线', value: "-apple-system-font,BlinkMacSystemFont, Helvetica Neue, PingFang SC, Hiragino Sans GB , Microsoft YaHei UI , Microsoft YaHei ,Arial,sans-serif" },
label: '无衬线', { label: '衬线', value: "Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, 'PingFang SC', Cambria, Cochin, Georgia, Times, 'Times New Roman', serif" }
value: "-apple-system-font,BlinkMacSystemFont, Helvetica Neue, PingFang SC, Hiragino Sans GB , Microsoft YaHei UI , Microsoft YaHei ,Arial,sans-serif"
},
{
label: '衬线',
value: "Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, 'PingFang SC', Cambria, Cochin, Georgia, Times, 'Times New Roman', serif"
}
], ],
sizeOption: [ sizeOption: [
{ label: '13px', value: '13px', desc: '稍小' }, { label: '13px', value: '13px', desc: '稍小' },
@ -23,16 +17,16 @@ let app = new Vue({
{ label: '15px', value: '15px', desc: '稍大' } { label: '15px', value: '15px', desc: '稍大' }
], ],
colorOption: [ colorOption: [
{ label: '经典蓝', value: 'rgba(15, 76, 129, 0.9)', hex: '最新流行' }, { label: '经典蓝', value: 'rgba(15, 76, 129, 1)', hex: '最新流行' },
{ label: '翡翠绿', value: 'rgba(0, 152, 116, 0.9)', hex: '清新且优雅' }, { label: '翡翠绿', value: 'rgba(0, 152, 116, 1)', hex: '优雅清新' },
{ label: '辣椒红', value: 'rgba(155, 35, 53, 0.9)', hex: '自信且迷人' } { label: '活力橘', value: 'rgba(250, 81, 81, 1)', hex: '热情活泼' }
], ],
showBox: true, showBox: true,
aboutDialogVisible: false aboutDialogVisible: false
}; };
d.currentFont = d.builtinFonts[0].value; d.currentFont = d.builtinFonts[0].value;
d.currentSize = d.sizeOption[1].value; d.currentSize = d.sizeOption[1].value;
d.currentColor = d.colorOption[2].value; d.currentColor = d.colorOption[1].value;
d.status = '1'; d.status = '1';
return d; return d;
}, },
@ -59,26 +53,26 @@ let app = new Vue({
matchBrackets: true, matchBrackets: true,
autofocus: true, autofocus: true,
extraKeys: { extraKeys: {
"Ctrl-F": function autoFormat(editor) { 'Ctrl-F': function autoFormat(editor) {
var totalLines = editor.lineCount(); const totalLines = editor.lineCount();
editor.autoFormatRange({ line: 0, ch: 0 }, { line: totalLines }); editor.autoFormatRange({ line: 0, ch: 0 }, { line: totalLines });
} }
}, },
} }
); );
// 自动提示 // 自动提示
this.cssEditor.on("keyup", (cm, e) => { this.cssEditor.on('keyup', (cm, e) => {
if ((e.keyCode >= 65 && e.keyCode <= 90) || e.keyCode === 189) { if ((e.keyCode >= 65 && e.keyCode <= 90) || e.keyCode === 189) {
cm.showHint(e); cm.showHint(e);
} }
}); });
this.editor.on("change", (cm, e) => { this.editor.on('change', (cm, e) => {
this.refresh(); this.refresh();
this.saveEditorContent(this.editor, '__editor_content'); this.saveEditorContent(this.editor, '__editor_content');
}); });
// 粘贴上传图片并插入 // 粘贴上传图片并插入
this.editor.on("paste", (cm, e) => { this.editor.on('paste', (cm, e) => {
if (!(e.clipboardData && e.clipboardData.items)) { if (!(e.clipboardData && e.clipboardData.items)) {
return; return;
} }
@ -87,15 +81,14 @@ let app = new Vue({
if (item.kind === 'file') { if (item.kind === 'file') {
const pasteFile = item.getAsFile(); const pasteFile = item.getAsFile();
let data = new FormData(); let data = new FormData();
data.append("file", pasteFile); data.append('file', pasteFile);
axios.post('https://imgkr.com/api/files/upload', data, { axios.post('https://imgkr.com/api/files/upload', data, {
headers: { headers: {
'Content-Type': 'multipart/form-data' 'Content-Type': 'multipart/form-data'
} }
}).then(resp => { }).then(resp => {
this.uploaded(resp.data) this.uploaded(resp.data)
}).catch(err => { }).catch(err => { })
})
} }
} }
}); });
@ -109,18 +102,11 @@ let app = new Vue({
size: this.currentSize, size: this.currentSize,
status: this.status status: this.status
}); });
// 如果有编辑内容被保存则读取,否则加载默认文档
if (localStorage.getItem("__editor_content")) {
this.editor.setValue(localStorage.getItem("__editor_content"));
} else {
this.editor.setValue(DEFAULT_CONTENT);
}
if (localStorage.getItem("__css_content")) { // 如果有编辑器内容被保存则读取,否则加载默认内容
this.cssEditor.setValue(localStorage.getItem("__css_content")); this.loadLocalStorage(this.editor, '__editor_content', DEFAULT_CONTENT);
} else { this.loadLocalStorage(this.cssEditor, '__css_content', DEFAULT_CSS_CONTENT);
this.cssEditor.setValue(DEFAULT_CSS_CONTENT);
}
}, },
methods: { methods: {
renderWeChat(source) { renderWeChat(source) {
@ -189,9 +175,6 @@ let app = new Vue({
}); });
} }
}, },
failed(error, file, fileList) {
console.log(error)
},
// 刷新右侧预览 // 刷新右侧预览
refresh() { refresh() {
this.output = this.renderWeChat(this.editor.getValue(0)); this.output = this.renderWeChat(this.editor.getValue(0));
@ -216,7 +199,7 @@ let app = new Vue({
statusChanged() { statusChanged() {
this.refresh(); this.refresh();
}, },
// 将左侧编辑器内容保存到 LocalStorage // 将编辑器内容保存到 LocalStorage
saveEditorContent(editor, name) { saveEditorContent(editor, name) {
const content = editor.getValue(0); const content = editor.getValue(0);
if (content) { if (content) {
@ -225,6 +208,13 @@ let app = new Vue({
localStorage.removeItem(name); localStorage.removeItem(name);
} }
}, },
loadLocalStorage(editor, name, content) {
if (localStorage.getItem(name)) {
editor.setValue(localStorage.getItem(name));
} else {
editor.setValue(content);
}
},
// 下载编辑器内容到本地 // 下载编辑器内容到本地
downloadEditorContent() { downloadEditorContent() {
let downLink = document.createElement('a'); let downLink = document.createElement('a');
@ -240,7 +230,7 @@ let app = new Vue({
// 自定义CSS样式 // 自定义CSS样式
async customStyle() { async customStyle() {
this.showBox = !this.showBox; this.showBox = !this.showBox;
let flag = await localStorage.getItem("__css_content") let flag = await localStorage.getItem('__css_content')
if (!flag) { if (!flag) {
this.cssEditor.setValue(DEFAULT_CSS_CONTENT); this.cssEditor.setValue(DEFAULT_CSS_CONTENT);
} }
@ -268,33 +258,27 @@ let app = new Vue({
e.clipboardData.setData('text/plain', text); e.clipboardData.setData('text/plain', text);
document.removeEventListener('copy', copyCall); document.removeEventListener('copy', copyCall);
}); });
if (document.execCommand('copy')) { // 执行复制
// 模拟一个选中的状态 document.execCommand('copy');
let clipboardDiv = document.getElementById('output');
clipboardDiv.focus(); // 模拟一个全选的状态
window.getSelection().removeAllRanges(); let clipboardDiv = document.getElementById('output');
let range = document.createRange(); clipboardDiv.focus();
range.setStartBefore(clipboardDiv.firstChild); window.getSelection().removeAllRanges();
range.setEndAfter(clipboardDiv.lastChild); let range = document.createRange();
window.getSelection().addRange(range); range.setStartBefore(clipboardDiv.firstChild);
this.refresh() range.setEndAfter(clipboardDiv.lastChild);
this.$notify({ window.getSelection().addRange(range);
showClose: true,
message: '已复制渲染后的文章到剪贴板,可直接到公众号后台粘贴', // 输出提示
offset: 80, this.$notify({
duration: 1600, showClose: true,
type: 'success' message: '已复制渲染后的文章到剪贴板,可直接到公众号后台粘贴',
}); offset: 80,
} else { duration: 1600,
this.$notify({ type: 'success'
showClose: true, });
message: '未能复制文章到剪贴板,请全选后右键复制',
offset: 80,
duration: 1600,
type: 'warning'
});
}
} }
}, },
updated() { updated() {

View File

@ -22,7 +22,8 @@
<link rel="stylesheet" href="libs/css/codemirror.min.css"> <link rel="stylesheet" href="libs/css/codemirror.min.css">
<link rel="stylesheet" href="libs/css/show-hint.css"> <link rel="stylesheet" href="libs/css/show-hint.css">
<link rel="stylesheet" href="libs/css/style-mirror.css"> <link rel="stylesheet" href="libs/css/style-mirror.css">
<link href="https://cdn.jsdelivr.net/npm/animate.css@3.5.1" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="libs/css/animate.css">
<!-- 默认CSS/JS --> <!-- 默认CSS/JS -->
<script src="assets/scripts/themes/default-theme-css.js"></script> <script src="assets/scripts/themes/default-theme-css.js"></script>
@ -44,8 +45,7 @@
<el-header class="top"> <el-header class="top">
<!-- 图片上传 --> <!-- 图片上传 -->
<el-upload action="https://imgkr.com/api/files/upload" headers="{'Content-Type': 'multipart/form-data'}" <el-upload action="https://imgkr.com/api/files/upload" headers="{'Content-Type': 'multipart/form-data'}"
:show-file-list="false" :multiple="true" accept=".jpg,.jpeg,.png,.gif" name="file" :on-success="uploaded" :show-file-list="false" :multiple="true" accept=".jpg,.jpeg,.png,.gif" name="file" :on-success="uploaded">
:on-error="failed">
<el-tooltip class="item" effect="dark" content="点击上传图片" placement="bottom-start"> <el-tooltip class="item" effect="dark" content="点击上传图片" placement="bottom-start">
<i class="el-icon-upload" size="medium">&nbsp;</i> <i class="el-icon-upload" size="medium">&nbsp;</i>
</el-tooltip> </el-tooltip>
@ -102,7 +102,7 @@
<el-main class="main-body"> <el-main class="main-body">
<el-row :gutter="10" class="main-section"> <el-row :gutter="10" class="main-section">
<el-col :span="12"> <el-col :span="12">
<textarea id="editor" type="textarea" placeholder="Your markdown here." v-model="source"> <textarea id="editor" type="textarea" placeholder="Your markdown text here." v-model="source">
</textarea> </textarea>
</el-col> </el-col>
<el-col :span="12" class="preview-wrapper" id="preview"> <el-col :span="12" class="preview-wrapper" id="preview">
@ -115,7 +115,7 @@
</el-col> </el-col>
<transition name="custom-classes-transition" enter-active-class="animated bounceInRight"> <transition name="custom-classes-transition" enter-active-class="animated bounceInRight">
<el-col id="cssBox" :span="12" v-show="showBox"> <el-col id="cssBox" :span="12" v-show="showBox">
<textarea id="cssEditor" type="textarea" placeholder="Custom css here."> <textarea id="cssEditor" type="textarea" placeholder="Your custom css here.">
</textarea> </textarea>
</el-col> </el-col>
</transition> </transition>
@ -133,14 +133,13 @@
</div> </div>
<span slot="footer" class="dialog-footer"> <span slot="footer" class="dialog-footer">
<a href="https://github.com/doocs/md" target="_blank"> <a href="https://github.com/doocs/md" target="_blank">
<el-button type="success" plain>GitHub 仓库 <el-button type="success" plain>GitHub 仓库</el-button>
</el-button>
</a> </a>
<a href="https://gitee.com/doocs/md" target="_blank"> <a href="https://gitee.com/doocs/md" target="_blank">
<el-button type="success" plain>Gitee 仓库 <el-button type="success" plain>Gitee 仓库</el-button>
</el-button>
</a> </a>
</span> </span>
</el-dialog> </el-dialog>
</div> </div>

11
libs/css/animate.css vendored Normal file

File diff suppressed because one or more lines are too long