parent
51205c9056
commit
841968d741
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* @Description:
|
||||
* @Author: tangjiang
|
||||
* @Github:
|
||||
* @Date: 2020-01-14 09:44:02
|
||||
* @LastEditors : tangjiang
|
||||
* @LastEditTime : 2020-01-14 17:02:45
|
||||
*/
|
||||
import types from "./actionTypes";
|
||||
import { fetchStaticList } from "../../services/staticService";
|
||||
|
||||
export const staticList = (id) => {
|
||||
return (dispatch, getState) => {
|
||||
const { params, total_count, other_info } = getState().staticReducer;
|
||||
|
||||
if (total_count !== 0 && total_count === other_info.length) return;
|
||||
fetchStaticList(id, params).then(res => {
|
||||
// console.log('统计数据=====>>>>>', res);
|
||||
const {data} = res;
|
||||
if (data.status === 0) {
|
||||
dispatch({
|
||||
type: types.GET_STATIC_INFO,
|
||||
payload: data.data
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const changeParams = (params) => {
|
||||
return {
|
||||
type: types.CHANGE_STATIC_PARAMS,
|
||||
payload: params
|
||||
}
|
||||
}
|
||||
|
||||
export const initTotal = () => {
|
||||
return {
|
||||
type: types.CHANGE_STATIC_TOTAL
|
||||
}
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* @Description: 统计
|
||||
* @Author: tangjiang
|
||||
* @Github:
|
||||
* @Date: 2020-01-14 09:34:49
|
||||
* @LastEditors : tangjiang
|
||||
* @LastEditTime : 2020-01-14 15:49:55
|
||||
*/
|
||||
import types from "../actions/actionTypes";
|
||||
|
||||
// const maps = {
|
||||
// 1: 'shixun_info', // 实训使用情况
|
||||
// 2: 'user_info', // 用户使用情况
|
||||
// 3: 'subject_info' // 实践课程使用情况
|
||||
// }
|
||||
const initalState = {
|
||||
subject_info: {},
|
||||
other_info: [],
|
||||
total_count: 0,
|
||||
total: {},
|
||||
params: {
|
||||
// sort_by: '',
|
||||
// sort_direction: 'desc', // desc || asc
|
||||
limit: 20, // 一页多少条
|
||||
page: 1, // 第几页
|
||||
type: 'subject_info' // 类型: 实训 shixun_info,
|
||||
}
|
||||
};
|
||||
|
||||
// const getGuid = () =>
|
||||
// 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
|
||||
// /* eslint-disable */
|
||||
// let r = (Math.random() * 16) | 0,
|
||||
// v = c == 'x' ? r : (r & 0x3) | 0x8;
|
||||
// return v.toString(16);
|
||||
// });
|
||||
|
||||
const staticReducer = (state = initalState, action) => {
|
||||
const { payload = {}, type } = action;
|
||||
const {subject_info, other_info = [], total = {}, total_count} = payload;
|
||||
switch (type) {
|
||||
case types.GET_STATIC_INFO:
|
||||
return {
|
||||
...state,
|
||||
subject_info,
|
||||
other_info: state.other_info.concat(other_info),
|
||||
total,
|
||||
total_count,
|
||||
params: Object.assign({}, state.params, { page: state.params.page + 1 })
|
||||
}
|
||||
case types.CHANGE_STATIC_PARAMS: {
|
||||
return {
|
||||
...state,
|
||||
params: Object.assign({}, state.params, payload)
|
||||
};
|
||||
}
|
||||
case types.CHANGE_STATIC_TOTAL: {
|
||||
return {
|
||||
...state,
|
||||
other_info: [],
|
||||
total: {}
|
||||
}
|
||||
}
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
export default staticReducer;
|
@ -0,0 +1,14 @@
|
||||
import axios from "axios";
|
||||
|
||||
/*
|
||||
* @Description:
|
||||
* @Author: tangjiang
|
||||
* @Github:
|
||||
* @Date: 2020-01-14 09:40:53
|
||||
* @LastEditors : tangjiang
|
||||
* @LastEditTime : 2020-01-14 10:47:19
|
||||
*/
|
||||
export async function fetchStaticList (id, params) {
|
||||
const url = `/paths/${id}/statistics_info.json`;
|
||||
return axios.get(url, { params });
|
||||
}
|
Loading…
Reference in new issue