diff --git a/mock/dashboard.js b/mock/dashboard.js
new file mode 100644
index 0000000..f5189fe
--- /dev/null
+++ b/mock/dashboard.js
@@ -0,0 +1,46 @@
+const qs = require('qs')
+const Mock = require('mockjs')
+const Watch = require("watchjs")
+
+let usersListData = {}
+if (!global.usersListData) {
+ const data = !!localStorage.getItem("antdUsersListData")
+ ? JSON.parse(localStorage.getItem("antdUsersListData"))
+ : Mock.mock({
+ 'data|100': [
+ {
+ 'id|+1': 1,
+ name: '@cname',
+ nickName: '@last',
+ phone: /^1[34578]\d{9}$/,
+ 'age|11-99': 1,
+ address: '@county(true)',
+ isMale: '@boolean',
+ email: '@email',
+ createTime: '@datetime',
+ avatar: function(){
+ return Mock.Random.image('100x100', Mock.Random.color(),"#757575",'png',this.nickName.substr(0,1))
+ }
+ }
+ ],
+ page: {
+ total: 100,
+ current: 1
+ }
+ })
+ usersListData = data
+ global.usersListData = usersListData
+ if (!localStorage.getItem("antdUsersListData")) {
+ localStorage.setItem("antdUsersListData", JSON.stringify(usersListData))
+ }
+} else {
+ usersListData = global.usersListData
+}
+
+Watch.watch(usersListData, function () {
+ localStorage.setItem("antdUsersListData", JSON.stringify(usersListData))
+})
+
+module.exports = {
+
+}
diff --git a/src/components/dashboard/weather.js b/src/components/dashboard/weather.js
index ba18f2e..f781a62 100644
--- a/src/components/dashboard/weather.js
+++ b/src/components/dashboard/weather.js
@@ -9,12 +9,12 @@ const Weather = React.createClass({
this.fetch()
},
fetch() {
- Ajax.getJSON("http://query.yahooapis.com/v1/public/yql", {
- q: "select * from json where url=\"http://www.zuimeitianqi.com/zuimei/myCity?flg=0\"",
- format: "json"
- }, function (data) {
- console.log(data)
- })
+ // Ajax.getJSON("http://query.yahooapis.com/v1/public/yql", {
+ // q: "select * from json where url=\"http://www.zuimeitianqi.com/zuimei/myCity?flg=0\"",
+ // format: "json"
+ // }, function (data) {
+ // console.log(data)
+ // })
},
render() {
return
diff --git a/src/index.js b/src/index.js
index 0b358ac..d562107 100644
--- a/src/index.js
+++ b/src/index.js
@@ -7,6 +7,7 @@ const app = dva()
// 2. Model
app.model(require('./models/app'))
app.model(require('./models/users'))
+app.model(require('./models/dashboard'))
// 3. Router
app.router(require('./router'))
diff --git a/src/models/dashboard.js b/src/models/dashboard.js
new file mode 100644
index 0000000..21de765
--- /dev/null
+++ b/src/models/dashboard.js
@@ -0,0 +1,40 @@
+import {myCity} from '../services/dashboard'
+import {parse} from 'qs'
+
+export default {
+ namespace : 'dashboard',
+ state : {
+ weather: {
+
+ },
+ },
+ subscriptions : {
+ setup({dispatch}) {
+ dispatch({type: 'queryWeather'})
+ }
+ },
+ effects : {
+ *queryWeather({
+ payload
+ }, {call, put}) {
+ const result = yield call(myCity, parse(payload))
+ const data = result.query.results.json
+ console.log(data)
+ // if (data.success) {
+ // yield put({
+ // type: 'loginSuccess',
+ // payload: {
+ // user: {
+ // name: data.username
+ // }
+ // }
+ // })
+ // } else {
+ // yield put({type: 'hideLoading'})
+ // }
+ },
+ },
+ reducers : {
+
+ }
+}
diff --git a/src/routes/dashboard.js b/src/routes/dashboard.js
index 27002d1..c080606 100644
--- a/src/routes/dashboard.js
+++ b/src/routes/dashboard.js
@@ -1,4 +1,5 @@
import React, {PropTypes} from 'react'
+import {connect} from 'dva'
import {Link} from 'dva/router'
import {Row, Col, Icon, Card} from 'antd'
import NumberCard from '../components/dashboard/numberCard'
@@ -101,4 +102,10 @@ Dashboard.propTypes = {
location: PropTypes.object
}
-export default Dashboard
+function mapStateToProps({ dashboard }) {
+ return { dashboard }
+}
+
+export default connect(mapStateToProps)(Dashboard)
+
+// export default connect(({dashboard}) => ({dashboard}))(Dashboard)
diff --git a/src/services/app.js b/src/services/app.js
index e8b2562..71b562e 100644
--- a/src/services/app.js
+++ b/src/services/app.js
@@ -21,10 +21,3 @@ export async function userInfo(params) {
data:params,
})
}
-
-// export async function myCity() {
-// return request('http://www.zuimeitianqi.com/zuimei/myCity', {
-// method: 'get',
-// data:{flg:0},
-// })
-// }
diff --git a/src/services/dashboard.js b/src/services/dashboard.js
new file mode 100644
index 0000000..b327778
--- /dev/null
+++ b/src/services/dashboard.js
@@ -0,0 +1,10 @@
+import { request } from '../utils'
+import qs from 'qs'
+
+export async function myCity() {
+ return request('http://www.zuimeitianqi.com/zuimei/myCity', {
+ method: 'get',
+ cross:true,
+ data:{flg:0},
+ })
+}
diff --git a/src/utils/request.js b/src/utils/request.js
index 87aa1fb..b44dec9 100644
--- a/src/utils/request.js
+++ b/src/utils/request.js
@@ -8,16 +8,22 @@ const Ajax = require("robe-ajax")
* @return {object} An object containing either "data" or "err"
*/
export default function request(url, options) {
-
- return Ajax.ajax({
+ if (options.cross) {
+ return Ajax.getJSON("http://query.yahooapis.com/v1/public/yql", {
+ q: "select * from json where url=\'"+url+"?"+Ajax.param(options.data)+"\'",
+ format: "json"
+ })
+ } else {
+ return Ajax.ajax({
url: url,
- method:options.method||'get',
- data:options.data||{},
- processData:options.method=='get'?true:false,
- dataType:'JSON',
- })
- .done((data) => {
- return data
- })
-
+ method: options.method || 'get',
+ data: options.data || {},
+ processData: options.method == 'get'
+ ? true
+ : false,
+ dataType: 'JSON'
+ }).done((data) => {
+ return data
+ })
+ }
}