import qs from 'qs'; import { MockAdapter } from '@/mock/mock-adapter'; const mock = MockAdapter.getInstance(); // 模拟数据 const mockDatas: Array<any> = [ ]; // GetDraft mock.onGet(new RegExp(/^\/orgdeptusers\/getdraft$/)).reply((config: any) => { console.groupCollapsed("实体:orgdeptuser 方法: GetDraft"); console.table({url:config.url, method: config.method, data:config.data}); // GetDraft let status = MockAdapter.mockStatus(config); if (status !== 200) { return [status, null]; } console.groupCollapsed("response数据 status: "+status+" data: "); console.table({}); console.groupEnd(); console.groupEnd(); return [status, {}]; }); // Save mock.onPost(new RegExp(/^\/orgdeptusers\/?([a-zA-Z0-9\-\;]{0,35})\/save$/)).reply((config: any) => { console.groupCollapsed("实体:orgdeptuser 方法: Save"); console.table({url:config.url, method: config.method, data:config.data}); let status = MockAdapter.mockStatus(config); if (status !== 200) { return [status, null]; } const paramArray:Array<any> = ['orgdeptuserid']; const matchArray:any = new RegExp(/^\/orgdeptusers\/([a-zA-Z0-9\-\;]{1,35})\/save$/).exec(config.url); let tempValue: any = {}; if(matchArray && matchArray.length >1 && paramArray && paramArray.length >0){ paramArray.forEach((item: any, index: number) => { Object.defineProperty(tempValue, item, { enumerable: true, value: matchArray[index + 1] }); }); } //let items = mockDatas ? mockDatas : []; //let _items = items.find((item: any) => Object.is(item.orgdeptuserid, tempValue.orgdeptuserid)); let data = JSON.parse(config.data); mockDatas.forEach((item)=>{ if(item['orgdeptuserid'] == tempValue['orgdeptuserid'] ){ for(let value in data){ if(item.hasOwnProperty(value)){ item[value] = data[value]; } } } }) console.groupCollapsed("response数据 status: "+status+" data: "); console.table(data); console.groupEnd(); console.groupEnd(); return [status, data]; }); // Create mock.onPost(new RegExp(/^\/orgdeptusers\/?([a-zA-Z0-9\-\;]{0,35})$/)).reply((config: any) => { console.groupCollapsed("实体:orgdeptuser 方法: Create"); console.table({url:config.url, method: config.method, data:config.data}); let status = MockAdapter.mockStatus(config); if (status !== 200) { return [status, null]; } const paramArray:Array<any> = ['orgdeptuserid']; const matchArray:any = new RegExp(/^\/orgdeptusers\/([a-zA-Z0-9\-\;]{1,35})$/).exec(config.url); let tempValue: any = {}; if(matchArray && matchArray.length >1 && paramArray && paramArray.length >0){ paramArray.forEach((item: any, index: number) => { Object.defineProperty(tempValue, item, { enumerable: true, value: matchArray[index + 1] }); }); } console.groupCollapsed("response数据 status: "+status+" data: "); console.table(mockDatas[0]); console.groupEnd(); console.groupEnd(); return [status, mockDatas[0]]; }); // Update mock.onPut(new RegExp(/^\/orgdeptusers\/?([a-zA-Z0-9\-\;]{0,35})$/)).reply((config: any) => { console.groupCollapsed("实体:orgdeptuser 方法: Update"); console.table({url:config.url, method: config.method, data:config.data}); let status = MockAdapter.mockStatus(config); if (status !== 200) { return [status, null]; } const paramArray:Array<any> = ['orgdeptuserid']; const matchArray:any = new RegExp(/^\/orgdeptusers\/([a-zA-Z0-9\-\;]{1,35})$/).exec(config.url); let tempValue: any = {}; if(matchArray && matchArray.length >1 && paramArray && paramArray.length >0){ paramArray.forEach((item: any, index: number) => { Object.defineProperty(tempValue, item, { enumerable: true, value: matchArray[index + 1] }); }); } //let items = mockDatas ? mockDatas : []; //let _items = items.find((item: any) => Object.is(item.orgdeptuserid, tempValue.orgdeptuserid)); let data = JSON.parse(config.data); mockDatas.forEach((item)=>{ if(item['orgdeptuserid'] == tempValue['orgdeptuserid'] ){ for(let value in data){ if(item.hasOwnProperty(value)){ item[value] = data[value]; } } } }) console.groupCollapsed("response数据 status: "+status+" data: "); console.table(data); console.groupEnd(); console.groupEnd(); return [status, data]; }); // CheckKey mock.onPost(new RegExp(/^\/orgdeptusers\/?([a-zA-Z0-9\-\;]{0,35})\/checkkey$/)).reply((config: any) => { console.groupCollapsed("实体:orgdeptuser 方法: CheckKey"); console.table({url:config.url, method: config.method, data:config.data}); let status = MockAdapter.mockStatus(config); if (status !== 200) { return [status, null]; } const paramArray:Array<any> = ['orgdeptuserid']; const matchArray:any = new RegExp(/^\/orgdeptusers\/([a-zA-Z0-9\-\;]{1,35})\/checkkey$/).exec(config.url); let tempValue: any = {}; if(matchArray && matchArray.length >1 && paramArray && paramArray.length >0){ paramArray.forEach((item: any, index: number) => { Object.defineProperty(tempValue, item, { enumerable: true, value: matchArray[index + 1] }); }); } //let items = mockDatas ? mockDatas : []; //let _items = items.find((item: any) => Object.is(item.orgdeptuserid, tempValue.orgdeptuserid)); let data = JSON.parse(config.data); mockDatas.forEach((item)=>{ if(item['orgdeptuserid'] == tempValue['orgdeptuserid'] ){ for(let value in data){ if(item.hasOwnProperty(value)){ item[value] = data[value]; } } } }) console.groupCollapsed("response数据 status: "+status+" data: "); console.table(data); console.groupEnd(); console.groupEnd(); return [status, data]; }); // FetchGetorgdeptuser mock.onGet(new RegExp(/^\/orgdeptusers\/fetchgetorgdeptuser$/)).reply((config: any) => { console.groupCollapsed("实体:orgdeptuser 方法: FetchGetorgdeptuser"); console.table({url:config.url, method: config.method, data:config.data}); let status = MockAdapter.mockStatus(config); if (status !== 200) { return [status, null]; } console.groupCollapsed("response数据 status: "+status+" data: "); console.table(mockDatas); console.groupEnd(); console.groupEnd(); return [status, mockDatas ? mockDatas : []]; }); // FetchGetorgdeptuser mock.onGet(new RegExp(/^\/orgdeptusers\/fetchgetorgdeptuser(\?[\w-./?%&=,]*)*$/)).reply((config: any) => { console.groupCollapsed("实体:orgdeptuser 方法: FetchGetorgdeptuser"); console.table({url:config.url, method: config.method, data:config.data}); if(config.url.includes('page')){ let url = config.url.split('?')[1]; let params = qs.parse(url); Object.assign(config, params); } let status = MockAdapter.mockStatus(config); if (status !== 200) { return [status, null]; } let total = mockDatas.length; let records: Array<any> = []; if(!config.page || !config.size){ records = mockDatas; }else{ if((config.page-1)*config.size < total){ records = mockDatas.slice(config.page,config.size); } } console.groupCollapsed("response数据 status: "+status+" data: "); console.table(records ? records : []); console.groupEnd(); console.groupEnd(); return [status, records ? records : []]; }); // FetchDefault mock.onGet(new RegExp(/^\/orgdeptusers\/fetchdefault$/)).reply((config: any) => { console.groupCollapsed("实体:orgdeptuser 方法: FetchDefault"); console.table({url:config.url, method: config.method, data:config.data}); let status = MockAdapter.mockStatus(config); if (status !== 200) { return [status, null]; } console.groupCollapsed("response数据 status: "+status+" data: "); console.table(mockDatas); console.groupEnd(); console.groupEnd(); return [status, mockDatas ? mockDatas : []]; }); // FetchDefault mock.onGet(new RegExp(/^\/orgdeptusers\/fetchdefault(\?[\w-./?%&=,]*)*$/)).reply((config: any) => { console.groupCollapsed("实体:orgdeptuser 方法: FetchDefault"); console.table({url:config.url, method: config.method, data:config.data}); if(config.url.includes('page')){ let url = config.url.split('?')[1]; let params = qs.parse(url); Object.assign(config, params); } let status = MockAdapter.mockStatus(config); if (status !== 200) { return [status, null]; } let total = mockDatas.length; let records: Array<any> = []; if(!config.page || !config.size){ records = mockDatas; }else{ if((config.page-1)*config.size < total){ records = mockDatas.slice(config.page,config.size); } } console.groupCollapsed("response数据 status: "+status+" data: "); console.table(records ? records : []); console.groupEnd(); console.groupEnd(); return [status, records ? records : []]; }); // URI参数传递情况未实现 // URI参数传递情况未实现 // URI参数传递情况未实现 // URI参数传递情况未实现 // URI参数传递情况未实现 // URI参数传递情况未实现 // URI参数传递情况未实现 // Get mock.onGet(new RegExp(/^\/orgdeptusers\/([a-zA-Z0-9\-\;]{1,35})$/)).reply((config: any) => { console.groupCollapsed("实体:orgdeptuser 方法: Get"); console.table({url:config.url, method: config.method, data:config.data}); let status = MockAdapter.mockStatus(config); if (status !== 200) { return [status, null]; } const paramArray:Array<any> = ['orgdeptuserid']; const matchArray:any = new RegExp(/^\/orgdeptusers\/([a-zA-Z0-9\-\;]{1,35})$/).exec(config.url); let tempValue: any = {}; if(matchArray && matchArray.length >1 && paramArray && paramArray.length >0){ paramArray.forEach((item: any, index: number) => { Object.defineProperty(tempValue, item, { enumerable: true, value: matchArray[index + 1] }); }); } let items = mockDatas ? mockDatas : []; let _items = items.find((item: any) => Object.is(item.orgdeptuserid, tempValue.orgdeptuserid)); console.groupCollapsed("response数据 status: "+status+" data: "); console.table(_items?_items:{}); console.groupEnd(); console.groupEnd(); return [status, _items?_items:{}]; }); // Remove mock.onDelete(new RegExp(/^\/orgdeptusers\/([a-zA-Z0-9\-\;]{1,35})$/)).reply((config: any) => { console.groupCollapsed("实体:orgdeptuser 方法: Remove"); console.table({url:config.url, method: config.method, data:config.data}); let status = MockAdapter.mockStatus(config); if (status !== 200) { return [status, null]; } const paramArray:Array<any> = ['orgdeptuserid']; const matchArray:any = new RegExp(/^\/orgdeptusers\/([a-zA-Z0-9\-\;]{1,35})$/).exec(config.url); let tempValue: any = {}; if(matchArray && matchArray.length >1 && paramArray && paramArray.length >0){ paramArray.forEach((item: any, index: number) => { Object.defineProperty(tempValue, item, { enumerable: true, value: matchArray[index + 1] }); }); } let items = mockDatas ? mockDatas : []; let _items = items.find((item: any) => Object.is(item.orgdeptuserid, tempValue.orgdeptuserid)); console.groupCollapsed("response数据 status: "+status+" data: "); console.table(_items?_items:{}); console.groupEnd(); console.groupEnd(); return [status, _items?_items:{}]; });