You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
821 B
33 lines
821 B
1 month ago
|
// utils/login.js
|
||
|
|
||
|
import axios from 'axios'
|
||
|
|
||
|
export async function autoLoginByToken() {
|
||
|
const urlParams = new URLSearchParams(window.location.search)
|
||
|
const token = urlParams.get('token')
|
||
|
|
||
|
if (token) {
|
||
|
try {
|
||
|
const res = await axios.post('/agentnew/token_login', { token: token },{
|
||
|
headers: {
|
||
|
'Content-Type': 'application/x-www-form-urlencoded'
|
||
|
},
|
||
|
})
|
||
|
if (res.data.status) {
|
||
|
// 可选:将 token 存入 localStorage
|
||
|
localStorage.setItem('token', res.data.data)
|
||
|
|
||
|
const url = new URL(window.location.href);
|
||
|
url.searchParams.delete('token');
|
||
|
window.location.replace(url.toString());
|
||
|
return true
|
||
|
} else {
|
||
|
return false
|
||
|
}
|
||
|
} catch (e) {
|
||
|
console.error('请求异常', e)
|
||
|
}
|
||
|
}
|
||
|
return false
|
||
|
}
|