mirror of
https://github.com/1Panel-dev/MaxKB.git
synced 2025-12-26 10:12:51 +00:00
feat: commit
This commit is contained in:
parent
f805f6dce1
commit
a91d8016f8
|
|
@ -2,14 +2,13 @@ import { Result } from '@/request/Result'
|
|||
import { get, post } from '@/request/index'
|
||||
import type { LoginRequest } from '@/api/type/login'
|
||||
import type { Ref } from 'vue'
|
||||
|
||||
/**
|
||||
* 登录
|
||||
* @param request 登录接口请求表单
|
||||
* @param loading 接口加载器
|
||||
* @returns 认证数据
|
||||
*/
|
||||
const login: (request: LoginRequest, loading?: Ref<boolean>) => Promise<Result<string>> = (
|
||||
const login: (request: LoginRequest, loading?: Ref<boolean>) => Promise<Result<any>> = (
|
||||
request,
|
||||
loading,
|
||||
) => {
|
||||
|
|
@ -20,7 +19,7 @@ const login: (request: LoginRequest, loading?: Ref<boolean>) => Promise<Result<s
|
|||
* 获取验证码
|
||||
* @param loading 接口加载器
|
||||
*/
|
||||
const getCaptcha: (loading?: Ref<boolean>) => Promise<Result<string>> = (loading) => {
|
||||
const getCaptcha: (loading?: Ref<boolean>) => Promise<Result<any>> = (loading) => {
|
||||
return get('/user/captcha', undefined, loading)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ instance.interceptors.request.use(
|
|||
const language = user.getLanguage()
|
||||
config.headers['Accept-Language'] = `${language}`
|
||||
if (token) {
|
||||
config.headers['AUTHORIZATION'] = `${token}`
|
||||
config.headers['AUTHORIZATION'] = `Bearer ${token}`
|
||||
}
|
||||
return config
|
||||
},
|
||||
|
|
@ -43,14 +43,14 @@ instance.interceptors.response.use(
|
|||
if (response.data) {
|
||||
if (response.data.code !== 200 && !(response.data instanceof Blob)) {
|
||||
if (response.config.url.includes('/application/authentication')) {
|
||||
return Promise.reject(response.data)
|
||||
return Promise.reject(response.data.data)
|
||||
}
|
||||
if (
|
||||
!response.config.url.includes('/valid') &&
|
||||
!response.config.url.includes('/function_lib/debug')
|
||||
) {
|
||||
MsgError(response.data.message)
|
||||
return Promise.reject(response.data)
|
||||
return Promise.reject(response.data.data)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -99,11 +99,12 @@ const promise: (
|
|||
}
|
||||
request
|
||||
.then((response) => {
|
||||
console.log(response)
|
||||
// blob类型的返回状态是response.status
|
||||
if (response.status === 200) {
|
||||
resolve(response?.data || response)
|
||||
resolve(response?.data?.data || response)
|
||||
} else {
|
||||
reject(response?.data || response)
|
||||
reject(response?.data?.data || response)
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
|
|
|
|||
|
|
@ -30,9 +30,9 @@ const useLoginStore = defineStore('login', {
|
|||
},
|
||||
|
||||
async asyncLogin(data: LoginRequest, loading?: Ref<boolean>) {
|
||||
return loginApi.login(data).then((ok) => {
|
||||
this.token = ok.data
|
||||
localStorage.setItem('token', ok.data)
|
||||
return loginApi.login(data).then((ok: any) => {
|
||||
this.token = ok.token
|
||||
localStorage.setItem('token', ok.token)
|
||||
const user = useUserStore()
|
||||
return user.profile()
|
||||
})
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@
|
|||
@click="loginHandle"
|
||||
:loading="loading"
|
||||
>
|
||||
>{{ $t('views.login.buttons.login') }}
|
||||
{{ $t('views.login.buttons.login') }}
|
||||
</el-button>
|
||||
<div class="operate-container flex-between mt-12">
|
||||
<el-button
|
||||
|
|
@ -135,7 +135,7 @@ const loginHandle = () => {
|
|||
}
|
||||
function makeCode() {
|
||||
loginApi.getCaptcha().then((res: any) => {
|
||||
identifyCode.value = res.data.captcha
|
||||
identifyCode.value = res.captcha
|
||||
})
|
||||
}
|
||||
onBeforeMount(() => {
|
||||
|
|
|
|||
Loading…
Reference in New Issue