From be58d839533d53fb567ca9c41fc700fde2f8e463 Mon Sep 17 00:00:00 2001 From: bob <312777916@qq.com> Date: Wed, 21 Aug 2024 21:51:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E7=99=BB=E5=BD=95=E8=AF=B7?= =?UTF-8?q?=E6=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .eslintrc.cjs | 2 +- .prettierrc.json | 2 +- src/api/user.js | 15 +++++++-- src/const/userConst.js | 1 + src/stores/user.js | 52 ++++++++++++++++++++++++++---- src/utils/request.js | 2 +- src/views/LoginPage.vue | 70 ++++++++++++++++++++++++++--------------- 7 files changed, 108 insertions(+), 36 deletions(-) diff --git a/.eslintrc.cjs b/.eslintrc.cjs index ec2b3a3..54965a8 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -17,7 +17,7 @@ module.exports = { { singleQuote: true, // 单引号 semi: false, // 无分号 - printWidth: 80, // 每行宽度至多80字符 + printWidth: 100, // 每行宽度至多100字符 trailingComma: 'none', // 不加对象|数组最后逗号 endOfLine: 'auto' // 换行符号不限制(win mac 不一致) } diff --git a/.prettierrc.json b/.prettierrc.json index 66e2335..ecdf3e0 100644 --- a/.prettierrc.json +++ b/.prettierrc.json @@ -5,4 +5,4 @@ "singleQuote": true, "printWidth": 100, "trailingComma": "none" -} \ No newline at end of file +} diff --git a/src/api/user.js b/src/api/user.js index 81c63ef..a1c4899 100644 --- a/src/api/user.js +++ b/src/api/user.js @@ -1,8 +1,8 @@ import request from '@/utils/request' -import { CLIENT_TYPE, CLIENT_NAME, CLIENT_VERSION } from '@/const/userConst' +import { CLIENT_TYPE, CLIENT_NAME, CLIENT_VERSION, CLIENT_ID } from '@/const/userConst' export const userRegisterService = ({ username, password }) => { - request.post('/user/register', { + return request.post('/user/register', { account: username, nickName: '', password: password, @@ -11,3 +11,14 @@ export const userRegisterService = ({ username, password }) => { clientVersion: CLIENT_VERSION }) } + +export const userLoginService = ({ username, password }) => { + return request.post('/user/login', { + account: username, + password: password, + clientId: CLIENT_ID, + clientType: CLIENT_TYPE, + clientName: CLIENT_NAME, + clientVersion: CLIENT_VERSION + }) +} diff --git a/src/const/userConst.js b/src/const/userConst.js index 2768587..daac06c 100644 --- a/src/const/userConst.js +++ b/src/const/userConst.js @@ -1,3 +1,4 @@ export const CLIENT_TYPE = 2 export const CLIENT_NAME = 'web' export const CLIENT_VERSION = '0.0.1' +export const CLIENT_ID = 'XXAA' diff --git a/src/stores/user.js b/src/stores/user.js index 64aa76e..d7cb82d 100644 --- a/src/stores/user.js +++ b/src/stores/user.js @@ -1,18 +1,58 @@ import { defineStore } from 'pinia' import { ref } from 'vue' -// 用户模块 token setToken...... +// 用户模块 export const userStore = defineStore( 'anyim-user', () => { - const token = ref('') - const setToken = (newToken) => { - token.value = newToken + const at = ref({ + token: '', + secret: '', + expiretime: null + }) + const rt = ref({ + token: '', + secret: '', + expiretime: null + }) + const setAt = (newAt) => { + const now = new Date() + at.value = { + token: newAt.token, + secret: newAt.secret, + expiretime: new Date(now.getTime() + newAt.expire * 1000) + } + } + const setRt = (newRt) => { + const now = new Date() + rt.value = { + token: newRt.token, + secret: newRt.secret, + expiretime: new Date(now.getTime() + newRt.expire * 1000) + } + } + const clearAt = () => { + at.value = { + token: '', + secret: '', + expiretime: null + } + } + const clearRt = () => { + rt.value = { + token: '', + secret: '', + expiretime: null + } } return { - token, - setToken + at, + rt, + setAt, + setRt, + clearAt, + clearRt } }, { diff --git a/src/utils/request.js b/src/utils/request.js index 6c66baf..08377ad 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -29,7 +29,7 @@ instance.interceptors.response.use( return res } - ElMessage.error(res.data.msg || '服务异常') + ElMessage.error(res.data.desc || '服务异常') return Promise.reject(res.data) }, (err) => { diff --git a/src/views/LoginPage.vue b/src/views/LoginPage.vue index 4593a31..0b65297 100644 --- a/src/views/LoginPage.vue +++ b/src/views/LoginPage.vue @@ -1,8 +1,11 @@