UnisKB/ui/src/views/chat/index.vue

95 lines
2.3 KiB
Vue
Raw Normal View History

2023-11-29 09:34:45 +00:00
<template>
2024-10-22 10:29:13 +00:00
<component
2024-10-23 05:33:37 +00:00
v-if="chat_show && init_data_end"
2024-10-22 10:29:13 +00:00
:applicationAvailable="applicationAvailable"
:is="currentTemplate"
:application_profile="application_profile"
:key="route.fullPath"
v-loading="loading"
/>
<Auth
v-else
:application_profile="application_profile"
:auth_type="application_profile.authentication_type"
v-model="is_auth"
></Auth>
2023-11-29 09:34:45 +00:00
</template>
<script setup lang="ts">
2024-10-23 05:33:37 +00:00
import { ref, onBeforeMount, computed } from 'vue'
2024-05-20 09:50:14 +00:00
import { useRoute } from 'vue-router'
2024-07-19 09:13:53 +00:00
import useStore from '@/stores'
2024-10-22 10:29:13 +00:00
import Auth from '@/views/chat/auth/index.vue'
const route = useRoute()
2024-07-22 10:52:56 +00:00
const { application, user } = useStore()
2024-05-20 09:50:14 +00:00
const components: any = import.meta.glob('@/views/chat/**/index.vue', {
eager: true
})
2024-10-22 10:29:13 +00:00
2023-11-30 10:50:42 +00:00
const {
2024-10-22 10:29:13 +00:00
query: { mode },
params: { accessToken }
2023-11-30 10:50:42 +00:00
} = route as any
2024-10-22 10:29:13 +00:00
const is_auth = ref<boolean>(false)
2024-05-20 09:50:14 +00:00
const currentTemplate = computed(() => {
2024-07-22 10:52:56 +00:00
let modeName = ''
if (mode && mode === 'embed') {
modeName = 'embed'
} else {
2024-07-30 03:02:49 +00:00
modeName = show_history.value || !user.isEnterprise() ? 'pc' : 'base'
2024-07-22 10:52:56 +00:00
}
const name = `/src/views/chat/${modeName}/index.vue`
2024-05-20 09:50:14 +00:00
return components[name].default
2023-11-30 10:50:42 +00:00
})
2024-10-22 10:29:13 +00:00
/**
* 是否显示对话
*/
const chat_show = computed(() => {
if (init_data_end.value) {
if (!applicationAvailable.value) {
return true
}
if (application_profile.value) {
if (application_profile.value.authentication && is_auth.value) {
return true
} else if (!application_profile.value.authentication) {
return true
}
}
}
return false
})
2024-07-22 10:52:56 +00:00
const loading = ref(false)
const show_history = ref(false)
2024-10-22 10:29:13 +00:00
const application_profile = ref<any>({})
/**
* 初始化结束
*/
const init_data_end = ref<boolean>(false)
const applicationAvailable = ref<boolean>(true)
2024-07-22 10:52:56 +00:00
function getAppProfile() {
2024-10-22 10:29:13 +00:00
return application.asyncGetAppProfile(loading).then((res: any) => {
2024-07-22 10:52:56 +00:00
show_history.value = res.data?.show_history
2024-10-22 10:29:13 +00:00
application_profile.value = res.data
2024-07-22 10:52:56 +00:00
})
}
2024-10-22 10:29:13 +00:00
function getAccessToken(token: string) {
return application.asyncAppAuthentication(token, loading).then(() => {
2024-10-23 05:33:37 +00:00
return getAppProfile()
2024-07-22 10:52:56 +00:00
})
2024-10-22 10:29:13 +00:00
}
2024-10-23 05:33:37 +00:00
onBeforeMount(() => {
user.changeUserType(2)
Promise.all([user.asyncGetProfile(), getAccessToken(accessToken)])
2024-10-22 10:29:13 +00:00
.catch(() => {
applicationAvailable.value = false
})
.finally(() => (init_data_end.value = true))
2024-07-19 09:13:53 +00:00
})
2024-05-20 09:50:14 +00:00
</script>
<style lang="scss"></style>