├── .babelrc ├── .editorconfig ├── .eslintignore ├── .eslintrc.js ├── .gitignore ├── .postcssrc.js ├── README.md ├── build ├── build.js ├── check-versions.js ├── logo.png ├── 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 ├── assets │ └── css │ │ ├── addCon.css │ │ ├── app.css │ │ ├── login.css │ │ ├── mailList.css │ │ ├── notes.css │ │ └── own.css ├── components │ ├── addCon.vue │ ├── app.vue │ ├── global.vue │ ├── login.vue │ ├── mailList.vue │ ├── noteItem.vue │ ├── notes.vue │ ├── own.vue │ ├── ownItem.vue │ └── register.vue ├── main.js ├── router │ └── index.js └── store │ ├── modules │ ├── contacts.js │ └── user.js │ └── vuex.js └── static ├── .gitkeep └── img ├── 1.jpg ├── bg.png ├── contact.jpg ├── logo.png ├── mailList.gif └── userImg.png /.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-vue-jsx", "transform-runtime"] 12 | } 13 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | // https://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/standard/standard/blob/master/docs/RULES-en.md 13 | extends: 'standard', 14 | // required to lint *.vue files 15 | plugins: [ 16 | 'html' 17 | ], 18 | // add your custom rules here 19 | rules: { 20 | // allow async-await 21 | 'generator-star-spacing': 'off', 22 | // allow debugger during development 23 | 'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off' 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /.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 | .vscode 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 "browserslist" field in package.json 6 | "postcss-import": {}, 7 | "autoprefixer": {} 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # mail list 2 | 3 | ## 前言 4 | > 最近在学习vue,就写了一个简易的SPA通讯录项目,该项目用了 5 | > - vue 6 | > - vue-router 7 | > - vuex 8 | > - axios 9 | > - localStorage 10 | > - sessionStorage 11 | > 12 | > 写这个项目之前我用vue写过很多小的页面部件,比如选项卡、路由跳转之类的,但毕竟这些涉及的知识是零散的,当系统的学习了之后我就想做一个整体性的项目,一方面巩固知识一方面打通经脉,所以就写了这个通讯录。 13 | > 14 | > 目前这个通讯录支持多用户注册,后期还可以用node写一个后台与之交互,我也会一直维护,完善以及优化项目,也会根据需求增添个别功能,学vue的朋友也可以clone下来练练手。 15 | > 16 | >从零出发完成一个SPA。 17 | 18 | 19 | ## 动图展示 20 | ![](https://github.com/windlany/mail_list/blob/master/static/img/mailList.gif) 21 | 22 | ## 运行项目 23 | ```bash 24 | # clone项目到本地 25 | git clone https://github.com/windlany/mail_list.git 26 | 27 | # 安装项目依赖 28 | npm install 29 | 30 | # 将项目部署在localhost:8080,运行一下命令打开浏览器的localhost:8080查看 31 | npm run dev 32 | ``` 33 | 34 | #### 2017.12.21 35 | - vue 36 | - vue-router 37 | - localStorage 38 | - axios 39 | 40 | #### 2017.12.23 41 | - 登录注册界面vuex 42 | - localStorae 43 | - axios 44 | - sessionStorage缓存用户信息以及已登录用户信息 45 | - 仅支持单用户注册 46 | 47 | #### 2017.12.24 48 | - 完善登录注册界面的vuex 49 | - localStorage缓存用户信息,sessionStorage缓存当前登录用户信息 50 | - 支持多用户注册 51 | 52 | #### 2018.1.12 53 | - 添加导航守卫 -------------------------------------------------------------------------------- /build/build.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | require('./check-versions')() 3 | 4 | process.env.NODE_ENV = 'production' 5 | 6 | const ora = require('ora') 7 | const rm = require('rimraf') 8 | const path = require('path') 9 | const chalk = require('chalk') 10 | const webpack = require('webpack') 11 | const config = require('../config') 12 | const webpackConfig = require('./webpack.prod.conf') 13 | 14 | const spinner = ora('building for production...') 15 | spinner.start() 16 | 17 | rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => { 18 | if (err) throw err 19 | webpack(webpackConfig, (err, stats) => { 20 | spinner.stop() 21 | if (err) throw err 22 | process.stdout.write(stats.toString({ 23 | colors: true, 24 | modules: false, 25 | children: false, // if you are using ts-loader, setting this to true will make tyescript errors show up during build 26 | chunks: false, 27 | chunkModules: false 28 | }) + '\n\n') 29 | 30 | if (stats.hasErrors()) { 31 | console.log(chalk.red(' Build failed with errors.\n')) 32 | process.exit(1) 33 | } 34 | 35 | console.log(chalk.cyan(' Build complete.\n')) 36 | console.log(chalk.yellow( 37 | ' Tip: built files are meant to be served over an HTTP server.\n' + 38 | ' Opening index.html over file:// won\'t work.\n' 39 | )) 40 | }) 41 | }) 42 | -------------------------------------------------------------------------------- /build/check-versions.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | const chalk = require('chalk') 3 | const semver = require('semver') 4 | const packageConfig = require('../package.json') 5 | const shell = require('shelljs') 6 | 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 | 30 | for (let i = 0; i < versionRequirements.length; i++) { 31 | const mod = versionRequirements[i] 32 | 33 | if (!semver.satisfies(mod.currentVersion, mod.versionRequirement)) { 34 | warnings.push(mod.name + ': ' + 35 | chalk.red(mod.currentVersion) + ' should be ' + 36 | chalk.green(mod.versionRequirement) 37 | ) 38 | } 39 | } 40 | 41 | if (warnings.length) { 42 | console.log('') 43 | console.log(chalk.yellow('To use this template, you must update following to modules:')) 44 | console.log() 45 | 46 | for (let i = 0; i < warnings.length; i++) { 47 | const warning = warnings[i] 48 | console.log(' ' + warning) 49 | } 50 | 51 | console.log() 52 | process.exit(1) 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /build/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/windlany/vue-mail-list/3122734319a9a725fce0d9fc77e815c158834728/build/logo.png -------------------------------------------------------------------------------- /build/utils.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | const path = require('path') 3 | const config = require('../config') 4 | const ExtractTextPlugin = require('extract-text-webpack-plugin') 5 | const packageConfig = require('../package.json') 6 | 7 | exports.assetsPath = function (_path) { 8 | const assetsSubDirectory = process.env.NODE_ENV === 'production' 9 | ? config.build.assetsSubDirectory 10 | : config.dev.assetsSubDirectory 11 | 12 | return path.posix.join(assetsSubDirectory, _path) 13 | } 14 | 15 | exports.cssLoaders = function (options) { 16 | options = options || {} 17 | 18 | const cssLoader = { 19 | loader: 'css-loader', 20 | options: { 21 | sourceMap: options.sourceMap 22 | } 23 | } 24 | 25 | const postcssLoader = { 26 | loader: 'postcss-loader', 27 | options: { 28 | sourceMap: options.sourceMap 29 | } 30 | } 31 | 32 | // generate loader string to be used with extract text plugin 33 | function generateLoaders (loader, loaderOptions) { 34 | const loaders = options.usePostCSS ? [cssLoader, postcssLoader] : [cssLoader] 35 | 36 | if (loader) { 37 | loaders.push({ 38 | loader: loader + '-loader', 39 | options: Object.assign({}, loaderOptions, { 40 | sourceMap: options.sourceMap 41 | }) 42 | }) 43 | } 44 | 45 | // Extract CSS when that option is specified 46 | // (which is the case during production build) 47 | if (options.extract) { 48 | return ExtractTextPlugin.extract({ 49 | use: loaders, 50 | fallback: 'vue-style-loader' 51 | }) 52 | } else { 53 | return ['vue-style-loader'].concat(loaders) 54 | } 55 | } 56 | 57 | // https://vue-loader.vuejs.org/en/configurations/extract-css.html 58 | return { 59 | css: generateLoaders(), 60 | postcss: generateLoaders(), 61 | less: generateLoaders('less'), 62 | sass: generateLoaders('sass', { indentedSyntax: true }), 63 | scss: generateLoaders('sass'), 64 | stylus: generateLoaders('stylus'), 65 | styl: generateLoaders('stylus') 66 | } 67 | } 68 | 69 | // Generate loaders for standalone style files (outside of .vue) 70 | exports.styleLoaders = function (options) { 71 | const output = [] 72 | const loaders = exports.cssLoaders(options) 73 | 74 | for (const extension in loaders) { 75 | const loader = loaders[extension] 76 | output.push({ 77 | test: new RegExp('\\.' + extension + '$'), 78 | use: loader 79 | }) 80 | } 81 | 82 | return output 83 | } 84 | 85 | exports.createNotifierCallback = () => { 86 | const notifier = require('node-notifier') 87 | 88 | return (severity, errors) => { 89 | if (severity !== 'error') return 90 | 91 | const error = errors[0] 92 | const filename = error.file && error.file.split('!').pop() 93 | 94 | notifier.notify({ 95 | title: packageConfig.name, 96 | message: severity + ': ' + error.name, 97 | subtitle: filename || '', 98 | icon: path.join(__dirname, 'logo.png') 99 | }) 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /build/vue-loader.conf.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | const utils = require('./utils') 3 | const config = require('../config') 4 | const isProduction = process.env.NODE_ENV === 'production' 5 | const sourceMapEnabled = isProduction 6 | ? config.build.productionSourceMap 7 | : config.dev.cssSourceMap 8 | 9 | module.exports = { 10 | loaders: utils.cssLoaders({ 11 | sourceMap: sourceMapEnabled, 12 | extract: isProduction 13 | }), 14 | cssSourceMap: sourceMapEnabled, 15 | cacheBusting: config.dev.cacheBusting, 16 | transformToRequire: { 17 | video: ['src', 'poster'], 18 | source: 'src', 19 | img: 'src', 20 | image: 'xlink:href' 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /build/webpack.base.conf.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | const path = require('path') 3 | const utils = require('./utils') 4 | const config = require('../config') 5 | const vueLoaderConfig = require('./vue-loader.conf') 6 | 7 | function resolve (dir) { 8 | return path.join(__dirname, '..', dir) 9 | } 10 | 11 | const createLintingRule = () => ({ 12 | test: /\.(js|vue)$/, 13 | loader: 'eslint-loader', 14 | enforce: 'pre', 15 | include: [resolve('src'), resolve('test')], 16 | options: { 17 | formatter: require('eslint-friendly-formatter'), 18 | emitWarning: !config.dev.showEslintErrorsInOverlay 19 | } 20 | }) 21 | 22 | module.exports = { 23 | context: path.resolve(__dirname, '../'), 24 | entry: { 25 | app: './src/main.js' 26 | }, 27 | output: { 28 | path: config.build.assetsRoot, 29 | filename: '[name].js', 30 | publicPath: process.env.NODE_ENV === 'production' 31 | ? config.build.assetsPublicPath 32 | : config.dev.assetsPublicPath 33 | }, 34 | resolve: { 35 | extensions: ['.js', '.vue', '.json'], 36 | alias: { 37 | 'vue$': 'vue/dist/vue.esm.js', 38 | '@': resolve('src'), 39 | } 40 | }, 41 | module: { 42 | rules: [ 43 | // ...(config.dev.useEslint ? [createLintingRule()] : []), 44 | { 45 | test: /\.vue$/, 46 | loader: 'vue-loader', 47 | options: vueLoaderConfig 48 | }, 49 | { 50 | test: /\.js$/, 51 | loader: 'babel-loader', 52 | include: [resolve('src'), resolve('test')] 53 | }, 54 | { 55 | test: /\.(png|jpe?g|gif|svg)(\?.*)?$/, 56 | loader: 'url-loader', 57 | options: { 58 | limit: 10000, 59 | name: utils.assetsPath('img/[name].[hash:7].[ext]') 60 | } 61 | }, 62 | { 63 | test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/, 64 | loader: 'url-loader', 65 | options: { 66 | limit: 10000, 67 | name: utils.assetsPath('media/[name].[hash:7].[ext]') 68 | } 69 | }, 70 | { 71 | test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/, 72 | loader: 'url-loader', 73 | options: { 74 | limit: 10000, 75 | name: utils.assetsPath('fonts/[name].[hash:7].[ext]') 76 | } 77 | } 78 | ] 79 | }, 80 | node: { 81 | // prevent webpack from injecting useless setImmediate polyfill because Vue 82 | // source contains it (although only uses it if it's native). 83 | setImmediate: false, 84 | // prevent webpack from injecting mocks to Node native modules 85 | // that does not make sense for the client 86 | dgram: 'empty', 87 | fs: 'empty', 88 | net: 'empty', 89 | tls: 'empty', 90 | child_process: 'empty' 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /build/webpack.dev.conf.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | const utils = require('./utils') 3 | const webpack = require('webpack') 4 | const config = require('../config') 5 | const merge = require('webpack-merge') 6 | const baseWebpackConfig = require('./webpack.base.conf') 7 | const HtmlWebpackPlugin = require('html-webpack-plugin') 8 | const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin') 9 | const portfinder = require('portfinder') 10 | 11 | const HOST = process.env.HOST 12 | const PORT = process.env.PORT && Number(process.env.PORT) 13 | 14 | const devWebpackConfig = merge(baseWebpackConfig, { 15 | module: { 16 | rules: utils.styleLoaders({ sourceMap: config.dev.cssSourceMap, usePostCSS: true }) 17 | }, 18 | // cheap-module-eval-source-map is faster for development 19 | devtool: config.dev.devtool, 20 | 21 | // these devServer options should be customized in /config/index.js 22 | devServer: { 23 | clientLogLevel: 'warning', 24 | historyApiFallback: true, 25 | hot: true, 26 | compress: true, 27 | host: HOST || config.dev.host, 28 | port: PORT || config.dev.port, 29 | open: config.dev.autoOpenBrowser, 30 | overlay: config.dev.errorOverlay 31 | ? { warnings: false, errors: true } 32 | : false, 33 | publicPath: config.dev.assetsPublicPath, 34 | proxy: config.dev.proxyTable, 35 | quiet: true, // necessary for FriendlyErrorsPlugin 36 | watchOptions: { 37 | poll: config.dev.poll, 38 | } 39 | }, 40 | plugins: [ 41 | new webpack.DefinePlugin({ 42 | 'process.env': require('../config/dev.env') 43 | }), 44 | new webpack.HotModuleReplacementPlugin(), 45 | new webpack.NamedModulesPlugin(), // HMR shows correct file names in console on update. 46 | new webpack.NoEmitOnErrorsPlugin(), 47 | // https://github.com/ampedandwired/html-webpack-plugin 48 | new HtmlWebpackPlugin({ 49 | filename: 'index.html', 50 | template: 'index.html', 51 | inject: true 52 | }), 53 | ] 54 | }) 55 | 56 | module.exports = new Promise((resolve, reject) => { 57 | portfinder.basePort = process.env.PORT || config.dev.port 58 | portfinder.getPort((err, port) => { 59 | if (err) { 60 | reject(err) 61 | } else { 62 | // publish the new Port, necessary for e2e tests 63 | process.env.PORT = port 64 | // add port to devServer config 65 | devWebpackConfig.devServer.port = port 66 | 67 | // Add FriendlyErrorsPlugin 68 | devWebpackConfig.plugins.push(new FriendlyErrorsPlugin({ 69 | compilationSuccessInfo: { 70 | messages: [`Your application is running here: http://${devWebpackConfig.devServer.host}:${port}`], 71 | }, 72 | onErrors: config.dev.notifyOnErrors 73 | ? utils.createNotifierCallback() 74 | : undefined 75 | })) 76 | 77 | resolve(devWebpackConfig) 78 | } 79 | }) 80 | }) 81 | -------------------------------------------------------------------------------- /build/webpack.prod.conf.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | const path = require('path') 3 | const utils = require('./utils') 4 | const webpack = require('webpack') 5 | const config = require('../config') 6 | const merge = require('webpack-merge') 7 | const baseWebpackConfig = require('./webpack.base.conf') 8 | const CopyWebpackPlugin = require('copy-webpack-plugin') 9 | const HtmlWebpackPlugin = require('html-webpack-plugin') 10 | const ExtractTextPlugin = require('extract-text-webpack-plugin') 11 | const OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin') 12 | const UglifyJsPlugin = require('uglifyjs-webpack-plugin') 13 | 14 | const env = require('../config/prod.env') 15 | 16 | const webpackConfig = merge(baseWebpackConfig, { 17 | module: { 18 | rules: utils.styleLoaders({ 19 | sourceMap: config.build.productionSourceMap, 20 | extract: true, 21 | usePostCSS: true 22 | }) 23 | }, 24 | devtool: config.build.productionSourceMap ? config.build.devtool : false, 25 | output: { 26 | path: config.build.assetsRoot, 27 | filename: utils.assetsPath('js/[name].[chunkhash].js'), 28 | chunkFilename: utils.assetsPath('js/[id].[chunkhash].js') 29 | }, 30 | plugins: [ 31 | // http://vuejs.github.io/vue-loader/en/workflow/production.html 32 | new webpack.DefinePlugin({ 33 | 'process.env': env 34 | }), 35 | new UglifyJsPlugin({ 36 | uglifyOptions: { 37 | compress: { 38 | warnings: false 39 | } 40 | }, 41 | sourceMap: config.build.productionSourceMap, 42 | parallel: true 43 | }), 44 | // extract css into its own file 45 | new ExtractTextPlugin({ 46 | filename: utils.assetsPath('css/[name].[contenthash].css'), 47 | // Setting the following option to `false` will not extract CSS from codesplit chunks. 48 | // Their CSS will instead be inserted dynamically with style-loader when the codesplit chunk has been loaded by webpack. 49 | // It's currently set to `true` because we are seeing that sourcemaps are included in the codesplit bundle as well when it's `false`, 50 | // increasing file size: https://github.com/vuejs-templates/webpack/issues/1110 51 | allChunks: true, 52 | }), 53 | // Compress extracted CSS. We are using this plugin so that possible 54 | // duplicated CSS from different components can be deduped. 55 | new OptimizeCSSPlugin({ 56 | cssProcessorOptions: config.build.productionSourceMap 57 | ? { safe: true, map: { inline: false } } 58 | : { safe: true } 59 | }), 60 | // generate dist index.html with correct asset hash for caching. 61 | // you can customize output by editing /index.html 62 | // see https://github.com/ampedandwired/html-webpack-plugin 63 | new HtmlWebpackPlugin({ 64 | filename: config.build.index, 65 | template: 'index.html', 66 | inject: true, 67 | minify: { 68 | removeComments: true, 69 | collapseWhitespace: true, 70 | removeAttributeQuotes: true 71 | // more options: 72 | // https://github.com/kangax/html-minifier#options-quick-reference 73 | }, 74 | // necessary to consistently work with multiple chunks via CommonsChunkPlugin 75 | chunksSortMode: 'dependency' 76 | }), 77 | // keep module.id stable when vender modules does not change 78 | new webpack.HashedModuleIdsPlugin(), 79 | // enable scope hoisting 80 | new webpack.optimize.ModuleConcatenationPlugin(), 81 | // split vendor js into its own file 82 | new webpack.optimize.CommonsChunkPlugin({ 83 | name: 'vendor', 84 | minChunks (module) { 85 | // any required modules inside node_modules are extracted to vendor 86 | return ( 87 | module.resource && 88 | /\.js$/.test(module.resource) && 89 | module.resource.indexOf( 90 | path.join(__dirname, '../node_modules') 91 | ) === 0 92 | ) 93 | } 94 | }), 95 | // extract webpack runtime and module manifest to its own file in order to 96 | // prevent vendor hash from being updated whenever app bundle is updated 97 | new webpack.optimize.CommonsChunkPlugin({ 98 | name: 'manifest', 99 | minChunks: Infinity 100 | }), 101 | // This instance extracts shared chunks from code splitted chunks and bundles them 102 | // in a separate chunk, similar to the vendor chunk 103 | // see: https://webpack.js.org/plugins/commons-chunk-plugin/#extra-async-commons-chunk 104 | new webpack.optimize.CommonsChunkPlugin({ 105 | name: 'app', 106 | async: 'vendor-async', 107 | children: true, 108 | minChunks: 3 109 | }), 110 | 111 | // copy custom static assets 112 | new CopyWebpackPlugin([ 113 | { 114 | from: path.resolve(__dirname, '../static'), 115 | to: config.build.assetsSubDirectory, 116 | ignore: ['.*'] 117 | } 118 | ]) 119 | ] 120 | }) 121 | 122 | if (config.build.productionGzip) { 123 | const CompressionWebpackPlugin = require('compression-webpack-plugin') 124 | 125 | webpackConfig.plugins.push( 126 | new CompressionWebpackPlugin({ 127 | asset: '[path].gz[query]', 128 | algorithm: 'gzip', 129 | test: new RegExp( 130 | '\\.(' + 131 | config.build.productionGzipExtensions.join('|') + 132 | ')$' 133 | ), 134 | threshold: 10240, 135 | minRatio: 0.8 136 | }) 137 | ) 138 | } 139 | 140 | if (config.build.bundleAnalyzerReport) { 141 | const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin 142 | webpackConfig.plugins.push(new BundleAnalyzerPlugin()) 143 | } 144 | 145 | module.exports = webpackConfig 146 | -------------------------------------------------------------------------------- /config/dev.env.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | const merge = require('webpack-merge') 3 | const prodEnv = require('./prod.env') 4 | 5 | module.exports = merge(prodEnv, { 6 | NODE_ENV: '"development"' 7 | }) 8 | -------------------------------------------------------------------------------- /config/index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | // Template version: 1.2.7 3 | // see http://vuejs-templates.github.io/webpack for documentation. 4 | 5 | const path = require('path') 6 | 7 | module.exports = { 8 | dev: { 9 | 10 | // Paths 11 | assetsSubDirectory: 'static', 12 | assetsPublicPath: '/', 13 | proxyTable: {}, 14 | 15 | // Various Dev Server settings 16 | host: 'localhost', // can be overwritten by process.env.HOST 17 | port: 8080, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined 18 | autoOpenBrowser: false, 19 | errorOverlay: true, 20 | notifyOnErrors: true, 21 | poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions- 22 | 23 | // Use Eslint Loader? 24 | // If true, your code will be linted during bundling and 25 | // linting errors and warnings will be shown in the console. 26 | useEslint: true, 27 | // If true, eslint errors and warnings will also be shown in the error overlay 28 | // in the browser. 29 | showEslintErrorsInOverlay: false, 30 | 31 | /** 32 | * Source Maps 33 | */ 34 | 35 | // https://webpack.js.org/configuration/devtool/#development 36 | devtool: 'eval-source-map', 37 | 38 | // If you have problems debugging vue-files in devtools, 39 | // set this to false - it *may* help 40 | // https://vue-loader.vuejs.org/en/options.html#cachebusting 41 | cacheBusting: true, 42 | 43 | // CSS Sourcemaps off by default because relative paths are "buggy" 44 | // with this option, according to the CSS-Loader README 45 | // (https://github.com/webpack/css-loader#sourcemaps) 46 | // In our experience, they generally work as expected, 47 | // just be aware of this issue when enabling this option. 48 | cssSourceMap: false, 49 | }, 50 | 51 | build: { 52 | // Template for index.html 53 | index: path.resolve(__dirname, '../dist/index.html'), 54 | 55 | // Paths 56 | assetsRoot: path.resolve(__dirname, '../dist'), 57 | assetsSubDirectory: 'static', 58 | assetsPublicPath: '/', 59 | 60 | /** 61 | * Source Maps 62 | */ 63 | 64 | productionSourceMap: true, 65 | // https://webpack.js.org/configuration/devtool/#production 66 | devtool: '#source-map', 67 | 68 | // Gzip off by default as many popular static hosts such as 69 | // Surge or Netlify already gzip all static assets for you. 70 | // Before setting to `true`, make sure to: 71 | // npm install --save-dev compression-webpack-plugin 72 | productionGzip: false, 73 | productionGzipExtensions: ['js', 'css'], 74 | 75 | // Run the build command with an extra argument to 76 | // View the bundle analyzer report after build finishes: 77 | // `npm run build --report` 78 | // Set to `true` or `false` to always turn it on or off 79 | bundleAnalyzerReport: process.env.npm_config_report 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /config/prod.env.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | module.exports = { 3 | NODE_ENV: '"production"' 4 | } 5 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | concats 7 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "concats", 3 | "version": "1.0.0", 4 | "description": "a concats book", 5 | "author": "lan <17713476019@163.com>", 6 | "private": true, 7 | "scripts": { 8 | "dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js", 9 | "start": "npm run dev", 10 | "lint": "eslint --ext .js,.vue src", 11 | "build": "node build/build.js" 12 | }, 13 | "dependencies": { 14 | "axios": "^0.17.1", 15 | "qs": "^6.5.1", 16 | "vue": "^2.5.2", 17 | "vue-router": "^3.0.1", 18 | "vuex": "^3.0.1" 19 | }, 20 | "devDependencies": { 21 | "autoprefixer": "^7.1.2", 22 | "babel-core": "^6.22.1", 23 | "babel-eslint": "^7.1.1", 24 | "babel-helper-vue-jsx-merge-props": "^2.0.3", 25 | "babel-loader": "^7.1.1", 26 | "babel-plugin-syntax-jsx": "^6.18.0", 27 | "babel-plugin-transform-runtime": "^6.22.0", 28 | "babel-plugin-transform-vue-jsx": "^3.5.0", 29 | "babel-preset-env": "^1.3.2", 30 | "babel-preset-stage-2": "^6.22.0", 31 | "chalk": "^2.0.1", 32 | "copy-webpack-plugin": "^4.0.1", 33 | "css-loader": "^0.28.0", 34 | "eslint": "^3.19.0", 35 | "eslint-config-standard": "^10.2.1", 36 | "eslint-friendly-formatter": "^3.0.0", 37 | "eslint-loader": "^1.7.1", 38 | "eslint-plugin-html": "^3.0.0", 39 | "eslint-plugin-import": "^2.7.0", 40 | "eslint-plugin-node": "^5.2.0", 41 | "eslint-plugin-promise": "^3.4.0", 42 | "eslint-plugin-standard": "^3.0.1", 43 | "extract-text-webpack-plugin": "^3.0.0", 44 | "file-loader": "^1.1.4", 45 | "friendly-errors-webpack-plugin": "^1.6.1", 46 | "html-webpack-plugin": "^2.30.1", 47 | "node-notifier": "^5.1.2", 48 | "optimize-css-assets-webpack-plugin": "^3.2.0", 49 | "ora": "^1.2.0", 50 | "portfinder": "^1.0.13", 51 | "postcss-import": "^11.0.0", 52 | "postcss-loader": "^2.0.8", 53 | "rimraf": "^2.6.0", 54 | "semver": "^5.3.0", 55 | "shelljs": "^0.7.6", 56 | "uglifyjs-webpack-plugin": "^1.1.1", 57 | "url-loader": "^0.5.8", 58 | "vue-loader": "^13.3.0", 59 | "vue-style-loader": "^3.0.1", 60 | "vue-template-compiler": "^2.5.2", 61 | "webpack": "^3.6.0", 62 | "webpack-bundle-analyzer": "^2.9.0", 63 | "webpack-dev-server": "^2.9.1", 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 | 6 | -------------------------------------------------------------------------------- /src/assets/css/addCon.css: -------------------------------------------------------------------------------- 1 | .rside h2 { 2 | width: 84%; 3 | text-align: center; 4 | padding: 20px; 5 | margin-top: 138px; 6 | font-size: 38px; 7 | font-family: "幼圆"; 8 | } 9 | .form { 10 | width: 82%; 11 | padding-top: 20px; 12 | } 13 | .form label { 14 | display: block; 15 | width: 770px; 16 | height: 42px; 17 | margin-left: 256px; 18 | margin-bottom: 15px; 19 | } 20 | .form span { 21 | display: inline-block; 22 | width: 87px; 23 | font-size: 16px; 24 | text-align: right; 25 | margin-right: 10px; 26 | } 27 | .form input { 28 | width: 300px; 29 | height: 40px; 30 | padding-left: 10px; 31 | box-sizing: border-box; 32 | font-size: 16px; 33 | border-radius: 5px; 34 | border: 1px solid #ccc; 35 | background-color: #fff; 36 | } 37 | .form select { 38 | height: 35px; 39 | width: 150px; 40 | border: 1px solid #ccc; 41 | padding-left: 10px; 42 | box-sizing: border-box; 43 | } 44 | .form select:focus, .form button:focus { 45 | outline: none; 46 | } 47 | .form button.nomal { 48 | width: 150px; 49 | border: none; 50 | height: 40px; 51 | font-size: 18px; 52 | border-radius: 5px; 53 | cursor: pointer; 54 | background-color: #0f88eb; 55 | color: #fff; 56 | } 57 | .form button.btn { 58 | background-color: #ccc; 59 | } 60 | input.error { 61 | border: 2px solid #ff0000; 62 | } 63 | em { 64 | color: rgb(255, 0, 0); 65 | } -------------------------------------------------------------------------------- /src/assets/css/app.css: -------------------------------------------------------------------------------- 1 | html { 2 | font-size: 10px; 3 | } 4 | li { 5 | list-style: none; 6 | } 7 | html, body, #contain { 8 | height: 100vh; 9 | margin: 0; 10 | } 11 | body { 12 | color: #555; 13 | font-family: 'Helvetica Neue',Helvetica,'PingFang SC','Hiragino Sans GB','Microsoft YaHei',Arial,sans-serif; 14 | background-color: #f7fafc; 15 | } 16 | #contain { 17 | width: 100%; 18 | text-align: center; 19 | padding-top: 92px; 20 | box-sizing: border-box; 21 | background-image: url(/static/img/bg.png); 22 | background-size: cover; 23 | } 24 | #contain h1 { 25 | color: #0f88eb; 26 | font-weight: 500; 27 | text-align: center; 28 | font-size: 70px; 29 | } 30 | #contain h2 { 31 | margin-top: 30px; 32 | margin-bottom: 20px; 33 | font-weight: 400; 34 | font-size: 18px; 35 | line-height: 1; 36 | text-align: center; 37 | } 38 | #contain .btns { 39 | font-size: 18px; 40 | text-align: center; 41 | margin-bottom: 25px; 42 | box-sizing: border-box; 43 | } 44 | a { 45 | color: #555; 46 | text-decoration: none; 47 | opacity: .7; 48 | font-weight: 500; 49 | } 50 | #contain .btn { 51 | margin-right: 20px; 52 | } 53 | .router-link-active { 54 | color: #0f88eb; 55 | opacity: 1; 56 | border-bottom: 2px solid; 57 | padding-bottom: 5px; 58 | } -------------------------------------------------------------------------------- /src/assets/css/login.css: -------------------------------------------------------------------------------- 1 | .login { 2 | width: 994px; 3 | margin: 0 auto; 4 | } 5 | .login label { 6 | padding-left: 347px; 7 | font-size: 15px; 8 | display: block; 9 | text-align: left; 10 | } 11 | .login .input { 12 | width: 300px; 13 | height: 47px; 14 | line-height: 47px; 15 | box-sizing: border-box; 16 | border: 1px solid #d5d5d5; 17 | border-bottom: none; 18 | box-shadow: none; 19 | padding: 10px 8px; 20 | background-color: #fff; 21 | } 22 | .login .last .input { 23 | border-bottom: 1px solid #d5d5d5; 24 | } 25 | .login .loginSub { 26 | margin-top: 18px; 27 | width: 300px; 28 | height: 41px; 29 | line-height: 41px; 30 | background-color: #0f88eb; 31 | color: #fff; 32 | font-size: 15px; 33 | border: none; 34 | border-radius: 3px; 35 | text-align: center; 36 | cursor: pointer; 37 | } 38 | .loginSub i { 39 | margin-left: 5px; 40 | font-size: 20px; 41 | } -------------------------------------------------------------------------------- /src/assets/css/mailList.css: -------------------------------------------------------------------------------- 1 | body, ul, h1, h2, p { 2 | padding: 0; 3 | margin: 0; 4 | } 5 | html { 6 | font-size: 10px; 7 | } 8 | html, body, #mailList { 9 | height: 100%; 10 | color: #555; 11 | } 12 | body { 13 | overflow-x: hidden; 14 | } 15 | #mailList { 16 | width: 100%; 17 | } 18 | .head { 19 | width: 100%; 20 | height: 90px; 21 | line-height: 90px; 22 | position: fixed; 23 | top: 0; 24 | background-color: #fff; 25 | display: flex; 26 | justify-content: space-between; 27 | z-index: 5; 28 | background-image: url(/static/img/bg.png); 29 | background-size: cover; 30 | } 31 | .head .logo { 32 | font-size: 50px; 33 | padding-left: 30px; 34 | color: #0f88eb; 35 | font-family: "幼圆"; 36 | } 37 | .head .welcome { 38 | font-size: 20px; 39 | font-family: "微软雅黑"; 40 | display: inline-block; 41 | margin-right: 30px; 42 | } 43 | .head .img { 44 | display: inline-block; 45 | width: 75px; 46 | height: 73px; 47 | border-radius: 35px; 48 | vertical-align: middle; 49 | margin-left: 10px; 50 | background-color: #eee; 51 | overflow: hidden; 52 | } 53 | .head img { 54 | width: 100%; 55 | height: 100%; 56 | } 57 | .lside { 58 | width: 300px; 59 | height: 90%; 60 | position: fixed; 61 | left: 0; 62 | top: 90px; 63 | z-index: 5; 64 | background-color: #eee; 65 | padding: 3px; 66 | box-sizing: border-box; 67 | } 68 | .lside li { 69 | height: 50px; 70 | line-height: 50px; 71 | padding-left: 30px; 72 | margin-bottom: 2px; 73 | box-sizing: border-box; 74 | font-size: 17px; 75 | border-top: none; 76 | cursor: pointer; 77 | background-color: #fff; 78 | list-style: none; 79 | } 80 | .lside li i { 81 | margin-right: 8px; 82 | } 83 | .lside li a { 84 | color: #555; 85 | text-decoration: none; 86 | width: 100%; 87 | height: 100%; 88 | display: inline-block; 89 | } 90 | .rside { 91 | width: 100%; 92 | height: 100%; 93 | background-color: #f7fafc; 94 | position: absolute; 95 | padding-left: 300px; 96 | box-sizing: border-box; 97 | z-index: 1; 98 | overflow-x: hidden; 99 | } 100 | li.act { 101 | background-color: #0f88eb; 102 | } 103 | li.act a { 104 | color: #fff; 105 | } 106 | .name { 107 | display: inline-block; 108 | max-width: 118px; 109 | white-space: nowrap; 110 | text-overflow: ellipsis; 111 | overflow: hidden; 112 | vertical-align: middle; 113 | } 114 | .out { 115 | position: absolute; 116 | bottom: 41px; 117 | right: 16px; 118 | cursor: pointer; 119 | } -------------------------------------------------------------------------------- /src/assets/css/notes.css: -------------------------------------------------------------------------------- 1 | .rside { 2 | /* padding-left: 160px; */ 3 | box-sizing: border-box; 4 | } 5 | #search { 6 | padding-top: 90px; 7 | } 8 | .search { 9 | padding-left: 181px; 10 | margin-top: 39px; 11 | } 12 | .search input { 13 | width: 640px; 14 | height: 39px; 15 | border: 2px solid #eee; 16 | border-right: none; 17 | border-top-left-radius: 5px; 18 | border-bottom-left-radius: 5px; 19 | padding-left: 10px; 20 | vertical-align: middle; 21 | font-size: 16px; 22 | } 23 | /* 去掉文本框聚焦时的边框 */ 24 | input:focus, button:focus { 25 | outline: none; 26 | } 27 | input[type="radio"] { 28 | cursor: pointer; 29 | } 30 | .search span { 31 | background-color: #fff; 32 | color: #555; 33 | font-size: 16px; 34 | padding: 10px 14px; 35 | border: 2px solid #eee; 36 | border-top-right-radius: 5px; 37 | border-bottom-right-radius: 5px; 38 | border-left: none; 39 | vertical-align: middle; 40 | } 41 | .all { 42 | font-size: 13px; 43 | margin: 10px 0; 44 | padding-left: 191px; 45 | } 46 | .select { 47 | padding-left: 181px; 48 | } 49 | .rside .ul { 50 | width: 1000px; 51 | height: auto; 52 | margin-top: 39px; 53 | margin-left: 132px; 54 | padding-left: 50px; 55 | box-sizing: border-box; 56 | } 57 | .none { 58 | margin-top: 122px; 59 | font-size: 33px; 60 | padding-left: 340px; 61 | } 62 | .arrow { 63 | width: 35px; 64 | height: 35px; 65 | line-height: 31px; 66 | position: fixed; 67 | z-index: 10; 68 | cursor: pointer; 69 | right: 91px; 70 | bottom: 80px; 71 | font-size: 24px; 72 | background-color: #ccc; 73 | text-align: center; 74 | border-radius: 18px; 75 | } 76 | .arrow a { 77 | color: #fff; 78 | width: 100%; 79 | height: 100%; 80 | display: inline-block; 81 | } -------------------------------------------------------------------------------- /src/assets/css/own.css: -------------------------------------------------------------------------------- 1 | @import './addCon.css'; 2 | 3 | .form input.read { 4 | background-color: #f7fafc; 5 | border: none; 6 | text-align: center; 7 | } 8 | .form button.large { 9 | width: 300px; 10 | } 11 | .editing button { 12 | width: 147px; 13 | height: 40px; 14 | font-size: 18px; 15 | border-radius: 5px; 16 | cursor: pointer; 17 | color: #fff; 18 | border: none; 19 | } 20 | .editing button.save { 21 | background-color: #0f88eb; 22 | margin-right: 5px; 23 | } 24 | .editing button.return { 25 | background-color: #ccc; 26 | } 27 | -------------------------------------------------------------------------------- /src/components/addCon.vue: -------------------------------------------------------------------------------- 1 | 34 | 35 | 76 | 77 | 80 | -------------------------------------------------------------------------------- /src/components/app.vue: -------------------------------------------------------------------------------- 1 | 12 | 13 | -------------------------------------------------------------------------------- /src/components/global.vue: -------------------------------------------------------------------------------- 1 | 6 | -------------------------------------------------------------------------------- /src/components/login.vue: -------------------------------------------------------------------------------- 1 | 18 | 19 | 53 | 54 | -------------------------------------------------------------------------------- /src/components/mailList.vue: -------------------------------------------------------------------------------- 1 | < 40 | 41 | 84 | 85 | 88 | -------------------------------------------------------------------------------- /src/components/noteItem.vue: -------------------------------------------------------------------------------- 1 | 27 | 28 | 60 | 61 | 136 | -------------------------------------------------------------------------------- /src/components/notes.vue: -------------------------------------------------------------------------------- 1 | 32 | 33 | < 90 | 91 | 94 | 95 | -------------------------------------------------------------------------------- /src/components/own.vue: -------------------------------------------------------------------------------- 1 | 37 | 38 | 103 | 104 | 107 | -------------------------------------------------------------------------------- /src/components/ownItem.vue: -------------------------------------------------------------------------------- 1 | 13 | 14 | 45 | 46 | -------------------------------------------------------------------------------- /src/components/register.vue: -------------------------------------------------------------------------------- 1 | 28 | 29 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /src/main.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import App from './App' 3 | import router from './router' 4 | import store from './store/vuex.js' 5 | 6 | Vue.config.productionTip = false; 7 | 8 | // 导航守卫,根据是否登录而路由 9 | router.beforeEach((to, from, next) => { 10 | if(to.meta.logined) { 11 | if(sessionStorage.login == 1) { // 若登录状态为1 12 | next(); 13 | } else { 14 | next({ 15 | path: '/home/login', 16 | }); 17 | } 18 | } else { 19 | next(); 20 | } 21 | }); 22 | 23 | new Vue({ 24 | el: '#app', 25 | router, 26 | store, 27 | template: '', 28 | components: { App }, 29 | }) 30 | -------------------------------------------------------------------------------- /src/router/index.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import Router from 'vue-router' 3 | 4 | // 懒加载 5 | const app = () => import('@/components/app.vue'); 6 | const login = () => import('@/components/login.vue'); 7 | const register = () => import('@/components/register.vue'); 8 | 9 | const mailList = () => import('@/components/mailList.vue'); 10 | const notes = () => import('@/components/notes.vue'); 11 | const addCon = () => import('@/components/addCon.vue'); 12 | const own = () => import('@/components/own.vue'); 13 | 14 | Vue.use(Router) 15 | 16 | export default new Router({ 17 | routes: [ 18 | {path: '/', redirect: '/home/register'}, 19 | { 20 | path: '/home', 21 | component: app, 22 | children: [ 23 | {path: 'login', component: login}, 24 | {path: 'register', component: register}, 25 | ] 26 | }, 27 | { 28 | path: '/contacts', 29 | component: mailList, 30 | children: [ 31 | { 32 | path: '', 33 | component: notes, 34 | meta: { logined: true } 35 | }, 36 | {path: 'add', component: addCon}, 37 | {path: 'own', component: own}, 38 | ] 39 | } 40 | ] 41 | }) 42 | -------------------------------------------------------------------------------- /src/store/modules/contacts.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue'; 2 | import router from '../../router'; 3 | 4 | const USER_INIT = 'USER_INIT'; // mail ilst初始化 5 | const USER_ADD = 'USER_ADD'; // 添加联系人 6 | const USER_REMOVE = 'USER_REMOVE'; 7 | const USER_CHANGE = 'USER_CHANGE'; 8 | const OWN_CHANGE = 'OWN_CHANGE'; 9 | 10 | var contactId = 0; 11 | 12 | export default { 13 | state: { 14 | items: [], 15 | own: {} 16 | }, 17 | mutations: { 18 | [USER_INIT](state, info) { 19 | state.items = info.items; 20 | state.own = info.own; 21 | }, 22 | [USER_ADD](state, user) { 23 | user.id = contactId++; 24 | user.imgSrc = '/static/img/userImg.png'; 25 | state.items.push(user); 26 | localStorage.items = JSON.stringify(JSON.parse(localStorage.items).push(user)); 27 | }, 28 | [USER_REMOVE](state, userId) { 29 | state.items = state.items.filter(function(item) { 30 | return item.id !== userId; 31 | }); 32 | }, 33 | [USER_CHANGE](state, user) { 34 | for(var key in state.items) 35 | if(state.items[key].id == user.id) { 36 | state.items[key].name = user.name; 37 | state.items[key].tel = user.tel; 38 | } 39 | }, 40 | [OWN_CHANGE](state, user) { 41 | var oldName = state.own.name; 42 | state.own = user; 43 | sessionStorage.setItem('user', JSON.stringify(user)); 44 | localStorage.setItem(sessionStorage.userId, JSON.stringify(user)); 45 | } 46 | }, 47 | actions: { 48 | userInit({commit}) { 49 | // 页面加载时获取数据 50 | if(sessionStorage.login && sessionStorage.login == 1) { 51 | var items = [ 52 | {name: '妈妈', tel: 1234555656, status: "亲人"}, 53 | {name: 'nic', tel: 1234555656, status: "朋友"}, 54 | {name: '爸爸', tel: 1234555656, status: "亲人"}, 55 | {name: 'wind', tel: 1234555656, status: "朋友"}, 56 | {name: 'lily', tel: 1234555656, status: "同学"}, 57 | {name: '爷爷', tel: 1234555656, status: "亲人"}, 58 | {name: 'tom', tel: 1234555656, status: "同学"}, 59 | {name: 'tom', tel: 1234555656, status: "同学"}, 60 | {name: 'tom', tel: 1234555656, status: "同学"}, 61 | {name: 'tom', tel: 1234555656, status: "同学"}, 62 | {name: '外婆', tel: 1234555656, status: "亲人"}, 63 | {name: 'tom', tel: 1234555656, status: "同学"}, 64 | {name: 'tom', tel: 1234555656, status: "同学"}, 65 | {name: 'tom', tel: 1234555656, status: "同学"}, 66 | {name: '外婆', tel: 1234555656, status: "亲人"}, 67 | ]; 68 | items = items.filter((item)=>{ 69 | item.id = contactId++; 70 | item.imgSrc = '/static/img/userImg.png'; 71 | return item; 72 | }); 73 | localStorage.items = JSON.stringify(items); 74 | var own = JSON.parse(sessionStorage.user); 75 | 76 | commit(USER_INIT, { 77 | items: JSON.parse(localStorage.items), 78 | own: own 79 | }); 80 | } else { 81 | alert('请先登录!'); 82 | router.replace('/home/login'); 83 | } 84 | }, 85 | userAdd({commit}, user) { 86 | commit(USER_ADD, user); 87 | }, 88 | userRemove({commit}, userId) { 89 | commit(USER_REMOVE, userId); 90 | }, 91 | userChange({commit}, user) { 92 | commit(USER_CHANGE, user); 93 | }, 94 | ownChange({commit}, user) { 95 | commit(OWN_CHANGE, user); 96 | } 97 | } 98 | } -------------------------------------------------------------------------------- /src/store/modules/user.js: -------------------------------------------------------------------------------- 1 | /* 2 | sessionStorage存储注册状态与登陆状态 3 | localstorage存储已注册用户信息 4 | */ 5 | 6 | import Vue from 'vue'; 7 | 8 | const REGISTER = 'REGISTER'; // 注册 9 | const SIGN_IN = 'SIGN_IN'; // 登录 10 | const SIGN_OUT = 'SIGN_OUT'; // 退出登录 11 | 12 | export default { 13 | state: {}, 14 | mutations: { 15 | [REGISTER](state, user) { 16 | // 判断是否同姓名 17 | var b = 0; 18 | for(var i = 0; i < localStorage.length; i++) 19 | if(localStorage.key(i).indexOf('user') != -1) // 为用户 20 | if(JSON.parse(localStorage.getItem(localStorage.key(i))).name == user.name) { 21 | b = 1; 22 | break; 23 | } 24 | 25 | if(b == 0) { 26 | // 添加本地存储用户 27 | localStorage.setItem('user'+localStorage.length, JSON.stringify(user)); 28 | sessionStorage.register = 1; // 注册成功 29 | } else { 30 | sessionStorage.register = 0; 31 | } 32 | }, 33 | [SIGN_IN](state, user) { 34 | // 根据tel找本地相应user 35 | var localuser = '', f = 0; 36 | 37 | for(var i = 0; i < localStorage.length; i++) 38 | if(localStorage.key(i).indexOf('user') != -1) // 为用户 39 | if(JSON.parse(localStorage.getItem(localStorage.key(i))).name == user.name) { 40 | localuser = JSON.parse(localStorage.getItem(localStorage.key(i))); 41 | f = 1; 42 | break; 43 | } 44 | 45 | // 存在该用户并密码正确 46 | if(f == 1 && user.psw == localuser.psw) { 47 | sessionStorage.login = 1; // 登陆成功 48 | sessionStorage.user = JSON.stringify(localuser); 49 | sessionStorage.userId = localStorage.key(i); 50 | } else { 51 | sessionStorage.login = 0; 52 | } 53 | }, 54 | [SIGN_OUT](state) { 55 | sessionStorage.register = 0; 56 | sessionStorage.login = 0; 57 | } 58 | }, 59 | actions: { 60 | register({commit}, user) { // 触发注册操作 61 | commit(REGISTER, user); 62 | }, 63 | signIn({commit}, user) { 64 | commit(SIGN_IN, user); // 触发登录操作 65 | }, 66 | signOut({commit}) { 67 | commit(SIGN_OUT); // 触发退出登录操作 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/store/vuex.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import Vuex from 'vuex' 3 | import user from './modules/user' 4 | import contacts from './modules/contacts' 5 | 6 | Vue.use(Vuex); 7 | 8 | export default new Vuex.Store({ 9 | strict: process.env.NODE_ENV !== 'production', //在非生产环境下,使用严格模式 10 | modules: { 11 | user: user, 12 | contacts: contacts 13 | } 14 | }); -------------------------------------------------------------------------------- /static/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/windlany/vue-mail-list/3122734319a9a725fce0d9fc77e815c158834728/static/.gitkeep -------------------------------------------------------------------------------- /static/img/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/windlany/vue-mail-list/3122734319a9a725fce0d9fc77e815c158834728/static/img/1.jpg -------------------------------------------------------------------------------- /static/img/bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/windlany/vue-mail-list/3122734319a9a725fce0d9fc77e815c158834728/static/img/bg.png -------------------------------------------------------------------------------- /static/img/contact.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/windlany/vue-mail-list/3122734319a9a725fce0d9fc77e815c158834728/static/img/contact.jpg -------------------------------------------------------------------------------- /static/img/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/windlany/vue-mail-list/3122734319a9a725fce0d9fc77e815c158834728/static/img/logo.png -------------------------------------------------------------------------------- /static/img/mailList.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/windlany/vue-mail-list/3122734319a9a725fce0d9fc77e815c158834728/static/img/mailList.gif -------------------------------------------------------------------------------- /static/img/userImg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/windlany/vue-mail-list/3122734319a9a725fce0d9fc77e815c158834728/static/img/userImg.png --------------------------------------------------------------------------------