|
| 1 | +<template> |
| 2 | +<div> |
| 3 | + <main class="container"> |
| 4 | + <div class="article article-container"> |
| 5 | + <div class="article-header"> |
| 6 | + <div class="article-header-top row"> |
| 7 | + <div class="col-xs-3 col-xs-offset-0"> |
| 8 | + <a class="article-back" @click="goback">返回</span></a> |
| 9 | + </div> |
| 10 | + <div class="article-header-top-title col-xs-4 col-xs-offset-1"> |
| 11 | + 在线试读 |
| 12 | + </div> |
| 13 | + </div> |
| 14 | + <div> |
| 15 | + <div class="article-title page-header">{{this.previewHeaderInfo[this.resolve(this.$route.path)].productTitle}}</div> |
| 16 | + <div class="product-article-author">{{this.previewHeaderInfo[this.resolve(this.$route.path)].authorList}}</div> |
| 17 | + <div class="product-article-author">{{this.previewHeaderInfo[this.resolve(this.$route.path)].translatorList}}</div> |
| 18 | + </div> |
| 19 | + <div class="buy-button-group row"> |
| 20 | + <router-link class="col-xs-10 col-xs-offset-1 col-sm-4 col-sm-offset-4 btn btn-success btn-lg" to="/goodscart"><span class="glyphicon glyphicon-ok"></span> {{ '购买 ('+this.previewHeaderInfo[this.resolve(this.$route.path)].productPrice +')'}}</router-link> |
| 21 | + </div> |
| 22 | + </div> |
| 23 | + |
| 24 | + <div v-html="this.articleContent" v-hljs> |
| 25 | + </div> |
| 26 | + |
| 27 | + <div class="buy-button-group row"> |
| 28 | + <router-link class="col-xs-10 col-xs-offset-1 col-sm-4 col-sm-offset-4 btn btn-success btn-lg" to="/goodscart"><span class="glyphicon glyphicon-ok"></span> {{ '购买 ('+this.previewHeaderInfo[this.resolve(this.$route.path)].productPrice +')'}}</router-link> |
| 29 | + </div> |
| 30 | + </div> |
| 31 | + </main> |
| 32 | +</div> |
| 33 | +</template> |
| 34 | + |
| 35 | +<script> |
| 36 | +import router from '@/router' |
| 37 | +import axios from 'axios' |
| 38 | +import hljs from 'highlight.js' |
| 39 | +
|
| 40 | +hljs.initHighlightingOnLoad() |
| 41 | +
|
| 42 | +export default { |
| 43 | + props: [], |
| 44 | + created() { |
| 45 | + this.fetchArticleContent() |
| 46 | + }, |
| 47 | + methods: { |
| 48 | + goback() { |
| 49 | + router.go(-1) |
| 50 | + }, |
| 51 | + resolve(url) { |
| 52 | + if (url.substr(url.length - 1, 1) === '/') { |
| 53 | + return url.substring(0, url.length - 1) |
| 54 | + } else { |
| 55 | + return url |
| 56 | + } |
| 57 | + }, |
| 58 | + fetchArticleContent() { |
| 59 | + axios.get(this.getArticleContentURL()) |
| 60 | + .then((response) => { |
| 61 | + this.articleContent = response.data |
| 62 | + }) |
| 63 | + .catch((error) => { |
| 64 | + this.articleContent = '这篇文章不见了' |
| 65 | + console.log('productsPreview 请求md出错了', error) |
| 66 | + }) |
| 67 | + }, |
| 68 | + getArticleContentURL() { |
| 69 | + let array = this.$route.path.split('/') |
| 70 | + return 'https://raw.githubusercontent.com/halfrost/articles/master/' + array[2] + '-summary' + '.md' |
| 71 | + } |
| 72 | + }, |
| 73 | + data() { |
| 74 | + return { |
| 75 | + articleContent: '', |
| 76 | + previewHeaderInfo: { |
| 77 | + '/products/swifter-tips/preview': { |
| 78 | + 'productTitle': 'Swifter - Swift 开发者必备 Tips', |
| 79 | + 'productPrice': '¥49.00', |
| 80 | + 'authorList': '王巍 著', |
| 81 | + 'translatorList': '' |
| 82 | + }, |
| 83 | + '/products/functional-swift/preview': { |
| 84 | + 'productTitle': '函数式 Swift', |
| 85 | + 'productPrice': '¥69.00', |
| 86 | + 'authorList': 'Chris Eidhof,Florian Kugler,Wouter Swierstra 著', |
| 87 | + 'translatorList': '陈聿菡,杜欣,王巍 译' |
| 88 | + }, |
| 89 | + '/products/core-data/preview': { |
| 90 | + 'productTitle': 'Core Data', |
| 91 | + 'productPrice': '¥69.00', |
| 92 | + 'authorList': 'Florian Kugler,Daniel Eggert 著', |
| 93 | + 'translatorList': '徐涛,钱世家,王巍 译' |
| 94 | + }, |
| 95 | + '/products/advanced-swift/preview': { |
| 96 | + 'productTitle': 'Swift 进阶', |
| 97 | + 'productPrice': '¥69.00', |
| 98 | + 'authorList': 'Chris Eidhof,Airspeed Velocity 著', |
| 99 | + 'translatorList': '王巍 译' |
| 100 | + } |
| 101 | + } |
| 102 | + } |
| 103 | + } |
| 104 | +} |
| 105 | +</script> |
| 106 | + |
| 107 | +<style> |
| 108 | +
|
| 109 | +</style> |
0 commit comments