chore:选择本地文件时增加类型限制

This commit is contained in:
zhaoxuhui 2018-11-05 18:34:15 +08:00
parent 468559bf7c
commit 66099fb4b2
5 changed files with 146 additions and 127 deletions

2
dist/index.js vendored

File diff suppressed because one or more lines are too long

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -1,7 +1,7 @@
{
"name": "vue-meditor",
"description": "一款使用marked和highlight.js开发的一款markdown编辑器",
"version": "0.8.0",
"version": "0.9.0",
"author": "zhaoxuhui<1258835133@qq.com>",
"license": "MIT",
"main": "dist/index.js",

View File

@ -76,7 +76,7 @@
</li>
<li name="导入本地文件" class="import-file" v-show="tools.importmd">
<span class="iconfont icon-daoru"></span>
<input type="file" @change="importFile($event)">
<input type="file" @change="importFile($event)" accept="text/markdown">
</li>
<li name="保存到本地" v-show="tools.exportmd">
<span class="iconfont icon-download" @click="exportMd"></span>

View File

@ -120,7 +120,10 @@ export default {
}
},
tools() {
const {allTools, toolbars} = this;
const {
allTools,
toolbars
} = this;
return Object.assign(allTools, toolbars)
}
},
@ -135,7 +138,13 @@ export default {
methods: {
init() {
this.themeName = this.theme;
const {autoSave, interval, theme, initialValue, mode} = this;
const {
autoSave,
interval,
theme,
initialValue,
mode
} = this;
this.value = initialValue;
this.preview = mode;
this.previewMarkdown = marked(initialValue, {
@ -172,7 +181,9 @@ export default {
this.scroll = side;
},
insertContent(str) { // 插入文本
const {preview} = this;
const {
preview
} = this;
if (preview === 2) {
return;
}
@ -382,7 +393,9 @@ export default {
this.slideDown = false;
},
enter(e) { // 回车事件
const {lastInsert} = this;
const {
lastInsert
} = this;
const list = ['- ', '1. ', '- [ ] ', '- [x] ']
if (list.includes(lastInsert)) {
this.insertContent(lastInsert);
@ -418,20 +431,26 @@ export default {
if (!file) {
return;
}
const {type} = file;
const {
type
} = file;
if (type !== 'text/markdown') {
this.$Notice.error('文件格式有误!');
alert('文件格式有误');
return;
}
const reader = new FileReader();
reader.readAsText(file, {encoding : 'utf-8'});
reader.readAsText(file, {
encoding: 'utf-8'
});
reader.onload = () => {
this.value = reader.result;
e.target.value = '';
}
},
exportMd() { // 导出文件到本地
const { value } = this;
const {
value
} = this;
var pom = document.createElement('a');
pom.setAttribute('href', 'data:text/plain;charset=UTF-8,' + encodeURIComponent(value));
pom.setAttribute('download', '未命名.md');