├── .editorconfig ├── .eslintrc.js ├── .gitignore ├── .idea ├── dictionaries │ └── zhouhaipeng.xml ├── jsLibraryMappings.xml ├── markdown-navigator.xml ├── markdown-navigator │ └── profiles_settings.xml ├── misc.xml ├── modules.xml ├── mynuxt.iml ├── vcs.xml └── watcherTasks.xml ├── README.md ├── assets ├── README.md └── css │ ├── base.css │ ├── base.css.map │ └── base.scss ├── components ├── AppLogo.vue ├── Footer.vue ├── PageAction.vue ├── README.md └── header.vue ├── layouts ├── README.md ├── default.vue ├── edit.vue └── error.vue ├── middleware ├── README.md └── auth.js ├── nginx.conf ├── nuxt.config.js ├── package-lock.json ├── package.json ├── pages ├── README.md ├── edit │ ├── _id.vue │ └── index.vue ├── index.vue ├── login │ └── index.vue └── news │ ├── _id.vue │ └── _list │ └── _id.vue ├── plugins ├── Util.js ├── element-ui.js └── nuxt-quill-plugin.js ├── server ├── api.js ├── db.js ├── listrouter.js └── slide.js ├── static ├── README.md ├── favicon.ico └── gt.js ├── store ├── README.md └── index.js └── utils ├── api.js ├── checkenv.js ├── net.js └── ui.js /.editorconfig: -------------------------------------------------------------------------------- 1 | # editorconfig.org 2 | root = true 3 | 4 | [*] 5 | indent_size = 2 6 | indent_style = space 7 | end_of_line = lf 8 | charset = utf-8 9 | trim_trailing_whitespace = true 10 | insert_final_newline = true 11 | 12 | [*.md] 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | env: { 4 | browser: true, 5 | node: true 6 | }, 7 | parserOptions: { 8 | parser: 'babel-eslint' 9 | }, 10 | extends: [ 11 | // https://github.com/vuejs/eslint-plugin-vue#priority-a-essential-error-prevention 12 | // consider switching to `plugin:vue/strongly-recommended` or `plugin:vue/recommended` for stricter rules. 13 | 'plugin:vue/essential' 14 | ], 15 | // required to lint *.vue files 16 | plugins: [ 17 | 'vue' 18 | ], 19 | // add your custom rules here 20 | rules: {} 21 | } 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # dependencies 2 | node_modules 3 | 4 | # logs 5 | npm-debug.log 6 | 7 | # Nuxt build 8 | .nuxt 9 | 10 | # Nuxt generate 11 | dist 12 | .idea 13 | -------------------------------------------------------------------------------- /.idea/dictionaries/zhouhaipeng.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/jsLibraryMappings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/markdown-navigator.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 36 | 37 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /.idea/markdown-navigator/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | Assignment issuesJavaScript 15 | 16 | 17 | Bitwise operation issuesJavaScript 18 | 19 | 20 | Code quality toolsJavaScript 21 | 22 | 23 | Code style issuesJavaScript 24 | 25 | 26 | Control flow issuesJavaScript 27 | 28 | 29 | DOM issuesJavaScript 30 | 31 | 32 | Data flow issuesJavaScript 33 | 34 | 35 | Error handlingJavaScript 36 | 37 | 38 | GeneralJavaScript 39 | 40 | 41 | Ignore 42 | 43 | 44 | JavaScript 45 | 46 | 47 | JavaScript function metricsJavaScript 48 | 49 | 50 | JavaScript validity issuesJavaScript 51 | 52 | 53 | Less 54 | 55 | 56 | Meteor 57 | 58 | 59 | Naming conventionsJavaScript 60 | 61 | 62 | Node.jsJavaScript 63 | 64 | 65 | Potentially confusing code constructsJavaScript 66 | 67 | 68 | Probable bugsJavaScript 69 | 70 | 71 | RELAX NG 72 | 73 | 74 | Sass/SCSS 75 | 76 | 77 | TypeScript 78 | 79 | 80 | Unit testingJavaScript 81 | 82 | 83 | XML 84 | 85 | 86 | XPath 87 | 88 | 89 | XSLT 90 | 91 | 92 | 93 | 94 | File Watchers 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 114 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/mynuxt.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/watcherTasks.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 16 | 23 | 24 | 35 | 42 | 43 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Nuxt-ssr是一个文章增删改查的SSR项目 2 | 3 | > Nuxt.js该项目是一个ssr结构完整的项目,适合新人练手使用,如果对您有帮助,请右上角给个star,鼓励一下,同时希望指正。也可以加 nuxt技术交流群,大家一起相互学习,相互成长。 4 | 5 | 6 | ## 用到的技术 7 | 8 | > Vue.js v2.0.0 9 | 10 | > Nuxt.js v1.0.0 11 | 12 | > Node.js v9.8.0 (必须>=8.0) 13 | 14 | > Express.js v4.x 15 | 16 | > MongoDB v3.4.7 17 | 18 | > element-ui v2.3.2 19 | 20 | 21 | ## 目录结构 22 | 23 | ``` 24 | ├── assets 资源目录 assets 用于组织未编译的静态资源如 LESS、SASS 或 JavaScript 25 | ├── build 打包后的文件 26 | ├── components 存放组件,用于组织应用的 Vue.js 组件 27 | │   ├── Footer 页面footer组件 28 | │   ├── .... 29 | ├── layouts 布局模板文件,默认default,通过为页面设置layout更改 30 | │   ├── edit 编辑/创建文章模板 31 | │ ├── .... 32 | ├── middleware 存放应用的中间件 33 | │   ├── auth.js                       路由是否登录拦截 34 | │   ├── ... 35 | ├── node_modules                       Node依赖文件 36 | ├── nuxt.config.js Nuxt主配置文件 37 | ├── pages 存放页面的目录 38 | │   ├── index.vue 首页 39 | │   ├── .... 40 | ├── plugins 存放插件,用于组织那些需要在 根vue.js应用 实例化之前需要运行的 Javascript 插件 41 | │   └── nuxt-quill-plugin.js 富文本编辑器插件 42 | ├── README.md README 43 | ├── server express后台目录 44 | │   ├── api.js server端接口 45 | │   ├── db.js 连接MongoDB数据库文件 46 | │   ├── listrouter.js server启动配置 47 | │   ├── .... 48 | ├── static 静态文件目录,此类文件不会被 Nuxt.js 调用 Webpack 进行构建编译处理。 服务器启动的时候,该目录下的文件会映射至应用的根路径 / 下 49 | ├── util 存放一些工具文件(自己添加) 50 | │   ├── net.js                          封装网络请求 51 | │   ├── ui.js                           封装ui弹框配置 52 | │   ├── ... 53 | ``` 54 | 55 | 56 | ## 前端开发指南 57 | 58 | > 首先需要安装 >=node8.0 因为nuxt1.0.0 必须在>=node8.0的环境下才可以安装成功 59 | 60 | > 安装element-ui, 安装方法页面[这个页面](http://element.eleme.io/#/zh-CN/component/quickstart)下面有比较详细的demo,可参考 61 | 62 | > 富文本编辑器nuxt-quill-plugin的安装与使用 [nuxt-quill-plugin](https://github.com/surmon-china/vue-quill-editor). 63 | 64 | > (划重点,因为本地前后端检测同一个接口无法实现,所以与下面的后端端口不同)前端监控的是3389端口 ,执行命令 "npm run dev"; 65 | 66 | 67 | 68 | ## 后端开发指南 69 | 70 | > 下载安装MongoDB, 具体详情不在此赘述,给上链接 [MongoDB](https://www.mongodb.com/download-center?jmp=nav#atlas). 71 | 72 | > 安装Express, 具体详情不在此赘述,给上链接 [Express](http://expressjs.com/zh-cn/4x/api.html) . 73 | 74 | > 安装supervisor 实时监控,可以进行全局,也可只安装在本项目中。全局安装方法:sudo npm install -g supervisor. 75 | 76 | > (划重点,因为本地前后端检测同一个接口无法实现,所以与上面的前端端口不同)后端监控的是3000端口, 需要,cd 到 server文件夹目录下,执行命令 "supervisor listrouter.js"; 77 | 78 | 79 | ## 阿里云部署 80 | 81 | > 具体部署步骤不在此详解,具体可看[详细教程](https://itcnz.github.io/20180418/%E9%98%BF%E9%87%8C%E4%BA%91%E9%83%A8%E7%BD%B2nuxt%E9%A1%B9%E7%9B%AE.html) 82 | 83 | 84 | ## 构建与运行 85 | 86 | ``` bash 87 | # install dependencies 88 | $ npm install # Or yarn install 89 | 90 | # serve with hot reload at localhost:3000 91 | $ npm run dev 92 | 93 | # build for production and launch server 94 | $ npm run build 95 | $ npm start 96 | 97 | # generate static project 98 | $ npm run generate 99 | ``` 100 | 101 | For detailed explanation on how things work, checkout the [Nuxt.js docs](https://github.com/nuxt/nuxt.js). 102 | -------------------------------------------------------------------------------- /assets/README.md: -------------------------------------------------------------------------------- 1 | # ASSETS 2 | 3 | This directory contains your un-compiled assets such as LESS, SASS, or JavaScript. 4 | 5 | More information about the usage of this directory in the documentation: 6 | https://nuxtjs.org/guide/assets#webpacked 7 | 8 | **This directory is not required, you can delete it if you don't want to use it.** 9 | -------------------------------------------------------------------------------- /assets/css/base.css: -------------------------------------------------------------------------------- 1 | * { 2 | padding: 0; 3 | margin: 0; } 4 | 5 | ul { 6 | list-style: none; } 7 | 8 | .container { 9 | min-height: 100vh; 10 | justify-content: center; 11 | align-items: center; 12 | margin: 10px 20px; 13 | padding: 20px; 14 | border-radius: 5px; 15 | -webkit-box-shadow: 0 0 6px rgba(99, 99, 99, 0.4); 16 | box-shadow: 0 0 6px rgba(99, 99, 99, 0.4); } 17 | 18 | h1 { 19 | margin-bottom: 20px; } 20 | 21 | /*# sourceMappingURL=base.css.map */ 22 | -------------------------------------------------------------------------------- /assets/css/base.css.map: -------------------------------------------------------------------------------- 1 | { 2 | "version": 3, 3 | "mappings": "AAAA,CAAC;EACC,OAAO,EAAE,CAAC;EACV,MAAM,EAAE,CAAC;;AAEX,EAAE;EACA,UAAU,EAAE,IAAI;;AAElB,UAAW;EACT,UAAU,EAAE,KAAK;EACjB,eAAe,EAAE,MAAM;EACvB,WAAW,EAAE,MAAM;EACnB,MAAM,EAAE,SAAS;EACjB,OAAO,EAAE,IAAI;EACb,aAAa,EAAE,GAAG;EAClB,kBAAkB,EAAE,6BAAyB;EAC7C,UAAU,EAAE,6BAAyB;;AAEvC,EAAE;EACA,aAAa,EAAE,IAAI", 4 | "sources": ["base.scss"], 5 | "names": [], 6 | "file": "base.css" 7 | } -------------------------------------------------------------------------------- /assets/css/base.scss: -------------------------------------------------------------------------------- 1 | *{ 2 | padding: 0; 3 | margin: 0; 4 | } 5 | ul{ 6 | list-style: none; 7 | } 8 | .container { 9 | min-height: 100vh; 10 | justify-content: center; 11 | align-items: center; 12 | margin: 10px 20px; 13 | padding: 20px; 14 | border-radius: 5px; 15 | -webkit-box-shadow: 0 0 6px hsla(0,0%,39%,.4); 16 | box-shadow: 0 0 6px hsla(0,0%,39%,.4); 17 | } 18 | h1{ 19 | margin-bottom: 20px; 20 | } 21 | -------------------------------------------------------------------------------- /components/AppLogo.vue: -------------------------------------------------------------------------------- 1 | 9 | 10 | 80 | -------------------------------------------------------------------------------- /components/Footer.vue: -------------------------------------------------------------------------------- 1 | 15 | 16 | 26 | -------------------------------------------------------------------------------- /components/PageAction.vue: -------------------------------------------------------------------------------- 1 | 14 | 15 | 36 | -------------------------------------------------------------------------------- /components/README.md: -------------------------------------------------------------------------------- 1 | # COMPONENTS 2 | 3 | The components directory contains your Vue.js Components. 4 | Nuxt.js doesn't supercharge these components. 5 | 6 | **This directory is not required, you can delete it if you don't want to use it.** 7 | -------------------------------------------------------------------------------- /components/header.vue: -------------------------------------------------------------------------------- 1 | 12 | 13 | 40 | 75 | -------------------------------------------------------------------------------- /layouts/README.md: -------------------------------------------------------------------------------- 1 | # LAYOUTS 2 | 3 | This directory contains your Application Layouts. 4 | 5 | More information about the usage of this directory in the documentation: 6 | https://nuxtjs.org/guide/views#layouts 7 | 8 | **This directory is not required, you can delete it if you don't want to use it.** 9 | -------------------------------------------------------------------------------- /layouts/default.vue: -------------------------------------------------------------------------------- 1 | 8 | 18 | 64 | -------------------------------------------------------------------------------- /layouts/edit.vue: -------------------------------------------------------------------------------- 1 | 32 | 33 | 155 | 156 | 166 | -------------------------------------------------------------------------------- /layouts/error.vue: -------------------------------------------------------------------------------- 1 | 10 | 17 | 22 | -------------------------------------------------------------------------------- /middleware/README.md: -------------------------------------------------------------------------------- 1 | # MIDDLEWARE 2 | 3 | This directory contains your Application Middleware. 4 | The middleware lets you define custom function to be ran before rendering a page or a group of pages (layouts). 5 | 6 | More information about the usage of this directory in the documentation: 7 | https://nuxtjs.org/guide/routing#middleware 8 | 9 | **This directory is not required, you can delete it if you don't want to use it.** 10 | -------------------------------------------------------------------------------- /middleware/auth.js: -------------------------------------------------------------------------------- 1 | import Cookie from 'js-cookie' 2 | export default function ({ route, req, res, redirect, error, store }) { 3 | 4 | //获取服务端cookie 5 | function getcookiesInServer(req) { 6 | let service_cookie = {}; 7 | req && req.headers.cookie && req.headers.cookie.split(';').forEach(function (val) { 8 | let parts = val.split('='); 9 | service_cookie[parts[0].trim()] = (parts[1] || '').trim(); 10 | }); 11 | return service_cookie; 12 | } 13 | 14 | //获取客户端cookie 15 | function getcookiesInClient(key) { 16 | return Cookie.get(key) ? Cookie.get(key) : '' 17 | } 18 | 19 | 20 | let isClient = process.client; 21 | let isServer = process.server; 22 | let redirectURL = '/login'; 23 | var authUser, path 24 | 25 | //在服务端 26 | if (isServer) { 27 | let cookies = getcookiesInServer(req) 28 | path = req.originalUrl; 29 | authUser = cookies.authUser ? cookies.authUser : '' 30 | } 31 | 32 | //在客户端判读是否需要登陆 33 | if (isClient) { 34 | authUser = getcookiesInClient('authUser') 35 | path = route.path; 36 | console.log('authUser------', authUser) 37 | console.log('path------', path) 38 | } 39 | 40 | if (path) { 41 | redirectURL = '/login' 42 | } 43 | 44 | //需要进行权限判断的页面开头 45 | if (!authUser) { 46 | redirect(redirectURL) 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /nginx.conf: -------------------------------------------------------------------------------- 1 | # For more information on configuration, see: 2 | # * Official English Documentation: http://nginx.org/en/docs/ 3 | # * Official Russian Documentation: http://nginx.org/ru/docs/ 4 | 5 | user nginx; 6 | worker_processes auto; 7 | error_log /var/log/nginx/error.log; 8 | pid /run/nginx.pid; 9 | 10 | # Load dynamic modules. See /usr/share/nginx/README.dynamic. 11 | include /usr/share/nginx/modules/*.conf; 12 | 13 | events { 14 | worker_connections 1024; 15 | } 16 | 17 | http { 18 | log_format main '$remote_addr - $remote_user [$time_local] "$request" ' 19 | '$status $body_bytes_sent "$http_referer" ' 20 | '"$http_user_agent" "$http_x_forwarded_for"'; 21 | 22 | access_log /var/log/nginx/access.log main; 23 | 24 | sendfile on; 25 | tcp_nopush on; 26 | tcp_nodelay on; 27 | keepalive_timeout 65; 28 | types_hash_max_size 2048; 29 | 30 | include /etc/nginx/mime.types; 31 | default_type application/octet-stream; 32 | 33 | # Load modular configuration files from the /etc/nginx/conf.d directory. 34 | # See http://nginx.org/en/docs/ngx_core_module.html#include 35 | # for more information. 36 | include /etc/nginx/conf.d/*.conf; 37 | 38 | server { 39 | listen 80; 40 | # listen [::]:80 default_server; 41 | server_name 127.0.0.1:3389; 42 | root /home/app; 43 | 44 | # Load configuration files for the default server block. 45 | include /etc/nginx/default.d/*.conf; 46 | 47 | location / { 48 | proxy_pass http://127.0.0.1:3389; 49 | } 50 | 51 | error_page 404 /404.html; 52 | location = /40x.html { 53 | } 54 | 55 | error_page 500 502 503 504 /50x.html; 56 | location = /50x.html { 57 | } 58 | } 59 | 60 | server { 61 | listen 8082; 62 | # listen [::]:80 default_server; 63 | server_name _; 64 | root /home/vue; 65 | 66 | # Load configuration files for the default server block. 67 | include /etc/nginx/default.d/*.conf; 68 | 69 | location / { 70 | index index.html index.htm; 71 | } 72 | 73 | location /teacher/static { 74 | alias /home/vue/static; 75 | } 76 | 77 | error_page 404 /404.html; 78 | location = /40x.html { 79 | } 80 | 81 | error_page 500 502 503 504 /50x.html; 82 | location = /50x.html { 83 | } 84 | } 85 | 86 | # Settings for a TLS enabled server. 87 | # 88 | # server { 89 | # listen 443 ssl http2 default_server; 90 | # listen [::]:443 ssl http2 default_server; 91 | # server_name _; 92 | # root /usr/share/nginx/html; 93 | # 94 | # ssl_certificate "/etc/pki/nginx/server.crt"; 95 | # ssl_certificate_key "/etc/pki/nginx/private/server.key"; 96 | # ssl_session_cache shared:SSL:1m; 97 | # ssl_session_timeout 10m; 98 | # ssl_ciphers HIGH:!aNULL:!MD5; 99 | # ssl_prefer_server_ciphers on; 100 | # 101 | # # Load configuration files for the default server block. 102 | # include /etc/nginx/default.d/*.conf; 103 | # 104 | # location / { 105 | # } 106 | # 107 | # error_page 404 /404.html; 108 | # location = /40x.html { 109 | # } 110 | # 111 | # error_page 500 502 503 504 /50x.html; 112 | # location = /50x.html { 113 | # } 114 | # } 115 | } 116 | -------------------------------------------------------------------------------- /nuxt.config.js: -------------------------------------------------------------------------------- 1 | 2 | module.exports = { 3 | /* 4 | ** Headers of the page 5 | */ 6 | head: { 7 | title: 'mynuxt', 8 | meta: [ 9 | { charset: 'utf-8' }, 10 | { name: 'viewport', content: 'width=device-width, initial-scale=1' }, 11 | { hid: 'description', name: 'description', content: 'Nuxt.js project' } 12 | ], 13 | link: [ 14 | { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' } 15 | ] 16 | }, 17 | /* 18 | ** Customize the progress bar color 19 | */ 20 | loading: { color: '#3B8070' }, 21 | /* 22 | ** Build configuration 23 | */ 24 | build: { 25 | /* 26 | ** Run ESLint on save 27 | */ 28 | vendor: ['axios', 'element-ui'], 29 | extend (config, { isDev, isClient }) { 30 | if (isDev && isClient) { 31 | config.module.rules.push({ 32 | enforce: 'pre', 33 | test: /\.(js|vue)$/, 34 | loader: 'eslint-loader', 35 | exclude: /(node_modules)/ 36 | }) 37 | } 38 | } 39 | }, 40 | // modules: [ 41 | // '@nuxtjs/axios', 42 | // '@nuxtjs/proxy' 43 | // ], 44 | // proxy: [ // 设置代理 45 | // ['/api', { target: 'http://localhost:3333' }] 46 | // ], 47 | plugins: [ 48 | { src: '~plugins/nuxt-quill-plugin.js', ssr: false }, 49 | { src: '~plugins/element-ui.js', ssr: true }, 50 | { src: '~plugins/util.js', ssr: false } 51 | ], 52 | 53 | css: [ 54 | '~assets/css/base.scss', 55 | 'element-ui/lib/theme-chalk/reset.css', 56 | 'element-ui/lib/theme-chalk/index.css' 57 | ], 58 | // router: { 59 | // middleware: 'chekRouter' 60 | // } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mynuxt", 3 | "version": "1.0.0", 4 | "description": "Nuxt.js project", 5 | "author": "zhouhaipeng ", 6 | "private": true, 7 | "scripts": { 8 | "dev": "nuxt", 9 | "build": "nuxt build", 10 | "start": "nuxt start", 11 | "generate": "nuxt generate", 12 | "lint": "eslint --ext .js,.vue --ignore-path .gitignore .", 13 | "precommit": "npm run lint" 14 | }, 15 | "config": { 16 | "nuxt": { 17 | "host": "0.0.0.0", 18 | "port": 3389 19 | } 20 | }, 21 | "dependencies": { 22 | "axios": "^0.16.2", 23 | "cookie-parser": "^1.4.3", 24 | "element-ui": "^2.2.1", 25 | "express": "^4.15.5", 26 | "express-session": "^1.15.6", 27 | "gt3-sdk": "^2.0.0", 28 | "js-cookie": "^2.2.0", 29 | "mongoose": "^4.11.13", 30 | "multer": "^1.3.0", 31 | "nuxt": "^1.4.0", 32 | "request": "^2.88.0", 33 | "vue-notification": "^1.3.7", 34 | "vue-quill-editor": "^3.0.5" 35 | }, 36 | "devDependencies": { 37 | "@nuxtjs/axios": "^5.1.1", 38 | "@nuxtjs/proxy": "^1.1.4", 39 | "babel-eslint": "^8.2.1", 40 | "eslint": "^4.15.0", 41 | "eslint-friendly-formatter": "^3.0.0", 42 | "eslint-loader": "^1.7.1", 43 | "eslint-plugin-vue": "^4.0.0", 44 | "moment": "^2.18.1", 45 | "node-sass": "^4.10.0", 46 | "sass-loader": "^6.0.7", 47 | "style-loader": "^0.20.3", 48 | "vue-style-loader": "^4.1.0" 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /pages/README.md: -------------------------------------------------------------------------------- 1 | # PAGES 2 | 3 | This directory contains your Application Views and Routes. 4 | The framework reads all the .vue files inside this directory and creates the router of your application. 5 | 6 | More information about the usage of this directory in the documentation: 7 | https://nuxtjs.org/guide/routing 8 | -------------------------------------------------------------------------------- /pages/edit/_id.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | 21 | -------------------------------------------------------------------------------- /pages/edit/index.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | 22 | -------------------------------------------------------------------------------- /pages/index.vue: -------------------------------------------------------------------------------- 1 | 19 | 20 | 38 | 39 | 61 | -------------------------------------------------------------------------------- /pages/login/index.vue: -------------------------------------------------------------------------------- 1 | 28 | 29 | 130 | 131 | 163 | -------------------------------------------------------------------------------- /pages/news/_id.vue: -------------------------------------------------------------------------------- 1 | 12 | 13 | 41 | 42 | 48 | -------------------------------------------------------------------------------- /pages/news/_list/_id.vue: -------------------------------------------------------------------------------- 1 | 22 | 23 | 85 | 86 | 110 | -------------------------------------------------------------------------------- /plugins/Util.js: -------------------------------------------------------------------------------- 1 | import Net from '~/utils/net' // 网络请求封装插件 2 | import UI from '~/utils/ui' // 自定义ui插件 3 | 4 | window.Util = { 5 | Net, 6 | UI 7 | } ; 8 | -------------------------------------------------------------------------------- /plugins/element-ui.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import {Input, Button, Form, FormItem, Pagination} from 'element-ui' 3 | 4 | export default () => { 5 | Vue.use(Input); 6 | Vue.use(Button); 7 | Vue.use(Form); 8 | Vue.use(FormItem); 9 | Vue.use(Pagination); 10 | } 11 | -------------------------------------------------------------------------------- /plugins/nuxt-quill-plugin.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import VueQuillEditor from 'vue-quill-editor/dist/ssr' 3 | 4 | Vue.use(VueQuillEditor) 5 | -------------------------------------------------------------------------------- /server/api.js: -------------------------------------------------------------------------------- 1 | var express = require('express'); 2 | var router = express.Router(); 3 | var moment = require('moment'); 4 | var request = require('request'); 5 | // 引入模型 6 | var listModel = require('./db'); 7 | 8 | // 极验api 9 | var session = require('express-session'); 10 | router.use(session({ 11 | secret: 'my-secret', 12 | resave: false, 13 | saveUninitialized: true 14 | })); 15 | 16 | var slide = require('./slide'); 17 | 18 | // CORS解决跨域问题 19 | router.all('*', (req, res, next) => { 20 | res.header("Access-Control-Allow-Origin", "*"); 21 | res.header("Access-Control-Allow-Headers", "X-Requested-With"); 22 | res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS"); 23 | res.header("X-Powered-By",' 3.2.1') 24 | res.header("Content-Type", "application/json;charset=utf-8"); 25 | next(); 26 | }); 27 | 28 | // 分页读取文章列表 29 | router.post('/api/newslist', (req, res, next) => { 30 | var reqBody = req.body; 31 | if (reqBody.pageIndex == null) { 32 | reqBody.pageIndex = 1; 33 | } 34 | if (reqBody.pagesize == null) { 35 | reqBody.pagesize = 5; 36 | } 37 | 38 | var resDatas = { 39 | msg: '请求成功', 40 | pageIndex: parseInt(reqBody.pageIndex), 41 | pagesize: parseInt(reqBody.pagesize) 42 | } 43 | 44 | 45 | // 方法一, 此方法查询参数条件下的数据并返回 46 | listModel.count().then(count => { 47 | resDatas.records = count; // 数据条数 48 | resDatas.total = Math.ceil(count/resDatas.pagesize); // 总页数 49 | 50 | if (resDatas.pageIndex > resDatas.total) resDatas.pageIndex = resDatas.total; 51 | var limit = resDatas.pagesize; 52 | var skip = (resDatas.pageIndex - 1) * resDatas.pagesize; 53 | 54 | listModel.find().sort({_id: -1}).limit(limit).skip(skip) 55 | .then((data) => { 56 | resDatas.rows = data; // 数据包 57 | res.send(resDatas); 58 | }) 59 | }); 60 | 61 | // 方法二, 此方式查询所有数据再根据分页参数返回对应的数据,超级慢 62 | // listModel.find((err, data) => { 63 | // if (err) { 64 | // res.send(err); 65 | // } else { 66 | // console.log('data---', data) 67 | // var data = data.reverse() 68 | // resDatas.records = data.length; 69 | // resDatas.total = Math.ceil(data.length/resDatas.pagesize) 70 | // var currentData = data.slice((resDatas.pageIndex-1) * resDatas.pagesize, resDatas.pageIndex * resDatas.pagesize); 71 | // resDatas.rows = currentData; 72 | // res.send(resDatas); 73 | // } 74 | // }); 75 | }); 76 | 77 | // 读取单个文章详情 78 | router.get('/api/newsone/:id', (req, res, next) => { 79 | listModel.findById(req.params.id, (err, data) => { 80 | if (err) { 81 | res.send(err); 82 | } else { 83 | res.send(data); 84 | } 85 | }); 86 | }); 87 | 88 | // 写入文章 89 | router.post('/api/newsedit', (req, res, next) => { 90 | 91 | let editList = new listModel({ 92 | title: req.body.title, 93 | author: req.body.author, 94 | date: req.body.date ? req.body.date : moment(Date.now()).format('YYYY-MM-DD HH:mm:ss'), 95 | content: req.body.content 96 | }); 97 | 98 | editList.save((err, data) => { 99 | 100 | if (err) { 101 | res.send(err); 102 | } else { 103 | res.send(data); 104 | } 105 | }); 106 | 107 | }); 108 | 109 | // 删除文章 110 | router.get('/api/newsdelet/:id',(req, res, next) => { 111 | 112 | listModel.findById(req.params.id, (err, data) => { 113 | data.remove((err, data) => { 114 | res.send({ 115 | msg: '你很叼哦,请求成功了!' 116 | }); 117 | res.end(); 118 | }); 119 | }); 120 | 121 | }); 122 | 123 | // 编辑文章 124 | router.post("/api/newsedit/:id", (req, res, next) => { 125 | listModel.findById(req.params.id, (err, data) => { 126 | data.content = req.body.content; 127 | data.date = req.body.date ? req.body.date : moment(Date.now()).format('YYYY-MM-DD HH:mm:ss'); 128 | data.author = req.body.author; 129 | data.title = req.body.title; 130 | 131 | data.save(function(err, data) { 132 | if (err) { 133 | res.send(err); 134 | } else { 135 | res.send(data); 136 | } 137 | }); 138 | 139 | }); 140 | }); 141 | 142 | 143 | // 登录操作 144 | router.post('/api/login', function (req, res) { 145 | if (req.body.userName !== '' && req.body.passWord === '123456') { 146 | return res.json({ userName: req.body.userName }) 147 | } 148 | res.status(401).json({ error: '账号或密码不正确!' }) 149 | }) 150 | 151 | 152 | // 极验接口 153 | router.get("/api/gt/register-slide", function (req, res) { 154 | 155 | // 向极验申请每次验证所需的challenge 156 | slide.register(null, function (err, data) { 157 | 158 | if (err) { 159 | res.status(500); 160 | res.send(err); 161 | return; 162 | } 163 | 164 | if (!data.success) { 165 | // 进入 failback,如果一直进入此模式,请检查服务器到极验服务器是否可访问 166 | // 可以通过修改 hosts 把极验服务器 api.geetest.com 指到不可访问的地址 167 | 168 | // 为以防万一,你可以选择以下两种方式之一: 169 | 170 | // 1. 继续使用极验提供的failback备用方案 171 | req.session.fallback = true; 172 | res.send(data); 173 | 174 | // 2. 使用自己提供的备用方案 175 | // todo 176 | 177 | } else { 178 | // 正常模式 179 | req.session.fallback = false; 180 | res.send(data); 181 | } 182 | }); 183 | }); 184 | 185 | router.post("/api/gt/validate-slide", function (req, res) { 186 | 187 | // 对ajax提供的验证凭证进行二次验证 188 | slide.validate(req.session.fallback, { 189 | geetest_challenge: req.body.geetest_challenge, 190 | geetest_validate: req.body.geetest_validate, 191 | geetest_seccode: req.body.geetest_seccode 192 | }, function (err, success) { 193 | 194 | if (err) { 195 | // 网络错误 196 | res.send({ 197 | status: "error", 198 | info: err 199 | }); 200 | 201 | } else if (!success) { 202 | 203 | // 二次验证失败 204 | res.send({ 205 | status: "fail", 206 | info: '登录失败' 207 | }); 208 | } else { 209 | 210 | res.send({ 211 | status: "success", 212 | info: '登录成功' 213 | }); 214 | } 215 | }); 216 | }); 217 | 218 | 219 | module.exports = router; 220 | -------------------------------------------------------------------------------- /server/db.js: -------------------------------------------------------------------------------- 1 | //引用mongoose模块 2 | var mongoose = require('mongoose'); 3 | var moment = require('moment'); 4 | mongoose.Promise = global.Promise; 5 | //连接数据库 6 | mongoose.connect('mongodb://localhost/blogdata', {useMongoClient: true}) 7 | var db = mongoose.connection; 8 | db.once('error',() => console.log('Mongo 连接失败!')); 9 | db.once('open',() => console.log('mongodb 连接成功!')); 10 | 11 | // 创建对象定义集合结构类型(其实就是表结构) 12 | var testSchema = new mongoose.Schema({ 13 | title:String, 14 | author:String, 15 | date: { 16 | type: String, 17 | default: moment(Date.now()).format('YYYY-MM-DD HH:mm:ss') 18 | }, 19 | content:String 20 | }); 21 | 22 | //列表 23 | var List = mongoose.model('List',testSchema); 24 | 25 | module.exports = List; 26 | -------------------------------------------------------------------------------- /server/listrouter.js: -------------------------------------------------------------------------------- 1 | // 引入编写好的api 2 | const api = require('./api'); 3 | // 引入文件模块 4 | const fs = require('fs'); 5 | // 引入处理路径的模块 6 | const path = require('path'); 7 | // 引入处理post数据的模块 8 | const bodyParser = require('body-parser') 9 | // 引入Express 10 | const express = require('express'); 11 | 12 | const app = express(); 13 | 14 | app.use(bodyParser.json()); 15 | app.use(bodyParser.urlencoded({extended: false})); 16 | app.use(api); 17 | // 18 | // 19 | // // 访问静态资源文件 这里是访问所有dist目录下的静态资源文件 20 | // app.use(express.static(path.resolve(__dirname, '../pages'))) 21 | // 22 | // // 编辑页面 23 | // app.get('/newsedit', (req, res) => { 24 | // const html = fs.readFileSync(path.resolve(__dirname, '../html/newsedit.html'), 'utf-8') 25 | // res.send(html) 26 | // }) 27 | // 28 | // // 列表页面 29 | // app.get('/newslist', (req, res) => { 30 | // const html = fs.readFileSync(path.resolve(__dirname, '../html/newslist.html'), 'utf-8') 31 | // res.send(html) 32 | // }) 33 | // 34 | // // 详情面 35 | // app.get('/newsdetail/:id', (req, res) => { 36 | // const html = fs.readFileSync(path.resolve(__dirname, '../pages/user/one.vue'), 'utf-8') 37 | // res.send(html) 38 | // }) 39 | // 40 | // 41 | // // 爬虫页面 42 | // app.get('/spider/', (req, res) => { 43 | // const html = fs.readFileSync(path.resolve(__dirname, '../html/spider.html'), 'utf-8') 44 | // res.send(html) 45 | // }) 46 | 47 | 48 | // 监听3333端口 49 | app.listen(3000); 50 | -------------------------------------------------------------------------------- /server/slide.js: -------------------------------------------------------------------------------- 1 | var Geetest = require('gt3-sdk'); 2 | 3 | var captcha = new Geetest({ 4 | geetest_id: '7892109bbe367080435f3d73236488ce', 5 | geetest_key: '8ecabdbf93c69a933ea4582cd87905fe' 6 | }); 7 | 8 | module.exports = captcha; 9 | -------------------------------------------------------------------------------- /static/README.md: -------------------------------------------------------------------------------- 1 | # STATIC 2 | 3 | This directory contains your static files. 4 | Each file inside this directory is mapped to /. 5 | 6 | Example: /static/robots.txt is mapped as /robots.txt. 7 | 8 | More information about the usage of this directory in the documentation: 9 | https://nuxtjs.org/guide/assets#static 10 | 11 | **This directory is not required, you can delete it if you don't want to use it.** 12 | -------------------------------------------------------------------------------- /static/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ITCNZ/Nuxt-ssr/859fc73f5cbda1616ebbe431359b7dfc3b609d30/static/favicon.ico -------------------------------------------------------------------------------- /static/gt.js: -------------------------------------------------------------------------------- 1 | "v0.4.6 Geetest Inc."; 2 | 3 | (function (window) { 4 | "use strict"; 5 | if (typeof window === 'undefined') { 6 | throw new Error('Geetest requires browser environment'); 7 | } 8 | 9 | var document = window.document; 10 | var Math = window.Math; 11 | var head = document.getElementsByTagName("head")[0]; 12 | 13 | function _Object(obj) { 14 | this._obj = obj; 15 | } 16 | 17 | _Object.prototype = { 18 | _each: function (process) { 19 | var _obj = this._obj; 20 | for (var k in _obj) { 21 | if (_obj.hasOwnProperty(k)) { 22 | process(k, _obj[k]); 23 | } 24 | } 25 | return this; 26 | } 27 | }; 28 | 29 | function Config(config) { 30 | var self = this; 31 | new _Object(config)._each(function (key, value) { 32 | self[key] = value; 33 | }); 34 | } 35 | 36 | Config.prototype = { 37 | api_server: 'api.geetest.com', 38 | protocol: 'http://', 39 | typePath: '/gettype.php', 40 | fallback_config: { 41 | slide: { 42 | static_servers: ["static.geetest.com", "dn-staticdown.qbox.me"], 43 | type: 'slide', 44 | slide: '/static/js/geetest.0.0.0.js' 45 | }, 46 | fullpage: { 47 | static_servers: ["static.geetest.com", "dn-staticdown.qbox.me"], 48 | type: 'fullpage', 49 | fullpage: '/static/js/fullpage.0.0.0.js' 50 | } 51 | }, 52 | _get_fallback_config: function () { 53 | var self = this; 54 | if (isString(self.type)) { 55 | return self.fallback_config[self.type]; 56 | } else if (self.new_captcha) { 57 | return self.fallback_config.fullpage; 58 | } else { 59 | return self.fallback_config.slide; 60 | } 61 | }, 62 | _extend: function (obj) { 63 | var self = this; 64 | new _Object(obj)._each(function (key, value) { 65 | self[key] = value; 66 | }) 67 | } 68 | }; 69 | var isNumber = function (value) { 70 | return (typeof value === 'number'); 71 | }; 72 | var isString = function (value) { 73 | return (typeof value === 'string'); 74 | }; 75 | var isBoolean = function (value) { 76 | return (typeof value === 'boolean'); 77 | }; 78 | var isObject = function (value) { 79 | return (typeof value === 'object' && value !== null); 80 | }; 81 | var isFunction = function (value) { 82 | return (typeof value === 'function'); 83 | }; 84 | 85 | var callbacks = {}; 86 | var status = {}; 87 | 88 | var random = function () { 89 | return parseInt(Math.random() * 10000) + (new Date()).valueOf(); 90 | }; 91 | 92 | var loadScript = function (url, cb) { 93 | var script = document.createElement("script"); 94 | script.charset = "UTF-8"; 95 | script.async = true; 96 | 97 | script.onerror = function () { 98 | cb(true); 99 | }; 100 | var loaded = false; 101 | script.onload = script.onreadystatechange = function () { 102 | if (!loaded && 103 | (!script.readyState || 104 | "loaded" === script.readyState || 105 | "complete" === script.readyState)) { 106 | 107 | loaded = true; 108 | setTimeout(function () { 109 | cb(false); 110 | }, 0); 111 | } 112 | }; 113 | script.src = url; 114 | head.appendChild(script); 115 | }; 116 | 117 | var normalizeDomain = function (domain) { 118 | // special domain: uems.sysu.edu.cn/jwxt/geetest/ 119 | // return domain.replace(/^https?:\/\/|\/.*$/g, ''); uems.sysu.edu.cn 120 | return domain.replace(/^https?:\/\/|\/$/g, ''); // uems.sysu.edu.cn/jwxt/geetest 121 | }; 122 | var normalizePath = function (path) { 123 | path = path.replace(/\/+/g, '/'); 124 | if (path.indexOf('/') !== 0) { 125 | path = '/' + path; 126 | } 127 | return path; 128 | }; 129 | var normalizeQuery = function (query) { 130 | if (!query) { 131 | return ''; 132 | } 133 | var q = '?'; 134 | new _Object(query)._each(function (key, value) { 135 | if (isString(value) || isNumber(value) || isBoolean(value)) { 136 | q = q + encodeURIComponent(key) + '=' + encodeURIComponent(value) + '&'; 137 | } 138 | }); 139 | if (q === '?') { 140 | q = ''; 141 | } 142 | return q.replace(/&$/, ''); 143 | }; 144 | var makeURL = function (protocol, domain, path, query) { 145 | domain = normalizeDomain(domain); 146 | 147 | var url = normalizePath(path) + normalizeQuery(query); 148 | if (domain) { 149 | url = protocol + domain + url; 150 | } 151 | 152 | return url; 153 | }; 154 | 155 | var load = function (protocol, domains, path, query, cb) { 156 | var tryRequest = function (at) { 157 | 158 | var url = makeURL(protocol, domains[at], path, query); 159 | loadScript(url, function (err) { 160 | if (err) { 161 | if (at >= domains.length - 1) { 162 | cb(true); 163 | } else { 164 | tryRequest(at + 1); 165 | } 166 | } else { 167 | cb(false); 168 | } 169 | }); 170 | }; 171 | tryRequest(0); 172 | }; 173 | 174 | 175 | var jsonp = function (domains, path, config, callback) { 176 | if (isObject(config.getLib)) { 177 | config._extend(config.getLib); 178 | callback(config); 179 | return; 180 | } 181 | if (config.offline) { 182 | callback(config._get_fallback_config()); 183 | return; 184 | } 185 | 186 | var cb = "geetest_" + random(); 187 | window[cb] = function (data) { 188 | if (data.status == 'success') { 189 | callback(data.data); 190 | } else if (!data.status) { 191 | callback(data); 192 | } else { 193 | callback(config._get_fallback_config()); 194 | } 195 | window[cb] = undefined; 196 | try { 197 | delete window[cb]; 198 | } catch (e) { 199 | } 200 | }; 201 | load(config.protocol, domains, path, { 202 | gt: config.gt, 203 | callback: cb 204 | }, function (err) { 205 | if (err) { 206 | callback(config._get_fallback_config()); 207 | } 208 | }); 209 | }; 210 | 211 | var throwError = function (errorType, config) { 212 | var errors = { 213 | networkError: '网络错误', 214 | gtTypeError: 'gt字段不是字符串类型' 215 | }; 216 | if (typeof config.onError === 'function') { 217 | config.onError(errors[errorType]); 218 | } else { 219 | throw new Error(errors[errorType]); 220 | } 221 | }; 222 | 223 | var detect = function () { 224 | return window.Geetest || document.getElementById("gt_lib"); 225 | }; 226 | 227 | if (detect()) { 228 | status.slide = "loaded"; 229 | } 230 | 231 | window.initGeetest = function (userConfig, callback) { 232 | 233 | var config = new Config(userConfig); 234 | 235 | if (userConfig.https) { 236 | config.protocol = 'https://'; 237 | } else if (!userConfig.protocol) { 238 | config.protocol = window.location.protocol + '//'; 239 | } 240 | 241 | // for KFC 242 | if (userConfig.gt === '050cffef4ae57b5d5e529fea9540b0d1' || 243 | userConfig.gt === '3bd38408ae4af923ed36e13819b14d42') { 244 | config.apiserver = 'yumchina.geetest.com/'; // for old js 245 | config.api_server = 'yumchina.geetest.com'; 246 | } 247 | 248 | if (isObject(userConfig.getType)) { 249 | config._extend(userConfig.getType); 250 | } 251 | jsonp([config.api_server || config.apiserver], config.typePath, config, function (newConfig) { 252 | var type = newConfig.type; 253 | var init = function () { 254 | config._extend(newConfig); 255 | callback(new window.Geetest(config)); 256 | }; 257 | 258 | callbacks[type] = callbacks[type] || []; 259 | var s = status[type] || 'init'; 260 | if (s === 'init') { 261 | status[type] = 'loading'; 262 | 263 | callbacks[type].push(init); 264 | 265 | load(config.protocol, newConfig.static_servers || newConfig.domains, newConfig[type] || newConfig.path, null, function (err) { 266 | if (err) { 267 | status[type] = 'fail'; 268 | throwError('networkError', config); 269 | } else { 270 | status[type] = 'loaded'; 271 | var cbs = callbacks[type]; 272 | for (var i = 0, len = cbs.length; i < len; i = i + 1) { 273 | var cb = cbs[i]; 274 | if (isFunction(cb)) { 275 | cb(); 276 | } 277 | } 278 | callbacks[type] = []; 279 | } 280 | }); 281 | } else if (s === "loaded") { 282 | init(); 283 | } else if (s === "fail") { 284 | throwError('networkError', config); 285 | } else if (s === "loading") { 286 | callbacks[type].push(init); 287 | } 288 | }); 289 | 290 | }; 291 | 292 | 293 | })(window); 294 | -------------------------------------------------------------------------------- /store/README.md: -------------------------------------------------------------------------------- 1 | # STORE 2 | 3 | This directory contains your Vuex Store files. 4 | Vuex Store option is implemented in the Nuxt.js framework. 5 | Creating a index.js file in this directory activate the option in the framework automatically. 6 | 7 | More information about the usage of this directory in the documentation: 8 | https://nuxtjs.org/guide/vuex-store 9 | 10 | **This directory is not required, you can delete it if you don't want to use it.** 11 | -------------------------------------------------------------------------------- /store/index.js: -------------------------------------------------------------------------------- 1 | // import Api from '~/utils/api' 2 | import Cookie from 'js-cookie' 3 | 4 | export const state = () => ({ 5 | // isLogin: true 6 | }) 7 | 8 | export const mutations = { 9 | // SET_USER: function (state, flag) { 10 | // state.isLogin = flag 11 | // } 12 | } 13 | 14 | export const actions = { 15 | 16 | // isLoginFn(state) { 17 | // state.isLogin = true 18 | // }, 19 | 20 | // async login({ commit }, opts) { 21 | // try { 22 | // const { data } = await Api.login(opts) 23 | // Cookie.set('authUser', data) 24 | // } catch (error) { 25 | // if (error.response && error.response.status === 401) { 26 | // throw new Error('Bad credentials') 27 | // } 28 | // throw error 29 | // } 30 | // }, 31 | 32 | async logout({ commit }) { 33 | Cookie.remove('authUser') 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /utils/api.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 封装前端接口 3 | */ 4 | 5 | import Checkenv from "./checkenv"; 6 | import Net from "./net"; 7 | 8 | 9 | export default class { 10 | 11 | /** 12 | * 文章列表 13 | */ 14 | static newslist(pageIndex,pagesize){ 15 | return Net.postJSON(Checkenv.url.api + "/newslist/", {}, {pageIndex: pageIndex, pagesize: pagesize}); 16 | } 17 | 18 | /** 19 | * 删除文章 20 | */ 21 | static newsDelet(Id){ 22 | return Net.getJSON(Checkenv.url.api + "/newsdelet/" + Id); 23 | } 24 | 25 | /** 26 | * 创建文章 27 | */ 28 | static newsEdit(data){ 29 | return Net.postJSON(Checkenv.url.api + "/newsedit/", {}, data); 30 | } 31 | 32 | /** 33 | * 修改文章 34 | */ 35 | static reEdit(Id, data){ 36 | return Net.postJSON(Checkenv.url.api + "/newsedit/" + Id, {}, data); 37 | } 38 | 39 | /** 40 | * 获取单个文章 41 | */ 42 | static newsOne(Id){ 43 | return Net.getJSON(Checkenv.url.api + "/newsone/" + Id); 44 | } 45 | 46 | /** 47 | * 登录页面 48 | */ 49 | static login(data){ 50 | return Net.postJSON(Checkenv.url.api + "/login", {}, data); 51 | } 52 | 53 | /** 54 | * 登出页面 55 | */ 56 | static logout(){ 57 | return Net.postJSON(Checkenv.url.api + "/logout"); 58 | } 59 | 60 | 61 | /** 62 | * 急眼1 63 | */ 64 | static JiyanSlide(){ 65 | return Net.getJSON(Checkenv.url.api + "/gt/register-slide?t=" + (new Date()).getTime()); 66 | } 67 | 68 | /** 69 | * 急眼2 70 | */ 71 | static JiyanValidate(data){ 72 | return Net.postJSON(Checkenv.url.api + "/gt/validate-slide", {}, data); 73 | } 74 | 75 | 76 | 77 | } 78 | -------------------------------------------------------------------------------- /utils/checkenv.js: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * 环境检查 4 | * @param localEnv 5 | */ 6 | 7 | 8 | var checkCurrentEnv = function (localEnv, rt) { 9 | var SERVER = { 10 | url: { 11 | api : "/api" 12 | }, 13 | env: "" 14 | }; 15 | 16 | var root = ""; 17 | 18 | if(typeof window != 'undefined'){ 19 | root = window.location.origin; 20 | } 21 | else{ 22 | root = rt; 23 | } 24 | 25 | var env, localEnv, port; 26 | if (localEnv) { 27 | env = localEnv == "formal" ? "" : localEnv; 28 | } else { 29 | localEnv = "dev"; 30 | //当前加载环境 dev:开发环境 test:测试环境 "": 生产环境或本地 pre 预发布 31 | env = "localhost" 32 | // env = root.indexOf("localhost") != -1 ? "localhost" : root.indexOf("dev") != -1 ? "dev" : root.indexOf("test") != -1 ? "test" : root.indexOf("pre") != -1 ? "pre" : ""; 33 | } 34 | 35 | SERVER.env = env; 36 | //端口检查 37 | for (var obj in SERVER.url) { 38 | var envTemp = env == "" ? "" : env == "localhost" ? "localhost" : (env + "."); 39 | // port = envTemp != '' ? '' : ":3333"; 40 | port = ":3000"; 41 | //服务地址 42 | if(envTemp == "localhost") { 43 | SERVER.url[obj] = "http://localhost"+port+ SERVER.url[obj]; 44 | // SERVER.url[obj] = "http://47.104.245.86:3000"+ SERVER.url[obj]; 45 | } else { 46 | SERVER.url[obj] = "http://" +envTemp+ "itcnz.top"+port+ SERVER.url[obj]; 47 | } 48 | } 49 | return SERVER; 50 | } 51 | 52 | 53 | //当前加载环境 dev:开发环境 test:测试环境 "": 生产环境或本地 pre 预发布 54 | let SERVER = checkCurrentEnv(""); 55 | 56 | console.log('当前服务器地址....',SERVER); 57 | 58 | 59 | export default SERVER; 60 | -------------------------------------------------------------------------------- /utils/net.js: -------------------------------------------------------------------------------- 1 | import UI from "./ui"; 2 | import axios from 'axios' 3 | import qs from 'qs'; 4 | 5 | var Net = { 6 | 7 | getJSON: function (url, params, config) { 8 | return new Promise(function(resolve, reject){ 9 | 10 | axios.get(url, config) 11 | .then(function(res){ 12 | res.status == 200 ? resolve(res) : reject('错误:', res.status); 13 | }) 14 | .catch(function(err){ 15 | UI.toast("哎呀,网络连接出错啦"); 16 | reject(err); 17 | }) 18 | }); 19 | }, 20 | 21 | postJSON: function (url, params, data, config) { 22 | 23 | var i = 0; 24 | var isHasPraram; 25 | 26 | //检测url 27 | if (url.indexOf("?") != -1) { 28 | isHasPraram = true; 29 | } 30 | 31 | for (var o in params) { 32 | if (params[o] == undefined || params[o] == null) { 33 | continue; 34 | } 35 | if (i == 0 && !isHasPraram) { 36 | url += "?" + o + "=" + params[o]; 37 | } 38 | else { 39 | url += "&" + o + "=" + params[o]; 40 | } 41 | i++; 42 | } 43 | 44 | return new Promise(function(resolve, reject){ 45 | 46 | axios.post(url, qs.stringify(data), config) 47 | .then(function(res){ 48 | res.status == 200 ? resolve(res) : reject('错误:', res.status); 49 | }) 50 | .catch(function(err){ 51 | UI.toast("哎呀,网络连接出错啦"); 52 | reject(err); 53 | }) 54 | }); 55 | } 56 | 57 | } 58 | 59 | 60 | export default Net; 61 | -------------------------------------------------------------------------------- /utils/ui.js: -------------------------------------------------------------------------------- 1 | import { Message, MessageBox} from 'element-ui' 2 | 3 | var UI = { 4 | toast : function(message,type){ 5 | let option = { 6 | 'message' : message, 7 | 'duration' : 2200 8 | }; 9 | if(type == 'error'){ 10 | Message.error(option) 11 | } 12 | else if (type == "success"){ 13 | Message.success(option); 14 | } 15 | else if (type == "warning"){ 16 | Message.warning(option); 17 | } 18 | else{ 19 | Message.info(option); 20 | } 21 | }, 22 | 23 | confirm : function(ct,title,option){ 24 | return MessageBox.confirm(ct,title,{ 25 | confirmButtonText: option && option.confirmButtonText || '确定', 26 | cancelButtonText: option && option.cancelButtonText || '取消' 27 | }) 28 | }, 29 | 30 | alert : function(content){ 31 | return MessageBox.alert(content,'提示',{ 32 | confirmButtonText:'确定' 33 | }) 34 | } 35 | 36 | }; 37 | 38 | export default UI; 39 | --------------------------------------------------------------------------------