|
@@ -0,0 +1,32 @@
|
|
|
|
|
+import consts from '@/consts'
|
|
|
|
|
+import { queryDashboard } from '@/services/dashboard'
|
|
|
|
|
+
|
|
|
|
|
+export default {
|
|
|
|
|
+ namespace: 'dashboard',
|
|
|
|
|
+ state: {
|
|
|
|
|
+ data: []
|
|
|
|
|
+ },
|
|
|
|
|
+ // 用于处理异步操作和业务逻辑,由action触发,但不能修改state
|
|
|
|
|
+ effects: {
|
|
|
|
|
+ *fetch({ payload }, { call, put }) {
|
|
|
|
|
+ const response = yield call(queryDashboard, payload)
|
|
|
|
|
+ if (response && response.code === consts.RET_CODE.SUCCESS) {
|
|
|
|
|
+ yield put({
|
|
|
|
|
+ type: 'show',
|
|
|
|
|
+ payload: response.data
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ // console.log(response)
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ // reducers:用于处理同步操作,由action触发,可修改state
|
|
|
|
|
+ reducers: {
|
|
|
|
|
+ // action:是由reducers及effects的触发器,一般是第一个对象,如:{type:'add',payload:todo}
|
|
|
|
|
+ show(state, action) {
|
|
|
|
|
+ return {
|
|
|
|
|
+ ...state,
|
|
|
|
|
+ data: action.payload.dashboard
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|