export default { 'POST /api/nex/v1/desktopImages/query': (req: any, res: any) => { const { page_size, page_num } = req.body; const data = []; for (let i = 1; i <= page_size; i++) { const id = (page_num - 1) * page_size + i; data.push({ id: id, image_name: `桌面镜像${id}`, parent_image: Math.floor(Math.random() * 5) + 1, cpu: '4核', memory: '8GB', image_version: `v1.0.${Math.floor(Math.random() * 10)}`, os_version: id % 3 === 0 ? 'Windows 11' : id % 3 === 1 ? 'Windows 10' : 'Ubuntu 22.04', image_status: Math.random() > 0.2 ? 1 : 2, create_time: new Date(Date.now() - Math.floor(Math.random() * 30 * 24 * 60 * 60 * 1000)).toISOString(), description: `这是桌面镜像${id}的描述信息`, desktopType: id % 2 === 0 ? 'standard' : 'custom', version: `1.0.${Math.floor(Math.random() * 10)}`, size: `${Math.floor(Math.random() * 50) + 20}GB`, status: Math.random() > 0.1 ? 'active' : Math.random() > 0.5 ? 'inactive' : 'building', file_name: `desktop_image_${id}.qcow2`, file_type: id % 2 === 0 ? '中型虚拟机' : '小型虚拟机', file_size: `${Math.floor(Math.random() * 10) + 1}TB`, desc: `这是测试的桌面镜像${id}`, }); } const result = { code: '200', message: '操作成功', data: { total: 50, page_num: page_num, page_size: page_size, data: data, }, }; setTimeout(() => { res.send(result); }, 300); }, 'POST /api/nex/v1/virtualImages/query': (req: any, res: any) => { const { page_size, page_num } = req.body; const data = []; for (let i = 1; i <= page_size; i++) { const id = (page_num - 1) * page_size + i; data.push({ id: id, image_name: `工具${id}`, description: `这是工具${id}的描述信息`, image_system_id: '1', image_system_name: '系统镜像1', os_version: 'Windows 10', storage_path: '/path/to/image', network_module: 'Ethernet', image_status: 'active', }); } const result = { code: '200', message: '操作成功', data: { total: 100, page_num: page_num, page_size: page_size, data: data, }, }; setTimeout(() => { res.send(result); }, 300); }, 'POST /api/nex/v1/tool/select/page': (req: any, res: any) => { const { page_size, page_num } = req.body; const data = []; for (let i = 1; i <= page_size; i++) { const id = (page_num - 1) * page_size + i; data.push({ id: id, tool_name: `工具${id}`, tool_type: Math.random() > 0.5 ? 'system' : Math.random() > 0.5 ? 'virtual' : 'desktop', file_size: `${Math.floor(Math.random() * 1000) + 100}MB`, version: `1.0.${Math.floor(Math.random() * 10)}`, create_time: new Date().toISOString(), description: `这是工具${id}的描述信息`, }); } const result = { code: '200', message: '操作成功', data: { total: 100, page_num: page_num, page_size: page_size, data: data, }, }; setTimeout(() => { res.send(result); }, 300); }, 'POST /api/nex/v1/queryimagesList': (req: any, res: any) => { const { page_size, page_num } = req.body; const data = []; function getRandomFormat() { const random = Math.random(); // 生成 0 ~ 1 的随机数 if (random < 0.33) { return 1; } else if (random < 0.66) { return 2; } else { return 3; } } for (let i = 1; i <= page_size; i++) { data.push({ id: i, image_name: `Win版 PR 2024 【支持win10、win11】.zip${ (page_num - 1) * page_size + i }`, image_file_name: `Win版 PR 2024 【支持win10、win11】.zip`, // image_type: getRandomFormat(), bt_path: `https://releases.ubuntu.com/20.04.6/ubuntu-20.04.6-desktop-amd64.iso.torrent`, image_version: '1.0.0', os_version: 'Ubuntu 20.04', image_status: Math.random() > 0.5 ? 1 : 2, storage_path: '/mock/images', create_time: +new Date(), description: `这是一个测试镜像文件,ID: ${i}`, }); } const result = { code: '200', message: '操作成功', data: { total: 520, page_num: page_num, page_size: page_size, data: data, }, }; setTimeout(() => { res.send(result); }, 500); }, 'POST /api/v1/images/file/chunk/upload': (req: any, res: any) => { // 打印所有接收到的字段 console.log('=== 分片上传信息 ==='); console.log('文件ID:', req.body.file_id); console.log('文件名:', req.body.file_name); console.log('文件大小:', req.body.file_size); console.log('分片索引:', req.body.shard_index); console.log('分片总数:', req.body.shard_total); console.log('分片大小:', req.body.chunk_size); console.log('分片MD5:', req.body.chunk_md5); // 如果有文件上传,打印文件信息 if (req.files && req.files.chunk) { console.log('上传的分片文件:', req.files.chunk); } // 模拟上传进度 const shardIndex = parseInt(req.body.shard_index); const shardTotal = parseInt(req.body.shard_total); console.log(`分片上传进度: ${shardIndex}/${shardTotal}`); // 修改判断逻辑:当分片索引等于分片总数时,表示上传完成 if (shardIndex === shardTotal) { console.log('文件上传完成!'); res.send({ uploadedChunks: shardIndex, success: true, totalChunks: shardTotal, message: '分片上传成功', status: 'completed', }); } else { // 模拟上传中 const progress = Math.round((shardIndex / shardTotal) * 100); console.log(`上传进度: ${progress}%`); res.send({ uploadedChunks: shardIndex, success: true, totalChunks: shardTotal, message: '分片上传成功', status: 'uploading', }); } }, // 'POST /api/nex/v1/network/select/page': (req: any, res: any) => { // const { page_size, page_num } = req.body; // const data = []; // const networkTypes = ['NAT', 'Isolated', 'Bridge']; // for (let i = 1; i <= page_size; i++) { // const id = (page_num - 1) * page_size + i; // const networkType = networkTypes[Math.floor(Math.random() * networkTypes.length)]; // data.push({ // id: id, // network_name: `网络${id}`, // bridge_name: `br${id}`, // network_type: networkType, // ip_range: networkType !== 'Bridge' ? `192.168.${id}.0/24` : null, // gateway: networkType !== 'Bridge' ? `192.168.${id}.1` : null, // subnet_mask: networkType !== 'Bridge' ? '255.255.255.0' : null, // dhcp_start: networkType !== 'Bridge' ? `192.168.${id}.100` : null, // dhcp_end: networkType !== 'Bridge' ? `192.168.${id}.200` : null, // dhcp_enabled: networkType !== 'Bridge' ? Math.random() > 0.3 : null, // auto_start: Math.random() > 0.5, // create_time: new Date(Date.now() - Math.floor(Math.random() * 30 * 24 * 60 * 60 * 1000)).toISOString(), // description: `这是网络${id}的描述信息`, // }); // } // const result = { // code: '200', // message: '操作成功', // data: { // total: 50, // page_num: page_num, // page_size: page_size, // data: data, // }, // }; // setTimeout(() => { // res.send(result); // }, 300); // }, };