add mockdata & update设备采集配置**
This commit is contained in:
78
src/views/base/equipmentPlcConnect/http.js
Normal file
78
src/views/base/equipmentPlcConnect/http.js
Normal file
@@ -0,0 +1,78 @@
|
||||
import Mock from 'mockjs';
|
||||
|
||||
const baseURL = 'http://192.168.1.49:48080/admin-api';
|
||||
|
||||
Mock.setup({
|
||||
timeout: 200,
|
||||
});
|
||||
|
||||
// @database
|
||||
const list = Mock.mock({
|
||||
'data|1-10': [
|
||||
{
|
||||
'id|+1': 1,
|
||||
productionLine: (options) => {
|
||||
// console.log('otpsion', options.context.currentContext);
|
||||
return `EQ${options.context.currentContext.id}`;
|
||||
},
|
||||
workshopSection: ({ context: { currentContext } }) =>
|
||||
`EQ${currentContext.id}_WS${Mock.Random.integer(1, 10)}`,
|
||||
equipmentName: ({ context: { currentContext } }) =>
|
||||
`设备${currentContext.id}`,
|
||||
equipmentCode: ({ context: { currentContext } }) =>
|
||||
`${currentContext.equipmentName}_Code`,
|
||||
plcCode: ({ context: { currentContext } }) =>
|
||||
`PLC_TABLE_CODE_${currentContext.id}`,
|
||||
plcTableName: ({ context: { currentContext } }) =>
|
||||
`PLC_TABLE_${currentContext.id}`,
|
||||
plcName: ({ context: { currentContext } }) => `PLC_${currentContext.id}`,
|
||||
'bindingParameters|1-10': 1,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
// @page
|
||||
Mock.mock(
|
||||
RegExp(baseURL + '/base/equipment-plc-connect/page' + '.*'),
|
||||
'get',
|
||||
(options) => {
|
||||
console.log('[Mock url]', options.url, list);
|
||||
return {
|
||||
code: 0,
|
||||
data: {
|
||||
list: list.data,
|
||||
total: list.data.length,
|
||||
},
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
// @create
|
||||
Mock.mock(baseURL + '/base/equipment-plc-connect/create', 'post', (options) => {
|
||||
console.log('options', options);
|
||||
const { url, type, body } = options;
|
||||
const newItem = JSON.parse(body);
|
||||
list.data.push(newItem);
|
||||
return {
|
||||
code: 0,
|
||||
data: null,
|
||||
msg: 'success',
|
||||
};
|
||||
});
|
||||
|
||||
// @update
|
||||
Mock.mock(
|
||||
baseURL + '/admin-api/base/equipment-plc-connect/update',
|
||||
'put',
|
||||
(options) => {
|
||||
const { url, type, body } = options;
|
||||
const { id } = JSON.parse(body);
|
||||
const newItem = list.data.find((item) => item.id == id);
|
||||
newItem = { ...newItem, ...JSON.parse(body) };
|
||||
return {
|
||||
code: 0,
|
||||
msg: 'success',
|
||||
data: null,
|
||||
};
|
||||
}
|
||||
);
|
||||
Reference in New Issue
Block a user