import { http, HttpResponse } from '@lingshu/vite-plugin-msw/msw'; import { uniqueId } from 'lodash-es'; const LingUrlPrefix = '/biz-gateway/lcdp/api/v1'; const modelIdBase = '778229670118928363'; const idBases = Array.from({ length: 10 }, () => `${uniqueId(`featureCategory_`)}+${modelIdBase}`); const dataMap = new Map(); dataMap.set(modelIdBase, idBases.map((id, index) => ({ id, categoryName: { 'zh-CN': `特征类别${index + 1}`, }, categoryCode: id, parentId: index === 0 ? '0' : idBases[0], }))); const featureGroupDefault = [ { fieldId: '0', fieldName: 'CURRENT_YEAR', sort: 0, caption: { 'zh-CN': '当前年份', }, fieldSchema: { type: 'DATETIME', caption: { 'zh-CN': '当前年份', }, fieldName: 'CURRENT_YEAR', extAttribute: { format: 'YYYY', start: { selection: 'unlimited', specific: null, preset: 'today', presetTime: null, }, end: { selection: 'unlimited', specific: null, preset: 'today', presetTime: null, }, }, customAttribute: {}, operationControl: { canCopy: true, canImport: true, canExport: true, }, required: false, defaultValue: [ null, ], defaultValueType: 'CONST', max: null, maxInclusive: true, min: null, minInclusive: true, unique: false, linkageType: 'FIELD', linkageContent: '', uiProps: {}, dataModelFieldId: '779533438027416274', dataModelId: '758146167501101367', fromTemplate: false, editable: true, tableName: 'cc1_base_data', referenceId: '0', fieldGroup: 0, referenced: false, builtin: true, sortable: true, }, }, { fieldId: '0', fieldName: 'CURRENT_ORG', sort: 1, caption: { 'zh-CN': '当前组织', }, fieldSchema: { type: 'ORG', caption: { 'zh-CN': '当前组织', }, fieldName: 'CURRENT_ORG', extAttribute: { refFields: [ 'name', 'code', ], filter: { type: 'group', operator: 'AND', children: null, }, displayContent: 'codeAndName', displayFormat: null, filterType: null, }, customAttribute: {}, operationControl: { canCopy: true, canImport: true, canExport: true, }, required: false, defaultValue: [], defaultValueType: 'CONST', max: null, maxInclusive: true, min: null, minInclusive: true, unique: false, linkageType: 'FIELD', linkageContent: '', uiProps: {}, dataModelFieldId: '779533438027416273', dataModelId: '758146167501101367', fromTemplate: false, editable: true, tableName: 'cc1_base_data', referenceId: '0', fieldGroup: 0, referenced: false, builtin: true, sortable: true, }, }, { fieldId: '0', fieldName: 'CURRENT_USER', sort: 2, caption: { 'zh-CN': '当前用户', }, fieldSchema: { type: 'EMPLOYEE', caption: { 'zh-CN': '当前用户', }, fieldName: 'CURRENT_USER', extAttribute: { refFields: [ 'name', 'account', ], filter: { type: 'group', operator: 'AND', children: null, }, displayContent: 'codeAndName', displayFormat: '3', filterType: 'CURRENT_USER', }, customAttribute: {}, operationControl: { canCopy: true, canImport: true, canExport: true, }, required: false, defaultValue: [ 'currentUser', ], defaultValueType: 'CONTEXT_VAR', max: null, maxInclusive: true, min: null, minInclusive: true, unique: false, linkageType: 'FIELD', linkageContent: '', uiProps: {}, dataModelFieldId: '779330580930731985', dataModelId: '758146167501101367', fromTemplate: false, editable: true, tableName: 'cc1_base_data', referenceId: '0', fieldGroup: 0, referenced: false, builtin: true, sortable: true, }, }, { fieldId: 'zuzhidanxuan', fieldName: 'zuzhidanxuan', sort: 3, caption: { 'zh-CN': '组织单选', }, fieldSchema: { type: 'ORG', caption: { 'zh-CN': '组织单选', }, fieldName: 'zuzhidanxuan', extAttribute: { refFields: [ 'name', 'code', ], filter: { type: 'group', operator: 'AND', children: null, }, displayContent: 'codeAndName', displayFormat: null, filterType: null, }, customAttribute: {}, operationControl: { canCopy: true, canImport: true, canExport: true, }, required: false, defaultValue: [], defaultValueType: 'CONST', max: null, maxInclusive: true, min: null, minInclusive: true, unique: false, linkageType: 'FIELD', linkageContent: '', uiProps: {}, dataModelFieldId: '779533438027416273', dataModelId: '758146167501101367', fromTemplate: false, editable: true, tableName: 'cc1_base_data', referenceId: '0', fieldGroup: 0, referenced: false, builtin: true, sortable: true, }, }, { fieldId: 'rendanxuan', fieldName: 'rendanxuan', sort: 4, caption: { 'zh-CN': '人单选', }, fieldSchema: { type: 'EMPLOYEE', caption: { 'zh-CN': '人单选', }, fieldName: 'rendanxuan', extAttribute: { refFields: [ 'name', 'account', ], filter: { type: 'group', operator: 'AND', children: null, }, displayContent: 'codeAndName', displayFormat: '3', filterType: 'CURRENT_USER', }, customAttribute: {}, operationControl: { canCopy: true, canImport: true, canExport: true, }, required: false, defaultValue: [ 'currentUser', ], defaultValueType: 'CONTEXT_VAR', max: null, maxInclusive: true, min: null, minInclusive: true, unique: false, linkageType: 'FIELD', linkageContent: '', uiProps: {}, dataModelFieldId: '779330580930731985', dataModelId: '758146167501101367', fromTemplate: false, editable: true, tableName: 'cc1_base_data', referenceId: '0', fieldGroup: 0, referenced: false, builtin: true, sortable: true, }, }, { fieldId: 'jichudanxuan', fieldName: 'jichudanxuan', sort: 5, caption: { 'zh-CN': '数据对象单选', }, fieldSchema: { type: 'BASIC_DATA_REF', caption: { 'zh-CN': '数据对象单选', }, fieldName: 'jichudanxuan', extAttribute: { refFields: [ 'ry', 'update_name', 'name', 'www.update_name', ], filter: { type: 'group', operator: 'AND', children: null, }, displayContent: 'nameAndCode', displayFormat: null, defaultPageId: '778229670060208106', filterType: null, }, customAttribute: {}, operationControl: { canCopy: true, canImport: true, canExport: true, }, required: false, defaultValue: [], defaultValueType: 'CONST', max: null, maxInclusive: true, min: null, minInclusive: true, unique: false, linkageType: 'FIELD', linkageContent: '', uiProps: {}, featureTag: '0', dataModelFieldId: '779554049872654274', dataModelId: '778229670118928363', fromTemplate: false, editable: true, tableName: 'gua_tag_field', referenceId: '778229670118928363', fieldGroup: 0, referenced: false, builtin: true, sortable: true, }, }, { fieldId: 'xiahuaduoxuan', fieldName: 'xiahuaduoxuan', sort: 6, caption: { 'zh-CN': '下拉单选', }, fieldSchema: { type: 'SINGLE_SELECTOR', caption: { 'zh-CN': '下拉单选', }, fieldName: 'xiahuaduoxuan', extAttribute: { referenceOption: [ { id: '1', value: 'a', label: { 'zh-CN': '你好', }, disabled: false, sort: 0, }, ], }, customAttribute: {}, operationControl: { canCopy: true, canImport: true, canExport: true, }, required: false, defaultValue: [ 'a', ], defaultValueType: 'FIXED', max: null, maxInclusive: true, min: null, minInclusive: true, unique: false, linkageType: 'FIELD', linkageContent: null, uiProps: {}, dataModelFieldId: '760387891669144305', dataModelId: '758146167501101367', fromTemplate: false, editable: true, tableName: 'cc1_base_data', referenceId: '760387891915134642', fieldGroup: 0, referenced: false, builtin: true, sortable: true, }, }, { fieldId: 'dandujizhuangtai', fieldName: 'dandujizhuangtai', sort: 7, caption: { 'zh-CN': '单据状态', }, fieldSchema: { type: 'BILL_STATUS', caption: { 'zh-CN': '单据状态', }, fieldName: 'dandujizhuangtai', extAttribute: { referenceOption: [ { id: '2968511070737', value: 'a', label: { 'zh-CN': 'a', }, disabled: false, sort: 0, changedBy: null, changedAt: null, }, { id: '5379544144189', value: 'b', label: { 'zh-CN': 'b', }, disabled: false, sort: 1, changedBy: null, changedAt: null, }, { id: '8079944907546', value: 'c', label: { 'zh-CN': 'c', }, disabled: false, sort: 2, changedBy: null, changedAt: null, }, ], }, customAttribute: {}, operationControl: { canCopy: true, canImport: true, canExport: true, }, required: false, defaultValue: [ '', ], defaultValueType: 'CONST', max: null, maxInclusive: true, min: null, minInclusive: true, unique: false, linkageType: 'FIELD', linkageContent: '', uiProps: {}, dataModelFieldId: '779533438023221968', dataModelId: '758146167501101367', fromTemplate: false, editable: true, tableName: 'cc1_base_data', referenceId: '0', fieldGroup: 0, referenced: false, builtin: true, sortable: true, }, }, ]; const featureDimensionSaveCmdListMap = new Map(); idBases.forEach(id => featureDimensionSaveCmdListMap.set(modelIdBase + id, featureGroupDefault)); const descriptionMap = new Map(); idBases.forEach((id, index) => descriptionMap.set(modelIdBase + id, { 'zh-CN': `特征类别${index + 1}的描述` })); const featureGroupMap = new Map(); function setData(modelId: string, data: any) { const id = data?.id || `${uniqueId(`featureCategory_`)}+${modelId}`; featureDimensionSaveCmdListMap.set(modelId + id, data.featureDimensionSaveCmdList || []); descriptionMap.set(modelId + id, data?.description || {}); const list = dataMap.get(modelId); if (list) { list.push({ id, categoryName: data?.categoryName || {}, categoryCode: data.categoryCode, parentId: data.parentId ? data.parentId : '0', }); } else { dataMap.set(modelId, [{ id, categoryName: data?.categoryName || {}, categoryCode: data.categoryCode, parentId: data.parentId ? data.parentId : '0', }]); } } function getData(modelId: string, id: string) { const list = dataMap.get(modelId) || []; const item = list.find((i: { id: string }) => i.id === id); return { ...item, featureDimensionSaveCmdList: featureDimensionSaveCmdListMap.get(modelId + id) || [], description: descriptionMap.get(modelId + id) || {}, }; } function delData(modelId: string, id: string) { const list = dataMap.get(modelId) || []; list.splice(list.findIndex((i: { id: string }) => i.id === id), 1); featureDimensionSaveCmdListMap.delete(modelId + id); descriptionMap.delete(modelId + id); } function updateData(modelId: string, id: string, data: any) { const list = dataMap.get(modelId) || []; list[list.findIndex((i: { id: string }) => i.id === id)] = { id, categoryName: data?.categoryName || {}, categoryCode: data.categoryCode, parentId: data.parentId ? data.parentId : '0', }; featureDimensionSaveCmdListMap.set(modelId + id, data.featureDimensionSaveCmdList || []); descriptionMap.set(modelId + id, data?.description || {}); } const handlers = [ http.post(`${LingUrlPrefix}/feature-category/category-list`, async ({ request }) => { const data: any = await request.json(); const modelId = data?.modelId || ''; const keyword = data?.keyword || []; // const isList = dataMap.get(modelId); // if (!isList) { // dataMap.set(modelId, list?.map((i, index) => ({ // ...i, // id: `${i.id}+${modelId}`, // categoryName: { 'zh-CN': `${i.categoryName['zh-CN']}_${modelId.slice(-4)}` }, // categoryCode: i.categoryCode + modelId, // parentId: index === 0 ? '0' : `${i.parentId}+${modelId}`, // }))); // } const dataList = dataMap.get(modelId); return HttpResponse.json({ code: '0', message: '', data: keyword?.length ? dataList?.filter((i: { categoryName: { [x: string]: string | any[] } }) => i.categoryName['zh-CN']?.includes(keyword)) || [] : dataList || [], }); }), http.post(`${LingUrlPrefix}/feature-category/save`, async ({ request }) => { const data: any = await request.json(); const modelId = data?.modelId || ''; setData(modelId, data); return HttpResponse.json({ code: '0', message: '', data: '', }); }), http.post(`${LingUrlPrefix}/feature-category/delete`, async ({ request }) => { const data: any = await request.json(); const modelId = data?.modelId || ''; const featureCategoryIds = data?.featureCategoryIds || []; featureCategoryIds.forEach((id: string) => delData(modelId, id)); // 模拟删除延迟 await new Promise(a => setTimeout(a, 300)); return HttpResponse.json({ code: '0', message: '', data: '', }); }), http.post(`${LingUrlPrefix}/feature-category/update`, async ({ request }) => { const data: any = await request.json(); const modelId = data?.modelId || ''; const id = data?.id || ''; updateData(modelId, id, data); // 模拟删除延迟 await new Promise(a => setTimeout(a, 2000)); return HttpResponse.json({ code: '0', message: '', data: '', }); }), http.get(`${LingUrlPrefix}/feature-category/category-detail`, async ({ request }) => { try { const id = new URL(request.url).searchParams.get('id') || ''; const modelId = new URL(request.url).searchParams.get('modelId') || ''; const detail = getData(modelId, id); // 模拟详情延迟 await new Promise(a => setTimeout(a, 300)); return HttpResponse.json({ code: '0', message: '', data: detail, }); } catch (e) { console.log(e); return HttpResponse.json({ code: '1', message: '获取特征类别详情失败', data: '', }); } }), http.get(`${LingUrlPrefix}/feature-category/dimension-with-group-by-category-id`, async ({ request }) => { try { const id = new URL(request.url).searchParams.get('categoryId') || ''; const modelId = new URL(request.url).searchParams.get('modelId') || ''; const detail = getData(modelId, id); // 模拟详情延迟 await new Promise(a => setTimeout(a, 300)); return HttpResponse.json({ code: '0', message: '', data: { featureDimensionDetailCoList: detail.featureDimensionSaveCmdList }, }); } catch (e) { console.log(e); return HttpResponse.json({ code: '1', message: '获取特征类别关联的特征维度失败', data: '', }); } }), http.post(`${LingUrlPrefix}/feature-variable/list`, async () => { // const data: any = await request.json(); // const modelId = data?.modelId || ''; // const id = data?.id || ''; return HttpResponse.json({ code: '0', message: '', data: Array.from({ length: 100 }, (_, index) => ({ id: `${index}`, fieldName: { 'zh-CN': `特征类别${index}` }, fieldId: `categoryCode${index}`, type: '啊dasd啊', })), }); }), http.post(`${LingUrlPrefix}/feature-var-lable/save`, async () => { // const data: any = await request.json(); // const modelId = data?.modelId || ''; // const id = data?.id || ''; return HttpResponse.json({ code: '0', message: '', data: { current: 1, size: 10, total: 100, records: Array.from({ length: 10 }, (_, index) => ({ id: `${index}`, fieldName: { 'zh-CN': `特征类别${index}` }, fieldId: `categoryCode${index}`, type: '啊dasd啊', })), }, }); }), http.post(`${LingUrlPrefix}/feature-group/save`, async ({ request }) => { const data: any = await request.json(); const modelId = data?.modelId || ''; const id = data?.id || ''; // const groupCode = data?.groupCode || ''; // const familyCode = data?.familyCode || ''; // const fieldName = data?.fieldName || ''; // const fieldValue = data?.fieldValue || ''; // const matchType = data?.matchType || ''; featureGroupMap.set(modelId + id, data); return HttpResponse.json({ code: '0', message: '', data: { current: 1, size: 10, total: 100, records: Array.from({ length: 10 }, (_, index) => ({ id: `${index}`, fieldName: { 'zh-CN': `特征类别${index}` }, fieldId: `categoryCode${index}`, type: '啊dasd啊', })), }, }); }), http.get(`${LingUrlPrefix}/feature-group/list/all`, async () => { // featureGroupMap.set(modelId + id, data); return HttpResponse.json({ code: '0', message: '', data: Array.from({ length: 200 }, _ => featureGroupDefault?.reduce((pre: Record, item: any) => { if (!item.fieldName) { return pre; } pre[(item as any).fieldName as string] = { _value: '', _object: { id: '1295273894690', value: 'a', label: { 'zh-CN': '你好', }, disabled: false, sort: 0, }, _matchType: '', }; return pre; }, { FEATURE_GROUP_CODE: { _value: '3333', _object: '3333', _matchType: '', } } as Record))?.map((i, j) => ({ ...i, isDeleted: j === 0, id: uniqueId('a') })), }); }), ]; export default handlers;