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

+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>