mirror of
https://github.com/zuiidea/antd-admin
synced 2026-11-01 23:43:55 +00:00
local mock data
This commit is contained in:
+3
-4
@@ -37,7 +37,6 @@ export default {
|
||||
*query({ payload }, { call, put }) {
|
||||
yield put({ type: 'showLoading' })
|
||||
const data = yield call(query, parse(payload))
|
||||
console.log("modae",data);
|
||||
if (data) {
|
||||
yield put({
|
||||
type: 'querySuccess',
|
||||
@@ -53,7 +52,7 @@ export default {
|
||||
},
|
||||
*'delete'({ payload }, { call, put }) {
|
||||
yield put({ type: 'showLoading' })
|
||||
const { data } = yield call(remove, { id: payload })
|
||||
const data = yield call(remove, { id: payload })
|
||||
if (data && data.success) {
|
||||
yield put({
|
||||
type: 'deleteSuccess',
|
||||
@@ -64,7 +63,7 @@ export default {
|
||||
*create({ payload }, { call, put }) {
|
||||
yield put({ type: 'hideModal' })
|
||||
yield put({ type: 'showLoading' })
|
||||
const { data } = yield call(create, payload)
|
||||
const data = yield call(create, payload)
|
||||
if (data && data.success) {
|
||||
yield put({
|
||||
type: 'createSuccess',
|
||||
@@ -77,7 +76,7 @@ export default {
|
||||
yield put({ type: 'showLoading' })
|
||||
const id = yield select(({ users }) => users.currentItem.id)
|
||||
const newUser = { ...payload, id }
|
||||
const { data } = yield call(update, newUser)
|
||||
const data = yield call(update, newUser)
|
||||
if (data && data.success) {
|
||||
yield put({
|
||||
type: 'updateSuccess',
|
||||
|
||||
@@ -7,7 +7,6 @@ export async function query(params) {
|
||||
body: qs.stringify(params),
|
||||
data:params,
|
||||
})
|
||||
// return request(`/api/users?${qs.stringify(params)}`)
|
||||
}
|
||||
|
||||
export async function create(params) {
|
||||
@@ -30,6 +29,6 @@ export async function update(params) {
|
||||
return request('/api/users', {
|
||||
method: 'put',
|
||||
body: qs.stringify(params),
|
||||
data:params,
|
||||
data: params,
|
||||
})
|
||||
}
|
||||
|
||||
+14
-14
@@ -1,6 +1,6 @@
|
||||
const qs = require('qs')
|
||||
const Mock = require('mockjs')
|
||||
const mockUser = require("../../mock/users")
|
||||
const mockData = [require("../../mock/users")]
|
||||
|
||||
function serialize(str) {
|
||||
let paramArray = str.split("&")
|
||||
@@ -11,19 +11,19 @@ function serialize(str) {
|
||||
return query
|
||||
}
|
||||
|
||||
for (let key in mockUser) {
|
||||
Mock.mock(eval("/" + key.split(" ")[1]), key.split(" ")[0].toLowerCase(), function (options) {
|
||||
options.query = !!options.url.split("?")[1]
|
||||
? serialize(options.url.split("?")[1])
|
||||
: {}
|
||||
let res = {}
|
||||
let result = {}
|
||||
res.json = function (data) {
|
||||
result = data
|
||||
}
|
||||
mockUser[key](options, res)
|
||||
return result
|
||||
})
|
||||
for (let i in mockData) {
|
||||
for (let key in mockData[i]) {
|
||||
Mock.mock(eval("/" + key.split(" ")[1]), key.split(" ")[0].toLowerCase(), function (options) {
|
||||
options.query = !!options.url.split("?")[1] ? serialize(options.url.split("?")[1]) : (!!options.body ? serialize(options.body) : {})
|
||||
let res = {}
|
||||
let result = {}
|
||||
res.json = function (data) {
|
||||
result = data
|
||||
}
|
||||
mockUser[key](options, res)
|
||||
return result
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Mock.setup({timeout: 400})
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import fetch from 'dva/fetch'
|
||||
const Ajax = require("robe-ajax")
|
||||
|
||||
function parseJSON(response) {
|
||||
@@ -23,14 +22,6 @@ function checkStatus(response) {
|
||||
* @return {object} An object containing either "data" or "err"
|
||||
*/
|
||||
export default function request(url, options) {
|
||||
// return fetch(url, options)
|
||||
// .then(checkStatus)
|
||||
// .then(parseJSON)
|
||||
// .then((data) => {
|
||||
// console.log(data);
|
||||
// return data
|
||||
// })
|
||||
// .catch((err) => ({ err }))
|
||||
|
||||
return Ajax.ajax({
|
||||
url: url,
|
||||
|
||||
Reference in New Issue
Block a user