├── mock └── .gitkeep ├── .roadhogrc.mock.js ├── .gitignore ├── src ├── assets │ └── yay.jpg ├── services │ ├── example.js │ └── index.js ├── constants.js ├── index.css ├── models │ └── maintop.js ├── router.js ├── index.js ├── components │ └── MainLayout.js ├── routes │ └── IndexPage.js └── utils │ ├── tool.js │ └── request.js ├── README.md ├── .editorconfig ├── dist └── index.html ├── public └── index.html ├── .roadhogrc ├── .eslintrc └── package.json /mock/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.roadhogrc.mock.js: -------------------------------------------------------------------------------- 1 | 2 | export default { 3 | }; 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | .DS_Store 3 | npm-debug.log* 4 | -------------------------------------------------------------------------------- /src/assets/yay.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cowkeys/lsn-dva-ant/master/src/assets/yay.jpg -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # lsn-dva-ant 2 | # an ant-design front-end repo made by dva frame, can be used to init a front project 3 | -------------------------------------------------------------------------------- /src/services/example.js: -------------------------------------------------------------------------------- 1 | import request from '../utils/request'; 2 | 3 | export async function query() { 4 | return request('/api/users'); 5 | } 6 | -------------------------------------------------------------------------------- /src/constants.js: -------------------------------------------------------------------------------- 1 | export const PAGE_SIZE = 15; 2 | export const PAGE_SIZE_MAX = 50; 3 | export const PAGE_SIZE_M = 20; 4 | export const PAGE_SIZE_ERR = 20; 5 | -------------------------------------------------------------------------------- /src/index.css: -------------------------------------------------------------------------------- 1 | 2 | html, body, :global(#root) { 3 | height: 100%; 4 | background:#404040; 5 | } 6 | tbody { 7 | background-color:#fbfbfb; 8 | } 9 | 10 | 11 | -------------------------------------------------------------------------------- /src/services/index.js: -------------------------------------------------------------------------------- 1 | import request from '../utils/request'; 2 | 3 | export function fetch({search}) { 4 | return request(`/api/dash/statistics`,{ 5 | method: "POST", 6 | headers: {'Content-Type': 'application/json'}, 7 | body: JSON.stringify({search}), 8 | }); 9 | } 10 | 11 | 12 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # http://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | indent_style = space 6 | indent_size = 2 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 | 15 | [Makefile] 16 | indent_style = tab 17 | -------------------------------------------------------------------------------- /src/models/maintop.js: -------------------------------------------------------------------------------- 1 | 2 | export default { 3 | 4 | namespace: 'maintop', 5 | 6 | state:{ 7 | conns:0, 8 | }, 9 | 10 | reducers: { 11 | conns(state, { payload: { conns=0 } }) { 12 | return { ...state,conns }; 13 | }, 14 | }, 15 | effects: {}, 16 | }; 17 | 18 | 19 | -------------------------------------------------------------------------------- /src/router.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { Router, Route } from 'dva/router'; 3 | import IndexPage from './routes/IndexPage'; 4 | 5 | function RouterConfig({ history }) { 6 | return ( 7 | 8 | 9 | 10 | ); 11 | } 12 | 13 | export default RouterConfig; 14 | -------------------------------------------------------------------------------- /dist/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | DashBoard 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | DashBoard 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import dva from 'dva'; 2 | import './index.css'; 3 | import createLoading from 'dva-loading'; 4 | // 1. Initialize 5 | const app = dva({}); 6 | // 2. Plugins 7 | // app.use({}); 8 | app.use(createLoading()); 9 | // 3. Model 10 | app.model(require('./models/maintop')); 11 | // 4. Router 12 | app.router(require('./router')); 13 | 14 | // 5. Start 15 | app.start('#root'); 16 | -------------------------------------------------------------------------------- /src/components/MainLayout.js: -------------------------------------------------------------------------------- 1 | import { connect } from 'dva'; 2 | 3 | const MainLayout = (prop) => { 4 | const {conns} = prop 5 | return ( 6 |
7 | Welcome : {conns} 8 |
9 | ); 10 | }; 11 | 12 | function mapStateToProps(state) { 13 | const { conns } = state.maintop; 14 | return { 15 | conns, 16 | }; 17 | } 18 | 19 | export default connect(mapStateToProps)(MainLayout); 20 | 21 | -------------------------------------------------------------------------------- /src/routes/IndexPage.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { connect } from 'dva'; 3 | import MainLayout from '../components/MainLayout' 4 | import io from 'socket.io-client' 5 | var socket = io(); 6 | const IndexPage = (prop) => { 7 | socket.on('conns', function (conns) { 8 | console.log('conn:',conns); 9 | }); 10 | return ( 11 | 12 | 13 | ); 14 | }; 15 | 16 | export default connect()(IndexPage); 17 | -------------------------------------------------------------------------------- /.roadhogrc: -------------------------------------------------------------------------------- 1 | { 2 | "entry": "src/index.js", 3 | "outputPath": "/Users/liushunan/noderepo/mdnweb/public", 4 | "env": { 5 | "development": { 6 | "extraBabelPlugins": [ 7 | "dva-hmr", 8 | "transform-runtime", 9 | ["import", { "libraryName": "antd", "style": "css" }] 10 | ] 11 | }, 12 | "production": { 13 | "extraBabelPlugins": [ 14 | "transform-runtime", 15 | ["import", { "libraryName": "antd", "style": "css" }] 16 | ] 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "parser": "babel-eslint", 3 | "extends": "airbnb", 4 | "rules": { 5 | "generator-star-spacing": [0], 6 | "consistent-return": [0], 7 | "react/forbid-prop-types": [0], 8 | "react/jsx-filename-extension": [1, { "extensions": [".js"] }], 9 | "global-require": [1], 10 | "import/prefer-default-export": [0], 11 | "react/jsx-no-bind": [0], 12 | "react/prop-types": [0], 13 | "react/prefer-stateless-function": [0], 14 | "no-else-return": [0], 15 | "no-restricted-syntax": [0], 16 | "import/no-extraneous-dependencies": [0], 17 | "no-use-before-define": [0], 18 | "jsx-a11y/no-static-element-interactions": [0], 19 | "no-nested-ternary": [0], 20 | "arrow-body-style": [0], 21 | "import/extensions": [0], 22 | "no-bitwise": [0], 23 | "no-cond-assign": [0], 24 | "import/no-unresolved": [0], 25 | "require-yield": [1] 26 | }, 27 | "parserOptions": { 28 | "ecmaFeatures": { 29 | "experimentalObjectRestSpread": true 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "scripts": { 4 | "start": "roadhog server", 5 | "build": "roadhog build", 6 | "lint": "eslint --ext .js src test", 7 | "precommit": "npm run lint" 8 | }, 9 | "engines": { 10 | "install-node": "6.9.2" 11 | }, 12 | "dependencies": { 13 | "antd": "^2.9.1", 14 | "babel-plugin-import": "^1.1.1", 15 | "babel-runtime": "^6.9.2", 16 | "dva": "^1.2.1", 17 | "dva-loading": "^0.2.1", 18 | "moment": "^2.18.1", 19 | "node-schedule": "^1.2.3", 20 | "react": "^15.4.0", 21 | "react-dom": "^15.4.0", 22 | "socket.io": "^2.0.1", 23 | "socket.io-client": "^2.0.1" 24 | }, 25 | "devDependencies": { 26 | "babel-eslint": "^7.1.1", 27 | "babel-plugin-dva-hmr": "^0.3.2", 28 | "babel-plugin-import": "^1.1.1", 29 | "babel-plugin-transform-runtime": "^6.9.0", 30 | "eslint": "^3.12.2", 31 | "eslint-config-airbnb": "^13.0.0", 32 | "eslint-plugin-import": "^2.2.0", 33 | "eslint-plugin-jsx-a11y": "^2.2.3", 34 | "eslint-plugin-react": "^6.8.0", 35 | "expect": "^1.20.2", 36 | "husky": "^0.12.0", 37 | "redbox-react": "^1.3.2", 38 | "roadhog": "^0.5.2" 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/utils/tool.js: -------------------------------------------------------------------------------- 1 | import moment from 'moment' 2 | 3 | module.exports = { 4 | timeFromUnix : function(u = "0") { 5 | if (!u) { 6 | return ""; 7 | } 8 | if (u=="0"){ 9 | return ""; 10 | } 11 | return moment.unix(u).format('YYYY-MM-DD HH:mm:ss'); 12 | }, 13 | unixToMoment:function(u = "0") { 14 | if (!u) { 15 | return null 16 | } 17 | return moment.unix(u) 18 | }, 19 | timeFromUnixMs : function(u = "0") { 20 | if (!u) { 21 | return ""; 22 | } 23 | if (u=="0") { 24 | return ""; 25 | } 26 | var day = moment(+u); 27 | var res = day.format('YYYY-MM-DD HH:mm:ss.SSSS'); 28 | return res; 29 | }, 30 | timeDiff : function(begin="0",real="0") { 31 | var begintime = moment(+begin); 32 | var realtime = moment(+real); 33 | var diftime = realtime.diff(begintime); 34 | return diftime; 35 | }, 36 | trim:function(value) { 37 | if (!String.prototype.trim) { 38 | String.prototype.trim = function () { 39 | return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, ''); 40 | }; 41 | } 42 | if (value){ 43 | return value.trim(); 44 | } 45 | return ""; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/utils/request.js: -------------------------------------------------------------------------------- 1 | import fetch from 'dva/fetch'; 2 | import { message } from 'antd'; 3 | 4 | function parseJSON(response) { 5 | return response.json(); 6 | } 7 | 8 | function checkStatus(response) { 9 | 10 | if (response.status >= 200 && response.status < 300) { 11 | return response; 12 | } 13 | 14 | const error = new Error(response.statusText||"errparseError"); 15 | error.response = response; 16 | throw error; 17 | } 18 | 19 | /** 20 | * Requests a URL, returning a promise. 21 | * 22 | * @param {string} url The URL we want to request 23 | * @param {object} [options] The options we want to pass to "fetch" 24 | * @return {object} An object containing either "data" or "err" 25 | */ 26 | export default function request(url, options={},tip = false) { 27 | options = { 28 | ...options, 29 | credentials: 'include', 30 | } 31 | return fetch(url, options) 32 | .then(checkStatus) 33 | .then(parseJSON) 34 | .then(function(data) { 35 | if (tip&&data.err) { 36 | message.error(" 错误! ",10); 37 | console.log(url," 错误! ",new Date() +' : ',data.err); 38 | } 39 | if (tip&&!data.err) { 40 | message.success("操作成功!",5); 41 | } 42 | return {data} 43 | }) 44 | .catch(function(err) { 45 | message.error("出现错误!"); 46 | console.log("错误!catch | ",new Date() +' : ',err); 47 | return {err} 48 | }) 49 | } 50 | --------------------------------------------------------------------------------