mirror of
https://github.com/zuiidea/antd-admin
synced 2026-11-03 00:14:00 +00:00
get data
This commit is contained in:
@@ -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 = {
|
||||
|
||||
}
|
||||
@@ -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 <div className={styles.weather}>
|
||||
|
||||
@@ -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'))
|
||||
|
||||
@@ -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 : {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
@@ -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},
|
||||
// })
|
||||
// }
|
||||
|
||||
@@ -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},
|
||||
})
|
||||
}
|
||||
+17
-11
@@ -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
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user