Skip to content

Commit

Permalink
add 博客preview
Browse files Browse the repository at this point in the history
  • Loading branch information
kk-cwh committed Apr 25, 2018
1 parent db1b80a commit 466aba2
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 13 deletions.
7 changes: 4 additions & 3 deletions src/store/modules/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import http from '@/libs/http.js';

const app = {
state: {
md:'',
username:'',
dashData:{userNumber:11,browNumber:4988,articleNumber:50,discussionNumber:20},
cachePage: [],
Expand Down Expand Up @@ -198,9 +199,9 @@ const app = {
let data = response.data
let user = data.data;
commit('setAvator',"https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=3448484253,3685836170&fm=27&gp=0.jpg")

this.state.username = user.name

resolve()
}
}).catch(error => {
Expand All @@ -216,7 +217,7 @@ const app = {
// }).then(response => {
// if (response.data) {
// // console.log(response.data)

// removeToken()
// commit('CLEAR_STATE')
// console.log(this.state)
Expand Down
6 changes: 5 additions & 1 deletion src/views/articles/add-article.vue
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ export default {
return self.parse(plainText);
}
});
this.offenUsedClass = [
{
Expand Down Expand Up @@ -308,7 +309,10 @@ export default {
this.publishTimeType = "immediately";
this.editPublishTime = false;
},
handlePreview() {},
handlePreview() {
this.$store.state.app.md = this.simplemde.value();
this.$router.push({name: "preview_article"});
},
handlePublish() { this.publishLoading = true;},
handleSaveDraft() {}
}
Expand Down
5 changes: 4 additions & 1 deletion src/views/articles/articles.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div>
<Row :gutter="16">
<Col span="4">
<Button @click="handleSelectAll(true)" type="primary">创建文章</Button>
<Button @click="toCreateArticle()" type="primary">创建文章</Button>
</Col>
<Col :xs="{ span: 14, offset: 2 }" :sm="{ span: 8, offset: 8}" :md="{ span: 6, offset: 10 }" :lg="{ span: 4, offset: 12 }" >
<Form label-position="right" :label-width="60">
Expand Down Expand Up @@ -173,6 +173,9 @@ export default {
console.log(datass);
}, toQuery() {
console.log('query', this.query)
},
toCreateArticle(){
this.$router.push({name: "add_article"});
}
}
}
Expand Down
37 changes: 29 additions & 8 deletions src/views/articles/preview.vue
Original file line number Diff line number Diff line change
@@ -1,19 +1,40 @@
<template>
<div>
<div class="nav-bar">
preview
</div>

</div>
<div class=" markdown " v-html="rawHtml"></div>
</template>


<script>
import emojione from 'emojione'
import marked from 'marked'
import hljs from 'highlight.js'
export default {
data() {
return {
rawHtml: ''
}
},
mounted() {
this.rawHtml = this.parse(this.$store.state.app.md)
},
methods: {
parse(content) {
marked.setOptions({
highlight: (code) => {
return hljs.highlightAuto(code).value
},
sanitize: true
})
return emojione.toImage(marked(content))
},
},
}
</script>
<style lang="less" scoped>
<style>
@import "simplemde/dist/simplemde.min.css";
@import "highlight.js/styles/atom-one-dark.css";
@import "./markdown.css";
</style>

0 comments on commit 466aba2

Please sign in to comment.