From a85277ea82da737a7f4187fef0eb9b843597d864 Mon Sep 17 00:00:00 2001 From: zuiidea Date: Mon, 27 Mar 2017 15:09:36 +0800 Subject: [PATCH 1/3] adjust components DataTable --- src/components/DataTable/DataTable.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/components/DataTable/DataTable.js b/src/components/DataTable/DataTable.js index 542080b..9a15473 100644 --- a/src/components/DataTable/DataTable.js +++ b/src/components/DataTable/DataTable.js @@ -66,6 +66,9 @@ class DataTable extends React.Component { ...fetchData, }, }).then((result) => { + if (!this.refs.DataTable) { + return + } const { pagination } = this.state pagination.total = result.total || pagination.total this.setState({ @@ -81,6 +84,7 @@ class DataTable extends React.Component { const { loading, dataSource, pagination } = this.state return ( Date: Mon, 27 Mar 2017 15:25:41 +0800 Subject: [PATCH 2/3] adjust dasheboard --- mock/dashboard.js | 349 ++++++++++++++++++++++++++++++---------------- 1 file changed, 225 insertions(+), 124 deletions(-) diff --git a/mock/dashboard.js b/mock/dashboard.js index 489529c..ed62e19 100644 --- a/mock/dashboard.js +++ b/mock/dashboard.js @@ -1,129 +1,230 @@ -import { color } from '../src/utils/theme' -const Mock = require('mockjs') -import mockStorge from '../src/utils/mockStorge' +import { myCity, queryWeather, query } from '../services/dashboard' +import { parse } from 'qs' -let dataKey = mockStorge('Dashboard', Mock.mock({ - 'sales|8': [ - { - 'name|+1': 2008, - 'Clothes|200-500': 1, - 'Food|180-400': 1, - 'Electronics|300-550': 1, - }, - ], - cpu: { - 'usage|50-600': 1, - space: 825, - 'cpu|40-90': 1, - 'data|20': [ - { - 'cpu|20-80': 1, - }, - ], +// zuimei 摘自 http://www.zuimeitianqi.com/res/js/index.js +let zuimei = { + parseActualData (actual) { + let weather = { + icon: `http://www.zuimeitianqi.com/res/icon/${zuimei.getIconName(actual.wea, 'big')}`, + name: zuimei.getWeatherName(actual.wea), + temperature: actual.tmp, + dateTime: new Date(actual.PTm).format('MM-dd hh:mm'), + } + return weather }, - browser: [ - { - name: 'Google Chrome', - percent: 43.3, - status: 1, - }, - { - name: 'Mozilla Firefox', - percent: 33.4, - status: 2, - }, - { - name: 'Apple Safari', - percent: 34.6, - status: 3, - }, - { - name: 'Internet Explorer', - percent: 12.3, - status: 4, - }, - { - name: 'Opera Mini', - percent: 3.3, - status: 1, - }, - { - name: 'Chromium', - percent: 2.53, - status: 1, - }, - ], - user: { - name: 'zuiidea', - email: 'zuiiidea@.gmail.com', - sales: 3241, - sold: 3556, - avatar: 'http://tva4.sinaimg.cn/crop.0.0.996.996.180/6ee6a3a3jw8f0ks5pk7btj20ro0rodi0.jpg', - }, - 'completed|12': [ - { - 'name|+1': 2008, - 'Task complete|200-1000': 1, - 'Cards Complete|200-1000': 1, - }, - ], - 'comments|5': [ - { - name: '@last', - 'status|1-3': 1, - content: '@sentence', - avatar () { - return Mock.Random.image('48x48', Mock.Random.color(), '#757575', 'png', this.name.substr(0, 1)) - }, - date () { - return `2016-${Mock.Random.date('MM-dd')} ${Mock.Random.time('HH:mm:ss')}` - }, - }, - ], - 'recentSales|36': [ - { - 'id|+1': 1, - name: '@last', - 'status|1-4': 1, - date () { - return `${Mock.Random.integer(2015, 2016)}-${Mock.Random.date('MM-dd')} ${Mock.Random.time('HH:mm:ss')}` - }, - 'price|10-200.1-2': 1, - }, - ], - quote: { - name: 'Joho Doe', - title: 'Graphic Designer', - content: 'I\'m selfish, impatient and a little insecure. I make mistakes, I am out of control and at times hard to handle. But if you can\'t handle me at my worst, then you sure as hell don\'t deserve me at my best.', - avatar: 'http://img.hb.aicdn.com/bc442cf0cc6f7940dcc567e465048d1a8d634493198c4-sPx5BR_fw236', - }, - numbers: [ - { - icon: 'pay-circle-o', - color: color.green, - title: 'Online Review', - number: 2781, - }, { - icon: 'team', - color: color.blue, - title: 'New Customers', - number: 3241, - }, { - icon: 'message', - color: color.purple, - title: 'Active Projects', - number: 253, - }, { - icon: 'shopping-cart', - color: color.red, - title: 'Referrals', - number: 4324, - }, - ], -})) -module.exports = { - 'GET /api/dashboard' (req, res) { - res.json(global[dataKey]) + getIconName (wea, flg) { + let myDate = new Date() + let hour = myDate.getHours() + let num = 0 + if (wea.indexOf('/') !== -1) { + let weas = wea.split('/') + if (hour < 12) { + num = zuimei.replaceIcon(weas[0]) + if (num < 6) { + num = `${num}_${flg}_night.png` + } else { + num = `${num}_${flg}.png` + } + } else if (hour >= 12) { + num = zuimei.replaceIcon(weas[1]) + if (hour >= 18) { + num = `${num}_${flg}_night.png` + } else { + num = `${num}_${flg}.png` + } + } + } else { + if ((hour >= 18 && hour <= 23) || (hour >= 0 && hour <= 6)) { + num = `${num}_${flg}_night.png` + } else { + num = `${num}_${flg}.png` + } + } + + return num + }, + + replaceIcon (num) { + if (num === 21) { + num = 7 + } else if (num === 22) { + num = 8 + } else if (num === 10 || num === 11 || num === 12 || num === 23 || num === 24 || num === 25) { + num = 9 + } else if (num === 13 || num === 15 || num === 26 || num === 27 || num === 34) { + num = 14 + } else if (num === 17 || num === 28) { + num = 16 + } else if (num === 35) { + num = 18 + } else if (num === 31 || num === 32 || num === 33) { + num = 20 + } else if (num === 30) { + num = 29 + } + + return num + }, + + getWeatherName (wea) { + let name = '' + if (wea.indexOf('/') !== -1) { + let weas = wea.split('/') + name = `${zuimei.getWeatherByCode(weas[0])}转${zuimei.getWeatherByCode(weas[1])}` + } else { + name = zuimei.getWeatherByCode(wea) + } + + return name + }, + + getWeatherByCode (num) { + let wea = '' + if (num === 0) { + wea = '晴' + } else if (num === 1) { + wea = '多云' + } else if (num === 2) { + wea = '阴' + } else if (num === 3) { + wea = '阵雨' + } else if (num === 4) { + wea = '雷阵雨' + } else if (num === 5) { + wea = '雷阵雨并伴有冰雹' + } else if (num === 6) { + wea = '雨夹雪' + } else if (num === 7) { + wea = '小雨' + } else if (num === 8) { + wea = '中雨' + } else if (num === 9) { + wea = '大雨' + } else if (num === 10) { + wea = '暴雨' + } else if (num === 11) { + wea = '大暴雨' + } else if (num === 12) { + wea = '特大暴雨' + } else if (num === 13) { + wea = '阵雪' + } else if (num === 14) { + wea = '小雪' + } else if (num === 15) { + wea = '中雪' + } else if (num === 16) { + wea = '大雪' + } else if (num === 17) { + wea = '暴雪' + } else if (num === 18) { + wea = '雾' + } else if (num === 19) { + wea = '冻雨' + } else if (num === 20) { + wea = '沙尘暴' + } else if (num === 21) { + wea = '小雨-中雨' + } else if (num === 22) { + wea = '中雨-大雨' + } else if (num === 23) { + wea = '大雨-暴雨' + } else if (num === 24) { + wea = '暴雨-大暴雨' + } else if (num === 25) { + wea = '大暴雨-特大暴雨' + } else if (num === 26) { + wea = '小雪-中雪' + } else if (num === 27) { + wea = '中雪-大雪' + } else if (num === 28) { + wea = '大雪-暴雪' + } else if (num === 29) { + wea = '浮沉' + } else if (num === 30) { + wea = '扬沙' + } else if (num === 31) { + wea = '强沙尘暴' + } else if (num === 32) { + wea = '飑' + } else if (num === 33) { + wea = '龙卷风' + } else if (num === 34) { + wea = '若高吹雪' + } else if (num === 35) { + wea = '轻雾' + } else if (num === 53) { + wea = '霾' + } else if (num === 99) { + wea = '未知' + } + + return wea + }, +} + +export default { + namespace: 'dashboard', + state: { + weather: { + city: '成都', + temperature: '5', + name: '晴', + icon: 'http://www.zuimeitianqi.com/res/icon/0_big.png', + dateTime: new Date().format('MM-dd hh:mm'), + }, + sales: [], + quote: { + avatar: 'http://img.hb.aicdn.com/bc442cf0cc6f7940dcc567e465048d1a8d634493198c4-sPx5BR_fw236', + }, + numbers: [], + recentSales: [], + comments: [], + completed: [], + browser: [], + cpu: {}, + user: { + avatar: 'http://img.hb.aicdn.com/bc442cf0cc6f7940dcc567e465048d1a8d634493198c4-sPx5BR_fw236', + }, + }, + subscriptions: { + setup ({ dispatch }) { + dispatch({ type: 'queryWeather' }) + dispatch({ type: 'query' }) + }, + }, + effects: { + *query ({ + payload, + }, { call, put }) { + const data = yield call(query, parse(payload)) + yield put({ type: 'queryWeather', payload: { ...data } }) + }, + *queryWeather ({ + payload, + }, { call, put }) { + const myCityResult = yield call(myCity, { flg: 0 }) + const result = yield call(queryWeather, { cityCode: myCityResult.hotCityList[2].cityCode }) + const weather = zuimei.parseActualData(result.data.actual) + weather.city = myCityResult.hotCityList[2].cityName + + yield put({ type: 'queryWeatherSuccess', payload: { + weather, + } }) + }, + }, + reducers: { + queryWeatherSuccess (state, action) { + return { + ...state, + ...action.payload, + } + }, + queryWeather (state, action) { + return { + ...state, + ...action.payload, + } + }, }, } From e1a6f41192f4aa5e38289456f3c567e11ac5250e Mon Sep 17 00:00:00 2001 From: zuiidea Date: Mon, 27 Mar 2017 20:27:58 +0800 Subject: [PATCH 3/3] dashboard --- mock/dashboard.js | 345 ++++++++++++++-------------------------- src/models/dashboard.js | 8 +- 2 files changed, 125 insertions(+), 228 deletions(-) diff --git a/mock/dashboard.js b/mock/dashboard.js index ed62e19..9a65a8a 100644 --- a/mock/dashboard.js +++ b/mock/dashboard.js @@ -1,230 +1,129 @@ -import { myCity, queryWeather, query } from '../services/dashboard' -import { parse } from 'qs' +import { color } from '../src/utils/theme' +const Mock = require('mockjs') +import mockStorge from '../src/utils/mockStorge' -// zuimei 摘自 http://www.zuimeitianqi.com/res/js/index.js -let zuimei = { - parseActualData (actual) { - let weather = { - icon: `http://www.zuimeitianqi.com/res/icon/${zuimei.getIconName(actual.wea, 'big')}`, - name: zuimei.getWeatherName(actual.wea), - temperature: actual.tmp, - dateTime: new Date(actual.PTm).format('MM-dd hh:mm'), - } - return weather +let dataKey = mockStorge('Dashboard', Mock.mock({ + 'sales|8': [ + { + 'name|+1': 2008, + 'Clothes|200-500': 1, + 'Food|180-400': 1, + 'Electronics|300-550': 1, + }, + ], + cpu: { + 'usage|50-600': 1, + space: 825, + 'cpu|40-90': 1, + 'data|20': [ + { + 'cpu|20-80': 1, + }, + ], }, - - getIconName (wea, flg) { - let myDate = new Date() - let hour = myDate.getHours() - let num = 0 - if (wea.indexOf('/') !== -1) { - let weas = wea.split('/') - if (hour < 12) { - num = zuimei.replaceIcon(weas[0]) - if (num < 6) { - num = `${num}_${flg}_night.png` - } else { - num = `${num}_${flg}.png` - } - } else if (hour >= 12) { - num = zuimei.replaceIcon(weas[1]) - if (hour >= 18) { - num = `${num}_${flg}_night.png` - } else { - num = `${num}_${flg}.png` - } - } - } else { - if ((hour >= 18 && hour <= 23) || (hour >= 0 && hour <= 6)) { - num = `${num}_${flg}_night.png` - } else { - num = `${num}_${flg}.png` - } - } - - return num + browser: [ + { + name: 'Google Chrome', + percent: 43.3, + status: 1, + }, + { + name: 'Mozilla Firefox', + percent: 33.4, + status: 2, + }, + { + name: 'Apple Safari', + percent: 34.6, + status: 3, + }, + { + name: 'Internet Explorer', + percent: 12.3, + status: 4, + }, + { + name: 'Opera Mini', + percent: 3.3, + status: 1, + }, + { + name: 'Chromium', + percent: 2.53, + status: 1, + }, + ], + user: { + name: 'zuiidea', + email: 'zuiiidea@.gmail.com', + sales: 3241, + sold: 3556, + avatar: 'http://tva4.sinaimg.cn/crop.0.0.996.996.180/6ee6a3a3jw8f0ks5pk7btj20ro0rodi0.jpg', }, - - replaceIcon (num) { - if (num === 21) { - num = 7 - } else if (num === 22) { - num = 8 - } else if (num === 10 || num === 11 || num === 12 || num === 23 || num === 24 || num === 25) { - num = 9 - } else if (num === 13 || num === 15 || num === 26 || num === 27 || num === 34) { - num = 14 - } else if (num === 17 || num === 28) { - num = 16 - } else if (num === 35) { - num = 18 - } else if (num === 31 || num === 32 || num === 33) { - num = 20 - } else if (num === 30) { - num = 29 - } - - return num + 'completed|12': [ + { + 'name|+1': 2008, + 'Task complete|200-1000': 1, + 'Cards Complete|200-1000': 1, + }, + ], + 'comments|5': [ + { + name: '@last', + 'status|1-3': 1, + content: '@sentence', + avatar () { + return Mock.Random.image('48x48', Mock.Random.color(), '#757575', 'png', this.name.substr(0, 1)) + }, + date () { + return `2016-${Mock.Random.date('MM-dd')} ${Mock.Random.time('HH:mm:ss')}` + }, + }, + ], + 'recentSales|36': [ + { + 'id|+1': 1, + name: '@last', + 'status|1-4': 1, + date () { + return `${Mock.Random.integer(2015, 2016)}-${Mock.Random.date('MM-dd')} ${Mock.Random.time('HH:mm:ss')}` + }, + 'price|10-200.1-2': 1, + }, + ], + quote: { + name: 'Joho Doe', + title: 'Graphic Designer', + content: 'I\'m selfish, impatient and a little insecure. I make mistakes, I am out of control and at times hard to handle. But if you can\'t handle me at my worst, then you sure as hell don\'t deserve me at my best.', + avatar: 'http://img.hb.aicdn.com/bc442cf0cc6f7940dcc567e465048d1a8d634493198c4-sPx5BR_fw236', }, + numbers: [ + { + icon: 'message', + color: color.green, + title: '总浏览PV', + number: 2781, + }, { + icon: 'team', + color: color.blue, + title: '总浏览UV', + number: 3241, + }, { + icon: 'shopping-cart', + color: color.purple, + title: '成交订单数', + number: 253, + }, { + icon: 'pay-circle-o', + color: color.red, + title: '交易额', + number: 4324, + }, + ], +})) - getWeatherName (wea) { - let name = '' - if (wea.indexOf('/') !== -1) { - let weas = wea.split('/') - name = `${zuimei.getWeatherByCode(weas[0])}转${zuimei.getWeatherByCode(weas[1])}` - } else { - name = zuimei.getWeatherByCode(wea) - } - - return name - }, - - getWeatherByCode (num) { - let wea = '' - if (num === 0) { - wea = '晴' - } else if (num === 1) { - wea = '多云' - } else if (num === 2) { - wea = '阴' - } else if (num === 3) { - wea = '阵雨' - } else if (num === 4) { - wea = '雷阵雨' - } else if (num === 5) { - wea = '雷阵雨并伴有冰雹' - } else if (num === 6) { - wea = '雨夹雪' - } else if (num === 7) { - wea = '小雨' - } else if (num === 8) { - wea = '中雨' - } else if (num === 9) { - wea = '大雨' - } else if (num === 10) { - wea = '暴雨' - } else if (num === 11) { - wea = '大暴雨' - } else if (num === 12) { - wea = '特大暴雨' - } else if (num === 13) { - wea = '阵雪' - } else if (num === 14) { - wea = '小雪' - } else if (num === 15) { - wea = '中雪' - } else if (num === 16) { - wea = '大雪' - } else if (num === 17) { - wea = '暴雪' - } else if (num === 18) { - wea = '雾' - } else if (num === 19) { - wea = '冻雨' - } else if (num === 20) { - wea = '沙尘暴' - } else if (num === 21) { - wea = '小雨-中雨' - } else if (num === 22) { - wea = '中雨-大雨' - } else if (num === 23) { - wea = '大雨-暴雨' - } else if (num === 24) { - wea = '暴雨-大暴雨' - } else if (num === 25) { - wea = '大暴雨-特大暴雨' - } else if (num === 26) { - wea = '小雪-中雪' - } else if (num === 27) { - wea = '中雪-大雪' - } else if (num === 28) { - wea = '大雪-暴雪' - } else if (num === 29) { - wea = '浮沉' - } else if (num === 30) { - wea = '扬沙' - } else if (num === 31) { - wea = '强沙尘暴' - } else if (num === 32) { - wea = '飑' - } else if (num === 33) { - wea = '龙卷风' - } else if (num === 34) { - wea = '若高吹雪' - } else if (num === 35) { - wea = '轻雾' - } else if (num === 53) { - wea = '霾' - } else if (num === 99) { - wea = '未知' - } - - return wea - }, -} - -export default { - namespace: 'dashboard', - state: { - weather: { - city: '成都', - temperature: '5', - name: '晴', - icon: 'http://www.zuimeitianqi.com/res/icon/0_big.png', - dateTime: new Date().format('MM-dd hh:mm'), - }, - sales: [], - quote: { - avatar: 'http://img.hb.aicdn.com/bc442cf0cc6f7940dcc567e465048d1a8d634493198c4-sPx5BR_fw236', - }, - numbers: [], - recentSales: [], - comments: [], - completed: [], - browser: [], - cpu: {}, - user: { - avatar: 'http://img.hb.aicdn.com/bc442cf0cc6f7940dcc567e465048d1a8d634493198c4-sPx5BR_fw236', - }, - }, - subscriptions: { - setup ({ dispatch }) { - dispatch({ type: 'queryWeather' }) - dispatch({ type: 'query' }) - }, - }, - effects: { - *query ({ - payload, - }, { call, put }) { - const data = yield call(query, parse(payload)) - yield put({ type: 'queryWeather', payload: { ...data } }) - }, - *queryWeather ({ - payload, - }, { call, put }) { - const myCityResult = yield call(myCity, { flg: 0 }) - const result = yield call(queryWeather, { cityCode: myCityResult.hotCityList[2].cityCode }) - const weather = zuimei.parseActualData(result.data.actual) - weather.city = myCityResult.hotCityList[2].cityName - - yield put({ type: 'queryWeatherSuccess', payload: { - weather, - } }) - }, - }, - reducers: { - queryWeatherSuccess (state, action) { - return { - ...state, - ...action.payload, - } - }, - queryWeather (state, action) { - return { - ...state, - ...action.payload, - } - }, +module.exports = { + 'GET /api/dashboard' (req, res) { + res.json(global[dataKey]) }, } diff --git a/src/models/dashboard.js b/src/models/dashboard.js index 6b83c13..b9adfe1 100644 --- a/src/models/dashboard.js +++ b/src/models/dashboard.js @@ -204,11 +204,9 @@ export default { payload, }, { call, put }) { const myCityResult = yield call(myCity, { flg: 0 }) - const myCityData = myCityResult.query.results.json - const result = yield call(queryWeather, { cityCode: myCityData.selectCityCode }) - const data = result.query.results.json - const weather = zuimei.parseActualData(data.data.actual) - weather.city = myCityData.selectCityName + const result = yield call(queryWeather, { cityCode: myCityResult.selectCityCode }) + const weather = zuimei.parseActualData(result.data.actual) + weather.city = myCityResult.selectCityName yield put({ type: 'queryWeatherSuccess', payload: { weather,