You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
haoliang-net/frontend/mock/brand.ts

101 lines
4.5 KiB
TypeScript

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import type { MockMethod } from './types'
const brands = [
{ id: 1, brandName: 'FANUC', deviceField: 'device', tagsPath: 'tags', isEnabled: 1, fieldCount: 16 },
{ 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', 'device_status', 'run_status', 'operate_mode',
'spindle_speed_set', 'feed_speed_set', 'spindle_speed_actual', 'feed_speed_actual',
'spindle_load', 'spindle_override', 'power_on_time', 'run_time', 'cutting_time',
'cycle_time', 'machining_status',
]
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: 'device_status', fieldName: '_io_status', matchBy: 'id', dataType: 'number', isRequired: 1 },
{ id: 4, standardField: 'run_status', fieldName: 'Tag9', matchBy: 'id', dataType: 'number', isRequired: 0 },
{ id: 5, standardField: 'operate_mode', fieldName: 'Tag10', matchBy: 'id', dataType: 'number', isRequired: 0 },
{ id: 6, standardField: 'spindle_speed_set', fieldName: 'Tag11', matchBy: 'id', dataType: 'number', isRequired: 0 },
{ id: 7, standardField: 'feed_speed_set', fieldName: 'Tag12', matchBy: 'id', dataType: 'number', isRequired: 0 },
{ id: 8, standardField: 'spindle_speed_actual', fieldName: 'Tag13', matchBy: 'id', dataType: 'number', isRequired: 0 },
{ id: 9, standardField: 'feed_speed_actual', fieldName: 'Tag14', matchBy: 'id', dataType: 'number', isRequired: 0 },
{ id: 10, standardField: 'spindle_load', fieldName: 'Tag15', matchBy: 'id', dataType: 'number', isRequired: 0 },
{ id: 11, standardField: 'spindle_override', fieldName: 'Tag16', matchBy: 'id', dataType: 'number', isRequired: 0 },
{ id: 12, standardField: 'power_on_time', fieldName: 'Tag17', matchBy: 'id', dataType: 'number', isRequired: 0 },
{ id: 13, standardField: 'run_time', fieldName: 'Tag18', matchBy: 'id', dataType: 'number', isRequired: 0 },
{ id: 14, standardField: 'cutting_time', fieldName: 'Tag19', matchBy: 'id', dataType: 'number', isRequired: 0 },
{ id: 15, standardField: 'cycle_time', fieldName: 'Tag20', matchBy: 'id', dataType: 'number', isRequired: 0 },
{ id: 16, standardField: 'machining_status', fieldName: 'Tag21', matchBy: 'id', dataType: 'string', 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