import {MockMethod} from 'vite-plugin-mock'; import {changeEmailApi, changePwdApi, checkAdminApi, loginApi, sendCodeApi, telegramBotApi} 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: loginApi, 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: '查询管理员失败'} } } } ] as MockMethod[];