登录跳转

master
veypi 3 years ago
parent e081e4ecb6
commit a2b5b56b78

@ -47,9 +47,6 @@
import BaseFrame from './frame.vue' import BaseFrame from './frame.vue'
import {IsDark} from '@/theme' import {IsDark} from '@/theme'
import {ref} from 'vue' import {ref} from 'vue'
import {useMessage} from 'naive-ui'
// @ts-ignore
window.$msg = useMessage()
let shown = ref(false) let shown = ref(false)

@ -7,6 +7,9 @@
<script lang="ts" setup> <script lang="ts" setup>
// @ts-nocheck // @ts-nocheck
import {onMounted} from 'vue' import {onMounted} from 'vue'
import {useMessage} from 'naive-ui'
// @ts-ignore
window.$msg = useMessage()
let emit = defineEmits<{ let emit = defineEmits<{
(e: 'update:modelValue', v: boolean): void (e: 'update:modelValue', v: boolean): void

@ -28,6 +28,7 @@ import api from '@/api'
import {useRoute, useRouter} from 'vue-router' import {useRoute, useRouter} from 'vue-router'
import {store} from '@/store' import {store} from '@/store'
import {modelsApp} from '@/models' import {modelsApp} from '@/models'
import util from '@/libs/util'
let msg = useMessage() let msg = useMessage()
const route = useRoute() const route = useRoute()
@ -69,17 +70,7 @@ function login() {
api.user.login(data.value.username, data.value.password).Start((url: string) => { api.user.login(data.value.username, data.value.password).Start((url: string) => {
msg.success('登录成功') msg.success('登录成功')
store.dispatch('user/fetchUserData') store.dispatch('user/fetchUserData')
let target = url redirect(route.query.redirect as string)
if (route.query.redirect) {
target = route.query.redirect as string
}
if (target && target.startsWith('http')) {
window.location.href = target
} else if (target) {
router.push(target)
} else {
router.push({name: 'home'})
}
}, e => { }, e => {
console.log(e) console.log(e)
msg.warning('登录失败:' + e) msg.warning('登录失败:' + e)
@ -88,17 +79,26 @@ function login() {
}) })
} }
function redirect() { function redirect(url?: string) {
console.log(uuid.value)
if (uuid.value !== store.state.oauuid) { if (uuid.value !== store.state.oauuid) {
api.app.get(uuid.value as string).Start((app: modelsApp) => { api.app.get(uuid.value as string).Start((app: modelsApp) => {
console.log(app.UserRefreshUrl) console.log(app.UserRefreshUrl)
api.token(uuid.value as string).get().Start(e => { api.token(uuid.value as string).get().Start(e => {
let url = app.UserRefreshUrl.replaceAll('$token', e) if (!url) {
console.log(url) url = app.UserRefreshUrl
}
e = encodeURIComponent(e)
url = url.replaceAll('$token', e)
window.location.href = url window.location.href = url
}) })
}, e => {
}) })
} else if (util.checkLogin()) {
if (url) {
router.push(url)
} else {
router.push({name: 'home'})
}
} }
} }

Loading…
Cancel
Save