|
|
|
import {MockMethod} from 'vite-plugin-mock';
|
|
|
|
import {changeEmailApi, changePwdApi, sendCodeApi, telegramBotApi} from "../src/interface";
|
|
|
|
|
|
|
|
|
|
|
|
const Mock = require('mockjs')
|
|
|
|
|
|
|
|
export default [
|
|
|
|
{
|
|
|
|
url: sendCodeApi,
|
|
|
|
method: 'post',
|
|
|
|
response: ({query}) => {
|
|
|
|
const result = Mock.mock({
|
|
|
|
'result': /OK|FAIL/,
|
|
|
|
})
|
|
|
|
if (result.result === 'OK') {
|
|
|
|
result.message = '验证码发送成功'
|
|
|
|
} else {
|
|
|
|
result.message = '验证码发送失败'
|
|
|
|
}
|
|
|
|
return result
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
url: changeEmailApi,
|
|
|
|
method: 'post',
|
|
|
|
response: ({query}) => {
|
|
|
|
const result = 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}) => {
|
|
|
|
debugger
|
|
|
|
const result = Mock.mock({
|
|
|
|
'result': /OK|FAIL/,
|
|
|
|
})
|
|
|
|
|
|
|
|
if (result.result === 'OK') {
|
|
|
|
result.message = '修改密码成功'
|
|
|
|
return result
|
|
|
|
} else {
|
|
|
|
return {
|
|
|
|
...result, ...Mock.mock({
|
|
|
|
'message': /修改失败,(密码不合法)/
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
url: telegramBotApi,
|
|
|
|
method: 'get',
|
|
|
|
response: ({query}) => {
|
|
|
|
debugger
|
|
|
|
const result = Mock.mock({
|
|
|
|
'result': Math.random() < 0.9 ? 'OK' : "FAIL",
|
|
|
|
})
|
|
|
|
|
|
|
|
if (result.result === 'OK') {
|
|
|
|
result.message = '获取机器人信息成功'
|
|
|
|
result.bot = Mock.mock({
|
|
|
|
name: /\w{5}/
|
|
|
|
})
|
|
|
|
return result
|
|
|
|
} else {
|
|
|
|
return {
|
|
|
|
...result, ...Mock.mock({
|
|
|
|
'message': '获取机器人信息失败'
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
url: telegramBotApi,
|
|
|
|
method: 'post',
|
|
|
|
response: ({body}) => {
|
|
|
|
debugger
|
|
|
|
const result = Mock.mock({
|
|
|
|
'result': Math.random() < 0.9 ? 'OK' : "FAIL",
|
|
|
|
})
|
|
|
|
|
|
|
|
if (result.res === 'OK') {
|
|
|
|
result.message = '机器人绑定成功'
|
|
|
|
} else {
|
|
|
|
return {
|
|
|
|
...result, ...Mock.mock({
|
|
|
|
'message': /机器人绑定失败,(token不合法)/
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
] as MockMethod[];
|