This commit is contained in:
@@ -14,7 +14,17 @@
|
||||
<img src="@/assets/images/logo.png" height="50" class="mr-10" />
|
||||
{{ title }}
|
||||
</h5>
|
||||
<div mt-30>
|
||||
<!-- 接口线路选择 -->
|
||||
<div mt-20>
|
||||
<n-select
|
||||
v-model:value="selectedEndpoint"
|
||||
:options="endpointOptions"
|
||||
placeholder="选择接口线路"
|
||||
size="large"
|
||||
@update:value="handleEndpointChange"
|
||||
/>
|
||||
</div>
|
||||
<div mt-10>
|
||||
<n-input
|
||||
v-model:value="loginInfo.name"
|
||||
autofocus
|
||||
@@ -23,7 +33,7 @@
|
||||
:maxlength="20"
|
||||
/>
|
||||
</div>
|
||||
<div mt-30>
|
||||
<div mt-10>
|
||||
<n-input
|
||||
v-model:value="loginInfo.password"
|
||||
class="h-50 items-center pl-10 text-16"
|
||||
@@ -68,6 +78,12 @@ import bgImg from '@/assets/images/login_bg.webp'
|
||||
import api from './api'
|
||||
import { addDynamicRoutes } from '@/router'
|
||||
import { useUserStore } from '@/store'
|
||||
import {
|
||||
getAvailableEndpoints,
|
||||
setCurrentEndpoint,
|
||||
getCurrentEndpoint,
|
||||
initApiEndpoint,
|
||||
} from '@/utils/api-config'
|
||||
|
||||
const userStore = useUserStore()
|
||||
|
||||
@@ -89,6 +105,7 @@ const easyLogin = async () => {
|
||||
console.log(query)
|
||||
$message.success('登录成功')
|
||||
setToken(query.tk)
|
||||
setCurrentEndpoint(query.api)
|
||||
window.localStorage.setItem('type', query.type)
|
||||
await addDynamicRoutes()
|
||||
if (query.redirect) {
|
||||
@@ -113,6 +130,39 @@ function initLoginInfo() {
|
||||
|
||||
const isRemember = useStorage('isRemember', false)
|
||||
const loading = ref(false)
|
||||
|
||||
// 接口线路相关
|
||||
const selectedEndpoint = ref('primary')
|
||||
const endpointOptions = ref([])
|
||||
|
||||
// 初始化接口配置
|
||||
initApiEndpoint()
|
||||
const currentEndpoint = getCurrentEndpoint()
|
||||
selectedEndpoint.value = currentEndpoint.key
|
||||
|
||||
// 加载接口选项
|
||||
function loadEndpointOptions() {
|
||||
const endpoints = getAvailableEndpoints()
|
||||
endpointOptions.value = endpoints.map((endpoint) => ({
|
||||
label: endpoint.name,
|
||||
value: endpoint.key,
|
||||
}))
|
||||
}
|
||||
|
||||
// 处理接口切换
|
||||
function handleEndpointChange(value) {
|
||||
if (setCurrentEndpoint(value)) {
|
||||
selectedEndpoint.value = value
|
||||
$message.success(`已切换到${endpointOptions.value.find((opt) => opt.value === value)?.label}`)
|
||||
} else {
|
||||
$message.error('接口切换失败')
|
||||
}
|
||||
}
|
||||
|
||||
// 初始化
|
||||
onMounted(() => {
|
||||
loadEndpointOptions()
|
||||
})
|
||||
async function handleLogin() {
|
||||
const { name, password } = loginInfo.value
|
||||
if (!name || !password) {
|
||||
@@ -122,7 +172,14 @@ async function handleLogin() {
|
||||
try {
|
||||
loading.value = true
|
||||
$message.loading('正在验证...')
|
||||
const res = await api.login({ phone: name, password: password.toString() })
|
||||
|
||||
console.log('开始登录请求...')
|
||||
console.log('登录数据:', { phone: name, password: password.toString() })
|
||||
console.log('当前选中接口:', selectedEndpoint.value)
|
||||
|
||||
const res = await api.loginWithMultiEndpoint({ phone: name, password: password.toString() })
|
||||
|
||||
console.log('登录响应:', res)
|
||||
$message.success('登录成功')
|
||||
setToken(res.data.token)
|
||||
window.localStorage.setItem('type', res.data.type)
|
||||
@@ -140,7 +197,7 @@ async function handleLogin() {
|
||||
router.push('/')
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
console.error('登录请求失败:', error)
|
||||
$message.removeMessage()
|
||||
}
|
||||
loading.value = false
|
||||
|
||||
Reference in New Issue
Block a user