github.com/easysoft/zendata@v0.0.0-20240513203326-705bd5a7fd67/ui/src/api/mock.js (about) 1 import request from '../utils/request' 2 3 const mocksApi = '/mocks' 4 5 export function listMock (keywords, page) { 6 return request({ 7 url: mocksApi, 8 method: 'get', 9 params: {keywords: keywords, page: page} 10 }) 11 } 12 13 export function getMock (id) { 14 return request({ 15 url: `${mocksApi}/${id}`, 16 method: 'get', 17 }) 18 } 19 20 export function saveMock (data) { 21 return request({ 22 url: mocksApi, 23 method: 'post', 24 data 25 }) 26 } 27 28 export function removeMock (id) { 29 return request({ 30 url: `${mocksApi}/${id}`, 31 method: 'delete' 32 }) 33 } 34 35 export function uploadMock (formData) { 36 return request({ 37 url: `${mocksApi}/upload`, 38 method: 'post', 39 data: formData, 40 }) 41 } 42 43 export function getPreviewData (id) { 44 return request({ 45 url: `${mocksApi}/getPreviewData`, 46 method: 'get', 47 params: {id}, 48 }) 49 } 50 51 export function getPreviewResp (id, url, method, code, media) { 52 return request({ 53 url: `${mocksApi}/getPreviewResp`, 54 method: 'post', 55 data: {id, url, method, code, media}, 56 }) 57 } 58 59 export function startMockService (id, act) { 60 return request({ 61 url: `${mocksApi}/startMockService`, 62 method: 'post', 63 params: {id, act} 64 }) 65 } 66 67 export function listSampleSrc (mockId) { 68 return request({ 69 url: `${mocksApi}/${mockId}/listSampleSrc`, 70 method: 'get' 71 }) 72 } 73 74 export function changeSampleSrc (mockId, key, value) { 75 return request({ 76 url: `${mocksApi}/${mockId}/changeSampleSrc`, 77 method: 'post', 78 data: {key, value} 79 }) 80 } 81 82 export function getMockDataSrc (paths) { 83 const dataSrc = {} 84 85 Object.keys(paths).forEach((pathKey) => { 86 const pathVal = paths[pathKey] 87 88 Object.keys(pathVal).forEach((methodKey) => { 89 const methodVal = pathVal[methodKey] 90 91 Object.keys(methodVal).forEach((codeKey) => { 92 const codeVal = methodVal[codeKey] 93 94 Object.keys(codeVal).forEach((mediaKey) => { 95 const samples = codeVal[mediaKey].samples 96 97 const arr = ['schema'] 98 Object.keys(samples).forEach((sampleKey) => { 99 // console.log(pathKey, methodKey, codeKey, mediaKey, sampleKey, samples[sampleKey]) 100 arr.push(sampleKey) 101 }) 102 103 dataSrc[`${pathKey}-${methodKey}-${codeKey}-${mediaKey}`] = arr 104 }) 105 106 }) 107 }) 108 }) 109 110 return dataSrc 111 }