登录处理

This commit is contained in:
speakeloudest 2025-12-30 22:54:57 -08:00
parent a9cbd2b921
commit ab5de5e0f5
7 changed files with 51 additions and 13 deletions

View File

@ -25,10 +25,14 @@
<script setup lang="ts"> <script setup lang="ts">
import { Laptop, Smartphone, Tablet, Monitor, Cpu, HelpCircle, X } from 'lucide-vue-next' import { Laptop, Smartphone, Tablet, Monitor, Cpu, HelpCircle, X } from 'lucide-vue-next'
import request from '@/utils/request'
import { toast } from 'vue-sonner'
interface Device { interface Device {
id: string id: string
name: string name: string
user_agent: string
identifier: string
type: 'mobile' | 'desktop' type: 'mobile' | 'desktop'
deviceId: string deviceId: string
} }
@ -37,13 +41,20 @@ defineProps<{
devices: Device[] devices: Device[]
}>() }>()
function delDevice(item) { const emit = defineEmits(['refresh'])
console.log('Device removed', item)
function delDevice(device: Device) {
if (confirm('请确认是否移除此设备?')) {
request.put('/api/v1/public/user/unbind_device', { id: device.id }).then(() => {
toast.success('设备已移除')
emit('refresh')
})
}
} }
interface DeviceTypeInfo { interface DeviceTypeInfo {
type: string type: string
icon: string iconComponent: any
} }
/** /**

View File

@ -106,18 +106,38 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ref } from 'vue' import { ref, onMounted, watch } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import type { LocationQueryValue } from 'vue-router'
import LoginFormModal from './components/LoginFormModal.vue' import LoginFormModal from './components/LoginFormModal.vue'
import DownloadButton from './components/DownloadButton.vue' import DownloadButton from './components/DownloadButton.vue'
import Logo from './logo.svg?component' import Logo from './logo.svg?component'
import MobileLogo from './mobile-logo.svg?component' import MobileLogo from './mobile-logo.svg?component'
import ScreenshotMobile from './screenshot-mobile.png' import ScreenshotMobile from './screenshot-mobile.png'
import ScreenshotDesktop from './screenshot-desktop.png' import ScreenshotDesktop from './screenshot-desktop.png'
import { AppleIcon, MonitorIcon, SmartphoneIcon, LocateFixedIcon } from 'lucide-vue-next'
const route = useRoute()
const router = useRouter()
const loginModalRef = ref<InstanceType<typeof LoginFormModal> | null>(null) const loginModalRef = ref<InstanceType<typeof LoginFormModal> | null>(null)
const openLoginModal = () => { const openLoginModal = () => {
loginModalRef.value?.show() loginModalRef.value?.show()
} }
onMounted(() => {
if (route.query.login === 'true') {
openLoginModal()
router.replace({ query: { ...route.query, login: undefined } })
}
})
watch(
() => route.query.login,
(newVal) => {
if (newVal === 'true') {
openLoginModal()
router.replace({ query: { ...route.query, login: undefined } })
}
},
)
</script> </script>

View File

@ -12,7 +12,7 @@
</div> </div>
</div> </div>
<div class="mb-5 px-[20px] text-white"> <div class="mb-5 px-[20px] text-white">
<DeviceList :devices="devices" /> <DeviceList :devices="devices" @refresh="emit('refresh')" />
</div> </div>
</div> </div>
<div> <div>
@ -78,7 +78,7 @@ const props = defineProps<{
selectedPlan: any selectedPlan: any
}>() }>()
const emit = defineEmits(['select-plan', 'pay']) const emit = defineEmits(['select-plan', 'pay', 'refresh'])
// --- Handlers --- // --- Handlers ---
const handlePlanSelect = (id: string) => { const handlePlanSelect = (id: string) => {
@ -127,7 +127,6 @@ const expireDateInfo = computed(() => {
function logout() { function logout() {
router.push('/') router.push('/')
localStorage.removeItem('Authorization') localStorage.removeItem('Authorization')
toast.success('退出成功')
} }
</script> </script>

View File

@ -12,7 +12,7 @@
</div> </div>
<div class="mb-5 pr-[25px] pl-[21px] text-white"> <div class="mb-5 pr-[25px] pl-[21px] text-white">
<DeviceList :devices="devices" /> <DeviceList :devices="devices" @refresh="emit('refresh')" />
</div> </div>
<div class="overflow-hidden rounded-4xl bg-[#A8FF53]"> <div class="overflow-hidden rounded-4xl bg-[#A8FF53]">
<div class="pt-7"> <div class="pt-7">
@ -65,7 +65,7 @@ const props = defineProps<{
selectedPlan: any selectedPlan: any
}>() }>()
const emit = defineEmits(['select-plan', 'pay']) const emit = defineEmits(['select-plan', 'pay', 'refresh'])
// --- Handlers --- // --- Handlers ---
const handlePlanSelect = (id: string) => { const handlePlanSelect = (id: string) => {
@ -114,7 +114,6 @@ const expireDateInfo = computed(() => {
function logout() { function logout() {
router.push('/') router.push('/')
localStorage.removeItem('Authorization') localStorage.removeItem('Authorization')
toast.success('退出成功')
} }
</script> </script>

View File

@ -34,6 +34,7 @@
:selected-plan="activePlan" :selected-plan="activePlan"
@select-plan="handlePlanSelect" @select-plan="handlePlanSelect"
@pay="handlePay" @pay="handlePay"
@refresh="init"
/> />
</div> </div>
<div class="container mx-auto hidden flex-1 items-center justify-center md:flex"> <div class="container mx-auto hidden flex-1 items-center justify-center md:flex">
@ -47,6 +48,7 @@
:selected-plan="activePlan" :selected-plan="activePlan"
@select-plan="handlePlanSelect" @select-plan="handlePlanSelect"
@pay="handlePay" @pay="handlePay"
@refresh="init"
/> />
</div> </div>
</div> </div>
@ -157,7 +159,6 @@ function init() {
// & // &
request.get('/api/v1/public/user/info').then((res: any) => { request.get('/api/v1/public/user/info').then((res: any) => {
devices.value = res.user_devices devices.value = res.user_devices
const emailInfo = res.auth_methods?.find((item: any) => item.auth_type === 'email') const emailInfo = res.auth_methods?.find((item: any) => item.auth_type === 'email')
if (emailInfo) { if (emailInfo) {
userSubInfo.value.email = emailInfo.auth_identifier userSubInfo.value.email = emailInfo.auth_identifier

View File

@ -21,4 +21,12 @@ const router = createRouter({
], ],
}) })
router.beforeEach((to, _from, next) => {
if (to.path === '/user-center' && !localStorage.getItem('Authorization')) {
next({ path: '/', query: { login: 'true' } })
} else {
next()
}
})
export default router export default router

View File

@ -7,7 +7,7 @@ import { HiAesUtil } from './HiAesUtil.ts'
const encryptionKey = 'c0qhq99a-nq8h-ropg-wrlc-ezj4dlkxqpzx' const encryptionKey = 'c0qhq99a-nq8h-ropg-wrlc-ezj4dlkxqpzx'
function redirectLogin() { function redirectLogin() {
localStorage.removeItem('Authorization') localStorage.removeItem('Authorization')
router.push('/') router.push({ path: '/', query: { login: 'true' } })
} }
export interface ExtraConfig { export interface ExtraConfig {
/** /**