Commit ebe6229d by zhanghaozhe

mock

parent d9f5c936
......@@ -9184,6 +9184,15 @@
}
}
},
"mockjs": {
"version": "1.0.1-beta3",
"resolved": "https://registry.npmjs.org/mockjs/-/mockjs-1.0.1-beta3.tgz",
"integrity": "sha1-0jTzwnJWOXVk8slVFC6JGQlTcgk=",
"dev": true,
"requires": {
"commander": "*"
}
},
"move-concurrently": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/move-concurrently/-/move-concurrently-1.0.1.tgz",
......
......@@ -150,6 +150,7 @@
"devDependencies": {
"babel-plugin-import": "^1.11.0",
"classnames": "^2.2.6",
"mockjs": "^1.0.1-beta3",
"sass-resources-loader": "^2.0.0"
},
"theme": "./src/assets/theme/config.js"
......
import React, {Component} from 'react'
import Routes from './router'
import cookie from 'js-cookie'
import {api} from '@/utils'
//拦截ajax请求,返回mock数据
import mock from '@/utils/mock'
// 默认样式
......@@ -13,8 +17,16 @@ import './assets/font/iconfont.css';
export default class App extends Component{
componentDidMount(){
//平台信息,后台统计用
//平台信息
cookie.set('plat', '5')
//拦截ajax请求,返回mock数据
mock()
api.get('/m/my_course/1/10')
.then(res => {
console.log(res)
})
}
render(){
return <Routes/>
......
......@@ -12,8 +12,8 @@ const PAGE_INTERVAL = 1
export const NUM_INTERVAL = 10
export const fetchCoursesListIfNeeded = () => (dispatch, getState) => {
const myCourses = getState().myCourses
const {switchTab, page} = myCourses
if (!switchTab) {
const {switchTab, page, noMore} = myCourses
if (!switchTab && !noMore) {
dispatch(getMyCourses({
page: page + PAGE_INTERVAL,
num: NUM_INTERVAL
......@@ -24,7 +24,14 @@ export const fetchCoursesListIfNeeded = () => (dispatch, getState) => {
export const getMyCourses = payload => dispatch => {
return api.get(`/m/my_course/${payload.page}/${payload.num}`)
.then(res => {
const {data,code,msg} = res.data
const {data, code, msg} = res.data
if (data.length === 0) {
dispatch(nomoreCourse())
return
}
if (data.length % 10 !== 0) {
dispatch(nomoreCourse())
}
dispatch(receiveMyCourses({
courseList: data,
statusCode: code,
......
const {mock} = require('mockjs')
export default function () {
mock(/my_course/, {
'code': '200',
'msg': 'ok',
'data|10': [{
'v_course_id|1-999': 222,
'course_id|1-999': 222,
'course_title': '@cparagraph(1,3)',
'simpledescription': '@csentence(3,5)',
'course_qq': /\d{8}/,
'lesson_name': /第\d{1,2}/,
'last_lesson|1558337743-1559288119': 0,
'ago|1558337743-1559288119': 0,
'seconds': 0,
'image_name': '@dataimage(150x108, 课程)'
}]
})
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment