import {MockMethod} from 'vite-plugin-mock'; import { addRoomApi, changeEmailApi, changePwdApi, checkAdminApi, getRoomApi, managerLoginApi, sendCodeApi, telegramBotApi, userLoginApi } from "../src/interface"; import {JSONResponse} from "../src/request"; const Mock = require('mockjs') export default [ { url: sendCodeApi, method: 'post', response: ({query}) => { const result: JSONResponse = Mock.mock({ 'result': /OK|FAIL/, }) if (result.result === "OK") { result.message = '验证码发送成功' } else { result.message = '验证码发送失败' } return result }, }, { url: changeEmailApi, method: 'post', response: ({query}) => { const result: JSONResponse = Mock.mock({ 'result': /OK|FAIL/, }) if (result.result === 'OK') { result.message = '邮箱更新成功' return result } else { return { ...result, ...Mock.mock({ 'message': /更新失败,(邮箱不合法|邮箱已绑定|请输入正确验证码)/ }) } } }, }, { url: changePwdApi, method: 'post', response: ({query}) => { const result: JSONResponse = { result: Math.random() < 0.9 ? 'OK' : "FAIL", } if (result.result === 'OK') { result.message = '修改密码成功' return result } else { return { ...result, ...Mock.mock({ 'message': /修改失败,(密码不合法)/ }) } } } }, { url: telegramBotApi, method: 'get', response: ({query}) => { const result: JSONResponse = { result: Math.random() < 0.9 ? 'OK' : "FAIL", } if (result.result === 'OK') { result.message = '获取机器人信息成功' result.body = Mock.mock({ bot: { name: /\w{5}/ } }) return result } else { return { ...result, ...Mock.mock({ 'message': '获取机器人信息失败' }) } } } }, { url: telegramBotApi, method: 'post', response: ({body}) => { const result: JSONResponse = { result: Math.random() < 0.9 ? 'OK' : "FAIL", } if (result.result === 'OK') { result.message = '机器人绑定成功' return result } else { return { ...result, ...Mock.mock({ 'message': /机器人绑定失败,(token不合法)/ }) } } } }, { url: managerLoginApi, method: "post", response: ({body}) => { const result: JSONResponse = { result: Math.random() < 0.9 ? 'OK' : "FAIL", } if (result.result === 'OK') { return { ...result, ...Mock.mock({ 'message': '登陆成功', 'body': { 'token': /[a-zA-Z0-9]{32}/, 'userEmail': body['userEmail'] } }) } } else { return { ...result, ...Mock.mock({ 'message': /登陆失败,(邮箱或密码错误)/ }) } } } }, { url: checkAdminApi, method: "get", response: ({query}) => { const result: JSONResponse = { result: Math.random() < 0.9 ? 'OK' : "FAIL", } if (result.result === 'OK') { return { ...Boolean(Math.round(Math.random())) ? { message: '管理员已存在', body: true } : { message: '管理员不存在', body: false }, ...result } } else { return {message: '查询管理员失败'} } } }, { url: userLoginApi, method: "post", response: ({body}) => { const result: JSONResponse = { result: Math.random() < 0.9 ? 'OK' : "FAIL", } if (result.result === 'OK') { return { ...result, ...Mock.mock({ 'message': '登陆成功', 'body': { 'token': /[a-zA-Z0-9]{32}/, 'userEmail': body['userEmail'] } }) } } else { return { ...result, ...Mock.mock({ 'message': /登陆失败,(邮箱或密码错误)/ }) } } } }, { url: addRoomApi, method: "post", response: ({body}) => { const result: JSONResponse = { result: Math.random() < 0.9 ? 'OK' : "FAIL", } if (result.result === 'OK') { return { ...result, message: '添加成功' } } else { return { ...result, message: '添加失败' } } } }, { url: getRoomApi, method: "get", response: ({body}) => { console.info(111111) const result: JSONResponse = { result: Math.random() < 0.9 ? 'OK' : "FAIL", } const data = Mock.mock({ "rooms|1-10": [ { "id|1-100": 100, user: '@cname', title: '@ctitle', "status|1-3": 1, "email|1": true, "telegram|1": true } ] }) return { ...result, ...data } } } ] as MockMethod[];