diff --git a/src/App.vue b/src/App.vue index 9d9c579..15f3941 100644 --- a/src/App.vue +++ b/src/App.vue @@ -3,20 +3,20 @@ -

直播间开播通知

+

bilibili直播通知后台管理

- + - 当前配置 - 修改telegram bot + 当前配置 + 修改telegram bot - 修改密码 - 修改邮箱 + 修改密码 + 修改邮箱 退出登录 @@ -34,7 +34,7 @@ import {defineComponent} from 'vue' import Config from "./components/Config.vue"; import {useStore} from "vuex"; -import {loginPath, registerPath} from "./router"; +import {configPath, loginPath, managerEmailPath, managerPasswordPath, registerPath, telegramPath} from "./router"; //@ts-ignore import crumbs from 'crumbsjs'; import {useRouter} from "vue-router"; @@ -51,7 +51,10 @@ export default defineComponent({ router.replace(loginPath) } - return {store, loginPath, registerPath, logout} + return { + store, loginPath, registerPath, logout, configPath, telegramPath + , managerEmailPath, managerPasswordPath + } } }) diff --git a/src/components/Email.vue b/src/components/Email.vue index b0c2417..c14c1a0 100644 --- a/src/components/Email.vue +++ b/src/components/Email.vue @@ -15,16 +15,7 @@ 新邮箱不能和当前邮箱一致
- - - - - - - - {{ sendCodeTip }} - - + 更换邮箱 @@ -37,18 +28,20 @@ + + \ No newline at end of file diff --git a/src/components/Login.vue b/src/components/Login.vue index 33595a1..4260778 100644 --- a/src/components/Login.vue +++ b/src/components/Login.vue @@ -1,17 +1,6 @@ diff --git a/src/components/Register.vue b/src/components/Register.vue index 54f6e4c..5b34e69 100644 --- a/src/components/Register.vue +++ b/src/components/Register.vue @@ -23,11 +23,14 @@ + 邮箱不能为空 + 邮箱不合法 + - - + + 注册 @@ -35,9 +38,11 @@ + + \ No newline at end of file diff --git a/src/request.ts b/src/request.ts index 8b03071..df78a8e 100644 --- a/src/request.ts +++ b/src/request.ts @@ -13,9 +13,29 @@ import {Message} from 'element3/src/components/Message' /** * 发送验证码 * @param userEmail + * @param callback + * @param success */ -export function sendCode(userEmail: string) { +export function sendCode(userEmail: string, callback: (second: number) => void, success: () => void) { + let second = 10 return fetch(new Request(sendCodeApi, {method: 'POST', body: JSON.stringify({userEmail})})) + .then(res => res.json()).then((res: JSONResponse) => { + message(res) + if (res.result === 'OK') { + console.info('发送验证码成功') + callback(second) + success() + const t = setInterval(function () { + if (second === 0) { + clearInterval(t) + } else { + callback(--second) + } + }, 1000) + } else { + second = 0 + } + }) } /** diff --git a/src/router.ts b/src/router.ts index ce25752..7ce94be 100644 --- a/src/router.ts +++ b/src/router.ts @@ -12,16 +12,21 @@ import {checkAdmin, JSONResponse} from "./request"; import crumbs from 'crumbsjs'; import {token_cookie_key} from "./global"; -export const registerPath = '/register' -export const loginPath = '/login' +const backend = '/backend' +export const registerPath = `${backend}/register` +export const loginPath = `${backend}/login` +export const configPath = `${backend}/config` +export const telegramPath = `${configPath}/telegram` +export const managerEmailPath = `${backend}/email` +export const managerPasswordPath = `${backend}/password` const routes = [ - {path: '/', redirect: '/config'}, + {path: backend, redirect: configPath}, {path: registerPath, component: Register}, - {path: '/config', component: Config}, - {path: '/config/telegram', component: TelegramBot}, - {path: '/email', component: Email}, - {path: '/password', component: Password}, + {path: configPath, component: Config}, + {path: telegramPath, component: TelegramBot}, + {path: managerEmailPath, component: Email}, + {path: managerPasswordPath, component: Password}, {path: loginPath, component: Login} ] @@ -32,27 +37,33 @@ export const router = createRouter({ }) //路由导航守卫 router.beforeEach(async (to, from) => { - let res: JSONResponse = await checkAdmin().then(res => res.json()) - - - if (![registerPath, loginPath].includes(to.fullPath)) { - if (res.body && crumbs.get(token_cookie_key)) { - return true - } else if (res.body) { - alert('请登录') - return loginPath + if (crumbs.get(token_cookie_key)) { + if ([registerPath, loginPath].includes(to.fullPath)) { + console.info('存在cookie,访问的路由是登录或注册,重定向到主页') + return '/' } else { - alert('请进行应用初始化操作') - return registerPath + console.info('放通路由') + return true } - } else if (to.fullPath === loginPath && crumbs.get(token_cookie_key)) { - return '/' - } else if (to.fullPath === loginPath && !res.body) { - return registerPath - } else if (to.fullPath === registerPath && res.body) { - return loginPath } else { - return true + let res: JSONResponse = await checkAdmin().then(res => res.json()) + if (res.body) { + if (to.fullPath === loginPath) { + console.info('放通路由') + return true + } else { + console.info('存在管理员,访问的不是登录路由,重定向到登录') + return loginPath + } + } else { + if (to.fullPath === registerPath) { + console.info('放通路由') + return true + } else { + console.info('不存在管理员,访问的不是注册路由,重定向到注册') + return registerPath + } + } } })