-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
caoli
committed
Oct 30, 2018
1 parent
57b6e2e
commit 58014af
Showing
14 changed files
with
164 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import 'font-awesome/css/font-awesome.min.css'; | ||
import 'simplemde/dist/simplemde.min.css'; | ||
import SimpleMDE from 'simplemde'; | ||
import Vue from 'vue'; | ||
import { Component, Prop, Watch } from 'vue-property-decorator'; | ||
|
||
@Component({ | ||
name: 'simplemde-md' | ||
}) | ||
export default class MarkDownEditor extends Vue { | ||
@Prop(String) id; | ||
@Prop({ type: Boolean, default: false }) autofocus; | ||
@Prop({ type: String, default: '' }) placeholder; | ||
@Prop({ type: Number, default: 400 }) height; | ||
@Prop({ type: Number, default: 10 }) zIndex; | ||
@Prop({ type: Array }) toolbar; | ||
|
||
simplemde: SimpleMDE = null; | ||
hasChange: boolean = false; | ||
|
||
// @Watch | ||
// value(val) { | ||
// if (val === this.simplemde.value() && !this.hasChange) return | ||
// this.simplemde.value(val); | ||
// } | ||
mounted() { | ||
this.simplemde = new SimpleMDE({ | ||
element: document.getElementById(this.id || 'markdown-editor-' + +new Date()), | ||
autoDownloadFontAwesome: false, | ||
autofocus: this.autofocus, | ||
toolbar: this.toolbar, | ||
spellChecker: false, | ||
insertTexts: { | ||
link: ['[', ']( )'] | ||
}, | ||
// hideIcons: ['guide', 'heading', 'quote', 'image', 'preview', 'side-by-side', 'fullscreen'], | ||
placeholder: this.placeholder | ||
}); | ||
// if (this.value) { | ||
// this.simplemde.value(this.value) | ||
// } | ||
this.simplemde.codemirror.on('change', () => { | ||
if (this.hasChange) { | ||
this.hasChange = true; | ||
} | ||
this.$emit('input', this.simplemde.value()); | ||
}); | ||
} | ||
destroyed() { | ||
this.simplemde.toTextArea(); | ||
this.simplemde = null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,17 @@ | ||
<template> | ||
<div style="font-size: 24px; text-align: center" v-if="article"> | ||
<div class="content" v-if="article"> | ||
<h1>{{article.title}}</h1> | ||
<iframe :src="article.url" frameborder="0" width="100%" height="600"></iframe> | ||
<iframe v-if="article.url" :src="article.url" frameborder="0" width="100%" height="600"></iframe> | ||
<div class="marktext" v-else v-html="article.content"></div> | ||
</div> | ||
</template> | ||
<style> | ||
.content { | ||
font-size: 24px; | ||
text-align: center | ||
} | ||
.content .marktext { | ||
margin-top: 24px; | ||
} | ||
</style> | ||
<script lang="ts" src="./index.ts"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import Vue from 'vue'; | ||
import { Getter, Action } from 'vuex-class'; | ||
import { Component, Prop, Watch } from 'vue-property-decorator'; | ||
import Article from '../../../../../../model/article'; | ||
|
||
@Component({ | ||
components: { | ||
MarkdownEditor: () => import('component/MarkdownEditor/index.vue') | ||
} | ||
}) | ||
export default class Write extends Vue { | ||
@Getter('article') article?: Article; | ||
@Action('saveArticle') saveArticle; | ||
@Action('getArticle') getArticle; | ||
text: string = ''; | ||
|
||
isShowEditor: boolean = false; | ||
|
||
async submit(status) { | ||
const showdown = await import('showdown'); | ||
const converter = new showdown.Converter(); | ||
const article = { | ||
...this.article, | ||
status, | ||
content : converter.makeHtml(this.text), | ||
}; | ||
const result = await this.saveArticle(article); | ||
if (result.status === 200 ) { | ||
this.$message(`添加成功`); | ||
this.article = {}; | ||
} else { | ||
this.$message(`添加失败: ${JSON.stringify(result)}`); | ||
} | ||
} | ||
|
||
@Watch('article') | ||
onArticleChanged(val: string, oldVal: string) { | ||
if (this.article) { | ||
// need html to markdown | ||
this.text = this.article.content || ''; | ||
} | ||
} | ||
|
||
mounted() { | ||
this.isShowEditor = true; | ||
const { id } = this.$route.params; | ||
if (id) { | ||
this.getArticle({ id }); | ||
} | ||
} | ||
|
||
destroyed() { | ||
this.$store.state.admin.article = {}; | ||
} | ||
} |
Oops, something went wrong.