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/worker.ts

52 lines
3.2 KiB
TypeScript

import type { MockMethod } from './types'
const workers = [
{ id: 1, code: 'W001', name: '张三', isEnabled: 1, machineCount: 2, machineNames: '西-1.8,西-2.0' },
{ id: 2, code: 'W002', name: '李四', isEnabled: 1, machineCount: 1, machineNames: '西-1.10' },
{ id: 3, code: 'W003', name: '王五', isEnabled: 0, machineCount: 0, machineNames: '-' },
]
const mock: MockMethod[] = [
{ url: '/mock-api/admin/worker', method: 'get', response: ({ query }: any) => {
let items = [...workers]
const page = Number(query.page) || 1
const pageSize = Number(query.pageSize) || 20
const original = items
if (query.isEnabled !== undefined && query.isEnabled !== '') items = items.filter((w: any) => w.isEnabled === Number(query.isEnabled))
if (query.keyword) items = items.filter((w: any) => w.name.includes(query.keyword) || w.code.includes(query.keyword))
const total = original.length
const start = (page - 1) * pageSize
const end = start + pageSize
items = items.slice(start, end)
return { code: 0, data: { items, total, page, pageSize } }
}},
{ url: '/mock-api/admin/worker/detail', method: 'get', response: ({ query }: any) => {
const w = workers.find((w: any) => w.id === Number(query.id))
return { code: 0, data: w || null }
}},
{ url: '/mock-api/admin/worker', method: 'post', response: () => ({ code: 0, message: 'success', data: { id: 4, name: '赵六' } }) },
{ url: '/mock-api/admin/worker/update', method: 'post', response: () => ({ code: 0, message: 'success', data: null }) },
{ url: '/mock-api/admin/worker/delete', method: 'post', response: () => ({ code: 0, message: 'success', data: null }) },
{ url: '/mock-api/admin/worker/batch-status', method: 'post', response: () => ({ code: 0, message: 'success', data: null }) },
{ url: '/mock-api/admin/worker/machines', method: 'get', response: () => ({ code: 0, data: { items: [
{ machineId: 1, machineName: '西-1.8', deviceCode: 'fanake_1.8', workshopName: 'A栋', brandName: 'FANUC', isOnline: 1, programName: '1566.NC' },
{ machineId: 2, machineName: '西-2.0', deviceCode: 'fanake_2.0', workshopName: 'A栋', brandName: 'FANUC', isOnline: 0, programName: null },
] } }) },
{ url: '/mock-api/admin/worker/production/today', method: 'get', response: () => ({ code: 0, data: { items: [
{ machineName: '西-1.8', programName: '1566.NC', quantity: 580, runTime: '4h20m', cuttingTime: '3h50m' },
{ machineName: '西-2.0', programName: '-', quantity: null, runTime: '-', cuttingTime: '-' },
] } }) },
{ url: '/mock-api/admin/worker/production/trend', method: 'get', response: () => ({ code: 0, data: { items: [
{ date: '2026-04-19', quantity: 980 }, { date: '2026-04-20', quantity: 920 },
{ date: '2026-04-21', quantity: 1100 }, { date: '2026-04-22', quantity: 1050 },
{ date: '2026-04-23', quantity: 990 }, { date: '2026-04-24', quantity: 1080 },
{ date: '2026-04-25', quantity: 580 },
] } }) },
{ url: '/mock-api/admin/worker/available-machines', method: 'get', response: () => ({ code: 0, data: { items: [
{ id: 5, name: '东-2.5', deviceCode: 'siemens_2.5', workshopName: 'B栋' },
{ id: 8, name: '北-4.1', deviceCode: 'fanake_4.1', workshopName: 'C栋' },
] } }) },
]
export default mock