├── .babelrc ├── .editorconfig ├── .eslintignore ├── .eslintrc.js ├── .gitignore ├── .postcssrc.js ├── README.md ├── build ├── build.js ├── check-versions.js ├── dev-client.js ├── dev-server.js ├── utils.js ├── vue-loader.conf.js ├── webpack.base.conf.js ├── webpack.dev.conf.js └── webpack.prod.conf.js ├── config ├── dev.env.js ├── index.js └── prod.env.js ├── index.html ├── package.json ├── src ├── App.vue ├── api │ ├── index.js │ └── resources.js ├── assets │ └── logo.png ├── components │ ├── ArticleDetail.vue │ ├── ArticleEdit.vue │ ├── ArticleList.vue │ ├── FooterBar.vue │ ├── HeaderBar.vue │ ├── Loading.vue │ ├── Pagination.vue │ ├── Signin.vue │ └── Signup.vue ├── config.js ├── filters │ └── index.js ├── main.js ├── router.js └── store │ ├── actions.js │ ├── getters.js │ ├── index.js │ ├── modules │ ├── article.js │ ├── comment.js │ ├── load.js │ └── user.js │ └── mutation-types.js ├── static ├── .gitkeep └── img │ └── user.png └── yarn.lock /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["env", { 4 | "modules": false, 5 | "targets": { 6 | "browsers": ["> 1%", "last 2 versions", "not ie <= 8"] 7 | } 8 | }], 9 | "stage-2" 10 | ], 11 | "plugins": ["transform-runtime"], 12 | "env": { 13 | "test": { 14 | "presets": ["env", "stage-2"], 15 | "plugins": ["istanbul"] 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | indent_style = space 6 | indent_size = 2 7 | end_of_line = lf 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | build/*.js 2 | config/*.js 3 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | // http://eslint.org/docs/user-guide/configuring 2 | 3 | module.exports = { 4 | root: true, 5 | parser: 'babel-eslint', 6 | parserOptions: { 7 | sourceType: 'module' 8 | }, 9 | env: { 10 | browser: true, 11 | }, 12 | // https://github.com/feross/standard/blob/master/RULES.md#javascript-standard-style 13 | extends: 'standard', 14 | // required to lint *.vue files 15 | plugins: [ 16 | 'html' 17 | ], 18 | // add your custom rules here 19 | 'rules': { 20 | // allow paren-less arrow functions 21 | 'arrow-parens': 0, 22 | // allow async-await 23 | 'generator-star-spacing': 0, 24 | // allow debugger during development 25 | 'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules/ 3 | dist/ 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | 8 | # Editor directories and files 9 | .idea 10 | *.suo 11 | *.ntvs* 12 | *.njsproj 13 | *.sln 14 | -------------------------------------------------------------------------------- /.postcssrc.js: -------------------------------------------------------------------------------- 1 | // https://github.com/michael-ciniawsky/postcss-load-config 2 | 3 | module.exports = { 4 | "plugins": { 5 | // to edit target browsers: use "browserslist" field in package.json 6 | "autoprefixer": {} 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # xwblog Vue 版 2 | 3 | ## 简介 4 | xwblog 是使用 Node.js + Mysql + Redis + 其它客户端框架开发的个人博客系统,前后端分离. 5 | 服务端有: [thinkjs 版](https://github.com/xwlyy/xwblog-api-thinkjs) 6 | ##### 此为客户端vue版, 需要配合服务端使用. 7 | 8 | ## 功能 9 | - 用户登录注册 10 | - 新建编辑文章 11 | - 评论 12 | - 貌似功能有点少啊,以后有空再加吧 13 | 14 | ## 开发 15 | 16 | ``` 17 | $ git clone https://github.com/xwlyy/xwblog-home-vue 18 | $ cd xwblog-home-vue 19 | $ npm install 20 | $ npm run dev 21 | ``` 22 | 在浏览器中打开 http://localhost:9090 23 | 24 | ## 调试 25 | - 默认开启 vue-devtools [chrome浏览器扩展](https://github.com/vuejs/vue-devtools), 生产环境自动关闭 26 | 27 | 28 | ## 生产环境构建 29 | 30 | ``` 31 | $ npm run build 32 | ``` 33 | 34 | ## 部署 35 | 用阿里云持续交付平台CRP实现持续集成、持续部署,免费的。当然跑项目用的服务还是得自己买。静态文件由Nginx返回. 36 | 37 | ## TODO 38 | - ~~vuex换成2.0版本~~ 39 | - ~~vue-resource换成axios~~ 40 | - 前端数据验证 41 | - uikit2换成uikit3 42 | - 写一个管理后台,UI组件库选的是element-ui(公司后台开发就用这个) 43 | - 可能还会专门为手机浏览览器写一个版本吧,UI组件库选的是mint-ui(公司微信端开发就用这个) 44 | - 用weex写一个APP(坑先挖着,反正管挖不管埋) 45 | -------------------------------------------------------------------------------- /build/build.js: -------------------------------------------------------------------------------- 1 | require('./check-versions')() 2 | 3 | process.env.NODE_ENV = 'production' 4 | 5 | var ora = require('ora') 6 | var rm = require('rimraf') 7 | var path = require('path') 8 | var chalk = require('chalk') 9 | var webpack = require('webpack') 10 | var config = require('../config') 11 | var webpackConfig = require('./webpack.prod.conf') 12 | 13 | var spinner = ora('building for production...') 14 | spinner.start() 15 | 16 | rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => { 17 | if (err) throw err 18 | webpack(webpackConfig, function (err, stats) { 19 | spinner.stop() 20 | if (err) throw err 21 | process.stdout.write(stats.toString({ 22 | colors: true, 23 | modules: false, 24 | children: false, 25 | chunks: false, 26 | chunkModules: false 27 | }) + '\n\n') 28 | 29 | console.log(chalk.cyan(' Build complete.\n')) 30 | console.log(chalk.yellow( 31 | ' Tip: built files are meant to be served over an HTTP server.\n' + 32 | ' Opening index.html over file:// won\'t work.\n' 33 | )) 34 | }) 35 | }) 36 | -------------------------------------------------------------------------------- /build/check-versions.js: -------------------------------------------------------------------------------- 1 | var chalk = require('chalk') 2 | var semver = require('semver') 3 | var packageConfig = require('../package.json') 4 | var shell = require('shelljs') 5 | function exec (cmd) { 6 | return require('child_process').execSync(cmd).toString().trim() 7 | } 8 | 9 | var versionRequirements = [ 10 | { 11 | name: 'node', 12 | currentVersion: semver.clean(process.version), 13 | versionRequirement: packageConfig.engines.node 14 | }, 15 | ] 16 | 17 | if (shell.which('npm')) { 18 | versionRequirements.push({ 19 | name: 'npm', 20 | currentVersion: exec('npm --version'), 21 | versionRequirement: packageConfig.engines.npm 22 | }) 23 | } 24 | 25 | module.exports = function () { 26 | var warnings = [] 27 | for (var i = 0; i < versionRequirements.length; i++) { 28 | var mod = versionRequirements[i] 29 | if (!semver.satisfies(mod.currentVersion, mod.versionRequirement)) { 30 | warnings.push(mod.name + ': ' + 31 | chalk.red(mod.currentVersion) + ' should be ' + 32 | chalk.green(mod.versionRequirement) 33 | ) 34 | } 35 | } 36 | 37 | if (warnings.length) { 38 | console.log('') 39 | console.log(chalk.yellow('To use this template, you must update following to modules:')) 40 | console.log() 41 | for (var i = 0; i < warnings.length; i++) { 42 | var warning = warnings[i] 43 | console.log(' ' + warning) 44 | } 45 | console.log() 46 | process.exit(1) 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /build/dev-client.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | require('eventsource-polyfill') 3 | var hotClient = require('webpack-hot-middleware/client?noInfo=true&reload=true') 4 | 5 | hotClient.subscribe(function (event) { 6 | if (event.action === 'reload') { 7 | window.location.reload() 8 | } 9 | }) 10 | -------------------------------------------------------------------------------- /build/dev-server.js: -------------------------------------------------------------------------------- 1 | require('./check-versions')() 2 | 3 | var config = require('../config') 4 | if (!process.env.NODE_ENV) { 5 | process.env.NODE_ENV = JSON.parse(config.dev.env.NODE_ENV) 6 | } 7 | 8 | // var opn = require('opn') 9 | var path = require('path') 10 | var express = require('express') 11 | var webpack = require('webpack') 12 | var proxyMiddleware = require('http-proxy-middleware') 13 | var webpackConfig = require('./webpack.dev.conf') 14 | 15 | // default port where dev server listens for incoming traffic 16 | var port = process.env.PORT || config.dev.port 17 | // automatically open browser, if not set will be false 18 | var autoOpenBrowser = !!config.dev.autoOpenBrowser 19 | // Define HTTP proxies to your custom API backend 20 | // https://github.com/chimurai/http-proxy-middleware 21 | var proxyTable = config.dev.proxyTable 22 | 23 | var app = express() 24 | var compiler = webpack(webpackConfig) 25 | 26 | var devMiddleware = require('webpack-dev-middleware')(compiler, { 27 | publicPath: webpackConfig.output.publicPath, 28 | quiet: true 29 | }) 30 | 31 | var hotMiddleware = require('webpack-hot-middleware')(compiler, { 32 | log: () => {}, 33 | heartbeat: 2000 34 | }) 35 | // force page reload when html-webpack-plugin template changes 36 | compiler.plugin('compilation', function (compilation) { 37 | compilation.plugin('html-webpack-plugin-after-emit', function (data, cb) { 38 | hotMiddleware.publish({ action: 'reload' }) 39 | cb() 40 | }) 41 | }) 42 | 43 | // proxy api requests 44 | Object.keys(proxyTable).forEach(function (context) { 45 | var options = proxyTable[context] 46 | if (typeof options === 'string') { 47 | options = { target: options } 48 | } 49 | app.use(proxyMiddleware(options.filter || context, options)) 50 | }) 51 | 52 | // handle fallback for HTML5 history API 53 | app.use(require('connect-history-api-fallback')()) 54 | 55 | // serve webpack bundle output 56 | app.use(devMiddleware) 57 | 58 | // enable hot-reload and state-preserving 59 | // compilation error display 60 | app.use(hotMiddleware) 61 | 62 | // serve pure static assets 63 | var staticPath = path.posix.join(config.dev.assetsPublicPath, config.dev.assetsSubDirectory) 64 | app.use(staticPath, express.static('./static')) 65 | 66 | var uri = 'http://localhost:' + port 67 | 68 | var _resolve 69 | var readyPromise = new Promise(resolve => { 70 | _resolve = resolve 71 | }) 72 | 73 | console.log('> Starting dev server...') 74 | devMiddleware.waitUntilValid(() => { 75 | console.log('> Listening at ' + uri + '\n') 76 | // when env is testing, don't need open it 77 | // if (autoOpenBrowser && process.env.NODE_ENV !== 'testing') { 78 | // opn(uri) 79 | // } 80 | _resolve() 81 | }) 82 | 83 | var server = app.listen(port) 84 | 85 | module.exports = { 86 | ready: readyPromise, 87 | close: () => { 88 | server.close() 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /build/utils.js: -------------------------------------------------------------------------------- 1 | var path = require('path') 2 | var config = require('../config') 3 | var ExtractTextPlugin = require('extract-text-webpack-plugin') 4 | 5 | exports.assetsPath = function (_path) { 6 | var assetsSubDirectory = process.env.NODE_ENV === 'production' 7 | ? config.build.assetsSubDirectory 8 | : config.dev.assetsSubDirectory 9 | return path.posix.join(assetsSubDirectory, _path) 10 | } 11 | 12 | exports.cssLoaders = function (options) { 13 | options = options || {} 14 | 15 | var cssLoader = { 16 | loader: 'css-loader', 17 | options: { 18 | minimize: process.env.NODE_ENV === 'production', 19 | sourceMap: options.sourceMap 20 | } 21 | } 22 | 23 | // generate loader string to be used with extract text plugin 24 | function generateLoaders (loader, loaderOptions) { 25 | var loaders = [cssLoader] 26 | if (loader) { 27 | loaders.push({ 28 | loader: loader + '-loader', 29 | options: Object.assign({}, loaderOptions, { 30 | sourceMap: options.sourceMap 31 | }) 32 | }) 33 | } 34 | 35 | // Extract CSS when that option is specified 36 | // (which is the case during production build) 37 | if (options.extract) { 38 | return ExtractTextPlugin.extract({ 39 | use: loaders, 40 | fallback: 'vue-style-loader' 41 | }) 42 | } else { 43 | return ['vue-style-loader'].concat(loaders) 44 | } 45 | } 46 | 47 | // https://vue-loader.vuejs.org/en/configurations/extract-css.html 48 | return { 49 | css: generateLoaders(), 50 | postcss: generateLoaders(), 51 | less: generateLoaders('less'), 52 | sass: generateLoaders('sass', { indentedSyntax: true }), 53 | scss: generateLoaders('sass'), 54 | stylus: generateLoaders('stylus'), 55 | styl: generateLoaders('stylus') 56 | } 57 | } 58 | 59 | // Generate loaders for standalone style files (outside of .vue) 60 | exports.styleLoaders = function (options) { 61 | var output = [] 62 | var loaders = exports.cssLoaders(options) 63 | for (var extension in loaders) { 64 | var loader = loaders[extension] 65 | output.push({ 66 | test: new RegExp('\\.' + extension + '$'), 67 | use: loader 68 | }) 69 | } 70 | return output 71 | } 72 | -------------------------------------------------------------------------------- /build/vue-loader.conf.js: -------------------------------------------------------------------------------- 1 | var utils = require('./utils') 2 | var config = require('../config') 3 | var isProduction = process.env.NODE_ENV === 'production' 4 | 5 | module.exports = { 6 | loaders: utils.cssLoaders({ 7 | sourceMap: isProduction 8 | ? config.build.productionSourceMap 9 | : config.dev.cssSourceMap, 10 | extract: isProduction 11 | }), 12 | transformToRequire: { 13 | video: 'src', 14 | source: 'src', 15 | img: 'src', 16 | image: 'xlink:href' 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /build/webpack.base.conf.js: -------------------------------------------------------------------------------- 1 | var path = require('path') 2 | var utils = require('./utils') 3 | var config = require('../config') 4 | var vueLoaderConfig = require('./vue-loader.conf') 5 | 6 | function resolve (dir) { 7 | return path.join(__dirname, '..', dir) 8 | } 9 | 10 | module.exports = { 11 | entry: { 12 | app: './src/main.js' 13 | }, 14 | output: { 15 | path: config.build.assetsRoot, 16 | filename: '[name].js', 17 | publicPath: process.env.NODE_ENV === 'production' 18 | ? config.build.assetsPublicPath 19 | : config.dev.assetsPublicPath 20 | }, 21 | resolve: { 22 | extensions: ['.js', '.vue', '.json'], 23 | alias: { 24 | 'vue$': 'vue/dist/vue.esm.js', 25 | '@': resolve('src') 26 | } 27 | }, 28 | module: { 29 | rules: [ 30 | { 31 | test: /\.(js|vue)$/, 32 | loader: 'eslint-loader', 33 | enforce: 'pre', 34 | include: [resolve('src'), resolve('test')], 35 | options: { 36 | formatter: require('eslint-friendly-formatter') 37 | } 38 | }, 39 | { 40 | test: /\.vue$/, 41 | loader: 'vue-loader', 42 | options: vueLoaderConfig 43 | }, 44 | { 45 | test: /\.js$/, 46 | loader: 'babel-loader', 47 | include: [resolve('src'), resolve('test')] 48 | }, 49 | { 50 | test: /\.(png|jpe?g|gif|svg)(\?.*)?$/, 51 | loader: 'url-loader', 52 | options: { 53 | limit: 10000, 54 | name: utils.assetsPath('img/[name].[hash:7].[ext]') 55 | } 56 | }, 57 | { 58 | test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/, 59 | loader: 'url-loader', 60 | options: { 61 | limit: 10000, 62 | name: utils.assetsPath('media/[name].[hash:7].[ext]') 63 | } 64 | }, 65 | { 66 | test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/, 67 | loader: 'url-loader', 68 | options: { 69 | limit: 10000, 70 | name: utils.assetsPath('fonts/[name].[hash:7].[ext]') 71 | } 72 | } 73 | ] 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /build/webpack.dev.conf.js: -------------------------------------------------------------------------------- 1 | var utils = require('./utils') 2 | var webpack = require('webpack') 3 | var config = require('../config') 4 | var merge = require('webpack-merge') 5 | var baseWebpackConfig = require('./webpack.base.conf') 6 | var HtmlWebpackPlugin = require('html-webpack-plugin') 7 | var FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin') 8 | 9 | // add hot-reload related code to entry chunks 10 | Object.keys(baseWebpackConfig.entry).forEach(function (name) { 11 | baseWebpackConfig.entry[name] = ['./build/dev-client'].concat(baseWebpackConfig.entry[name]) 12 | }) 13 | 14 | module.exports = merge(baseWebpackConfig, { 15 | module: { 16 | rules: utils.styleLoaders({ sourceMap: config.dev.cssSourceMap }) 17 | }, 18 | // cheap-module-eval-source-map is faster for development 19 | devtool: '#cheap-module-eval-source-map', 20 | plugins: [ 21 | new webpack.DefinePlugin({ 22 | 'process.env': config.dev.env 23 | }), 24 | // https://github.com/glenjamin/webpack-hot-middleware#installation--usage 25 | new webpack.HotModuleReplacementPlugin(), 26 | new webpack.NoEmitOnErrorsPlugin(), 27 | // https://github.com/ampedandwired/html-webpack-plugin 28 | new HtmlWebpackPlugin({ 29 | filename: 'index.html', 30 | template: 'index.html', 31 | inject: true 32 | }), 33 | new FriendlyErrorsPlugin() 34 | ] 35 | }) 36 | -------------------------------------------------------------------------------- /build/webpack.prod.conf.js: -------------------------------------------------------------------------------- 1 | var path = require('path') 2 | var utils = require('./utils') 3 | var webpack = require('webpack') 4 | var config = require('../config') 5 | var merge = require('webpack-merge') 6 | var baseWebpackConfig = require('./webpack.base.conf') 7 | var CopyWebpackPlugin = require('copy-webpack-plugin') 8 | var HtmlWebpackPlugin = require('html-webpack-plugin') 9 | var ExtractTextPlugin = require('extract-text-webpack-plugin') 10 | var OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin') 11 | 12 | var env = config.build.env 13 | 14 | var webpackConfig = merge(baseWebpackConfig, { 15 | module: { 16 | rules: utils.styleLoaders({ 17 | sourceMap: config.build.productionSourceMap, 18 | extract: true 19 | }) 20 | }, 21 | devtool: config.build.productionSourceMap ? '#source-map' : false, 22 | output: { 23 | path: config.build.assetsRoot, 24 | filename: utils.assetsPath('js/[name].[chunkhash].js'), 25 | chunkFilename: utils.assetsPath('js/[id].[chunkhash].js') 26 | }, 27 | plugins: [ 28 | // http://vuejs.github.io/vue-loader/en/workflow/production.html 29 | new webpack.DefinePlugin({ 30 | 'process.env': env 31 | }), 32 | new webpack.optimize.UglifyJsPlugin({ 33 | compress: { 34 | warnings: false 35 | }, 36 | sourceMap: true 37 | }), 38 | // extract css into its own file 39 | new ExtractTextPlugin({ 40 | filename: utils.assetsPath('css/[name].[contenthash].css') 41 | }), 42 | // Compress extracted CSS. We are using this plugin so that possible 43 | // duplicated CSS from different components can be deduped. 44 | new OptimizeCSSPlugin({ 45 | cssProcessorOptions: { 46 | safe: true 47 | } 48 | }), 49 | // generate dist index.html with correct asset hash for caching. 50 | // you can customize output by editing /index.html 51 | // see https://github.com/ampedandwired/html-webpack-plugin 52 | new HtmlWebpackPlugin({ 53 | filename: config.build.index, 54 | template: 'index.html', 55 | inject: true, 56 | minify: { 57 | removeComments: true, 58 | collapseWhitespace: true, 59 | removeAttributeQuotes: true 60 | // more options: 61 | // https://github.com/kangax/html-minifier#options-quick-reference 62 | }, 63 | // necessary to consistently work with multiple chunks via CommonsChunkPlugin 64 | chunksSortMode: 'dependency' 65 | }), 66 | // split vendor js into its own file 67 | new webpack.optimize.CommonsChunkPlugin({ 68 | name: 'vendor', 69 | minChunks: function (module, count) { 70 | // any required modules inside node_modules are extracted to vendor 71 | return ( 72 | module.resource && 73 | /\.js$/.test(module.resource) && 74 | module.resource.indexOf( 75 | path.join(__dirname, '../node_modules') 76 | ) === 0 77 | ) 78 | } 79 | }), 80 | // extract webpack runtime and module manifest to its own file in order to 81 | // prevent vendor hash from being updated whenever app bundle is updated 82 | new webpack.optimize.CommonsChunkPlugin({ 83 | name: 'manifest', 84 | chunks: ['vendor'] 85 | }), 86 | // copy custom static assets 87 | new CopyWebpackPlugin([ 88 | { 89 | from: path.resolve(__dirname, '../static'), 90 | to: config.build.assetsSubDirectory, 91 | ignore: ['.*'] 92 | } 93 | ]) 94 | ] 95 | }) 96 | 97 | if (config.build.productionGzip) { 98 | var CompressionWebpackPlugin = require('compression-webpack-plugin') 99 | 100 | webpackConfig.plugins.push( 101 | new CompressionWebpackPlugin({ 102 | asset: '[path].gz[query]', 103 | algorithm: 'gzip', 104 | test: new RegExp( 105 | '\\.(' + 106 | config.build.productionGzipExtensions.join('|') + 107 | ')$' 108 | ), 109 | threshold: 10240, 110 | minRatio: 0.8 111 | }) 112 | ) 113 | } 114 | 115 | if (config.build.bundleAnalyzerReport) { 116 | var BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin 117 | webpackConfig.plugins.push(new BundleAnalyzerPlugin()) 118 | } 119 | 120 | module.exports = webpackConfig 121 | -------------------------------------------------------------------------------- /config/dev.env.js: -------------------------------------------------------------------------------- 1 | var merge = require('webpack-merge') 2 | var prodEnv = require('./prod.env') 3 | 4 | module.exports = merge(prodEnv, { 5 | NODE_ENV: '"development"' 6 | }) 7 | -------------------------------------------------------------------------------- /config/index.js: -------------------------------------------------------------------------------- 1 | // see http://vuejs-templates.github.io/webpack for documentation. 2 | var path = require('path') 3 | 4 | module.exports = { 5 | build: { 6 | env: require('./prod.env'), 7 | index: path.resolve(__dirname, '../dist/index.html'), 8 | assetsRoot: path.resolve(__dirname, '../dist'), 9 | assetsSubDirectory: 'static', 10 | assetsPublicPath: '/', 11 | productionSourceMap: true, 12 | // Gzip off by default as many popular static hosts such as 13 | // Surge or Netlify already gzip all static assets for you. 14 | // Before setting to `true`, make sure to: 15 | // npm install --save-dev compression-webpack-plugin 16 | productionGzip: false, 17 | productionGzipExtensions: ['js', 'css'], 18 | // Run the build command with an extra argument to 19 | // View the bundle analyzer report after build finishes: 20 | // `npm run build --report` 21 | // Set to `true` or `false` to always turn it on or off 22 | bundleAnalyzerReport: process.env.npm_config_report 23 | }, 24 | dev: { 25 | env: require('./dev.env'), 26 | port: 9090, 27 | autoOpenBrowser: true, 28 | assetsSubDirectory: 'static', 29 | assetsPublicPath: '/', 30 | proxyTable: { 31 | '/home': { 32 | target: 'http://localhost:9001/', 33 | changeOrigin: true 34 | } 35 | }, 36 | // CSS Sourcemaps off by default because relative paths are "buggy" 37 | // with this option, according to the CSS-Loader README 38 | // (https://github.com/webpack/css-loader#sourcemaps) 39 | // In our experience, they generally work as expected, 40 | // just be aware of this issue when enabling this option. 41 | cssSourceMap: false 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /config/prod.env.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | NODE_ENV: '"production"' 3 | } 4 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | thinkjs-vue-blog 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "xwblog-home-vue", 3 | "version": "1.0.0", 4 | "description": "A Vue.js project", 5 | "author": "xwlyy ", 6 | "private": true, 7 | "scripts": { 8 | "dev": "node build/dev-server.js", 9 | "start": "node build/dev-server.js", 10 | "build": "node build/build.js", 11 | "lint": "eslint --ext .js,.vue src" 12 | }, 13 | "dependencies": { 14 | "vue": "^2.3.3", 15 | "vue-router": "^2.6.0" 16 | }, 17 | "devDependencies": { 18 | "autoprefixer": "^7.1.2", 19 | "axios": "^0.16.2", 20 | "babel-core": "^6.22.1", 21 | "babel-eslint": "^7.1.1", 22 | "babel-loader": "^7.1.1", 23 | "babel-plugin-transform-runtime": "^6.22.0", 24 | "babel-preset-env": "^1.3.2", 25 | "babel-preset-stage-2": "^6.22.0", 26 | "babel-register": "^6.22.0", 27 | "chalk": "^2.0.1", 28 | "connect-history-api-fallback": "^1.3.0", 29 | "copy-webpack-plugin": "^4.0.1", 30 | "css-loader": "^0.28.0", 31 | "cssnano": "^3.10.0", 32 | "eslint": "^3.19.0", 33 | "eslint-config-standard": "^6.2.1", 34 | "eslint-friendly-formatter": "^3.0.0", 35 | "eslint-loader": "^1.7.1", 36 | "eslint-plugin-html": "^3.0.0", 37 | "eslint-plugin-promise": "^3.4.0", 38 | "eslint-plugin-standard": "^2.0.1", 39 | "eventsource-polyfill": "^0.9.6", 40 | "express": "^4.14.1", 41 | "extract-text-webpack-plugin": "^2.0.0", 42 | "file-loader": "^0.11.1", 43 | "friendly-errors-webpack-plugin": "^1.1.3", 44 | "highlight.js": "^9.6.0", 45 | "html-webpack-plugin": "^2.28.0", 46 | "http-proxy-middleware": "^0.17.3", 47 | "lodash": "^4.17.4", 48 | "marked": "^0.3.6", 49 | "opn": "^5.1.0", 50 | "optimize-css-assets-webpack-plugin": "^2.0.0", 51 | "ora": "^1.2.0", 52 | "rimraf": "^2.6.0", 53 | "semver": "^5.3.0", 54 | "shelljs": "^0.7.6", 55 | "url-loader": "^0.5.8", 56 | "vue-loader": "^12.1.0", 57 | "vue-style-loader": "^3.0.1", 58 | "vue-template-compiler": "^2.3.3", 59 | "vuex": "^2.3.1", 60 | "webpack": "^2.6.1", 61 | "webpack-bundle-analyzer": "^2.2.1", 62 | "webpack-dev-middleware": "^1.10.0", 63 | "webpack-hot-middleware": "^2.18.0", 64 | "webpack-merge": "^4.1.0" 65 | }, 66 | "engines": { 67 | "node": ">= 4.0.0", 68 | "npm": ">= 3.0.0" 69 | }, 70 | "browserslist": [ 71 | "> 1%", 72 | "last 2 versions", 73 | "not ie <= 8" 74 | ] 75 | } 76 | -------------------------------------------------------------------------------- /src/App.vue: -------------------------------------------------------------------------------- 1 | 10 | 11 | 23 | 24 | 29 | -------------------------------------------------------------------------------- /src/api/index.js: -------------------------------------------------------------------------------- 1 | import {ArticleResource, UserResource, CommentResource} from './resources' 2 | 3 | export default { 4 | getArticleDetail: function (params) { 5 | return ArticleResource.get('detail', {params}) 6 | }, 7 | getArticleList: function (params) { 8 | return ArticleResource.get('list', {params}) 9 | }, 10 | addArticle: function (data) { 11 | return ArticleResource.post('add', data) 12 | }, 13 | modifyArticle: function (data) { 14 | return ArticleResource.post('modify', data) 15 | }, 16 | getUserDetail: function () { 17 | return UserResource.get('index') 18 | }, 19 | signin: function (user) { 20 | return UserResource.put('signin', user) 21 | }, 22 | signup: function (user) { 23 | return UserResource.post('signup', user) 24 | }, 25 | signout: function () { 26 | return UserResource.delete('signout') 27 | }, 28 | modifyUser: function (user) { 29 | return UserResource.put('modify', user) 30 | }, 31 | modifyPassword: function (user) { 32 | return UserResource.put('password', user) 33 | }, 34 | getCommentList: function (params) { 35 | return CommentResource.get('list', {params}) 36 | }, 37 | addComment: function (data) { 38 | return CommentResource.post('add', data) 39 | }, 40 | modifyComment: function (data) { 41 | return CommentResource.put('modify', data) 42 | }, 43 | deleteComment: function (params) { 44 | return CommentResource.delete('delete', {params}) 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/api/resources.js: -------------------------------------------------------------------------------- 1 | import axios from 'axios' 2 | 3 | export const ArticleResource = axios.create({baseURL: 'home/article'}) 4 | export const UserResource = axios.create({baseURL: 'home/user'}) 5 | export const CommentResource = axios.create({baseURL: 'home/comment'}) 6 | -------------------------------------------------------------------------------- /src/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drafish/vue-blog/1546764dcbe9424fc738d12e0c094b77e1a9f770/src/assets/logo.png -------------------------------------------------------------------------------- /src/components/ArticleDetail.vue: -------------------------------------------------------------------------------- 1 | 73 | 74 | 123 | -------------------------------------------------------------------------------- /src/components/ArticleEdit.vue: -------------------------------------------------------------------------------- 1 | 28 | 29 | 92 | -------------------------------------------------------------------------------- /src/components/ArticleList.vue: -------------------------------------------------------------------------------- 1 | 22 | 23 | 49 | -------------------------------------------------------------------------------- /src/components/FooterBar.vue: -------------------------------------------------------------------------------- 1 | 15 | -------------------------------------------------------------------------------- /src/components/HeaderBar.vue: -------------------------------------------------------------------------------- 1 | 31 | 32 | 52 | 53 | 54 | 57 | -------------------------------------------------------------------------------- /src/components/Loading.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | 12 | -------------------------------------------------------------------------------- /src/components/Pagination.vue: -------------------------------------------------------------------------------- 1 | 26 | 27 | 41 | 42 | 47 | -------------------------------------------------------------------------------- /src/components/Signin.vue: -------------------------------------------------------------------------------- 1 | 28 | 29 | 55 | -------------------------------------------------------------------------------- /src/components/Signup.vue: -------------------------------------------------------------------------------- 1 | 34 | 35 | 62 | -------------------------------------------------------------------------------- /src/config.js: -------------------------------------------------------------------------------- 1 | export const API_ROOT = (process.env.NODE_ENV === 'production') 2 | ? 'https://vue.paidepaiper.top/' 3 | : 'http://localhost:9001/' 4 | -------------------------------------------------------------------------------- /src/filters/index.js: -------------------------------------------------------------------------------- 1 | export function smartDate (timestamp) { 2 | if (typeof (timestamp) === 'string') { 3 | timestamp = parseInt(timestamp) 4 | } 5 | if (isNaN(timestamp)) { 6 | return '' 7 | } 8 | var today = new Date() 9 | var now = today.getTime() 10 | var s = '刚刚' 11 | var t = now - timestamp 12 | if (t > 604800000) { 13 | // 1 week ago: 14 | var that = new Date(timestamp) 15 | var y = that.getFullYear() 16 | var m = that.getMonth() + 1 17 | var d = that.getDate() 18 | var hh = that.getHours() 19 | var mm = that.getMinutes() 20 | s = y === today.getFullYear() ? '' : y + '年' 21 | s = s + m + '月' + d + '日' + hh + ':' + (mm < 10 ? '0' : '') + mm 22 | } else if (t >= 86400000) { 23 | // 1-6 days ago: 24 | s = Math.floor(t / 86400000) + '天前' 25 | } else if (t >= 3600000) { 26 | // 1-23 hours ago: 27 | s = Math.floor(t / 3600000) + '小时前' 28 | } else if (t >= 60000) { 29 | s = Math.floor(t / 60000) + '分钟前' 30 | } 31 | return s 32 | } 33 | -------------------------------------------------------------------------------- /src/main.js: -------------------------------------------------------------------------------- 1 | // The Vue build version to load with the `import` command 2 | // (runtime-only or standalone) has been set in webpack.base.conf with an alias. 3 | import Vue from 'vue' 4 | // import VueResource from 'vue-resource' 5 | import store from './store' 6 | import App from './App' 7 | import router from './router' 8 | import { smartDate } from './filters' 9 | 10 | // Vue.use(VueResource) 11 | 12 | Vue.config.productionTip = false 13 | 14 | Vue.filter('smartDate', smartDate) 15 | 16 | /* eslint-disable no-new */ 17 | new Vue({ 18 | el: '#app', 19 | store, 20 | router, 21 | template: '', 22 | components: { App } 23 | }) 24 | -------------------------------------------------------------------------------- /src/router.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import Router from 'vue-router' 3 | import ArticleList from '@/components/ArticleList' 4 | import ArticleDetail from '@/components/ArticleDetail' 5 | import ArticleEdit from '@/components/ArticleEdit' 6 | import Signin from '@/components/Signin' 7 | import Signup from '@/components/Signup' 8 | 9 | Vue.use(Router) 10 | 11 | export default new Router({ 12 | routes: [ 13 | { 14 | path: '/', 15 | name: 'ArticleList', 16 | component: ArticleList 17 | }, 18 | { 19 | path: '/signin', 20 | name: 'Signin', 21 | component: Signin 22 | }, 23 | { 24 | path: '/signup', 25 | name: 'Signup', 26 | component: Signup 27 | }, 28 | { 29 | path: '/article/:id', 30 | name: 'ArticleDetail', 31 | component: ArticleDetail 32 | }, 33 | { 34 | path: '/edit/:id', 35 | name: 'ArticleEdit', 36 | component: ArticleEdit 37 | } 38 | ] 39 | }) 40 | -------------------------------------------------------------------------------- /src/store/actions.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drafish/vue-blog/1546764dcbe9424fc738d12e0c094b77e1a9f770/src/store/actions.js -------------------------------------------------------------------------------- /src/store/getters.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drafish/vue-blog/1546764dcbe9424fc738d12e0c094b77e1a9f770/src/store/getters.js -------------------------------------------------------------------------------- /src/store/index.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import Vuex from 'vuex' 3 | import * as actions from './actions' 4 | import * as getters from './getters' 5 | import article from './modules/article' 6 | import comment from './modules/comment' 7 | import user from './modules/user' 8 | import createLogger from 'vuex/dist/logger' 9 | 10 | Vue.use(Vuex) 11 | 12 | const debug = process.env.NODE_ENV !== 'production' 13 | 14 | export default new Vuex.Store({ 15 | actions, 16 | getters, 17 | modules: { 18 | article, 19 | comment, 20 | user 21 | }, 22 | strict: debug, 23 | plugins: debug ? [createLogger()] : [] 24 | }) 25 | -------------------------------------------------------------------------------- /src/store/modules/article.js: -------------------------------------------------------------------------------- 1 | import marked from 'marked' 2 | import highlightjs from 'highlight.js' 3 | import 'highlight.js/styles/github.css' 4 | import _ from 'lodash' 5 | import * as types from '../mutation-types' 6 | import api from '../../api' 7 | 8 | marked.setOptions({ 9 | highlight: (code) => highlightjs.highlightAuto(code).value 10 | }) 11 | 12 | const formatPage = (itemCount, pageIndex, pageSize) => { 13 | let pageCount, offset, limit 14 | pageCount = parseInt(itemCount / pageSize) 15 | if (itemCount % pageSize > 0) { 16 | pageCount = pageCount + 1 17 | } 18 | if (itemCount === 0 || pageIndex > pageCount) { 19 | offset = 0 20 | limit = 0 21 | pageIndex = 1 22 | } else { 23 | offset = pageSize * (pageIndex - 1) 24 | limit = parseInt(pageSize) 25 | } 26 | return { 27 | itemCount, 28 | pageIndex, 29 | pageSize, 30 | pageCount, 31 | offset: offset, 32 | limit: limit 33 | } 34 | } 35 | 36 | const state = { 37 | detail: {user: {}}, 38 | list: [], 39 | page: {} 40 | } 41 | 42 | // getters 43 | const getters = { 44 | articleDetail: state => state.detail, 45 | articleList: state => state.list, 46 | articlePage: state => state.page 47 | } 48 | 49 | // actions 50 | const actions = { 51 | getArticleList ({ commit }, params) { 52 | api.getArticleList(params).then(res => { 53 | res.data.data.data.map(item => { 54 | item.content = marked(item.content) 55 | }) 56 | let page = _.pick(res.data.data, 'currentPage', 'numsPerPage', 'count', 'totalPages') 57 | page = formatPage(page.count, page.currentPage, page.numsPerPage) 58 | commit(types.SET_ARTICLES, {list: res.data.data.data, page}) 59 | }) 60 | }, 61 | getArticleDetail ({ commit }, id) { 62 | api.getArticleDetail({id}).then(res => { 63 | res.data.data.marked = marked(res.data.data.content) 64 | commit(types.SET_ARTICLE, res.data.data) 65 | }) 66 | }, 67 | async addArticle ({ commit }, data) { 68 | let res = await api.addArticle(data) 69 | return res 70 | }, 71 | async modifyArticle ({ commit }, data) { 72 | await api.modifyArticle(data) 73 | } 74 | } 75 | 76 | const mutations = { 77 | 78 | [types.SET_ARTICLE] (state, detail) { 79 | state.detail = detail 80 | }, 81 | [types.SET_ARTICLES] (state, {list, page}) { 82 | state.list = list 83 | state.page = page 84 | } 85 | } 86 | 87 | export default { 88 | state, 89 | getters, 90 | actions, 91 | mutations 92 | } 93 | -------------------------------------------------------------------------------- /src/store/modules/comment.js: -------------------------------------------------------------------------------- 1 | import marked from 'marked' 2 | import highlightjs from 'highlight.js' 3 | import 'highlight.js/styles/github.css' 4 | import _ from 'lodash' 5 | import * as types from '../mutation-types' 6 | import api from '../../api' 7 | 8 | marked.setOptions({ 9 | highlight: (code) => highlightjs.highlightAuto(code).value 10 | }) 11 | 12 | const formatPage = (itemCount, pageIndex, pageSize) => { 13 | let pageCount, offset, limit 14 | pageCount = parseInt(itemCount / pageSize) 15 | if (itemCount % pageSize > 0) { 16 | pageCount = pageCount + 1 17 | } 18 | if (itemCount === 0 || pageIndex > pageCount) { 19 | offset = 0 20 | limit = 0 21 | pageIndex = 1 22 | } else { 23 | offset = pageSize * (pageIndex - 1) 24 | limit = parseInt(pageSize) 25 | } 26 | return { 27 | itemCount, 28 | pageIndex, 29 | pageSize, 30 | pageCount, 31 | offset: offset, 32 | limit: limit 33 | } 34 | } 35 | 36 | const state = { 37 | list: [], 38 | page: {} 39 | } 40 | 41 | // getters 42 | const getters = { 43 | commentList: state => state.list, 44 | commentPage: state => state.page 45 | } 46 | 47 | // actions 48 | const actions = { 49 | getCommentList ({ commit }, params) { 50 | api.getCommentList(params).then(res => { 51 | res.data.data.data.map(item => { 52 | item.content = marked(item.content) 53 | }) 54 | let page = _.pick(res.data.data, 'currentPage', 'numsPerPage', 'count', 'totalPages') 55 | page = formatPage(page.count, page.currentPage, page.numsPerPage) 56 | commit(types.SET_COMMENTS, {list: res.data.data.data, page}) 57 | }) 58 | }, 59 | addComment ({ commit }, data) { 60 | api.addComment(data).then(res => { 61 | res.data.data.content = marked(res.data.data.content) 62 | commit(types.CONCAT_COMMENT, res.data.data) 63 | }) 64 | } 65 | } 66 | 67 | const mutations = { 68 | 69 | [types.SET_COMMENTS] (state, {list, page}) { 70 | state.list = list 71 | state.page = page 72 | }, 73 | [types.CONCAT_COMMENT] (state, comment) { 74 | state.list.unshift(comment) 75 | } 76 | } 77 | 78 | export default { 79 | state, 80 | getters, 81 | actions, 82 | mutations 83 | } 84 | -------------------------------------------------------------------------------- /src/store/modules/load.js: -------------------------------------------------------------------------------- 1 | import {SET_ISFETCH} from '../mutation-types' 2 | 3 | const state = { 4 | isFetch: 0 5 | } 6 | 7 | const mutations = { 8 | [SET_ISFETCH] (state, isFetch) { 9 | state.isFetch = isFetch 10 | } 11 | } 12 | 13 | export default { 14 | state, 15 | mutations 16 | } 17 | -------------------------------------------------------------------------------- /src/store/modules/user.js: -------------------------------------------------------------------------------- 1 | import * as types from '../mutation-types' 2 | import api from '../../api' 3 | 4 | const state = { 5 | detail: {} 6 | } 7 | 8 | // getters 9 | const getters = { 10 | userDetail: state => state.detail 11 | } 12 | 13 | // actions 14 | const actions = { 15 | 16 | getUserDetail ({ commit }, id) { 17 | api.getUserDetail({id}).then(res => { 18 | commit(types.SET_USER, res.data.data) 19 | }) 20 | }, 21 | async signin ({ commit }, data) { 22 | let res = await api.signin(data) 23 | commit(types.SET_USER, res.data.data) 24 | }, 25 | async signup ({ commit }, data) { 26 | let res = await api.signup(data) 27 | commit(types.SET_USER, res.data.data) 28 | }, 29 | signout ({ commit }, data) { 30 | api.signout().then(res => { 31 | commit(types.CLEAR_USER) 32 | }) 33 | } 34 | } 35 | 36 | const mutations = { 37 | 38 | [types.SET_USER] (state, detail) { 39 | state.detail = detail 40 | }, 41 | [types.CLEAR_USER] (state) { 42 | state.detail = {} 43 | } 44 | } 45 | 46 | export default { 47 | state, 48 | getters, 49 | actions, 50 | mutations 51 | } 52 | -------------------------------------------------------------------------------- /src/store/mutation-types.js: -------------------------------------------------------------------------------- 1 | export const SET_ARTICLES = 'SET_ARTICLES' 2 | export const SET_ISFETCH = 'SET_ISFETCH' 3 | 4 | export const SET_ARTICLE = 'SET_ARTICLE' 5 | export const SET_COMMENTS = 'SET_COMMENTS' 6 | export const CONCAT_COMMENT = 'CONCAT_COMMENT' 7 | 8 | export const SET_USER = 'SET_USER' 9 | export const CLEAR_USER = 'CLEAR_USER' 10 | -------------------------------------------------------------------------------- /static/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drafish/vue-blog/1546764dcbe9424fc738d12e0c094b77e1a9f770/static/.gitkeep -------------------------------------------------------------------------------- /static/img/user.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drafish/vue-blog/1546764dcbe9424fc738d12e0c094b77e1a9f770/static/img/user.png --------------------------------------------------------------------------------