Add login modal experience (#16)

This commit is contained in:
AceDataCloud committed 2024-01-03 01:12:47 +08:00
1 parent d536508293
commit ccae7257e5
11 files changed
+95 -20

No files matched your search

+1 -1
View File
@@ -184,7 +184,7 @@ export default defineComponent({
}
.btn {
display: block;
z-index: 10000;
z-index: 100;
cursor: pointer;
position: absolute;
top: 7px;
+60
View File
@@ -0,0 +1,60 @@
<template>
<el-dialog
:model-value="!authenticated"
modal-class="dialog"
width="400px"
:show-close="false"
:close-on-press-escape="false"
:close-on-click-modal="false"
>
<iframe width="360" height="560" :src="iframeUrl" frameborder="0" />
</el-dialog>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import { ElDialog } from 'element-plus';
import { getBaseUrlAuth } from '@/utils';
export default defineComponent({
name: 'AuthPanel',
components: {
ElDialog
},
data() {
return {
iframeUrl: `${getBaseUrlAuth()}/auth/login`
};
},
computed: {
authenticated() {
return !!this.$store.state.token.access;
}
},
mounted() {
window.addEventListener('message', async (event: MessageEvent) => {
if (event.origin !== getBaseUrlAuth()) {
return;
}
if (event.data.name === 'login') {
const data = event.data.data;
const token = {
access: data.access_token,
refresh: data.refresh_token,
expiration: data.expires_in
};
await this.$store.dispatch('setToken', token);
await this.$store.dispatch('getUser');
window.location.reload();
}
});
}
});
</script>
<style lang="scss" scoped>
.dialog {
width: 400px;
height: 600px;
}
</style>
+6 -3
View File
@@ -27,7 +27,7 @@
<div class="link">
<help-entry />
</div>
<div class="link">
<div v-if="authenticated" class="link">
<el-tooltip effect="dark" :content="$t('common.nav.logOut')" placement="right">
<el-button class="button" @click="onLogout">
<font-awesome-icon icon="fa-solid fa-arrow-right-from-bracket" />
@@ -43,7 +43,6 @@ import { defineComponent } from 'vue';
import { ElButton, ElTooltip } from 'element-plus';
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
import {
ROUTE_AUTH_LOGIN,
ROUTE_CHAT_CONVERSATION,
ROUTE_CHAT_CONVERSATION_NEW,
ROUTE_CONSOLE_ROOT,
@@ -84,10 +83,14 @@ export default defineComponent({
]
};
},
computed: {
authenticated() {
return !!this.$store.state.token.access;
}
},
methods: {
onLogout() {
this.$store.dispatch('resetToken');
this.$router.push({ name: ROUTE_AUTH_LOGIN });
},
onConsole() {
this.$router.push({ name: ROUTE_CONSOLE_ROOT });
+3 -3
View File
@@ -1,5 +1,5 @@
<template>
<el-alert v-if="show" :title="content" type="success" center :closable="false" show-icon class="alert-succcess-info">
<el-alert v-if="show" :title="content" type="success" center :closable="false" show-icon class="alert-success-info">
</el-alert>
</template>
@@ -36,12 +36,12 @@ export default defineComponent({
</script>
<style lang="scss">
.alert-succcess-info {
.alert-success-info {
position: fixed;
top: 110px;
left: 50%;
transform: translate(-50%, 0);
z-index: 1000;
z-index: 100;
width: 10%;
}
</style>