├── .babelrc ├── .editorconfig ├── .eslintignore ├── .eslintrc.js ├── .gitignore ├── .postcssrc.js ├── README.md ├── _redirects ├── build ├── build.js ├── check-versions.js ├── dev-client.js ├── dev-server.js ├── load-minified.js ├── service-worker-dev.js ├── service-worker-prod.js ├── utils.js ├── vue-loader.conf.js ├── webpack.base.conf.js ├── webpack.dev.conf.js ├── webpack.prod.conf.js └── webpack.test.conf.js ├── config ├── dev.env.js ├── index.js ├── prod.env.js └── test.env.js ├── index.html ├── package-lock.json ├── package.json ├── src ├── .gitrepo ├── App.vue ├── assets │ └── logo.png ├── components │ └── PageContainer.vue ├── data │ ├── tabs-map.js │ └── tabs.json ├── main.js ├── mixins │ └── global-mixins.js ├── pages │ ├── About.vue │ ├── Home.vue │ ├── New.vue │ ├── NotFound.vue │ ├── Notifications.vue │ ├── Search.vue │ ├── User.vue │ ├── login │ │ ├── Login.vue │ │ └── LoginCamera.vue │ ├── settings │ │ ├── Settings.vue │ │ └── SettingsTabs.vue │ └── topic │ │ ├── Topic.vue │ │ └── TopicReply.vue ├── router │ └── index.js ├── store │ ├── actions.js │ ├── getters.js │ ├── index.js │ ├── mutations.js │ └── state.js └── utils │ ├── bus.js │ └── time-formattor.js ├── static ├── img │ └── icons │ │ ├── android-chrome-192x192.png │ │ ├── android-chrome-512x512.png │ │ ├── apple-touch-icon-120x120.png │ │ ├── apple-touch-icon-152x152.png │ │ ├── apple-touch-icon-180x180.png │ │ ├── apple-touch-icon-60x60.png │ │ ├── apple-touch-icon-76x76.png │ │ ├── apple-touch-icon.png │ │ ├── favicon-16x16.png │ │ ├── favicon-32x32.png │ │ ├── favicon.ico │ │ ├── msapplication-icon-144x144.png │ │ ├── mstile-150x150.png │ │ └── safari-pinned-tab.svg └── manifest.json └── test └── unit ├── .eslintrc ├── index.js ├── karma.conf.js └── specs └── Hello.spec.js /.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/ 2 | /config/ 3 | /dist/ 4 | /*.js 5 | /test/unit/coverage/ 6 | -------------------------------------------------------------------------------- /.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 | /test/unit/coverage 8 | 9 | # Editor directories and files 10 | .idea 11 | *.suo 12 | *.ntvs* 13 | *.njsproj 14 | *.sln 15 | -------------------------------------------------------------------------------- /.postcssrc.js: -------------------------------------------------------------------------------- 1 | // https://github.com/michael-ciniawsky/postcss-load-config 2 | 3 | module.exports = { 4 | "plugins": { 5 | // to edit target browsers: use "browserlist" field in package.json 6 | "autoprefixer": {} 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CNode-V 2 | 3 | > A Vue.js project 4 | 5 | ## Build Setup 6 | 7 | ``` bash 8 | # install dependencies 9 | npm install 10 | 11 | # serve with hot reload at localhost:8080 12 | npm run dev 13 | 14 | # build for production with minification 15 | npm run build 16 | 17 | # build for production and view the bundle analyzer report 18 | npm run build --report 19 | 20 | # run unit tests 21 | npm run unit 22 | 23 | # run all tests 24 | npm test 25 | ``` 26 | 27 | For detailed explanation on how things work, checkout the [guide](http://vuejs-templates.github.io/webpack/) and [docs for vue-loader](http://vuejs.github.io/vue-loader). 28 | 29 | ## Todo 30 | 31 | - [x] 登录模块放到左侧抽屉 32 | - [x] 帖子编辑 33 | - [x] 清除缓存 34 | - [x] 通知数量 35 | - [x] 夜晚模式 36 | - [x] 站外链接控制 37 | - [ ] TAB状态管理 38 | - [x] PWA说明 39 | - [ ] 路由模式调整 40 | - [ ] 调整抽屉在PC端的交互 41 | - [ ] 分享 42 | - [ ] 分享页打开时,返回主页问题 43 | - [ ] 通知 44 | - [ ] 下拉刷新 45 | - [ ] 代码块样式调整 46 | -------------------------------------------------------------------------------- /_redirects: -------------------------------------------------------------------------------- 1 | # for using frontend router 2 | /* /index.html 404 3 | -------------------------------------------------------------------------------- /build/build.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | require('./check-versions')() 4 | 5 | process.env.NODE_ENV = 'production' 6 | 7 | const ora = require('ora') 8 | const rm = require('rimraf') 9 | const path = require('path') 10 | const chalk = require('chalk') 11 | const webpack = require('webpack') 12 | const config = require('../config') 13 | const webpackConfig = require('./webpack.prod.conf') 14 | 15 | const spinner = ora('building for production...') 16 | spinner.start() 17 | 18 | rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => { 19 | if (err) throw err 20 | webpack(webpackConfig, function (err, stats) { 21 | spinner.stop() 22 | if (err) throw err 23 | process.stdout.write(stats.toString({ 24 | colors: true, 25 | modules: false, 26 | children: false, 27 | chunks: false, 28 | chunkModules: false 29 | }) + '\n\n') 30 | 31 | console.log(chalk.cyan(' Build complete.\n')) 32 | console.log(chalk.yellow( 33 | ' Tip: built files are meant to be served over an HTTP server.\n' + 34 | ' Opening index.html over file:// won\'t work.\n' 35 | )) 36 | }) 37 | }) 38 | -------------------------------------------------------------------------------- /build/check-versions.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | const chalk = require('chalk') 4 | const semver = require('semver') 5 | const packageConfig = require('../package.json') 6 | const shell = require('shelljs') 7 | function exec (cmd) { 8 | return require('child_process').execSync(cmd).toString().trim() 9 | } 10 | 11 | const versionRequirements = [ 12 | { 13 | name: 'node', 14 | currentVersion: semver.clean(process.version), 15 | versionRequirement: packageConfig.engines.node 16 | }, 17 | ] 18 | 19 | if (shell.which('npm')) { 20 | versionRequirements.push({ 21 | name: 'npm', 22 | currentVersion: exec('npm --version'), 23 | versionRequirement: packageConfig.engines.npm 24 | }) 25 | } 26 | 27 | module.exports = function () { 28 | const warnings = [] 29 | for (let i = 0; i < versionRequirements.length; i++) { 30 | const mod = versionRequirements[i] 31 | if (!semver.satisfies(mod.currentVersion, mod.versionRequirement)) { 32 | warnings.push(mod.name + ': ' + 33 | chalk.red(mod.currentVersion) + ' should be ' + 34 | chalk.green(mod.versionRequirement) 35 | ) 36 | } 37 | } 38 | 39 | if (warnings.length) { 40 | console.log('') 41 | console.log(chalk.yellow('To use this template, you must update following to modules:')) 42 | console.log() 43 | for (let i = 0; i < warnings.length; i++) { 44 | const warning = warnings[i] 45 | console.log(' ' + warning) 46 | } 47 | console.log() 48 | process.exit(1) 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /build/dev-client.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | /* eslint-disable */ 4 | require('eventsource-polyfill') 5 | var hotClient = require('webpack-hot-middleware/client?noInfo=true&reload=true') 6 | 7 | hotClient.subscribe(function (event) { 8 | if (event.action === 'reload') { 9 | window.location.reload() 10 | } 11 | }) 12 | -------------------------------------------------------------------------------- /build/dev-server.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | require('./check-versions')() 4 | 5 | const config = require('../config') 6 | if (!process.env.NODE_ENV) { 7 | process.env.NODE_ENV = JSON.parse(config.dev.env.NODE_ENV) 8 | } 9 | 10 | const opn = require('opn') 11 | const path = require('path') 12 | const express = require('express') 13 | const webpack = require('webpack') 14 | const fs = require('fs') 15 | const https = require('https') 16 | const proxyMiddleware = require('http-proxy-middleware') 17 | const webpackConfig = process.env.NODE_ENV === 'testing' 18 | ? require('./webpack.prod.conf') 19 | : require('./webpack.dev.conf') 20 | 21 | // default port where dev server listens for incoming traffic 22 | const port = process.env.PORT || config.dev.port 23 | // automatically open browser, if not set will be false 24 | const autoOpenBrowser = !!config.dev.autoOpenBrowser 25 | // Define HTTP proxies to your custom API backend 26 | // https://github.com/chimurai/http-proxy-middleware 27 | const proxyTable = config.dev.proxyTable 28 | 29 | const app = express() 30 | const compiler = webpack(webpackConfig) 31 | 32 | const devMiddleware = require('webpack-dev-middleware')(compiler, { 33 | publicPath: webpackConfig.output.publicPath, 34 | quiet: true 35 | }) 36 | 37 | const hotMiddleware = require('webpack-hot-middleware')(compiler, { 38 | log: false 39 | }) 40 | // force page reload when html-webpack-plugin template changes 41 | compiler.plugin('compilation', function (compilation) { 42 | compilation.plugin('html-webpack-plugin-after-emit', function (data, cb) { 43 | hotMiddleware.publish({ action: 'reload' }) 44 | cb() 45 | }) 46 | }) 47 | 48 | // enable hot-reload and state-preserving 49 | // compilation error display 50 | app.use(hotMiddleware) 51 | 52 | // proxy api requests 53 | Object.keys(proxyTable).forEach(function (context) { 54 | let options = proxyTable[context] 55 | if (typeof options === 'string') { 56 | options = { target: options } 57 | } 58 | app.use(proxyMiddleware(options.filter || context, options)) 59 | }) 60 | 61 | // handle fallback for HTML5 history API 62 | app.use(require('connect-history-api-fallback')()) 63 | 64 | // serve webpack bundle output 65 | app.use(devMiddleware) 66 | 67 | // serve pure static assets 68 | const staticPath = path.posix.join(config.dev.assetsPublicPath, config.dev.assetsSubDirectory) 69 | app.use(staticPath, express.static('./static')) 70 | 71 | const uri = 'http://localhost:' + port 72 | 73 | let _resolve 74 | const readyPromise = new Promise(resolve => { 75 | _resolve = resolve 76 | }) 77 | 78 | console.log('> Starting dev server...') 79 | devMiddleware.waitUntilValid(() => { 80 | console.log('> Listening at ' + uri + '\n') 81 | // when env is testing, don't need open it 82 | if (autoOpenBrowser && process.env.NODE_ENV !== 'testing') { 83 | opn(uri) 84 | } 85 | _resolve() 86 | }) 87 | 88 | // const server = https.createServer({ 89 | // key: fs.readFileSync(path.resolve(__dirname, 'server.key')), 90 | // cert: fs.readFileSync(path.resolve(__dirname, 'server.cert')) 91 | // }, app).listen(port) 92 | 93 | const server = app.listen(port) 94 | 95 | module.exports = { 96 | ready: readyPromise, 97 | close: () => { 98 | server.close() 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /build/load-minified.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | const fs = require('fs') 4 | const UglifyJS = require('uglify-es') 5 | 6 | module.exports = function(filePath) { 7 | const code = fs.readFileSync(filePath, 'utf-8') 8 | const result = UglifyJS.minify(code) 9 | if (result.error) return '' 10 | return result.code 11 | } 12 | -------------------------------------------------------------------------------- /build/service-worker-dev.js: -------------------------------------------------------------------------------- 1 | // This service worker file is effectively a 'no-op' that will reset any 2 | // previous service worker registered for the same host:port combination. 3 | // In the production build, this file is replaced with an actual service worker 4 | // file that will precache your site's local assets. 5 | // See https://github.com/facebookincubator/create-react-app/issues/2272#issuecomment-302832432 6 | 7 | self.addEventListener('install', () => self.skipWaiting()); 8 | 9 | self.addEventListener('activate', () => { 10 | self.clients.matchAll({ type: 'window' }).then(windowClients => { 11 | for (let windowClient of windowClients) { 12 | // Force open pages to refresh, so that they have a chance to load the 13 | // fresh navigation response from the local dev server. 14 | windowClient.navigate(windowClient.url); 15 | } 16 | }); 17 | }); -------------------------------------------------------------------------------- /build/service-worker-prod.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | 'use strict'; 3 | 4 | // Check to make sure service workers are supported in the current browser, 5 | // and that the current page is accessed from a secure origin. Using a 6 | // service worker from an insecure origin will trigger JS console errors. 7 | var isLocalhost = Boolean(window.location.hostname === 'localhost' || 8 | // [::1] is the IPv6 localhost address. 9 | window.location.hostname === '[::1]' || 10 | // 127.0.0.1/8 is considered localhost for IPv4. 11 | window.location.hostname.match( 12 | /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/ 13 | ) 14 | ); 15 | 16 | window.addEventListener('load', function() { 17 | if ('serviceWorker' in navigator && 18 | (window.location.protocol === 'https:' || isLocalhost)) { 19 | navigator.serviceWorker.register('service-worker.js') 20 | .then(function(registration) { 21 | // updatefound is fired if service-worker.js changes. 22 | registration.onupdatefound = function() { 23 | // updatefound is also fired the very first time the SW is installed, 24 | // and there's no need to prompt for a reload at that point. 25 | // So check here to see if the page is already controlled, 26 | // i.e. whether there's an existing service worker. 27 | if (navigator.serviceWorker.controller) { 28 | // The updatefound event implies that registration.installing is set 29 | var installingWorker = registration.installing; 30 | 31 | installingWorker.onstatechange = function() { 32 | switch (installingWorker.state) { 33 | case 'installed': 34 | // At this point, the old content will have been purged and the 35 | // fresh content will have been added to the cache. 36 | // It's the perfect time to display a "New content is 37 | // available; please refresh." message in the page's interface. 38 | break; 39 | 40 | case 'redundant': 41 | throw new Error('The installing ' + 42 | 'service worker became redundant.'); 43 | 44 | default: 45 | // Ignore 46 | } 47 | }; 48 | } 49 | }; 50 | }).catch(function(e) { 51 | console.error('Error during service worker registration:', e); 52 | }); 53 | } 54 | }); 55 | })(); 56 | -------------------------------------------------------------------------------- /build/utils.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | const path = require('path') 4 | const config = require('../config') 5 | const ExtractTextPlugin = require('extract-text-webpack-plugin') 6 | 7 | exports.assetsPath = function (_path) { 8 | const assetsSubDirectory = process.env.NODE_ENV === 'production' 9 | ? config.build.assetsSubDirectory 10 | : config.dev.assetsSubDirectory 11 | return path.posix.join(assetsSubDirectory, _path) 12 | } 13 | 14 | exports.cssLoaders = function (options) { 15 | options = options || {} 16 | 17 | const cssLoader = { 18 | loader: 'css-loader', 19 | options: { 20 | minimize: process.env.NODE_ENV === 'production', 21 | sourceMap: options.sourceMap 22 | } 23 | } 24 | 25 | // generate loader string to be used with extract text plugin 26 | function generateLoaders (loader, loaderOptions) { 27 | const loaders = [cssLoader] 28 | if (loader) { 29 | loaders.push({ 30 | loader: loader + '-loader', 31 | options: Object.assign({}, loaderOptions, { 32 | sourceMap: options.sourceMap 33 | }) 34 | }) 35 | } 36 | 37 | // Extract CSS when that option is specified 38 | // (which is the case during production build) 39 | if (options.extract) { 40 | return ExtractTextPlugin.extract({ 41 | use: loaders, 42 | fallback: 'vue-style-loader' 43 | }) 44 | } else { 45 | return ['vue-style-loader'].concat(loaders) 46 | } 47 | } 48 | 49 | // https://vue-loader.vuejs.org/en/configurations/extract-css.html 50 | return { 51 | css: generateLoaders(), 52 | postcss: generateLoaders(), 53 | less: generateLoaders('less'), 54 | sass: generateLoaders('sass', { indentedSyntax: true }), 55 | scss: generateLoaders('sass'), 56 | stylus: generateLoaders('stylus'), 57 | styl: generateLoaders('stylus') 58 | } 59 | } 60 | 61 | // Generate loaders for standalone style files (outside of .vue) 62 | exports.styleLoaders = function (options) { 63 | const output = [] 64 | const loaders = exports.cssLoaders(options) 65 | for (const extension in loaders) { 66 | const loader = loaders[extension] 67 | output.push({ 68 | test: new RegExp('\\.' + extension + '$'), 69 | use: loader 70 | }) 71 | } 72 | return output 73 | } 74 | -------------------------------------------------------------------------------- /build/vue-loader.conf.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | const utils = require('./utils') 4 | const config = require('../config') 5 | const isProduction = process.env.NODE_ENV === 'production' 6 | 7 | module.exports = { 8 | loaders: utils.cssLoaders({ 9 | sourceMap: isProduction 10 | ? config.build.productionSourceMap 11 | : config.dev.cssSourceMap, 12 | extract: isProduction 13 | }), 14 | transformToRequire: { 15 | video: ['src', 'poster'], 16 | source: 'src', 17 | img: 'src', 18 | image: 'xlink:href' 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /build/webpack.base.conf.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | const path = require('path') 4 | const utils = require('./utils') 5 | const config = require('../config') 6 | const vueLoaderConfig = require('./vue-loader.conf') 7 | 8 | function resolve (dir) { 9 | return path.join(__dirname, '..', dir) 10 | } 11 | 12 | module.exports = { 13 | entry: { 14 | app: './src/main.js' 15 | }, 16 | output: { 17 | path: config.build.assetsRoot, 18 | filename: '[name].js', 19 | publicPath: process.env.NODE_ENV === 'production' 20 | ? config.build.assetsPublicPath 21 | : config.dev.assetsPublicPath 22 | }, 23 | resolve: { 24 | extensions: ['.js', '.vue', '.json'], 25 | alias: { 26 | 'vue$': 'vue/dist/vue.esm.js', 27 | '@': resolve('src') 28 | } 29 | }, 30 | module: { 31 | rules: [ 32 | { 33 | test: /\.(js|vue)$/, 34 | loader: 'eslint-loader', 35 | enforce: 'pre', 36 | include: [resolve('src'), resolve('test')], 37 | options: { 38 | formatter: require('eslint-friendly-formatter') 39 | } 40 | }, 41 | { 42 | test: /\.vue$/, 43 | loader: 'vue-loader', 44 | options: vueLoaderConfig 45 | }, 46 | { 47 | test: /\.js$/, 48 | loader: 'babel-loader', 49 | include: [resolve('src'), resolve('test')] 50 | }, 51 | { 52 | test: /\.(png|jpe?g|gif|svg)(\?.*)?$/, 53 | loader: 'url-loader', 54 | options: { 55 | limit: 10000, 56 | name: utils.assetsPath('img/[name].[hash:7].[ext]') 57 | } 58 | }, 59 | { 60 | test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/, 61 | loader: 'url-loader', 62 | options: { 63 | limit: 10000, 64 | name: utils.assetsPath('media/[name].[hash:7].[ext]') 65 | } 66 | }, 67 | { 68 | test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/, 69 | loader: 'url-loader', 70 | options: { 71 | limit: 10000, 72 | name: utils.assetsPath('fonts/[name].[hash:7].[ext]') 73 | } 74 | } 75 | ] 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /build/webpack.dev.conf.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | const fs = require('fs') 4 | const path = require('path') 5 | const utils = require('./utils') 6 | const webpack = require('webpack') 7 | const config = require('../config') 8 | const merge = require('webpack-merge') 9 | const baseWebpackConfig = require('./webpack.base.conf') 10 | const HtmlWebpackPlugin = require('html-webpack-plugin') 11 | const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin') 12 | 13 | // add hot-reload related code to entry chunks 14 | Object.keys(baseWebpackConfig.entry).forEach(function (name) { 15 | baseWebpackConfig.entry[name] = ['./build/dev-client'].concat(baseWebpackConfig.entry[name]) 16 | }) 17 | 18 | module.exports = merge(baseWebpackConfig, { 19 | module: { 20 | rules: utils.styleLoaders({ sourceMap: config.dev.cssSourceMap }) 21 | }, 22 | // cheap-module-eval-source-map is faster for development 23 | devtool: '#cheap-module-eval-source-map', 24 | plugins: [ 25 | new webpack.DefinePlugin({ 26 | 'process.env': config.dev.env 27 | }), 28 | // https://github.com/glenjamin/webpack-hot-middleware#installation--usage 29 | new webpack.HotModuleReplacementPlugin(), 30 | new webpack.NoEmitOnErrorsPlugin(), 31 | // https://github.com/ampedandwired/html-webpack-plugin 32 | new HtmlWebpackPlugin({ 33 | filename: 'index.html', 34 | template: 'index.html', 35 | inject: true, 36 | serviceWorkerLoader: `` 38 | }), 39 | new FriendlyErrorsPlugin() 40 | ] 41 | }) 42 | -------------------------------------------------------------------------------- /build/webpack.prod.conf.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | const fs = require('fs') 4 | const path = require('path') 5 | const utils = require('./utils') 6 | const webpack = require('webpack') 7 | const config = require('../config') 8 | const merge = require('webpack-merge') 9 | const baseWebpackConfig = require('./webpack.base.conf') 10 | const CopyWebpackPlugin = require('copy-webpack-plugin') 11 | const HtmlWebpackPlugin = require('html-webpack-plugin') 12 | const ExtractTextPlugin = require('extract-text-webpack-plugin') 13 | const OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin') 14 | const SWPrecacheWebpackPlugin = require('sw-precache-webpack-plugin') 15 | const loadMinified = require('./load-minified') 16 | 17 | const env = process.env.NODE_ENV === 'testing' 18 | ? require('../config/test.env') 19 | : config.build.env 20 | 21 | const webpackConfig = merge(baseWebpackConfig, { 22 | module: { 23 | rules: utils.styleLoaders({ 24 | sourceMap: config.build.productionSourceMap, 25 | extract: true 26 | }) 27 | }, 28 | devtool: config.build.productionSourceMap ? '#source-map' : false, 29 | output: { 30 | path: config.build.assetsRoot, 31 | filename: utils.assetsPath('js/[name].[chunkhash].js'), 32 | chunkFilename: utils.assetsPath('js/[id].[chunkhash].js') 33 | }, 34 | plugins: [ 35 | // http://vuejs.github.io/vue-loader/en/workflow/production.html 36 | new webpack.DefinePlugin({ 37 | 'process.env': env 38 | }), 39 | new webpack.optimize.UglifyJsPlugin({ 40 | compress: { 41 | warnings: false 42 | }, 43 | sourceMap: true 44 | }), 45 | // extract css into its own file 46 | new ExtractTextPlugin({ 47 | filename: utils.assetsPath('css/[name].[contenthash].css') 48 | }), 49 | // Compress extracted CSS. We are using this plugin so that possible 50 | // duplicated CSS from different components can be deduped. 51 | new OptimizeCSSPlugin({ 52 | cssProcessorOptions: { 53 | safe: true 54 | } 55 | }), 56 | // generate dist index.html with correct asset hash for caching. 57 | // you can customize output by editing /index.html 58 | // see https://github.com/ampedandwired/html-webpack-plugin 59 | new HtmlWebpackPlugin({ 60 | filename: process.env.NODE_ENV === 'testing' 61 | ? 'index.html' 62 | : config.build.index, 63 | template: 'index.html', 64 | inject: true, 65 | minify: { 66 | removeComments: true, 67 | collapseWhitespace: true, 68 | removeAttributeQuotes: true 69 | // more options: 70 | // https://github.com/kangax/html-minifier#options-quick-reference 71 | }, 72 | // necessary to consistently work with multiple chunks via CommonsChunkPlugin 73 | chunksSortMode: 'dependency', 74 | serviceWorkerLoader: `` 76 | }), 77 | // split vendor js into its own file 78 | new webpack.optimize.CommonsChunkPlugin({ 79 | name: 'vendor', 80 | minChunks: function (module, count) { 81 | // any required modules inside node_modules are extracted to vendor 82 | return ( 83 | module.resource && 84 | /\.js$/.test(module.resource) && 85 | module.resource.indexOf( 86 | path.join(__dirname, '../node_modules') 87 | ) === 0 88 | ) 89 | } 90 | }), 91 | // extract webpack runtime and module manifest to its own file in order to 92 | // prevent vendor hash from being updated whenever app bundle is updated 93 | new webpack.optimize.CommonsChunkPlugin({ 94 | name: 'manifest', 95 | chunks: ['vendor'] 96 | }), 97 | // copy custom static assets 98 | new CopyWebpackPlugin([ 99 | { 100 | from: path.resolve(__dirname, '../static'), 101 | to: config.build.assetsSubDirectory, 102 | ignore: ['.*'] 103 | }, 104 | { 105 | from: path.resolve(__dirname, '../_redirects'), 106 | to: config.build.assetsRoot 107 | } 108 | ]), 109 | // service worker caching 110 | new SWPrecacheWebpackPlugin({ 111 | cacheId: 'cnode-v', 112 | filename: 'service-worker.js', 113 | staticFileGlobs: ['dist/**/*.{js,html,css}'], 114 | minify: true, 115 | stripPrefix: 'dist/' 116 | }) 117 | ] 118 | }) 119 | 120 | if (config.build.productionGzip) { 121 | const CompressionWebpackPlugin = require('compression-webpack-plugin') 122 | 123 | webpackConfig.plugins.push( 124 | new CompressionWebpackPlugin({ 125 | asset: '[path].gz[query]', 126 | algorithm: 'gzip', 127 | test: new RegExp( 128 | '\\.(' + 129 | config.build.productionGzipExtensions.join('|') + 130 | ')$' 131 | ), 132 | threshold: 10240, 133 | minRatio: 0.8 134 | }) 135 | ) 136 | } 137 | 138 | if (config.build.bundleAnalyzerReport) { 139 | const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin 140 | webpackConfig.plugins.push(new BundleAnalyzerPlugin()) 141 | } 142 | 143 | module.exports = webpackConfig 144 | -------------------------------------------------------------------------------- /build/webpack.test.conf.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | // This is the webpack config used for unit tests. 4 | 5 | const utils = require('./utils') 6 | const webpack = require('webpack') 7 | const merge = require('webpack-merge') 8 | const baseConfig = require('./webpack.base.conf') 9 | 10 | const webpackConfig = merge(baseConfig, { 11 | // use inline sourcemap for karma-sourcemap-loader 12 | module: { 13 | rules: utils.styleLoaders() 14 | }, 15 | devtool: '#inline-source-map', 16 | resolveLoader: { 17 | alias: { 18 | // necessary to to make lang="scss" work in test when using vue-loader's ?inject option 19 | // see discussion at https://github.com/vuejs/vue-loader/issues/724 20 | 'scss-loader': 'sass-loader' 21 | } 22 | }, 23 | plugins: [ 24 | new webpack.DefinePlugin({ 25 | 'process.env': require('../config/test.env') 26 | }) 27 | ] 28 | }) 29 | 30 | // no need for app entry during tests 31 | delete webpackConfig.entry 32 | 33 | module.exports = webpackConfig 34 | -------------------------------------------------------------------------------- /config/dev.env.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | const merge = require('webpack-merge') 4 | const prodEnv = require('./prod.env') 5 | 6 | module.exports = merge(prodEnv, { 7 | NODE_ENV: '"development"' 8 | }) 9 | -------------------------------------------------------------------------------- /config/index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | // see http://vuejs-templates.github.io/webpack for documentation. 4 | const path = require('path') 5 | 6 | module.exports = { 7 | build: { 8 | env: require('./prod.env'), 9 | index: path.resolve(__dirname, '../dist/index.html'), 10 | assetsRoot: path.resolve(__dirname, '../dist'), 11 | assetsSubDirectory: 'static', 12 | assetsPublicPath: '/', 13 | productionSourceMap: true, 14 | // Gzip off by default as many popular static hosts such as 15 | // Surge or Netlify already gzip all static assets for you. 16 | // Before setting to `true`, make sure to: 17 | // npm install --save-dev compression-webpack-plugin 18 | productionGzip: false, 19 | productionGzipExtensions: ['js', 'css'], 20 | // Run the build command with an extra argument to 21 | // View the bundle analyzer report after build finishes: 22 | // `npm run build --report` 23 | // Set to `true` or `false` to always turn it on or off 24 | bundleAnalyzerReport: process.env.npm_config_report 25 | }, 26 | dev: { 27 | env: require('./dev.env'), 28 | port: 8080, 29 | autoOpenBrowser: true, 30 | assetsSubDirectory: 'static', 31 | assetsPublicPath: '/', 32 | proxyTable: {}, 33 | // CSS Sourcemaps off by default because relative paths are "buggy" 34 | // with this option, according to the CSS-Loader README 35 | // (https://github.com/webpack/css-loader#sourcemaps) 36 | // In our experience, they generally work as expected, 37 | // just be aware of this issue when enabling this option. 38 | cssSourceMap: false 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /config/prod.env.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | NODE_ENV: '"production"' 3 | } 4 | -------------------------------------------------------------------------------- /config/test.env.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | const merge = require('webpack-merge') 4 | const devEnv = require('./dev.env') 5 | 6 | module.exports = merge(devEnv, { 7 | NODE_ENV: '"testing"' 8 | }) 9 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | CNode-V 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | <% for (var chunk of webpack.chunks) { 25 | for (var file of chunk.files) { 26 | if (file.match(/\.(js|css)$/)) { %> 27 | <% }}} %> 28 | 29 | 30 | 33 |
34 | 35 | <%= htmlWebpackPlugin.options.serviceWorkerLoader %> 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "CNode-V", 3 | "version": "0.9.4", 4 | "description": "A Vue.js project", 5 | "author": "oodzchen", 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 | "unit": "cross-env BABEL_ENV=test karma start test/unit/karma.conf.js --single-run", 12 | "test": "npm run unit", 13 | "lint": "eslint --ext .js,.vue src test/unit/specs" 14 | }, 15 | "dependencies": { 16 | "@fortawesome/fontawesome-free": "^5.6.3", 17 | "axios": "^0.18.0", 18 | "lodash": "^4.17.13", 19 | "promise-polyfill": "^8.1.0", 20 | "vue": "^2.5.2", 21 | "vue-analytics": "^5.16.1", 22 | "vue-localstorage": "^0.6.2", 23 | "vue-qrcode-reader": "^1.3.3", 24 | "vue-router": "^3.0.1", 25 | "vuetify": "^1.0.0", 26 | "vuex": "^3.0.1" 27 | }, 28 | "devDependencies": { 29 | "autoprefixer": "^7.1.5", 30 | "babel-core": "^6.26.0", 31 | "babel-eslint": "^8.0.1", 32 | "babel-loader": "^7.1.2", 33 | "babel-plugin-istanbul": "^4.1.5", 34 | "babel-plugin-transform-runtime": "^6.23.0", 35 | "babel-preset-env": "^1.6.0", 36 | "babel-preset-stage-2": "^6.24.1", 37 | "babel-register": "^6.26.0", 38 | "chai": "^4.1.2", 39 | "chalk": "^2.1.0", 40 | "connect-history-api-fallback": "^1.4.0", 41 | "copy-webpack-plugin": "^4.1.1", 42 | "cross-env": "^5.0.5", 43 | "css-loader": "^0.28.7", 44 | "cssnano": "^3.10.0", 45 | "eslint": "^4.9.0", 46 | "eslint-config-standard": "^10.2.1", 47 | "eslint-friendly-formatter": "^3.0.0", 48 | "eslint-loader": "^1.9.0", 49 | "eslint-plugin-html": "^3.2.2", 50 | "eslint-plugin-import": "^2.7.0", 51 | "eslint-plugin-node": "^5.2.0", 52 | "eslint-plugin-promise": "^3.6.0", 53 | "eslint-plugin-standard": "^3.0.1", 54 | "eventsource-polyfill": "^0.9.6", 55 | "express": "^4.16.2", 56 | "extract-text-webpack-plugin": "^3.0.0", 57 | "file-loader": "^1.1.5", 58 | "friendly-errors-webpack-plugin": "^1.6.1", 59 | "html-webpack-plugin": "^2.30.1", 60 | "http-proxy-middleware": "^0.17.4", 61 | "inject-loader": "^3.0.1", 62 | "karma": "^3.1.4", 63 | "karma-coverage": "^1.1.1", 64 | "karma-mocha": "^1.3.0", 65 | "karma-phantomjs-launcher": "^1.0.4", 66 | "karma-phantomjs-shim": "^1.5.0", 67 | "karma-sinon-chai": "^1.3.2", 68 | "karma-sourcemap-loader": "^0.3.7", 69 | "karma-spec-reporter": "0.0.31", 70 | "karma-webpack": "^2.0.5", 71 | "mocha": "^4.0.1", 72 | "opn": "^5.1.0", 73 | "optimize-css-assets-webpack-plugin": "^3.2.0", 74 | "ora": "^1.3.0", 75 | "phantomjs-prebuilt": "^2.1.15", 76 | "rimraf": "^2.6.2", 77 | "semver": "^5.4.1", 78 | "shelljs": "^0.7.8", 79 | "sinon": "^4.0.1", 80 | "sinon-chai": "^2.14.0", 81 | "stylus": "^0.54.5", 82 | "stylus-loader": "^3.0.2", 83 | "sw-precache-webpack-plugin": "^0.11.4", 84 | "uglify-es": "^3.1.3", 85 | "url-loader": "^0.6.2", 86 | "vue-loader": "^13.3.0", 87 | "vue-style-loader": "^3.0.3", 88 | "vue-template-compiler": "^2.5.2", 89 | "webpack": "^3.7.1", 90 | "webpack-bundle-analyzer": "^2.9.0", 91 | "webpack-dev-middleware": "^1.12.0", 92 | "webpack-hot-middleware": "^2.19.1", 93 | "webpack-merge": "^4.1.0" 94 | }, 95 | "engines": { 96 | "node": ">= 4.0.0", 97 | "npm": ">= 3.0.0" 98 | }, 99 | "browserslist": [ 100 | "> 1%", 101 | "last 2 versions", 102 | "not ie <= 8" 103 | ] 104 | } 105 | -------------------------------------------------------------------------------- /src/.gitrepo: -------------------------------------------------------------------------------- 1 | ; DO NOT EDIT (unless you know what you are doing) 2 | ; 3 | ; This subdirectory is a git "subrepo", and this file is maintained by the 4 | ; git-subrepo command. See https://github.com/git-commands/git-subrepo#readme 5 | ; 6 | [subrepo] 7 | remote = https://github.com/vuetifyjs/templates-common.git 8 | branch = subrepo/webpack-src 9 | commit = 090741fa8ba4da0c6f85db64eff64550704123e1 10 | parent = 4dcf7cd0218dbf2fe4a1c3b1cf56ff0f66a95276 11 | method = merge 12 | cmdver = 0.4.0 13 | -------------------------------------------------------------------------------- /src/App.vue: -------------------------------------------------------------------------------- 1 | 21 | 22 | 58 | 59 | 102 | -------------------------------------------------------------------------------- /src/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oodzchen/CNode-V/f21ad2c0a3396998fe2503dd65b8f40d4c692d00/src/assets/logo.png -------------------------------------------------------------------------------- /src/components/PageContainer.vue: -------------------------------------------------------------------------------- 1 | 75 | 76 | 91 | 92 | 159 | 160 | -------------------------------------------------------------------------------- /src/data/tabs-map.js: -------------------------------------------------------------------------------- 1 | import TABS from './tabs' 2 | let tabsMap = {} 3 | 4 | TABS.forEach(item => { 5 | tabsMap[item.category] = item.name 6 | }) 7 | export default tabsMap 8 | -------------------------------------------------------------------------------- /src/data/tabs.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "category": "all", 4 | "name": "全部" 5 | }, 6 | { 7 | "category": "good", 8 | "name": "精华" 9 | }, 10 | { 11 | "category": "share", 12 | "name": "分享" 13 | }, 14 | { 15 | "category": "ask", 16 | "name": "问答" 17 | }, 18 | { 19 | "category": "job", 20 | "name": "招聘" 21 | }, 22 | { 23 | "category": "dev", 24 | "name": "测试" 25 | } 26 | ] -------------------------------------------------------------------------------- /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 'promise-polyfill/src/polyfill' 4 | import Vue from 'vue' 5 | import App from './App' 6 | import router from './router' 7 | import '@fortawesome/fontawesome-free/css/all.css' 8 | import Vuetify from 'vuetify' 9 | import 'vuetify/dist/vuetify.min.css' 10 | import mixins from './mixins/global-mixins' 11 | import VueLocalStorage from 'vue-localstorage' 12 | import VueAnalytics from 'vue-analytics' 13 | import timeFormattor from '@/utils/time-formattor' 14 | import store from '@/store' 15 | 16 | import PageContainer from '@/components/PageContainer' 17 | 18 | Vue.use(VueLocalStorage) 19 | Vue.use(Vuetify, { 20 | iconfont: 'fa', 21 | theme: { 22 | primary: '#80BD01', 23 | secondary: '#424242', 24 | accent: '#00C853', 25 | error: '#FF5252', 26 | info: '#2196F3', 27 | success: '#4CAF50', 28 | warning: '#FFC107', 29 | dark: '#212121' 30 | } 31 | }) 32 | Vue.use(VueAnalytics, { 33 | id: 'UA-131361758-1', 34 | router, 35 | autoTracking: { 36 | page: process.env.NODE_ENV !== 'development', 37 | pageviewOnLoad: false 38 | }, 39 | debug: process.env.DEBUG ? { 40 | enabled: true, 41 | trace: false, 42 | sendHitTask: true 43 | } : false 44 | }) 45 | 46 | Vue.component('page-container', PageContainer) 47 | 48 | Vue.mixin(mixins) 49 | Vue.filter('timeFormattor', timeFormattor) 50 | 51 | Vue.config.productionTip = false 52 | 53 | /* eslint-disable no-new */ 54 | window.mainApp = new Vue({ 55 | el: '#app', 56 | store, 57 | router, 58 | components: { App }, 59 | template: '' 60 | }) 61 | -------------------------------------------------------------------------------- /src/mixins/global-mixins.js: -------------------------------------------------------------------------------- 1 | import axios from 'axios' 2 | 3 | export default { 4 | methods: { 5 | async ajax (path, options) { 6 | let config = Object.assign({ 7 | url: path, 8 | baseURL: 'https://cnodejs.org/api/v1' 9 | }, options) 10 | 11 | if (config.method && config.method.toLowerCase() === 'post') { 12 | config.headers = { 13 | 'Content-Type': 'application/x-www-form-urlencoded' 14 | } 15 | } 16 | 17 | if (config.data) { 18 | config.data = Object.keys(config.data).map(key => { 19 | return encodeURIComponent(key) + '=' + encodeURIComponent(config.data[key]) 20 | }).join('&') 21 | } 22 | 23 | if (config.showloading) { 24 | this.showPageLoading() 25 | } 26 | 27 | let response = await axios(config) 28 | .catch(e => { 29 | if (e) { 30 | let data = e.response.data 31 | if (data && data.error_msg) { 32 | this.alert('error', data.error_msg) 33 | } else { 34 | this.alert('error', '请求失败') 35 | } 36 | throw new Error(e) 37 | } 38 | }).finally((res) => { 39 | this.hidePageLoading() 40 | }) 41 | 42 | if (!response.data.success) { 43 | this.alert('error', response.data.error_msg) 44 | return null 45 | } 46 | 47 | return response.data 48 | }, 49 | alert (type, text) { 50 | this.$store.commit('CHANGE_SNACK', { 51 | show: true, 52 | type: type, 53 | text: text 54 | }) 55 | }, 56 | showPageLoading () { 57 | this.$store.commit('CHANGE_PAGELOADING', true) 58 | }, 59 | hidePageLoading () { 60 | this.$store.commit('CHANGE_PAGELOADING', false) 61 | }, 62 | getToken (callbackUrl, addHistory) { 63 | let token = this.$localStorage.get('accessToken') 64 | if (token) { 65 | return token 66 | } else { 67 | let path = `/login?redirect=${encodeURIComponent(callbackUrl)}` 68 | if (addHistory) { 69 | this.$router.push(path) 70 | } else { 71 | this.$router.replace(path) 72 | } 73 | } 74 | }, 75 | findClosestComponentByClass (className) { 76 | if (this === this.$root) return null 77 | 78 | if (this.$parent.$el.classList.contains(className)) { 79 | return this.$parent 80 | } else { 81 | return this.$parent.findClosestComponentByClass(className) 82 | } 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/pages/About.vue: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/pages/Home.vue: -------------------------------------------------------------------------------- 1 | 103 | 104 | 124 | 125 | 126 | 334 | 335 | -------------------------------------------------------------------------------- /src/pages/New.vue: -------------------------------------------------------------------------------- 1 | 41 | 42 | 46 | 47 | 48 | 144 | 145 | -------------------------------------------------------------------------------- /src/pages/NotFound.vue: -------------------------------------------------------------------------------- 1 | 19 | -------------------------------------------------------------------------------- /src/pages/Notifications.vue: -------------------------------------------------------------------------------- 1 | 45 | 46 | 51 | 52 | 53 | 116 | 117 | -------------------------------------------------------------------------------- /src/pages/Search.vue: -------------------------------------------------------------------------------- 1 | 13 | 14 | 28 | 29 | -------------------------------------------------------------------------------- /src/pages/User.vue: -------------------------------------------------------------------------------- 1 | 84 | 85 | 93 | 94 | 95 | 179 | 180 | -------------------------------------------------------------------------------- /src/pages/login/Login.vue: -------------------------------------------------------------------------------- 1 | 44 | 45 | 100 | 101 | -------------------------------------------------------------------------------- /src/pages/login/LoginCamera.vue: -------------------------------------------------------------------------------- 1 | 15 | 16 | 68 | 69 | -------------------------------------------------------------------------------- /src/pages/settings/Settings.vue: -------------------------------------------------------------------------------- 1 | 71 | 72 | 123 | 124 | -------------------------------------------------------------------------------- /src/pages/settings/SettingsTabs.vue: -------------------------------------------------------------------------------- 1 | 27 | 28 | 34 | 35 | 69 | 70 | -------------------------------------------------------------------------------- /src/pages/topic/Topic.vue: -------------------------------------------------------------------------------- 1 | 126 | 127 | 173 | 174 | 175 | 354 | 355 | -------------------------------------------------------------------------------- /src/pages/topic/TopicReply.vue: -------------------------------------------------------------------------------- 1 | 29 | 30 | 34 | 35 | 36 | 84 | 85 | -------------------------------------------------------------------------------- /src/router/index.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import Router from 'vue-router' 3 | 4 | import Home from '@/pages/Home' 5 | import Topic from '@/pages/topic/Topic' 6 | import User from '@/pages/User' 7 | import Search from '@/pages/Search' 8 | import New from '@/pages/New' 9 | import Notifications from '@/pages/Notifications' 10 | import Login from '@/pages/login/Login' 11 | import Settings from '@/pages/settings/Settings' 12 | import About from '@/pages/About' 13 | import NotFound from '@/pages/NotFound' 14 | 15 | Vue.use(Router) 16 | 17 | export default new Router({ 18 | routes: [ 19 | { 20 | path: '*', 21 | component: NotFound 22 | }, 23 | { 24 | path: '/', 25 | name: 'Home', 26 | component: Home 27 | }, 28 | { 29 | path: '/topic/:id', 30 | component: Topic, 31 | props: route => ({ 32 | id: route.params.id, 33 | reply: false 34 | }) 35 | }, 36 | { 37 | path: '/topic/:id/reply', 38 | component: Topic, 39 | props: route => ({ 40 | id: route.params.id, 41 | reply: true 42 | }) 43 | }, 44 | { 45 | path: '/topic/:id/edit', 46 | component: New, 47 | props: route => ({ 48 | id: route.params.id, 49 | isEdit: true 50 | }) 51 | }, 52 | { 53 | path: '/user/:id', 54 | component: User, 55 | props: true 56 | }, 57 | { 58 | path: '/search', 59 | component: Search 60 | }, 61 | { 62 | path: '/new', 63 | component: New 64 | }, 65 | { 66 | path: '/notifications', 67 | component: Notifications 68 | }, 69 | { 70 | path: '/login', 71 | component: Login, 72 | props: route => ({ 73 | redirect: route.query.redirect ? decodeURIComponent(route.query.redirect) : '' 74 | }) 75 | }, 76 | { 77 | path: '/login/camera', 78 | component: Login, 79 | props: { 80 | camera: true 81 | } 82 | }, 83 | { 84 | path: '/settings', 85 | component: Settings 86 | }, 87 | { 88 | path: '/settings/tabs', 89 | component: Settings, 90 | props: { 91 | chooseTabs: true 92 | } 93 | }, 94 | { 95 | path: '/about', 96 | component: About 97 | } 98 | ], 99 | scrollBehavior (to, from, savedPosition) { 100 | return { 101 | x: 0, 102 | y: 0 103 | } 104 | } 105 | }) 106 | -------------------------------------------------------------------------------- /src/store/actions.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oodzchen/CNode-V/f21ad2c0a3396998fe2503dd65b8f40d4c692d00/src/store/actions.js -------------------------------------------------------------------------------- /src/store/getters.js: -------------------------------------------------------------------------------- 1 | export default { 2 | nightMode: state => state.themeColor === 'dark', 3 | unreadTopicsMap: state => { 4 | let obj = {} 5 | 6 | state.unreadMsgs.forEach(msg => { 7 | obj[msg.topic.id] = obj[msg.topic.id] ? [...obj[msg.topic.id], msg.id] : [msg.id] 8 | }) 9 | return obj 10 | }, 11 | unreadTopicIds: (state, getter) => { 12 | return Object.keys(getter.unreadTopicsMap) 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/store/index.js: -------------------------------------------------------------------------------- 1 | import state from './state' 2 | import mutations from './mutations' 3 | import getters from './getters' 4 | import Vue from 'vue' 5 | import Vuex from 'vuex' 6 | 7 | Vue.use(Vuex) 8 | 9 | export default new Vuex.Store({ 10 | state, 11 | mutations, 12 | getters 13 | }) 14 | -------------------------------------------------------------------------------- /src/store/mutations.js: -------------------------------------------------------------------------------- 1 | export default { 2 | CHANGE_THEME (state, color) { 3 | state.themeColor = color 4 | }, 5 | CHANGE_SNACK (state, payload) { 6 | state.snack = Object.assign(state.snack, payload) 7 | }, 8 | CHANGE_PAGELOADING (state, payload) { 9 | state.pageLoading = payload 10 | }, 11 | UPDATE_MSGS (state, payload) { 12 | state.readMsgs = payload.read 13 | state.unreadMsgs = payload.unread 14 | }, 15 | READ_SINGLE_MSG (state, msgId) { 16 | let msgIndex 17 | let msgObj 18 | 19 | state.unreadMsgs.forEach((msg, index) => { 20 | if (msg.id === msgId) { 21 | msgIndex = index 22 | msgObj = msg 23 | } 24 | }) 25 | 26 | if (!msgIndex) return 27 | 28 | msgObj.has_read = true 29 | state.readMsgs.unshift(state.unreadMsgs.splice(msgIndex, 1)) 30 | }, 31 | READ_ALL_MSGS (state) { 32 | Array.from(state.unreadMsgs) 33 | .reverse() 34 | .forEach(item => { 35 | item.has_read = true 36 | state.readMsgs.unshift(item) 37 | }) 38 | state.unreadMsgs = [] 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/store/state.js: -------------------------------------------------------------------------------- 1 | export default { 2 | themeColor: 'primary', 3 | snack: { 4 | show: false, 5 | type: '', 6 | text: '', 7 | timeout: 3000 8 | }, 9 | pageLoading: false, 10 | unreadMsgs: [], 11 | readMsgs: [] 12 | } 13 | -------------------------------------------------------------------------------- /src/utils/bus.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | export default new Vue() 3 | -------------------------------------------------------------------------------- /src/utils/time-formattor.js: -------------------------------------------------------------------------------- 1 | export default function (timeStr) { 2 | let date = new Date(timeStr) 3 | let seconds = (Date.now() - date.getTime()) / 1000 4 | let text = '' 5 | 6 | if (seconds < 60) { 7 | text = '刚刚' 8 | } else if (seconds < 60 * 60) { 9 | text = Math.floor(seconds / 60) + '分钟前' 10 | } else if (seconds < 60 * 60 * 24) { 11 | text = Math.floor(seconds / (60 * 60)) + '小时前' 12 | } else if (seconds < 60 * 60 * 24 * 30) { 13 | text = Math.floor(seconds / (60 * 60 * 24)) + '天前' 14 | } else if (seconds < 60 * 60 * 24 * 30 * 12) { 15 | text = Math.floor(seconds / (60 * 60 * 24 * 30)) + '个月前' 16 | } else { 17 | text = Math.floor(seconds / (60 * 60 * 24 * 30 * 12)) + '年前' 18 | } 19 | 20 | return text 21 | } 22 | -------------------------------------------------------------------------------- /static/img/icons/android-chrome-192x192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oodzchen/CNode-V/f21ad2c0a3396998fe2503dd65b8f40d4c692d00/static/img/icons/android-chrome-192x192.png -------------------------------------------------------------------------------- /static/img/icons/android-chrome-512x512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oodzchen/CNode-V/f21ad2c0a3396998fe2503dd65b8f40d4c692d00/static/img/icons/android-chrome-512x512.png -------------------------------------------------------------------------------- /static/img/icons/apple-touch-icon-120x120.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oodzchen/CNode-V/f21ad2c0a3396998fe2503dd65b8f40d4c692d00/static/img/icons/apple-touch-icon-120x120.png -------------------------------------------------------------------------------- /static/img/icons/apple-touch-icon-152x152.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oodzchen/CNode-V/f21ad2c0a3396998fe2503dd65b8f40d4c692d00/static/img/icons/apple-touch-icon-152x152.png -------------------------------------------------------------------------------- /static/img/icons/apple-touch-icon-180x180.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oodzchen/CNode-V/f21ad2c0a3396998fe2503dd65b8f40d4c692d00/static/img/icons/apple-touch-icon-180x180.png -------------------------------------------------------------------------------- /static/img/icons/apple-touch-icon-60x60.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oodzchen/CNode-V/f21ad2c0a3396998fe2503dd65b8f40d4c692d00/static/img/icons/apple-touch-icon-60x60.png -------------------------------------------------------------------------------- /static/img/icons/apple-touch-icon-76x76.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oodzchen/CNode-V/f21ad2c0a3396998fe2503dd65b8f40d4c692d00/static/img/icons/apple-touch-icon-76x76.png -------------------------------------------------------------------------------- /static/img/icons/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oodzchen/CNode-V/f21ad2c0a3396998fe2503dd65b8f40d4c692d00/static/img/icons/apple-touch-icon.png -------------------------------------------------------------------------------- /static/img/icons/favicon-16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oodzchen/CNode-V/f21ad2c0a3396998fe2503dd65b8f40d4c692d00/static/img/icons/favicon-16x16.png -------------------------------------------------------------------------------- /static/img/icons/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oodzchen/CNode-V/f21ad2c0a3396998fe2503dd65b8f40d4c692d00/static/img/icons/favicon-32x32.png -------------------------------------------------------------------------------- /static/img/icons/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oodzchen/CNode-V/f21ad2c0a3396998fe2503dd65b8f40d4c692d00/static/img/icons/favicon.ico -------------------------------------------------------------------------------- /static/img/icons/msapplication-icon-144x144.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oodzchen/CNode-V/f21ad2c0a3396998fe2503dd65b8f40d4c692d00/static/img/icons/msapplication-icon-144x144.png -------------------------------------------------------------------------------- /static/img/icons/mstile-150x150.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oodzchen/CNode-V/f21ad2c0a3396998fe2503dd65b8f40d4c692d00/static/img/icons/mstile-150x150.png -------------------------------------------------------------------------------- /static/img/icons/safari-pinned-tab.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Layer 1 6 | 7 | 8 | -------------------------------------------------------------------------------- /static/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "CNode-V", 3 | "short_name": "CNode-V", 4 | "icons": [ 5 | { 6 | "src": "/static/img/icons/android-chrome-192x192.png", 7 | "sizes": "192x192", 8 | "type": "image/png" 9 | }, 10 | { 11 | "src": "/static/img/icons/android-chrome-512x512.png", 12 | "sizes": "512x512", 13 | "type": "image/png" 14 | } 15 | ], 16 | "start_url": "/index.html", 17 | "scope": "/", 18 | "display": "standalone", 19 | "background_color": "#FFFFFF", 20 | "theme_color": "#80BD01" 21 | } 22 | -------------------------------------------------------------------------------- /test/unit/.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "mocha": true 4 | }, 5 | "globals": { 6 | "expect": true, 7 | "sinon": true 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /test/unit/index.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | 3 | Vue.config.productionTip = false 4 | 5 | // require all test files (files that ends with .spec.js) 6 | const testsContext = require.context('./specs', true, /\.spec$/) 7 | testsContext.keys().forEach(testsContext) 8 | 9 | // require all src files except main.js for coverage. 10 | // you can also change this to match only the subset of files that 11 | // you want coverage for. 12 | const srcContext = require.context('../../src', true, /^\.\/(?!main(\.js)?$)/) 13 | srcContext.keys().forEach(srcContext) 14 | -------------------------------------------------------------------------------- /test/unit/karma.conf.js: -------------------------------------------------------------------------------- 1 | // This is a karma config file. For more details see 2 | // http://karma-runner.github.io/0.13/config/configuration-file.html 3 | // we are also using it with karma-webpack 4 | // https://github.com/webpack/karma-webpack 5 | 6 | var webpackConfig = require('../../build/webpack.test.conf') 7 | 8 | module.exports = function (config) { 9 | config.set({ 10 | // to run in additional browsers: 11 | // 1. install corresponding karma launcher 12 | // http://karma-runner.github.io/0.13/config/browsers.html 13 | // 2. add it to the `browsers` array below. 14 | browsers: ['PhantomJS'], 15 | frameworks: ['mocha', 'sinon-chai', 'phantomjs-shim'], 16 | reporters: ['spec', 'coverage'], 17 | files: ['./index.js'], 18 | preprocessors: { 19 | './index.js': ['webpack', 'sourcemap'] 20 | }, 21 | webpack: webpackConfig, 22 | webpackMiddleware: { 23 | noInfo: true 24 | }, 25 | coverageReporter: { 26 | dir: './coverage', 27 | reporters: [ 28 | { type: 'lcov', subdir: '.' }, 29 | { type: 'text-summary' } 30 | ] 31 | } 32 | }) 33 | } 34 | -------------------------------------------------------------------------------- /test/unit/specs/Hello.spec.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import Hello from '@/components/Hello' 3 | 4 | describe('Hello.vue', () => { 5 | it('should render correct contents', () => { 6 | const Constructor = Vue.extend(Hello) 7 | const vm = new Constructor().$mount() 8 | expect(vm.$el.querySelector('.hello h1').textContent) 9 | .to.equal('Welcome to Your Vue.js PWA') 10 | }) 11 | }) 12 | --------------------------------------------------------------------------------