186 lines
6.8 KiB
TypeScript
186 lines
6.8 KiB
TypeScript
import { MockMethod, Recordable } from 'vite-plugin-mock'
|
|
import { resultPageSuccess, resultSuccess } from './_util'
|
|
import moment from 'moment'
|
|
import { Random } from 'mockjs'
|
|
|
|
export default [
|
|
// 获取单个订单信息
|
|
{
|
|
url: /\/api\/v1\/orders\/\d+$/,
|
|
method: 'get',
|
|
timeout: 500,
|
|
response: (opt: { url: Recordable }) => {
|
|
const orderId = opt.url.split('/')[4]
|
|
return resultSuccess({
|
|
id: Number(orderId),
|
|
'no|1': 'ZJP@integer(1001, 2000)',
|
|
'status|1': ['生产中', '待生产', '已完成', '暂停中', '已暂停'],
|
|
'priority|1-5': 1,
|
|
'finishedNum|200-1000': 1,
|
|
'productNum|1000-3000': 1,
|
|
beginTime: '@/now("yyyy-MM-dd HH:mm:ss")', // 开始时间
|
|
endTime: '@/now("yyyy-MM-dd")', // 结束时间
|
|
orderSendTime: '@/now("yyyy-MM-dd")', // 订单下发时间 string,非空
|
|
planBeginTime: () => {
|
|
let now = moment.now()
|
|
now += 24 * 60 * 60 * 1000 * Number((Math.random() * 10).toFixed())
|
|
return moment(now).format('yyyy-MM-DD')
|
|
}, // 计划开始时间 string,非空
|
|
planEndTime: () => {
|
|
let now = moment.now()
|
|
now += 24 * 60 * 60 * 1000 * Number((Math.random() * 20).toFixed())
|
|
return moment(now).format('yyyy-MM-DD')
|
|
}, // 计划结束时间 string,非空
|
|
technologyId: '@/integer(1,10)',
|
|
technologyName: '@/cword(3,10)',
|
|
remark: '6日维护',
|
|
'updatedAt|1684332167-1684432167': 1684432167,
|
|
'createdAt|1684332167-1684432167': 1684432167
|
|
})
|
|
}
|
|
},
|
|
|
|
// 获取详细资料
|
|
{
|
|
url: /\/api\/v1\/orders\/\d+\/detail$/,
|
|
method: 'get',
|
|
timeout: 500,
|
|
response: (opt: { url: Recordable }) => {
|
|
const orderId = opt.url.split('/')[4]
|
|
if (Number(orderId)) {
|
|
return resultSuccess({
|
|
id: Number(orderId),
|
|
'no|1': 'ZJP@integer(1001, 2000)',
|
|
'status|1': ['生产中', '待生产', '已完成', '暂停中', '已暂停'],
|
|
'priority|1-5': 1,
|
|
'finishedNum|200-1000': 1,
|
|
'productNum|1000-3000': 1,
|
|
beginTime: '@/now("yyyy-MM-dd HH:mm:ss")', // 开始时间
|
|
endTime: '@/now("yyyy-MM-dd HH:mm:ss")', // 结束时间
|
|
orderSendTime: '@/now("yyyy-MM-dd")', // 订单下发时间 string,非空
|
|
planBeginTime: () => {
|
|
let now = moment.now()
|
|
now += 24 * 60 * 60 * 1000 * Number((Math.random() * 10).toFixed())
|
|
return moment(now).format('yyyy-MM-DD')
|
|
}, // 计划开始时间 string,非空
|
|
planEndTime: () => {
|
|
let now = moment.now()
|
|
now += 24 * 60 * 60 * 1000 * Number((Math.random() * 20).toFixed())
|
|
return moment(now).format('yyyy-MM-DD')
|
|
}, // 计划结束时间 string,非空
|
|
technologyId: '@/integer(1,10)',
|
|
technologyName: '@/cword(3,10)',
|
|
remark: '6日维护',
|
|
'updatedAt|1684332167-1684432167': 1684432167,
|
|
'createdAt|1684332167-1684432167': 1684432167
|
|
})
|
|
}
|
|
return resultSuccess(null)
|
|
}
|
|
},
|
|
// 获取订单列表接口
|
|
{
|
|
url: '/api/v1/work-orders',
|
|
method: 'get',
|
|
response: (opt: { url: Recordable; query: Recordable }) => {
|
|
return resultPageSuccess({
|
|
page: Number(opt.query['page']),
|
|
limit: Number(opt.query['limit']),
|
|
'total|5-30': 10,
|
|
'data|30': [
|
|
// 生成 10 条数据
|
|
{
|
|
'id|+1': 1, // 自增 ID
|
|
'priority|1-3': 1, // 随机生成 1 到 3 的优先级
|
|
'planNum|1-100': 1, // 随机生成 1 到 100 的计划数量
|
|
'finishedNum|0-100': 1, // 随机生成 0 到 100 的完成数量
|
|
'status|1-5': 1, // 状态值为 1 生产中, 2 待生产, 3 已完成, 4 暂停中, 5 已暂停
|
|
'technologyId|0-10': 1, // 随机生成技术 ID
|
|
no: '@/datetime("yyyyMMddHHmmss")', // 随机生成订单编号
|
|
disabled: Random.boolean(), // 随机生成禁用状态
|
|
planBeginTime: '@/datetime("yyyy-MM-dd HH:mm:ss")', // 随机生成计划开始时间
|
|
planEndTime: '@/datetime("yyyy-MM-dd HH:mm:ss")', // 随机生成计划结束时间
|
|
'processId|20250101-20250531': 20250101,
|
|
beginTime: '@/datetime("yyyy-MM-dd HH:mm:ss")',
|
|
endTime: '@/datetime("yyyy-MM-dd HH:mm:ss")',
|
|
'BeginTime|1626792551-1726794000': 1, // 随机生成 Unix 时间戳
|
|
'EndTime|0': 0, // EndTime 保持为 0
|
|
remark: '测试', // 固定测试备注
|
|
createdAt: '@/now("second")', // 当前时间的 Unix 时间戳
|
|
updatedAt: '@/now("second")' // 当前时间的 Unix 时间戳
|
|
}
|
|
]
|
|
})
|
|
}
|
|
},
|
|
// 获取工艺订单列表接口
|
|
{
|
|
url: /\/api\/v1\/processes\/\d+\/work-orders$/,
|
|
method: 'get',
|
|
response: (opt: { url: Recordable; query: Recordable }) => {
|
|
return resultPageSuccess({
|
|
page: Number(opt.query['page']),
|
|
limit: Number(opt.query['limit']),
|
|
total: 4,
|
|
'data|4': [
|
|
{
|
|
// 属性 id 是一个自增数,起始值为 1,每次增 1
|
|
'id|+1': 1,
|
|
'no|1': 'ZJP@integer(1001, 2000)',
|
|
// 'deviceId': '@/number', // 设备编号 string,长度50,非空,订单下到设备,原则上按mes排产加工
|
|
// processId: number // 执行工步号 int,非空
|
|
'status|1': ['生产中', '待生产', '已完成', '暂停中', '已暂停'],
|
|
'priority|1-5': 1,
|
|
'finishedNum|200-1000': 1,
|
|
'productNum|1000-3000': 1,
|
|
beginTime: '@/now("yyyy-MM-dd HH:mm:ss")', // 开始时间
|
|
endTime: '@/now("yyyy-MM-dd")', // 结束时间
|
|
orderSendTime: '@/now("yyyy-MM-dd")', // 订单下发时间 string,非空
|
|
planBeginTime: '@/now("yyyy-MM-dd")', // 计划开始时间 string,非空
|
|
planEndTime: '@/now("yyyy-MM-dd")', // 计划结束时间 string,非空
|
|
technologyId: '@/integer(1,10)',
|
|
technologyName: '@/cword(3,10)',
|
|
remark: '6日维护',
|
|
'updatedAt|1684332167-1684432167': 1684432167,
|
|
'createdAt|1684332167-1684432167': 1684432167
|
|
}
|
|
]
|
|
})
|
|
}
|
|
},
|
|
|
|
// 新建订单接口
|
|
{
|
|
url: '/api/v1/work-orders',
|
|
method: 'post',
|
|
response: () => {
|
|
return resultSuccess(null)
|
|
}
|
|
},
|
|
// 编辑订单接口
|
|
{
|
|
url: /\/api\/v1\/orders\/\d+$/,
|
|
method: 'put',
|
|
response: () => {
|
|
return resultSuccess(null)
|
|
}
|
|
},
|
|
// 删除订单
|
|
{
|
|
url: /\/api\/v1\/orders\/\d+/,
|
|
method: 'delete',
|
|
response: () => {
|
|
return resultSuccess(null)
|
|
}
|
|
},
|
|
// 批量删除订单
|
|
{
|
|
url: /\/api\/v1\/orders\/batch-delete$/,
|
|
method: 'post',
|
|
timeout: 300,
|
|
response: () => {
|
|
return resultSuccess(null)
|
|
}
|
|
}
|
|
] as MockMethod[]
|