diff --git a/src/components/Layout/Footer/index.js b/src/components/Layout/Footer/index.js deleted file mode 100644 index c701b83..0000000 --- a/src/components/Layout/Footer/index.js +++ /dev/null @@ -1,17 +0,0 @@ -import React from 'react'; -import {BackTop} from 'antd'; -import {config} from '../../utils/lib.js' - -const Footer = React.createClass({ - render() { - return ( -
-
- {config.footer} -
-
- ) - } -}) - -export default Footer; diff --git a/src/components/Layout/Header/index.js b/src/components/Layout/Header/index.js deleted file mode 100644 index 6c96ad4..0000000 --- a/src/components/Layout/Header/index.js +++ /dev/null @@ -1,29 +0,0 @@ -import React from 'react'; -import { Icon, Menu, Dropdown } from 'antd'; -import { config, ajax, signOut } from '../../utils/lib.js' -import './index.less'; - -const SubMenu = Menu.SubMenu; - -const Header = React.createClass({ - signOut(){ - ajax({ - url:config.user.signOut - }) - }, - render() { - return ( -
- - {this.props.userName}}> - - 注销 - - - -
- ); - } -}) - -module.exports = Header diff --git a/src/components/Layout/Header/index.less b/src/components/Layout/Header/index.less deleted file mode 100644 index 1f32a43..0000000 --- a/src/components/Layout/Header/index.less +++ /dev/null @@ -1,8 +0,0 @@ -.ant-layout-header { - background: #fff; - .header-menu { - > li { - float: right; - } - } -} diff --git a/src/components/layout/footer.jsx b/src/components/layout/footer.jsx index 0999137..fd8dbfe 100644 --- a/src/components/layout/footer.jsx +++ b/src/components/layout/footer.jsx @@ -1,10 +1,11 @@ import React, {PropTypes} from 'react' import styles from './main.less' +import {config} from '../../utils' function Footer({location}) { return (
- 底部 + {config.footerText}
) } diff --git a/src/components/layout/main.less b/src/components/layout/main.less index d27695a..75135fe 100644 --- a/src/components/layout/main.less +++ b/src/components/layout/main.less @@ -16,7 +16,7 @@ height: 40px; line-height: 40px; cursor: pointer; - margin: 16px 0; + margin: 28px 0; img { width: 40px; diff --git a/src/components/layout/sider.jsx b/src/components/layout/sider.jsx index e4a218e..42a6888 100644 --- a/src/components/layout/sider.jsx +++ b/src/components/layout/sider.jsx @@ -1,49 +1,47 @@ -import React, { PropTypes } from 'react' -import { Menu, Icon } from 'antd' +import React, {PropTypes} from 'react' +import {Menu, Icon} from 'antd' +import { Link } from 'dva/router' import styles from './main.less' +import {config, menu} from '../../utils' -const SubMenu = Menu.SubMenu; -const MenuItemGroup = Menu.ItemGroup; +const getMenus = function (menuArray,parentPath){ + parentPath = parentPath || '/' + return menuArray.map(item =>{ + if(!!item.child){ + return ( + {item.icon ? : ''} {item.name}}> + {getMenus(item.child,parentPath + item.key + '/')} + + ) + }else { + return ( + + + {item.icon ? : ''} + {item.name} + + + ) + } + }) +} -function Sider({ location }) { +function Sider({location}) { return (
- - Ant Design -
- - Navigation One}> - - Option 1 - Option 2 - - - Option 3 - Option 4 - - - Navigation Two}> - Option 5 - Option 6 - - Option 7 - Option 8 - - - Navigation Three}> - Option 9 - Option 10 - Option 11 - Option 12 - - + + {config.logoText} +
+ + {getMenus(menu)} + ) } Sider.propTypes = { - location: PropTypes.object, + location: PropTypes.object } export default Sider diff --git a/src/config.js b/src/config.js deleted file mode 100644 index 7bdabcc..0000000 --- a/src/config.js +++ /dev/null @@ -1,21 +0,0 @@ -module.exports = { - name: 'Ant Design 管理后台', - footer: 'Ant Design Admin 版权所有 © 2016 由 zuiidea 支持', - logoImg:'https://t.alipayobjects.com/images/rmsweb/T1B9hfXcdvXXXXXXXX.svg', - logoText:'Ant Design', - debug: true, - logLevel: 'debug', - needLogin:true, - - api: { - host: 'http://localhost:8080', - path: '/api', - timeout: 15000, - }, - - user: { - info: '/getInfo', - signIn: '/signIn', - signOut:'/signOut', - }, -}; diff --git a/src/index.html b/src/index.html index f65f403..72385cf 100644 --- a/src/index.html +++ b/src/index.html @@ -2,7 +2,7 @@ - Demo + Ant Design Admin diff --git a/src/index.js b/src/index.js index b2fb758..62bf7d3 100644 --- a/src/index.js +++ b/src/index.js @@ -1,5 +1,4 @@ import './index.html' -import './index.less' import dva from 'dva' // 1. Initialize diff --git a/src/index.less b/src/index.less deleted file mode 100644 index a85bb0d..0000000 --- a/src/index.less +++ /dev/null @@ -1,29 +0,0 @@ -.normal { - width: 200px; - margin: 100px auto; - padding: 20px; - border: 1px solid #ccc; - box-shadow: 0 0 20px #ccc; -} - -.record { - border-bottom: 1px solid #ccc; - padding-bottom: 8px; - color: #ccc; -} - -.current { - text-align: center; - font-size: 40px; - padding: 40px 0; -} - -.button { - text-align: center; - button { - width: 100px; - height: 40px; - background: #aaa; - color: #fff; - } -} diff --git a/src/menu.js b/src/menu.js deleted file mode 100644 index ff69a4a..0000000 --- a/src/menu.js +++ /dev/null @@ -1,118 +0,0 @@ -module.exports = [ - { - key: 'dashboard', - name: '仪表盘', - icon: 'laptop' - }, - { - key: 'index', - name: '数据相关', - icon: 'file-text', - child: [ - { - key: 'list', - name: '数据列表', - }, - ], - }, - { - key: 'navigation', - name: '测试导航', - icon: 'setting', - child: [ - { - key: 'navigation1', - name: '二级导航1', - }, - { - key: 'navigation2', - name: '二级导航2', - child: [ - { - key: 'navigation21', - name: '三级导航1', - }, - { - key: 'navigation22', - name: '三级导航2', - }, - ], - }, - ], - }, - // { - // key: 'test', - // name: '菜单三', - // icon: 'laptop', - // child: [ - // { - // key: 'aaa', - // name: '选项a', - // }, - // { - // key: 'bbb', - // name: '选项b', - // }, - // { - // key: 'ccc', - // name: '选项c', - // }, - // { - // key: 'sanjiaaa', // 最多只能到三级导航 - // name: '三级导航aaa', - // child: [ - // { - // key: '666aa', - // name: '选项6', - // }, - // ], - // }, - // { - // key: 'sanjibbb', // 最多只能到三级导航 - // name: '三级导航bbb', - // child: [ - // { - // key: '666bb', - // name: '选项6', - // }, - // ], - // }, - // ], - // }, - // { - // key: 'menu4', - // name: '菜单四', - // icon: 'notification', - // child: [ - // { - // key: 'menu4', - // name: '菜单四一', - // }, - // ], - // }, - // { - // key: 'menu5', - // name: '菜单五', - // icon: 'folder', - // child: [ - // { - // key: 'menu51', - // name: '菜单五一', - // }, - // { - // key: 'menu52', - // name: '菜单五二', - // }, - // { - // key: 'menu53', - // name: '菜单五三', - // child: [ - // { - // key: 'menu531', - // name: '菜单五三一', - // }, - // ], - // }, - // ], - // }, -]; diff --git a/src/routes/dashboard.jsx b/src/routes/dashboard.jsx index c1e4984..14b6434 100644 --- a/src/routes/dashboard.jsx +++ b/src/routes/dashboard.jsx @@ -1,14 +1,13 @@ import React, { PropTypes } from 'react' import { Link } from 'dva/router' import Main from '../components/layout/main' -import styles from './app.less' function Dashboard() { return ( -
+

Hello Antd.


-
diff --git a/src/services/users.js b/src/services/users.js index 56b20bc..35c5376 100644 --- a/src/services/users.js +++ b/src/services/users.js @@ -1,4 +1,4 @@ -import request from '../utils/request' +import { request } from '../utils' import qs from 'qs' export async function query(params) { diff --git a/src/utils/Logger.js b/src/utils/Logger.js deleted file mode 100644 index 87d180c..0000000 --- a/src/utils/Logger.js +++ /dev/null @@ -1,107 +0,0 @@ -import config from '../config' - -class Logger { - - static LOG_LEVEL_DEBUG = 1 - static LOG_LEVEL_INFO = 2 - static LOG_LEVEL_WARN = 3 - static LOG_LEVEL_ERROR = 4 - - static loggerMap = new Map() - - static defaultLogger = new Logger() - - static getLogger(name) { - if (name && name !== '') { - if (Logger.loggerMap.has(name)) { - return Logger.loggerMap.get(name) - } - const logger = new Logger(name) - Logger.loggerMap.set(name, logger) - return logger - } else { - return Logger.defaultLogger - } - } - - constructor(name) { - this.name = name - const configLogLevel = config.logLevel - - if (configLogLevel === 'debug') { - this.logLevel = Logger.LOG_LEVEL_DEBUG - } else if (configLogLevel === 'info') { - this.logLevel = Logger.LOG_LEVEL_INFO - } else if (configLogLevel === 'warn') { - this.logLevel = Logger.LOG_LEVEL_WARN - } else if (configLogLevel === 'error') { - this.logLevel = Logger.LOG_LEVEL_ERROR - } else { - this.error('unsupported logLevel: %s, use INFO instead', configLogLevel) - this.logLevel = Logger.LOG_LEVEL_INFO - } - } - - setLogLevel(newLogLevel) { - if (isNaN(newLogLevel)) { - this.error('setLogLevel error, not a number: %s', newLogLevel) - } - if (newLogLevel < 1 || newLogLevel > 4) { - this.error('setLogLevel error, input = %s, must between 1 and 4', newLogLevel) - } - this.logLevel = newLogLevel - } - - info(pattern, ...args) { - if (this.logLevel > Logger.LOG_LEVEL_INFO) { - return - } - if (this.name) { - args.unshift(`${this.name}: ${pattern}`) - } else { - args.unshift(pattern) - console.log.apply(console, args) - } - } - - error(pattern, ...args) { - if (this.logLevel > Logger.LOG_LEVEL_ERROR) { - return - } - args.unshift('background: red color: #bada55') - if (this.name) { - args.unshift(`%c${this.name}: ${pattern}`) - } else { - args.unshift(`%c${pattern}`) - console.error.apply(console, args) - } - } - - debug(pattern, ...args) { - if (this.logLevel > Logger.LOG_LEVEL_DEBUG) { - return - } - args.unshift('background: black color: #bada55') - if (this.name) { - args.unshift(`%c${this.name}: ${pattern}`) - } else { - args.unshift(`%c${pattern}`) - console.debug.apply(console, args) - } - } - - warn(pattern, ...args) { - if (this.logLevel > Logger.LOG_LEVEL_WARN) { - return - } - args.unshift('background: yellow color: black') - if (this.name) { - args.unshift(`%c${this.name}: ${pattern}`) - } else { - args.unshift(`%c${pattern}`) - console.warn.apply(console, args) - } - } -} - -export default Logger diff --git a/src/utils/config.js b/src/utils/config.js new file mode 100644 index 0000000..d3dd761 --- /dev/null +++ b/src/utils/config.js @@ -0,0 +1,7 @@ +module.exports = { + name: 'Ant Design Admin', + footerText: 'Ant Design Admin 版权所有 © 2016 由 zuiidea 支持', + logoSrc:'https://t.alipayobjects.com/images/rmsweb/T1B9hfXcdvXXXXXXXX.svg', + logoText:'Antd Admin', + needLogin:true, +}; diff --git a/src/utils/index.js b/src/utils/index.js index 1e3fe05..b977539 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -1,53 +1,9 @@ -/** 对Date的扩展,将 Date 转化为指定格式的String * 月(M)、日(d)、12小时(h)、24小时(H)、分(m)、秒(s)、周(E)、季度(q) - * 可以用 1-2 个占位符 * 年(y)可以用 1-4 个占位符,毫秒(S)只能用 1 个占位符(是 1-3 位的数字) - * eg: - * (new Date()).format("yyyy-MM-dd hh:mm:ss.S")==> 2006-07-02 08:09:04.423 - * (new Date()).format("yyyy-MM-dd E HH:mm:ss") ==> 2009-03-10 二 20:09:04 - * (new Date()).format("yyyy-MM-dd EE hh:mm:ss") ==> 2009-03-10 周二 08:09:04 - * (new Date()).format("yyyy-MM-dd EEE hh:mm:ss") ==> 2009-03-10 星期二 08:09:04 - * (new Date()).format("yyyy-M-d h:m:s.S") ==> 2006-7-2 8:9:4.18 - */ -Date.prototype.format = function (fmt) { - var o = { - "M+": this.getMonth() + 1, - "d+": this.getDate(), - "h+": this.getHours() % 12 == 0 ? 12 : this.getHours() % 12, - "H+": this.getHours(), - "m+": this.getMinutes(), - "s+": this.getSeconds(), - "q+": Math.floor((this.getMonth() + 3) / 3), - "S": this.getMilliseconds() - }; - var week = { - "0": "/u65e5", - "1": "/u4e00", - "2": "/u4e8c", - "3": "/u4e09", - "4": "/u56db", - "5": "/u4e94", - "6": "/u516d" - }; - if (/(y+)/.test(fmt)) { - fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length)); - } - if (/(E+)/.test(fmt)) { - fmt = fmt.replace(RegExp.$1, ((RegExp.$1.length > 1) ? (RegExp.$1.length > 2 ? "/u661f/u671f" : "/u5468") : "") + week[this.getDay() + ""]); - } - for (var k in o) { - if (new RegExp("(" + k + ")").test(fmt)) { - fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length))); - } - } - return fmt; -}; +import config from './config' +import menu from './menu' +import request from './request' -/** - * 在当前日期的基础上再增加几天 - * - * @param num 要增加的天数 - */ -Date.prototype.plusDays = function (num) { - var tmp = new Date(); - tmp.setDate(this.getDate() + num); - return tmp; -}; +module.exports = { + config, + menu, + request, +} diff --git a/src/utils/lib.js b/src/utils/lib.js deleted file mode 100644 index 007ed59..0000000 --- a/src/utils/lib.js +++ /dev/null @@ -1,58 +0,0 @@ -import config from 'config' -import Logger from './logger' -import reqwest from 'reqwest' - -function ajax(data){ - - if(config.debug && data.url.indexOf('http')<0){ - setTimeout(function(){ - if(data.url==config.user.info){ - if(localStorage.getItem("username")&&localStorage.getItem("username")=="guest"&& - localStorage.getItem("password")&&localStorage.getItem("password")=='guest'){ - data.success({ - message:'登录成功', - isSuccess:true, - userName:"guest" - }) - }else { - data.success({ - message:'获取信息成功', - isSuccess:false, - userName:"guest" - }) - } - - }else if (data.url==config.user.signIn) { - if(data.complete){ - data.complete() - } - if(data.data.username=='guest'&&data.data.password=='guest'){ - localStorage.setItem("username","guest") - localStorage.setItem("password","guest") - data.success({ - message:'登录成功', - isSuccess:true, - userName:"guest" - }) - }else { - data.success({ - message:'密码错误', - isSuccess:false - }) - } - }else if (data.url==config.user.signOut) { - localStorage.removeItem("username") - localStorage.removeItem("password") - location.reload() - } - },500) - }else { - reqwest(data) - } -} - -module.exports = { - config, - ajax, - Logger -} diff --git a/src/utils/lib.less b/src/utils/lib.less deleted file mode 100644 index 80b04d2..0000000 --- a/src/utils/lib.less +++ /dev/null @@ -1,52 +0,0 @@ -@import "./utility.less"; - -// table -.ant-table { - .ant-table-thead > tr > th { - text-align: center; - } - - td { - text-align: center; - } -} -.ant-table-small .ant-table-body > table{ - padding: 0; -} - -.ant-table-pagination { - float: none; - display: table; - margin: 16px auto; -} - - -// scrollbar -::-webkit-scrollbar-corner { - background-color: transparent; -} - -::-webkit-scrollbar-button { - width: 0; - height: 0; - display: none; -} - -::-webkit-scrollbar-thumb { - width: 7px; - background-color: #b4babf; - border-radius: 7px; -} - -::-webkit-scrollbar { - width: 7px; - height: 7px; -} - -::-webkit-scrollbar-track { - width: 15px; -} - -::-webkit-scrollbar:hover { - background-color: transparent; -} diff --git a/src/utils/menu.js b/src/utils/menu.js new file mode 100644 index 0000000..a58b829 --- /dev/null +++ b/src/utils/menu.js @@ -0,0 +1,37 @@ +module.exports = [ + { + key: 'dashboard', + name: '仪表盘', + icon: 'laptop' + }, + { + key: 'users', + name: '用户管理', + icon: 'user', + }, + { + key: 'navigation', + name: '测试导航', + icon: 'setting', + child: [ + { + key: 'navigation1', + name: '二级导航1', + }, + { + key: 'navigation2', + name: '二级导航2', + child: [ + { + key: 'navigation21', + name: '三级导航1', + }, + { + key: 'navigation22', + name: '三级导航2', + }, + ], + }, + ], + }, +];