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.
32 lines
830 B
32 lines
830 B
// 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
|
|
}
|
|
|