|
@@ -9,7 +9,7 @@
|
|
|
<!-- 登录输入框 -->
|
|
<!-- 登录输入框 -->
|
|
|
<div class="login-wrapper">
|
|
<div class="login-wrapper">
|
|
|
<div class="login-input">
|
|
<div class="login-input">
|
|
|
- <span>AI课程</span>
|
|
|
|
|
|
|
+ <span>人工智能通识课平台</span>
|
|
|
<el-form
|
|
<el-form
|
|
|
ref="loginFormRef"
|
|
ref="loginFormRef"
|
|
|
:model="loginData.loginForm"
|
|
:model="loginData.loginForm"
|
|
@@ -62,7 +62,7 @@
|
|
|
</template>
|
|
</template>
|
|
|
|
|
|
|
|
<script setup>
|
|
<script setup>
|
|
|
-import { ref, onMounted, computed } from 'vue'
|
|
|
|
|
|
|
+import { ref, onMounted, computed ,onUnmounted} from 'vue'
|
|
|
import { useRouter } from 'vue-router'
|
|
import { useRouter } from 'vue-router'
|
|
|
import { HomeFilled, Avatar, Lock } from '@element-plus/icons-vue'
|
|
import { HomeFilled, Avatar, Lock } from '@element-plus/icons-vue'
|
|
|
import { getTenantIdByName, login } from '@/api/login/login.js'
|
|
import { getTenantIdByName, login } from '@/api/login/login.js'
|
|
@@ -103,16 +103,19 @@ const getTenantId = async () => {
|
|
|
if (res && res.data) {
|
|
if (res && res.data) {
|
|
|
//记录租户id
|
|
//记录租户id
|
|
|
tenantId.value = res.data
|
|
tenantId.value = res.data
|
|
|
|
|
+ return true; // 租户验证成功
|
|
|
} else {
|
|
} else {
|
|
|
- ElMessage.error('获取租户 ID 失败,请检查租户名称')
|
|
|
|
|
- return
|
|
|
|
|
|
|
+ ElMessage.error('租户填写错误!')
|
|
|
|
|
+ return false; // 租户验证失败
|
|
|
}
|
|
}
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
- ElMessage.error('获取租户 ID 出错,请重试')
|
|
|
|
|
|
|
+ ElMessage.error('租户填写错误!')
|
|
|
console.error('获取租户 ID 错误:', error)
|
|
console.error('获取租户 ID 错误:', error)
|
|
|
- return
|
|
|
|
|
|
|
+ return false; // 租户验证失败
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
// 登录
|
|
// 登录
|
|
|
const handleLogin = async params => {
|
|
const handleLogin = async params => {
|
|
|
if (!loginFormRef.value) return
|
|
if (!loginFormRef.value) return
|
|
@@ -120,7 +123,13 @@ const handleLogin = async params => {
|
|
|
if (valid) {
|
|
if (valid) {
|
|
|
loginLoading.value = true
|
|
loginLoading.value = true
|
|
|
try {
|
|
try {
|
|
|
- await getTenantId()
|
|
|
|
|
|
|
+ // 先验证租户是否存在
|
|
|
|
|
+ const tenantValid = await getTenantId()
|
|
|
|
|
+ if (!tenantValid) {
|
|
|
|
|
+ // 租户验证失败,不执行登录
|
|
|
|
|
+ loginLoading.value = false
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
const loginDataLoginForm = { ...loginData.value.loginForm }
|
|
const loginDataLoginForm = { ...loginData.value.loginForm }
|
|
|
// 构建包含 headers 的请求参数
|
|
// 构建包含 headers 的请求参数
|
|
|
const res = await login(
|
|
const res = await login(
|
|
@@ -183,6 +192,8 @@ const handleLogin = async params => {
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
// 在组件挂载时检查登录状态和恢复登录信息
|
|
// 在组件挂载时检查登录状态和恢复登录信息
|
|
|
onMounted(() => {
|
|
onMounted(() => {
|
|
|
const storedStatus = localStorage.getItem('isLoggedIn') // isLoggedIn
|
|
const storedStatus = localStorage.getItem('isLoggedIn') // isLoggedIn
|
|
@@ -207,6 +218,21 @@ onMounted(() => {
|
|
|
isLoggedIn.value = true
|
|
isLoggedIn.value = true
|
|
|
router.push('/home')
|
|
router.push('/home')
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ const handleKeyPress = (event) => {
|
|
|
|
|
+ // 检查是否按下回车键(keyCode 13)
|
|
|
|
|
+ if (event.key === 'Enter' || event.keyCode === 13) {
|
|
|
|
|
+ handleLogin()
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ document.addEventListener('keydown', handleKeyPress)
|
|
|
|
|
+
|
|
|
|
|
+ // 在组件卸载时移除事件监听
|
|
|
|
|
+ onUnmounted(() => {
|
|
|
|
|
+ document.removeEventListener('keydown', handleKeyPress)
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
})
|
|
})
|
|
|
</script>
|
|
</script>
|
|
|
|
|
|