diff --git a/mock/test.ts b/mock/test.ts index 23eee0e..d90ea78 100644 --- a/mock/test.ts +++ b/mock/test.ts @@ -1,5 +1,6 @@ import {MockMethod} from 'vite-plugin-mock'; -import {changeEmailApi, changePwdApi, sendCodeApi, telegramBotApi} from "../src/interface"; +import {changeEmailApi, changePwdApi, checkAdminApi, loginApi, sendCodeApi, telegramBotApi} from "../src/interface"; +import {JSONResponse} from "../src/request"; const Mock = require('mockjs') @@ -9,10 +10,10 @@ export default [ url: sendCodeApi, method: 'post', response: ({query}) => { - const result = Mock.mock({ + const result: JSONResponse = Mock.mock({ 'result': /OK|FAIL/, }) - if (result.result === 'OK') { + if (result.result === "OK") { result.message = '验证码发送成功' } else { result.message = '验证码发送失败' @@ -24,7 +25,7 @@ export default [ url: changeEmailApi, method: 'post', response: ({query}) => { - const result = Mock.mock({ + const result: JSONResponse = Mock.mock({ 'result': /OK|FAIL/, }) @@ -45,10 +46,9 @@ export default [ url: changePwdApi, method: 'post', response: ({query}) => { - debugger - const result = Mock.mock({ - 'result': /OK|FAIL/, - }) + const result: JSONResponse = { + result: Math.random() < 0.9 ? 'OK' : "FAIL", + } if (result.result === 'OK') { result.message = '修改密码成功' @@ -66,15 +66,16 @@ export default [ url: telegramBotApi, method: 'get', response: ({query}) => { - debugger - const result = Mock.mock({ - 'result': Math.random() < 0.9 ? 'OK' : "FAIL", - }) + const result: JSONResponse = { + result: Math.random() < 0.9 ? 'OK' : "FAIL", + } if (result.result === 'OK') { result.message = '获取机器人信息成功' - result.bot = Mock.mock({ - name: /\w{5}/ + result.body = Mock.mock({ + bot: { + name: /\w{5}/ + } }) return result } else { @@ -90,13 +91,13 @@ export default [ url: telegramBotApi, method: 'post', response: ({body}) => { - debugger - const result = Mock.mock({ - 'result': Math.random() < 0.9 ? 'OK' : "FAIL", - }) + const result: JSONResponse = { + result: Math.random() < 0.9 ? 'OK' : "FAIL", + } - if (result.res === 'OK') { + if (result.result === 'OK') { result.message = '机器人绑定成功' + return result } else { return { ...result, ...Mock.mock({ @@ -105,5 +106,55 @@ export default [ } } } + }, + { + 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[]; \ No newline at end of file diff --git a/package.json b/package.json index ed9cd64..a72c7ef 100644 --- a/package.json +++ b/package.json @@ -3,10 +3,11 @@ "version": "0.0.0", "scripts": { "dev": "vite", - "build": "vuedx-typecheck . && vite build", + "build": "vite build", "serve": "vite preview" }, "dependencies": { + "crumbsjs": "^0.2.1", "element3": "^0.0.39", "vue": "^3.0.5", "vue-router": "4", @@ -15,8 +16,6 @@ "devDependencies": { "@vitejs/plugin-vue": "^1.1.4", "@vue/compiler-sfc": "^3.0.5", - "@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", diff --git a/src/App.vue b/src/App.vue index 9954a19..9d9c579 100644 --- a/src/App.vue +++ b/src/App.vue @@ -3,12 +3,10 @@ -

直播间状态通知

+

直播间开播通知

- + - - 当前配置 @@ -19,15 +17,14 @@ 修改密码 修改邮箱 - 退出登录 + 退出登录
- - + @@ -37,15 +34,24 @@ import {defineComponent} from 'vue' import Config from "./components/Config.vue"; import {useStore} from "vuex"; - +import {loginPath, registerPath} from "./router"; +//@ts-ignore +import crumbs from 'crumbsjs'; +import {useRouter} from "vue-router"; export default defineComponent({ name: 'App', components: {Config}, setup() { const store = useStore() + const router = useRouter() + + const logout = () => { + crumbs.deleteAll() + router.replace(loginPath) + } - return {store} + return {store, loginPath, registerPath, logout} } }) diff --git a/src/components/AsyncComponent.vue b/src/components/AsyncComponent.vue deleted file mode 100644 index aa9b474..0000000 --- a/src/components/AsyncComponent.vue +++ /dev/null @@ -1,28 +0,0 @@ - - - - - \ No newline at end of file diff --git a/src/components/Config.vue b/src/components/Config.vue index 61cdcf2..a721114 100644 --- a/src/components/Config.vue +++ b/src/components/Config.vue @@ -1,3 +1,4 @@ +