From f00c70b44db4c8215d3733077e686de2dd71c39e Mon Sep 17 00:00:00 2001
From: pan <1029559041@qq.com>
Date: Sat, 20 Feb 2021 05:21:40 +0800
Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0telegram=20bot=E6=8E=A8?=
=?UTF-8?q?=E9=80=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
mock/test.ts | 47 ++++++++++++++++++-
package.json | 2 +-
src/App.vue | 17 ++++---
src/components/Config.vue | 44 ++++++++++++++++++
src/components/Email.vue | 4 +-
src/components/Home.vue | 24 ----------
src/components/Password.vue | 4 +-
src/components/TelegramBot.vue | 82 ++++++++++++++++++++++++++++++++++
src/components/Vue3.vue | 49 --------------------
src/interface.ts | 4 +-
src/request.ts | 22 ++++++++-
src/router.ts | 6 ++-
src/store.ts | 2 +-
13 files changed, 218 insertions(+), 89 deletions(-)
create mode 100644 src/components/Config.vue
delete mode 100644 src/components/Home.vue
create mode 100644 src/components/TelegramBot.vue
delete mode 100644 src/components/Vue3.vue
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 @@
+
+
+
+
+ 机器人Api Token
+
+
+
+
+
+
+ 测试token
+
+
+
+
+
+
+
+ 即将绑定的机器人
+
+
+
+
+
+ 绑定
+
+
+
+
+
+
+
+
\ 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 @@
-
- {{num}}*2={{double}}
- {{num2.count}}*3={{triple}}
-
-
-
-
-
-
-
-
\ 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) {