diff --git a/mock/test.ts b/mock/test.ts index 0fc5799..23eee0e 100644 --- a/mock/test.ts +++ b/mock/test.ts @@ -1,5 +1,5 @@ import {MockMethod} from 'vite-plugin-mock'; -import {changeEmailApi, changePwdApi, sendCodeApi} from "../src/interface"; +import {changeEmailApi, changePwdApi, sendCodeApi, telegramBotApi} from "../src/interface"; const Mock = require('mockjs') @@ -45,6 +45,7 @@ export default [ url: changePwdApi, method: 'post', response: ({query}) => { + debugger const result = Mock.mock({ 'result': /OK|FAIL/, }) @@ -60,5 +61,49 @@ export default [ } } } + }, + { + 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[]; \ No newline at end of file diff --git a/package.json b/package.json index ebf8069..ed9cd64 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,6 @@ }, "dependencies": { "element3": "^0.0.39", - "mockjs": "^1.1.0", "vue": "^3.0.5", "vue-router": "4", "vuex": "^4.0.0" @@ -19,6 +18,7 @@ "@vuedx/typecheck": "^0.6.0", "@vuedx/typescript-plugin-vue": "^0.6.0", "cross-env": "^7.0.3", + "mockjs": "^1.1.0", "node-sass": "^5.0.0", "sass": "^1.32.7", "sass-loader": "^11.0.1", diff --git a/src/App.vue b/src/App.vue index 6b4c463..9954a19 100644 --- a/src/App.vue +++ b/src/App.vue @@ -7,8 +7,15 @@ - 主页 - + + + + + 当前配置 + 修改telegram bot + + + 修改密码 修改邮箱 @@ -19,7 +26,7 @@ - + @@ -28,13 +35,13 @@ + + \ No newline at end of file diff --git a/src/components/Email.vue b/src/components/Email.vue index 5a76016..c2af6cd 100644 --- a/src/components/Email.vue +++ b/src/components/Email.vue @@ -30,7 +30,7 @@ - 返回 + 返回 @@ -80,7 +80,7 @@ export default defineComponent({ res => { message(res) if (res.result === 'OK') { - router.replace('/home') + router.replace('/config') } } ) diff --git a/src/components/Home.vue b/src/components/Home.vue deleted file mode 100644 index ad57957..0000000 --- a/src/components/Home.vue +++ /dev/null @@ -1,24 +0,0 @@ - - - - - \ No newline at end of file diff --git a/src/components/Password.vue b/src/components/Password.vue index bc46af2..a0786a1 100644 --- a/src/components/Password.vue +++ b/src/components/Password.vue @@ -24,7 +24,7 @@ - 返回 + 返回 @@ -55,7 +55,7 @@ export default defineComponent({ .then(res => { message(res) if (res.result === 'OK') { - router.replace('/home') + router.replace('/config') } }) diff --git a/src/components/TelegramBot.vue b/src/components/TelegramBot.vue new file mode 100644 index 0000000..a360946 --- /dev/null +++ b/src/components/TelegramBot.vue @@ -0,0 +1,82 @@ + + + + + \ No newline at end of file diff --git a/src/components/Vue3.vue b/src/components/Vue3.vue deleted file mode 100644 index 72a9f9d..0000000 --- a/src/components/Vue3.vue +++ /dev/null @@ -1,49 +0,0 @@ - - - - - \ No newline at end of file diff --git a/src/interface.ts b/src/interface.ts index 9ad4ea8..df3a68d 100644 --- a/src/interface.ts +++ b/src/interface.ts @@ -1,3 +1,5 @@ export const sendCodeApi = '/api/change/email/code' export const changeEmailApi = '/api/change/email' -export const changePwdApi = '/api/change/pwd' \ No newline at end of file +export const changePwdApi = '/api/change/pwd' +export const telegramBotApi = '/api/telegram/bot' +export const testTelegramBotApi = (token: string) => `https://api.telegram.org/bot${token}/getMe` \ No newline at end of file diff --git a/src/request.ts b/src/request.ts index 99f5883..a7d213d 100644 --- a/src/request.ts +++ b/src/request.ts @@ -1,4 +1,4 @@ -import {changeEmailApi, changePwdApi, sendCodeApi} from "./interface"; +import {changeEmailApi, changePwdApi, sendCodeApi, telegramBotApi, testTelegramBotApi} from "./interface"; // @ts-ignore import {Message} from 'element3/src/components/Message' @@ -29,6 +29,26 @@ export function changePwd(userEmail: string, password: string) { return fetch(new Request(changePwdApi, {method: 'POST', body: JSON.stringify({userEmail, password})})) } +/** + * 获取telegram bot + * @param userEmail + */ +export function getTelegramBot(userEmail: string) { + return fetch(new Request(`${telegramBotApi}?userEmail=${userEmail}`)) +} + +/** + * 测试机器人token + * @param token + */ +export function testTelegramBot(token: string) { + return fetch(new Request(testTelegramBotApi(token))) +} + +export function bindTelegramBot(userEmail: string, token: string) { + return fetch(new Request(telegramBotApi), {method: 'POST', body: JSON.stringify({userEmail, token})}) +} + export function message(res: any) { new Message({ showClose: true, diff --git a/src/router.ts b/src/router.ts index 871d530..a3fe2eb 100644 --- a/src/router.ts +++ b/src/router.ts @@ -1,13 +1,15 @@ import {createRouter, createWebHashHistory, useRoute} from "vue-router"; import Email from "./components/Email.vue"; -import Home from "./components/Home.vue"; +import Config from "./components/Config.vue"; import {useStore} from "vuex"; import {onMounted} from "vue"; import Password from "./components/Password.vue"; +import TelegramBot from "./components/TelegramBot.vue"; const routes = [ - {path: '/home', component: Home}, + {path: '/config', component: Config}, + {path: '/config/telegram', component: TelegramBot}, {path: '/email', component: Email}, {path: '/password', component: Password} ] diff --git a/src/store.ts b/src/store.ts index 5708707..04de0da 100644 --- a/src/store.ts +++ b/src/store.ts @@ -5,7 +5,7 @@ export const store = createStore({ user: { email: '1029559041@qq.com' }, - route: '/home' + route: '/config' }), mutations: { setUser(state, user) {