Closed HelenGuohx closed 5 years ago
import {getIncomeDetail, getCostDetail, getIncomeDetailByCompany,getCostDetailByCompany } from '../../services/BI/administrationAnalysis'; import {message} from 'antd'; import { query } from '../../services/BI/checkBill'; export default { namespace: 'administrationAnalysis', state: { dataSource:{"income":0,"cost":0,"value": 2}, //{收入,成本,切换值} detailData:{}, incomeDetailData:[], costDetailData:[], value:0, dateRange: undefined, }, reducers: { querySuccess(state,action){ console.log("querySuccess=============",action.payload); return {...state, dataSource:action.payload, value: action.payload.value} }, getPieDetailSuccess(state,action){ console.log("getPieDetailSuccess", action.payload); return {...state, detailData: action.payload} }, onDateRangeChange(state,action){ console.log("onDateRangeChange",action.payload) return{...state, dateRange: action.payload} } }, effects: { *query({payload},{select,put,call}){ // let funcId =yield select(state => state.administrationAnalysis.funcId)//从state里获取值 // if(!funcId){ // yield put({ // type: 'querySuccess', // payload:{funcId:Number(sessionStorage.funcId)} // }); // } // funcId =yield select(state => state.administrationAnalysis.funcId)//从state里获取值 // let dateRange = yield select(state=> state.administrationAnalysis.dateRange) // let wdid = JSON.parse(sessionStorage.childrenwd).wdid // console.log(==) // let wdid = 0 // console.log(JSON.parse(sessionStorage.childrenwd)) console.log(getIncomeDetail) // incomeRes = yield call(query) // costRes = yield call(getCostDetail,{payload:dateRange,funcId:funcId,wdid}) // if (costRes.data.code==0&&incomeRes.data.code==0){ // yield put({ // type: 'querySuccess', // payload: {income: incomeRes.data.data, cost: costRes.data.data} // }); // } }, *query2({payload},{select,call, put}){ console.log("payload") let funcId =yield select(state => state.statementCenter.funcId)//从state里获取值 if(!funcId){ yield put({ type: 'querySuccess', payload:{funcId:Number(sessionStorage.funcId)} }); } funcId =yield select(state => state.statementCenter.funcId)//从state里获取值 // let dateRange =yield select(state => state.administrationAnalysis.dateRange)//从state里获取值 // console.log("dateRange",dateRange) // let wdid = payload.row.wdid // let value = sessionStorage.adminAnalysisValue // console.log("query payload",payload) // // let value = payload // let res = new Object() // let res1= new Object() // let res2= new Object() // if (value==1){ // // res=yield call (query) // res1=yield call(getIncomeDetail,{payload: dateRange,funcId:funcId, wdid: wdid}) // res2=yield call(getCostDetail,{payload: dateRange,funcId:funcId, wdid: wdid}) // } // else if(value==2){ // res1=yield call (getIncomeDetailByCompany,{payload: dateRange, funcId:funcId}) // res2=yield call(getCostDetailByCompany,{payload: dateRange, funcId:funcId}) //没想好其他方法就沿用之前的数据 // } // console.log("administrationAnalysis res1",res1) // console.log("administrationAnalysis res2",res2) // if(res1.data!==undefined&&res2.data!==undefined){ // if (res1['data']['code'] == 0&&res2['data']['code'] == 0){ // // sessionStorage.seriesValue=value // yield put({ // 'type':'querySuccess', // 'payload':{"income":res1["data"]["data"],"cost":res2["data"]["data"],"value": value} // }) // }else{ // message.error(res1['data']['msg']) // message.error(res2['data']['msg']) // } // } // else{ // message.error("res1 res2 is undefined") // } } }, subscriptions: { setup({ dispatch, history }) { return history.listen(location => { if (location.pathname === '/app/BI/finance-report/administration-analysis') { sessionStorage.adminAnalysisValue = 1 sessionStorage.childrenwd = JSON.stringify(location.state.params) dispatch({ type: 'query', }); } }); }, } }
路由监听到路径,触发dispatch,进入query函数触发异步请求
在进入query函数,若存在call函数,则不会进入query函数,直接render
{ "private": true, "scripts": { "start": "roadhog server", "build": " roadhog build", "lint": "eslint --ext .js src test", "precommit": "npm run lint" }, "engines": { "install-node": "6.9.2" }, "dependencies": { "@antv/data-set": "^0.8.9", "ant-design-pro": "^1.3.0", "antd": "^3.0.3", "babel-plugin-import": "^1.4.0", "babel-runtime": "^6.9.2", "bizcharts": "^3.1.10", "dva": "^1.2.1", "echarts": "^4.1.0", "echarts-for-react": "^2.0.13", "react": "^15.4.0", "react-amap": "^1.0.3", "react-dnd": "^2.5.4", "react-dnd-html5-backend": "^2.5.4", "react-dom": "^15.4.0" }, "devDependencies": { "babel-eslint": "^7.1.1", "babel-plugin-dva-hmr": "^0.3.2", "babel-plugin-transform-runtime": "^6.9.0", "eslint": "^3.12.2", "eslint-config-airbnb": "^13.0.0", "eslint-plugin-import": "^2.2.0", "eslint-plugin-jsx-a11y": "^2.2.3", "eslint-plugin-react": "^6.8.0", "expect": "^1.20.2", "http-proxy-middleware": "^0.18.0", "husky": "^0.12.0", "redbox-react": "^1.3.2", "roadhog": "^0.5.2" } } debug的浏览器版本:Google Chrome版本 68.0.3440.84(正式版本) (64 位)
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Code to reproduce the issue: (请提供可复现的代码或者步骤)
Expected behavior: (预期的正常效果)
路由监听到路径,触发dispatch,进入query函数触发异步请求
Actual behavior: (实际效果)
在进入query函数,若存在call函数,则不会进入query函数,直接render
Versions of packages used: (哪个库的哪个版本出现的问题)
{ "private": true, "scripts": { "start": "roadhog server", "build": " roadhog build", "lint": "eslint --ext .js src test", "precommit": "npm run lint" }, "engines": { "install-node": "6.9.2" }, "dependencies": { "@antv/data-set": "^0.8.9", "ant-design-pro": "^1.3.0", "antd": "^3.0.3", "babel-plugin-import": "^1.4.0", "babel-runtime": "^6.9.2", "bizcharts": "^3.1.10", "dva": "^1.2.1", "echarts": "^4.1.0", "echarts-for-react": "^2.0.13", "react": "^15.4.0", "react-amap": "^1.0.3", "react-dnd": "^2.5.4", "react-dnd-html5-backend": "^2.5.4", "react-dom": "^15.4.0" }, "devDependencies": { "babel-eslint": "^7.1.1", "babel-plugin-dva-hmr": "^0.3.2", "babel-plugin-transform-runtime": "^6.9.0", "eslint": "^3.12.2", "eslint-config-airbnb": "^13.0.0", "eslint-plugin-import": "^2.2.0", "eslint-plugin-jsx-a11y": "^2.2.3", "eslint-plugin-react": "^6.8.0", "expect": "^1.20.2", "http-proxy-middleware": "^0.18.0", "husky": "^0.12.0", "redbox-react": "^1.3.2", "roadhog": "^0.5.2" } } debug的浏览器版本:Google Chrome版本 68.0.3440.84(正式版本) (64 位)