chore:选择本地文件时增加类型限制
This commit is contained in:
parent
468559bf7c
commit
66099fb4b2
2
dist/index.js
vendored
2
dist/index.js
vendored
File diff suppressed because one or more lines are too long
2
dist/index.js.map
vendored
2
dist/index.js.map
vendored
File diff suppressed because one or more lines are too long
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "vue-meditor",
|
"name": "vue-meditor",
|
||||||
"description": "一款使用marked和highlight.js开发的一款markdown编辑器",
|
"description": "一款使用marked和highlight.js开发的一款markdown编辑器",
|
||||||
"version": "0.8.0",
|
"version": "0.9.0",
|
||||||
"author": "zhaoxuhui<1258835133@qq.com>",
|
"author": "zhaoxuhui<1258835133@qq.com>",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
|
@ -76,7 +76,7 @@
|
|||||||
</li>
|
</li>
|
||||||
<li name="导入本地文件" class="import-file" v-show="tools.importmd">
|
<li name="导入本地文件" class="import-file" v-show="tools.importmd">
|
||||||
<span class="iconfont icon-daoru"></span>
|
<span class="iconfont icon-daoru"></span>
|
||||||
<input type="file" @change="importFile($event)">
|
<input type="file" @change="importFile($event)" accept="text/markdown">
|
||||||
</li>
|
</li>
|
||||||
<li name="保存到本地" v-show="tools.exportmd">
|
<li name="保存到本地" v-show="tools.exportmd">
|
||||||
<span class="iconfont icon-download" @click="exportMd"></span>
|
<span class="iconfont icon-download" @click="exportMd"></span>
|
||||||
|
@ -120,7 +120,10 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
tools() {
|
tools() {
|
||||||
const {allTools, toolbars} = this;
|
const {
|
||||||
|
allTools,
|
||||||
|
toolbars
|
||||||
|
} = this;
|
||||||
return Object.assign(allTools, toolbars)
|
return Object.assign(allTools, toolbars)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -135,7 +138,13 @@ export default {
|
|||||||
methods: {
|
methods: {
|
||||||
init() {
|
init() {
|
||||||
this.themeName = this.theme;
|
this.themeName = this.theme;
|
||||||
const {autoSave, interval, theme, initialValue, mode} = this;
|
const {
|
||||||
|
autoSave,
|
||||||
|
interval,
|
||||||
|
theme,
|
||||||
|
initialValue,
|
||||||
|
mode
|
||||||
|
} = this;
|
||||||
this.value = initialValue;
|
this.value = initialValue;
|
||||||
this.preview = mode;
|
this.preview = mode;
|
||||||
this.previewMarkdown = marked(initialValue, {
|
this.previewMarkdown = marked(initialValue, {
|
||||||
@ -172,7 +181,9 @@ export default {
|
|||||||
this.scroll = side;
|
this.scroll = side;
|
||||||
},
|
},
|
||||||
insertContent(str) { // 插入文本
|
insertContent(str) { // 插入文本
|
||||||
const {preview} = this;
|
const {
|
||||||
|
preview
|
||||||
|
} = this;
|
||||||
if (preview === 2) {
|
if (preview === 2) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -382,7 +393,9 @@ export default {
|
|||||||
this.slideDown = false;
|
this.slideDown = false;
|
||||||
},
|
},
|
||||||
enter(e) { // 回车事件
|
enter(e) { // 回车事件
|
||||||
const {lastInsert} = this;
|
const {
|
||||||
|
lastInsert
|
||||||
|
} = this;
|
||||||
const list = ['- ', '1. ', '- [ ] ', '- [x] ']
|
const list = ['- ', '1. ', '- [ ] ', '- [x] ']
|
||||||
if (list.includes(lastInsert)) {
|
if (list.includes(lastInsert)) {
|
||||||
this.insertContent(lastInsert);
|
this.insertContent(lastInsert);
|
||||||
@ -418,20 +431,26 @@ export default {
|
|||||||
if (!file) {
|
if (!file) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const {type} = file;
|
const {
|
||||||
|
type
|
||||||
|
} = file;
|
||||||
if (type !== 'text/markdown') {
|
if (type !== 'text/markdown') {
|
||||||
this.$Notice.error('文件格式有误!');
|
alert('文件格式有误');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const reader = new FileReader();
|
const reader = new FileReader();
|
||||||
reader.readAsText(file, {encoding : 'utf-8'});
|
reader.readAsText(file, {
|
||||||
|
encoding: 'utf-8'
|
||||||
|
});
|
||||||
reader.onload = () => {
|
reader.onload = () => {
|
||||||
this.value = reader.result;
|
this.value = reader.result;
|
||||||
e.target.value = '';
|
e.target.value = '';
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
exportMd() { // 导出文件到本地
|
exportMd() { // 导出文件到本地
|
||||||
const { value } = this;
|
const {
|
||||||
|
value
|
||||||
|
} = this;
|
||||||
var pom = document.createElement('a');
|
var pom = document.createElement('a');
|
||||||
pom.setAttribute('href', 'data:text/plain;charset=UTF-8,' + encodeURIComponent(value));
|
pom.setAttribute('href', 'data:text/plain;charset=UTF-8,' + encodeURIComponent(value));
|
||||||
pom.setAttribute('download', '未命名.md');
|
pom.setAttribute('download', '未命名.md');
|
||||||
|
Loading…
Reference in New Issue
Block a user