// 引入mockjs import Mock from 'mockjs' const Random = Mock.Random // 项目域名 import config from './config' const delay = 500 // 模拟请求时长 // const config = 'http://192.168.1.163:8080/sk_anchor_pc/' const res = { status: 0, errMsg: '' } // var Req = require('@/libs/request') // var OPTIONS = Req.OPTIONS || Req.default.OPTIONS const commonReturn = {res, inf: {}} // 通用返回 const imgUrl = 'static/imgs/headimg.jpg' // 通用示例图片 // const videoUrl = 'https://vjs.zencdn.net/v/oceans.mp4' // 通用示例视频 var mockJson = { commSuc: commonReturn, // 获取key 'weixin!ajaxGetInfoByCode': { res, inf: { "key": "123", "nickname": "昵称", "imgUrl": imgUrl, "shareImg": imgUrl, "shareTitle": "分享标题" } }, // 获取OSS参数 'oss!ajaxGetAccess': { res, "inf": { "accessId": "", "policy": "", "signature": "", "dir": "", "host": "", "expire": "" } }, // ticket 'weixin!ajaxGetJsTicket': { res, inf: { ticket: '123' } } } /** * 生成回调函数 * @param {object|function} data mockJson 对应项 */ function createCallback (data) { return function () { if (typeof data === 'function') { return data() } else { return data } } } // 设置延迟响应,模拟向后端请求数据 Mock.setup({timeout: delay}) for (var key in mockJson) { var obj = mockJson[key] var url = key Mock.mock(config.domain + url, createCallback(obj)) } // Mock.mock( url, post/get , 返回的数据); // Mock.mock('/news/index', 'post', {});