登录逻辑简单处理
This commit is contained in:
parent
dd1137ba60
commit
300aaf32da
@ -39,6 +39,7 @@
|
||||
"eslint-config-prettier": "^8.1.0",
|
||||
"eslint-plugin-vue": "^9.0.0",
|
||||
"prettier": "^2.5.1",
|
||||
"ts-md5": "^1.3.1",
|
||||
"typescript": "^4.5.4"
|
||||
},
|
||||
"engines": {
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { api } from 'src/boot/axios';
|
||||
import { PageDto, PageQueryDto } from './ApiCommon';
|
||||
import { Md5 } from 'ts-md5';
|
||||
|
||||
const UserUriBase = '/api/user';
|
||||
|
||||
@ -32,7 +33,7 @@ interface LoginInfo {
|
||||
password: string;
|
||||
}
|
||||
|
||||
const PasswordSult = '';
|
||||
const PasswordSult = 'sdfs';
|
||||
|
||||
/**
|
||||
* 用户登录
|
||||
@ -40,6 +41,12 @@ const PasswordSult = '';
|
||||
* @returns
|
||||
*/
|
||||
export async function login(loginInfo: LoginInfo): Promise<string> {
|
||||
const md5 = new Md5();
|
||||
const encryptedPassword = md5
|
||||
.appendStr(`${loginInfo.password}${PasswordSult}`)
|
||||
.end();
|
||||
const info = { ...loginInfo, password: encryptedPassword };
|
||||
console.log(info);
|
||||
const response = await api.post(`${UserUriBase}/login`, loginInfo);
|
||||
return response.data;
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ interface ErrorData {
|
||||
status: number;
|
||||
title: string;
|
||||
detail: string;
|
||||
properties: { [key: string]: unknown };
|
||||
code: number;
|
||||
}
|
||||
|
||||
export class ApiError {
|
||||
@ -37,7 +37,7 @@ export class ApiError {
|
||||
const response = origin.response;
|
||||
if (response) {
|
||||
const err = response.data as ErrorData;
|
||||
this.code = err.properties.code as number;
|
||||
this.code = err.code;
|
||||
this.title = err.title;
|
||||
this.detail = err.detail;
|
||||
} else {
|
||||
|
@ -1,5 +1,5 @@
|
||||
function getHost(): string {
|
||||
return '192.168.3.212:9081';
|
||||
return '192.168.3.7:9081';
|
||||
}
|
||||
|
||||
export function getHttpBase() {
|
||||
|
@ -21,7 +21,7 @@
|
||||
<q-input
|
||||
filled
|
||||
v-model="loginInfo.account"
|
||||
label="Username"
|
||||
label="账号"
|
||||
lazy-rules
|
||||
/>
|
||||
|
||||
@ -29,7 +29,7 @@
|
||||
type="password"
|
||||
filled
|
||||
v-model="loginInfo.password"
|
||||
label="Password"
|
||||
label="密码"
|
||||
lazy-rules
|
||||
/>
|
||||
|
||||
@ -49,15 +49,33 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { useQuasar } from 'quasar';
|
||||
import { ApiError } from 'src/boot/axios';
|
||||
import { login } from 'src/api/UserApi';
|
||||
import { saveJwtToken } from 'src/configs/TokenManage';
|
||||
import { reactive } from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
|
||||
const $q = useQuasar();
|
||||
|
||||
const loginInfo = reactive({
|
||||
account: '',
|
||||
password: '',
|
||||
});
|
||||
|
||||
function doLogin() {
|
||||
async function doLogin() {
|
||||
console.log(loginInfo);
|
||||
try {
|
||||
const token = await login(loginInfo);
|
||||
saveJwtToken(token);
|
||||
useRouter().push({ name: 'home' });
|
||||
} catch (err) {
|
||||
const apiErr = err as ApiError;
|
||||
$q.notify({
|
||||
type: 'negative',
|
||||
message: apiErr.title,
|
||||
});
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
|
@ -3137,6 +3137,11 @@ toidentifier@1.0.1:
|
||||
resolved "https://registry.npmmirror.com/toidentifier/-/toidentifier-1.0.1.tgz#3be34321a88a820ed1bd80dfaa33e479fbb8dd35"
|
||||
integrity sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==
|
||||
|
||||
ts-md5@^1.3.1:
|
||||
version "1.3.1"
|
||||
resolved "https://registry.npmmirror.com/ts-md5/-/ts-md5-1.3.1.tgz#f5b860c0d5241dd9bb4e909dd73991166403f511"
|
||||
integrity sha512-DiwiXfwvcTeZ5wCE0z+2A9EseZsztaiZtGrtSaY5JOD7ekPnR/GoIVD5gXZAlK9Na9Kvpo9Waz5rW64WKAWApg==
|
||||
|
||||
tslib@^1.8.1:
|
||||
version "1.14.1"
|
||||
resolved "https://registry.npmmirror.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"
|
||||
|
Loading…
Reference in New Issue
Block a user