控制器中间件授权改造完成

This commit is contained in:
GeekMaster
2025-08-26 14:22:14 +08:00
parent 728de61bd6
commit b6d81890cf
23 changed files with 168 additions and 334 deletions

View File

@@ -34,6 +34,7 @@
<button
class="w-full h-12 rounded-xl text-base font-medium text-white bg-gradient-to-r from-blue-500 to-purple-600 hover:from-blue-600 hover:to-purple-700 transition-all duration-300 hover:-translate-y-0.5 hover:shadow-lg active:translate-y-0 shadow-md"
@click="submitLogin"
type="button"
>
{{ loading ? '登录中...' : '登 录' }}
</button>
@@ -210,6 +211,7 @@
<button
class="w-full h-12 rounded-xl text-base font-medium text-white bg-gradient-to-r from-blue-500 to-purple-600 hover:from-blue-600 hover:to-purple-700 transition-all duration-300 hover:-translate-y-0.5 hover:shadow-lg active:translate-y-0 shadow-md"
@click="submitRegister"
type="button"
>
{{ loading ? '注册中...' : '注 册' }}
</button>

View File

@@ -1,133 +0,0 @@
/**
* 设备检测工具函数
* 用于判断当前设备类型支持PC端和移动端的智能识别
*/
/**
* 检测设备类型
* @returns {string} 'mobile' | 'desktop'
*/
export const detectDevice = () => {
const userAgent = navigator.userAgent.toLowerCase()
// 移动设备关键词检测
const mobileKeywords = [
'mobile',
'android',
'iphone',
'ipad',
'phone',
'blackberry',
'opera mini',
'windows phone',
'iemobile',
]
// 平板设备关键词检测
const tabletKeywords = ['tablet', 'ipad', 'playbook', 'silk', 'kindle']
// 检查是否为移动设备
const isMobile = mobileKeywords.some((keyword) => userAgent.includes(keyword))
// 检查是否为平板设备
const isTablet = tabletKeywords.some((keyword) => userAgent.includes(keyword))
// 检查屏幕尺寸
const screenWidth = window.innerWidth
const screenHeight = window.innerHeight
// 移动设备判断逻辑
if (isMobile || isTablet || screenWidth <= 768) {
return 'mobile'
}
return 'desktop'
}
/**
* 检测是否为移动设备
* @returns {boolean}
*/
export const isMobileDevice = () => {
return detectDevice() === 'mobile'
}
/**
* 检测是否为桌面设备
* @returns {boolean}
*/
export const isDesktopDevice = () => {
return detectDevice() === 'desktop'
}
/**
* 获取设备跳转路径
* @param {string} deviceType - 设备类型
* @param {string} defaultPath - 默认路径
* @returns {string} 跳转路径
*/
export const getDeviceRedirectPath = (deviceType, defaultPath = '/') => {
if (deviceType === 'mobile') {
return '/mobile'
}
return defaultPath
}
/**
* 根据当前设备获取跳转路径
* @param {string} defaultPath - 默认路径
* @returns {string} 跳转路径
*/
export const getCurrentDeviceRedirectPath = (defaultPath = '/') => {
const deviceType = detectDevice()
return getDeviceRedirectPath(deviceType, defaultPath)
}
/**
* 检测屏幕尺寸
* @returns {object} { width, height, isSmall, isMedium, isLarge }
*/
export const getScreenInfo = () => {
const width = window.innerWidth
const height = window.innerHeight
return {
width,
height,
isSmall: width <= 768,
isMedium: width > 768 && width <= 1024,
isLarge: width > 1024,
}
}
/**
* 检测浏览器类型
* @returns {string} 浏览器类型
*/
export const detectBrowser = () => {
const userAgent = navigator.userAgent.toLowerCase()
if (userAgent.includes('chrome')) return 'chrome'
if (userAgent.includes('firefox')) return 'firefox'
if (userAgent.includes('safari') && !userAgent.includes('chrome')) return 'safari'
if (userAgent.includes('edge')) return 'edge'
if (userAgent.includes('opera')) return 'opera'
return 'unknown'
}
/**
* 检测操作系统
* @returns {string} 操作系统类型
*/
export const detectOS = () => {
const userAgent = navigator.userAgent.toLowerCase()
if (userAgent.includes('windows')) return 'windows'
if (userAgent.includes('mac')) return 'macos'
if (userAgent.includes('linux')) return 'linux'
if (userAgent.includes('android')) return 'android'
if (userAgent.includes('ios')) return 'ios'
return 'unknown'
}

View File

@@ -30,12 +30,7 @@
</div>
<div class="login-content">
<login-dialog
:show="true"
@hide="handleLoginHide"
@success="handleLoginSuccess"
ref="loginDialogRef"
/>
<login-dialog :show="true" @success="handleLoginSuccess" ref="loginDialogRef" />
</div>
</div>
</div>
@@ -45,7 +40,7 @@
<script setup>
import LoginDialog from '@/components/LoginDialog.vue'
import { setUserToken } from '@/store/session'
import { getCurrentDeviceRedirectPath } from '@/utils/device'
import { isMobile } from '@/utils/libs'
import { onMounted, ref } from 'vue'
import { useRouter } from 'vue-router'
@@ -58,16 +53,13 @@ if (token) {
router.push('/chat')
}
// 处理登录弹窗隐藏
const handleLoginHide = () => {
const redirectPath = getCurrentDeviceRedirectPath()
router.push(redirectPath)
}
// 处理登录成功
const handleLoginSuccess = () => {
const redirectPath = getCurrentDeviceRedirectPath()
router.push(redirectPath)
if (isMobile()) {
router.push('/mobile')
} else {
router.push('/chat')
}
}
onMounted(() => {

View File

@@ -34,7 +34,6 @@
:show="true"
active="register"
:inviteCode="inviteCode"
@hide="handleRegisterHide"
@success="handleRegisterSuccess"
ref="loginDialogRef"
/>
@@ -46,7 +45,7 @@
<script setup>
import LoginDialog from '@/components/LoginDialog.vue'
import { getCurrentDeviceRedirectPath } from '@/utils/device'
import { isMobile } from '@/utils/libs'
import { onMounted, ref } from 'vue'
import { useRouter } from 'vue-router'
@@ -54,16 +53,13 @@ const router = useRouter()
const loginDialogRef = ref(null)
const inviteCode = ref(router.currentRoute.value.query.invite_code || '')
// 处理注册弹窗隐藏
const handleRegisterHide = () => {
const redirectPath = getCurrentDeviceRedirectPath()
router.push(redirectPath)
}
// 处理注册成功
const handleRegisterSuccess = () => {
const redirectPath = getCurrentDeviceRedirectPath()
router.push(redirectPath)
if (isMobile()) {
router.push('/mobile')
} else {
router.push('/chat')
}
}
onMounted(() => {