feat(mock): 添加12个模块的Mock数据
自定义Vite configureServer中间件,支持所有API端点的Mock数据返回 Ultraworked with Sisyphus Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>main
parent
9a99b926ac
commit
b43550acc2
@ -0,0 +1,82 @@
|
||||
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 } }),
|
||||
},
|
||||
{
|
||||
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 }),
|
||||
},
|
||||
{
|
||||
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
|
||||
@ -0,0 +1,70 @@
|
||||
import type { MockMethod } from './types'
|
||||
|
||||
const mock: MockMethod[] = [
|
||||
{
|
||||
url: '/mock-api/admin/dashboard/summary',
|
||||
method: 'get',
|
||||
response: {
|
||||
code: 0,
|
||||
data: {
|
||||
onlineCount: 142,
|
||||
totalMachines: 160,
|
||||
todayProduction: 2847,
|
||||
activeAlerts: 3,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
url: '/mock-api/admin/collector/status',
|
||||
method: 'get',
|
||||
response: {
|
||||
code: 0,
|
||||
data: {
|
||||
status: 'running',
|
||||
uptimeSeconds: 316800,
|
||||
lastCollectTime: '2026-04-25T17:36:38',
|
||||
successCount: 1280,
|
||||
failCount: 5,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
url: '/mock-api/admin/dashboard/machine-rank',
|
||||
method: 'get',
|
||||
response: {
|
||||
code: 0,
|
||||
data: {
|
||||
items: [
|
||||
{ rank: 1, machineId: 1, machineName: '西-1.8', program: '1566.NC', quantity: 580, status: 1 },
|
||||
{ rank: 2, machineId: 2, machineName: '西-1.10', program: 'O123.NC', quantity: 420, status: 1 },
|
||||
{ rank: 3, machineId: 3, machineName: '东-2.0', program: 'A456.NC', quantity: 380, status: 1 },
|
||||
{ rank: 4, machineId: 4, machineName: '东-2.5', program: 'B789.NC', quantity: 310, status: 0 },
|
||||
{ rank: 5, machineId: 5, machineName: '南-3.1', program: 'C012.NC', quantity: 290, status: 1 },
|
||||
{ rank: 6, machineId: 6, machineName: '南-3.2', program: 'D345.NC', quantity: 240, status: 1 },
|
||||
{ rank: 7, machineId: 7, machineName: '北-4.0', program: 'E678.NC', quantity: 210, status: 1 },
|
||||
{ rank: 8, machineId: 8, machineName: '北-4.1', program: 'F901.NC', quantity: 180, status: 0 },
|
||||
{ rank: 9, machineId: 9, machineName: '西-1.5', program: 'G234.NC', quantity: 150, status: 1 },
|
||||
{ rank: 10, machineId: 10, machineName: '东-2.8', program: 'H567.NC', quantity: 87, status: 1 },
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
url: '/mock-api/admin/dashboard/worker-rank',
|
||||
method: 'get',
|
||||
response: {
|
||||
code: 0,
|
||||
data: {
|
||||
items: [
|
||||
{ rank: 1, workerId: 1, workerName: '张三', machineCount: 3, totalQuantity: 1240 },
|
||||
{ rank: 2, workerId: 2, workerName: '李四', machineCount: 2, totalQuantity: 980 },
|
||||
{ rank: 3, workerId: 3, workerName: '王五', machineCount: 4, totalQuantity: 870 },
|
||||
{ rank: 4, workerId: 4, workerName: '赵六', machineCount: 2, totalQuantity: 650 },
|
||||
{ rank: 5, workerId: 5, workerName: '孙七', machineCount: 3, totalQuantity: 520 },
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
export default mock
|
||||
@ -0,0 +1,24 @@
|
||||
import type { MockMethod } from './types'
|
||||
|
||||
const mock: MockMethod[] = [
|
||||
{
|
||||
url: '/mock-api/admin/login',
|
||||
method: 'post',
|
||||
response: (req: any) => {
|
||||
const { username, password, rememberMe } = req.body
|
||||
if (username === 'admin' && password === 'admin123') {
|
||||
return {
|
||||
code: 0,
|
||||
message: 'success',
|
||||
data: {
|
||||
token: rememberMe ? 'eyJhbGciOiJIUzI1NiJ9.admin.7d' : 'eyJhbGciOiJIUzI1NiJ9.admin.8h',
|
||||
expiresIn: rememberMe ? 604800 : 28800,
|
||||
},
|
||||
}
|
||||
}
|
||||
return { code: 40001, message: '用户名或密码错误', data: null }
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
export default mock
|
||||
@ -0,0 +1,119 @@
|
||||
import type { MockMethod } from './types'
|
||||
|
||||
const machines = [
|
||||
{ id: 1, name: '西-1.8', deviceCode: 'fanake_1.8', workshopId: 1, workshopName: 'A栋', brandId: 1, brandName: 'FANUC', collectAddressId: 1, ipAddress: '10.1.1.8', isOnline: 1, workerId: 1, workerName: '张三', isEnabled: 1 },
|
||||
{ id: 2, name: '西-1.10', deviceCode: 'fanake_1.10', workshopId: 1, workshopName: 'A栋', brandId: 1, brandName: 'FANUC', collectAddressId: 1, ipAddress: '10.1.1.10', isOnline: 1, workerId: 2, workerName: '李四', isEnabled: 1 },
|
||||
{ id: 3, name: '东-2.0', deviceCode: 'fanake_2.0', workshopId: 2, workshopName: 'B栋', brandId: 1, brandName: 'FANUC', collectAddressId: 2, ipAddress: '10.1.2.0', isOnline: 0, workerId: 3, workerName: '王五', isEnabled: 1 },
|
||||
{ id: 4, name: '东-2.5', deviceCode: 'siemens_2.5', workshopId: 2, workshopName: 'B栋', brandId: 2, brandName: 'SIEMENS', collectAddressId: 2, ipAddress: '10.1.2.5', isOnline: 0, workerId: null, workerName: null, isEnabled: 0 },
|
||||
{ id: 5, name: '南-3.1', deviceCode: 'fanake_3.1', workshopId: 3, workshopName: 'C栋', brandId: 1, brandName: 'FANUC', collectAddressId: 1, ipAddress: '10.1.3.1', isOnline: 1, workerId: 4, workerName: '赵六', isEnabled: 1 },
|
||||
]
|
||||
|
||||
const mock: MockMethod[] = [
|
||||
{
|
||||
url: '/mock-api/admin/machine',
|
||||
method: 'get',
|
||||
response: ({ query }: any) => {
|
||||
let items = [...machines]
|
||||
if (query.workshopId) items = items.filter((m: any) => m.workshopId === Number(query.workshopId))
|
||||
if (query.isOnline !== undefined && query.isOnline !== '') items = items.filter((m: any) => m.isOnline === Number(query.isOnline))
|
||||
if (query.brandId) items = items.filter((m: any) => m.brandId === Number(query.brandId))
|
||||
if (query.keyword) items = items.filter((m: any) => m.name.includes(query.keyword) || m.deviceCode.includes(query.keyword))
|
||||
return { code: 0, data: { items, total: items.length, page: Number(query.page || 1), pageSize: Number(query.pageSize || 20) } }
|
||||
},
|
||||
},
|
||||
{
|
||||
url: '/mock-api/admin/machine/detail',
|
||||
method: 'get',
|
||||
response: ({ query }: any) => {
|
||||
const id = Number(query.id)
|
||||
const m = machines.find((m: any) => m.id === id)
|
||||
return { code: 0, data: m || null }
|
||||
},
|
||||
},
|
||||
{
|
||||
url: '/mock-api/admin/machine/status',
|
||||
method: 'get',
|
||||
response: () => ({
|
||||
code: 0,
|
||||
data: { programName: '1566.NC', partCount: 580, runStatus: '运行中', operateMode: '自动', spindleSpeedSet: 3000, feedSpeedSet: 500, spindleSpeedActual: 2980, feedSpeedActual: 480, spindleLoad: 65, machiningStatus: 'G01', lastCollectTime: '2026-04-25T17:36:38' },
|
||||
}),
|
||||
},
|
||||
{
|
||||
url: '/mock-api/admin/machine',
|
||||
method: 'post',
|
||||
response: () => ({ code: 0, message: 'success', data: { id: 161, name: '新机床' } }),
|
||||
},
|
||||
{
|
||||
url: '/mock-api/admin/machine/update',
|
||||
method: 'post',
|
||||
response: () => ({ code: 0, message: 'success', data: null }),
|
||||
},
|
||||
{
|
||||
url: '/mock-api/admin/machine/delete',
|
||||
method: 'post',
|
||||
response: () => ({ code: 0, message: 'success', data: null }),
|
||||
},
|
||||
{
|
||||
url: '/mock-api/admin/machine/batch-status',
|
||||
method: 'post',
|
||||
response: () => ({ code: 0, message: 'success', data: null }),
|
||||
},
|
||||
{
|
||||
url: '/mock-api/admin/machine/production/today',
|
||||
method: 'get',
|
||||
response: () => ({
|
||||
code: 0,
|
||||
data: { items: [
|
||||
{ programName: '1566.NC', quantity: 580, runTime: '4h20m', cuttingTime: '3h50m' },
|
||||
{ programName: 'O123.NC', quantity: 120, runTime: '2h10m', cuttingTime: '1h45m' },
|
||||
] },
|
||||
}),
|
||||
},
|
||||
{
|
||||
url: '/mock-api/admin/machine/production/trend',
|
||||
method: 'get',
|
||||
response: () => ({
|
||||
code: 0,
|
||||
data: { items: [
|
||||
{ date: '2026-04-19', quantity: 820 }, { date: '2026-04-20', quantity: 760 },
|
||||
{ date: '2026-04-21', quantity: 910 }, { date: '2026-04-22', quantity: 850 },
|
||||
{ date: '2026-04-23', quantity: 780 }, { date: '2026-04-24', quantity: 900 },
|
||||
{ date: '2026-04-25', quantity: 700 },
|
||||
] },
|
||||
}),
|
||||
},
|
||||
{
|
||||
url: '/mock-api/admin/machine/collect-records',
|
||||
method: 'get',
|
||||
response: () => ({
|
||||
code: 0,
|
||||
data: { items: [
|
||||
{ collectTime: '2026-04-25T17:36:35', programName: '1566.NC', partCount: 580, runStatus: '运行中' },
|
||||
{ collectTime: '2026-04-25T17:36:05', programName: '1566.NC', partCount: 579, runStatus: '运行中' },
|
||||
{ collectTime: '2026-04-25T17:35:35', programName: '1566.NC', partCount: 578, runStatus: '运行中' },
|
||||
] },
|
||||
}),
|
||||
},
|
||||
{
|
||||
url: '/mock-api/admin/workshop/list',
|
||||
method: 'get',
|
||||
response: () => ({ code: 0, data: { items: [{ id: 1, name: 'A栋' }, { id: 2, name: 'B栋' }, { id: 3, name: 'C栋' }] } }),
|
||||
},
|
||||
{
|
||||
url: '/mock-api/admin/brand/list',
|
||||
method: 'get',
|
||||
response: () => ({ code: 0, data: { items: [{ id: 1, brandName: 'FANUC' }, { id: 2, brandName: 'SIEMENS' }, { id: 3, brandName: 'MITSUBISHI' }] } }),
|
||||
},
|
||||
{
|
||||
url: '/mock-api/admin/collect-address/list',
|
||||
method: 'get',
|
||||
response: () => ({ code: 0, data: { items: [{ id: 1, name: 'FANUC-A栋', brandId: 1 }, { id: 2, name: 'FANUC-B栋', brandId: 1 }] } }),
|
||||
},
|
||||
{
|
||||
url: '/mock-api/admin/worker/list',
|
||||
method: 'get',
|
||||
response: () => ({ code: 0, data: { items: [{ id: 1, name: '张三', code: 'W001' }, { id: 2, name: '李四', code: 'W002' }, { id: 3, name: '王五', code: 'W003' }] } }),
|
||||
},
|
||||
]
|
||||
|
||||
export default mock
|
||||
@ -0,0 +1,16 @@
|
||||
/**
|
||||
* Mock 路由类型定义
|
||||
* 替代 vite-plugin-mock 的 MockMethod 类型
|
||||
*/
|
||||
export interface MockRequest {
|
||||
query: Record<string, string>
|
||||
body: any
|
||||
url: string
|
||||
method: string
|
||||
}
|
||||
|
||||
export interface MockMethod {
|
||||
url: string
|
||||
method?: 'get' | 'post' | 'put' | 'delete' | 'patch'
|
||||
response?: ((req: MockRequest) => any) | any
|
||||
}
|
||||
Loading…
Reference in New Issue