import type { MockMethod } from './types' const brands = [ { id: 1, brandName: 'FANUC', deviceField: 'device', tagsPath: 'tags', isEnabled: 1, fieldCount: 8 }, { id: 2, brandName: 'SIEMENS', deviceField: 'device', tagsPath: 'tags', isEnabled: 1, fieldCount: 12 }, { id: 3, brandName: 'MITSUBISHI', deviceField: 'device', tagsPath: 'tags', isEnabled: 0, fieldCount: 8 }, ] const standardFields = [ 'program_name', 'part_count', 'total_part_count', 'device_status', 'run_status', 'operate_mode', 'power_on_time', 'run_time', ] // FANUC字段映射(与实际FANUC采集JSON中的tag id一致) const fanucMappings = [ { id: 1, standardField: 'program_name', fieldName: 'Tag5', matchBy: 'id', dataType: 'string', isRequired: 1 }, { id: 2, standardField: 'part_count', fieldName: 'Tag8', matchBy: 'id', dataType: 'number', isRequired: 1 }, { id: 3, standardField: 'total_part_count', fieldName: 'Tag1', matchBy: 'id', dataType: 'number', isRequired: 0 }, { id: 4, standardField: 'device_status', fieldName: '_io_status', matchBy: 'id', dataType: 'number', isRequired: 1 }, { id: 5, standardField: 'run_status', fieldName: 'Tag9', matchBy: 'id', dataType: 'number', isRequired: 0 }, { id: 6, standardField: 'operate_mode', fieldName: 'Tag11', matchBy: 'id', dataType: 'number', isRequired: 0 }, { id: 7, standardField: 'power_on_time', fieldName: 'Tag22', matchBy: 'id', dataType: 'number', isRequired: 0 }, { id: 8, standardField: 'run_time', fieldName: 'Tag23', matchBy: 'id', dataType: 'number', isRequired: 0 }, ] const mock: MockMethod[] = [ { url: '/mock-api/admin/brand', method: 'get', response: () => ({ code: 0, data: { items: brands } }), }, { // 参数化路由:匹配 /mock-api/admin/brand/1, /mock-api/admin/brand/2 等 url: '/mock-api/admin/brand/:id', method: 'get', response: ({ params }: any) => { const id = Number(params.id) const b = brands.find((b: any) => b.id === id) return { code: 0, data: { ...b, mappings: id === 1 ? fanucMappings : [] } } }, }, { // 兼容旧URL格式 url: '/mock-api/admin/brand/detail', method: 'get', response: ({ query }: any) => { const id = Number(query.id) const b = brands.find((b: any) => b.id === id) return { code: 0, data: { ...b, mappings: id === 1 ? fanucMappings : [] } } }, }, { url: '/mock-api/admin/brand', method: 'post', response: () => ({ code: 0, message: 'success', data: { id: 4, brandName: '新品牌' } }), }, { url: '/mock-api/admin/brand/update', method: 'post', response: () => ({ code: 0, message: 'success', data: null }), }, { url: '/mock-api/admin/brand/delete', method: 'post', response: () => ({ code: 0, message: 'success', data: null }), }, { // 参数化路由:POST /mock-api/admin/brand/:id/copy url: '/mock-api/admin/brand/:id/copy', method: 'post', response: () => ({ code: 0, message: 'success', data: { id: 4, brandName: '新复制品牌' } }), }, { // 兼容旧URL格式 url: '/mock-api/admin/brand/copy', method: 'post', response: () => ({ code: 0, message: 'success', data: { id: 4, brandName: '新复制品牌' } }), }, { url: '/mock-api/admin/brand/toggle', method: 'post', response: () => ({ code: 0, message: 'success', data: null }), }, { url: '/mock-api/admin/brand/standard-fields', method: 'get', response: () => ({ code: 0, data: { items: standardFields } }), }, ] export default mock