-
Notifications
You must be signed in to change notification settings - Fork 2.6k
feat: Dialogue built-in user information function #4188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -114,6 +114,7 @@ import { | |
| onMounted, | ||
| onBeforeUnmount, | ||
| provide, | ||
| onBeforeMount, | ||
| } from 'vue' | ||
| import { useRoute } from 'vue-router' | ||
| import applicationApi from '@/api/application/application' | ||
|
|
@@ -169,7 +170,7 @@ const emit = defineEmits([ | |
| 'openParagraph', | ||
| 'openParagraphDocument', | ||
| ]) | ||
| const { application, common } = useStore() | ||
| const { application, common, chatUser } = useStore() | ||
| const isMobile = computed(() => { | ||
| return common.isMobile() || mode === 'embed' || mode === 'mobile' | ||
| }) | ||
|
|
@@ -645,7 +646,16 @@ const handleScroll = () => { | |
| } | ||
| } | ||
| } | ||
|
|
||
| onBeforeMount(() => { | ||
| window.chatUserProfile = () => { | ||
| if (props.type === 'ai-chat') { | ||
| if (chatUser.chat_profile?.authentication_type === 'login') { | ||
| return chatUser.getChatUserProfile() | ||
| } | ||
| } | ||
| return Promise.resolve(null) | ||
| } | ||
| }) | ||
| onMounted(() => { | ||
| if (isUserInput.value && localStorage.getItem(`${accessToken}userForm`)) { | ||
| const userFormData = JSON.parse(localStorage.getItem(`${accessToken}userForm`) || '{}') | ||
|
|
@@ -668,6 +678,7 @@ onMounted(() => { | |
|
|
||
| onBeforeUnmount(() => { | ||
| window.sendMessage = null | ||
| window.userProfile = null | ||
| }) | ||
|
|
||
| function setScrollBottom() { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The provided code has several potential issues and improvements: Potential Issues:
Optimization Suggestions:
Here’s an updated version of your code with some optimizations: // Assuming accessToken and props are already defined elsewhere
import {
ref,
computed,
defineComponent,
watchEffect,
} from 'vue';
import { useRoute } from 'vue-router';
export default defineComponent({
setup(props) {
const route = useRoute();
const accessToken = '';
// Other variable declarations
const handleScroll = () => {
// Scroll handling logic
if (scrollPosition.value >= scrollLimit.value) {
fetchMoreData();
}
};
watchEffect(() => {
fetchUserData();
});
async function fetchUserData() {
// Logic to fetch user data
}
async function fetchMoreData() {
// Logic to load more data
}
return {
handleScroll,
};
},
});This version uses Vue 3's Composition API features, makes the code cleaner, and avoids unnecessary global function registrations. Adjust variable names and constants as needed for your specific use case. |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,9 @@ | ||
| import {defineStore} from 'pinia' | ||
| import { defineStore } from 'pinia' | ||
| import ChatAPI from '@/api/chat/chat' | ||
| import type {ChatProfile, ChatUserProfile} from '@/api/type/chat' | ||
| import type {LoginRequest} from '@/api/type/user' | ||
| import type {Ref} from 'vue' | ||
| import {getBrowserLang} from '@/locales/index' | ||
| import type { ChatProfile, ChatUserProfile } from '@/api/type/chat' | ||
| import type { LoginRequest } from '@/api/type/user' | ||
| import type { Ref } from 'vue' | ||
| import { getBrowserLang } from '@/locales/index' | ||
|
|
||
| interface ChatUser { | ||
| // 用户id | ||
|
|
@@ -41,6 +41,7 @@ const useChatUserStore = defineStore('chat-user', { | |
| async getChatUserProfile() { | ||
| const res = await ChatAPI.getChatUserProfile() | ||
| this.chatUserProfile = res.data | ||
| return res.data | ||
| }, | ||
| applicationProfile() { | ||
| return ChatAPI.applicationProfile().then((ok) => { | ||
|
|
@@ -148,7 +149,6 @@ const useChatUserStore = defineStore('chat-user', { | |
| return ok.data | ||
| }) | ||
| }, | ||
|
|
||
| }, | ||
| }) | ||
|
|
||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The provided code appears to be a Pinia store implementation for managing user-related data and chat functionality. There are no significant irregularities or critical issues, but there are some minor improvements that can be made:
interface ChatUser {
// 用户id
}
const useChatUserStore = defineStore('chat-user', {
state: () => ({
/* ... */
}),
actions: {
async getChatUserProfile() {
const res = await ChatAPI.getChatUserProfile();
this.chatUserProfile = res.data;
+ return res.data;
}
},
});
These improvements focus on making the code cleaner, easier to read, and potentially safer by reducing unnecessary types and ensuring clear variable names where appropriate. |
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The provided code snippet is not complete, but I can see that there might be some issues or areas for improvement, especially with type annotations for
sendMessage:Type Annotations: The current type annotation for
sendMessageuses "?", which is equivalent to "null | undefined". This means that either the function could exist as a regular function without arguments (() => any) or it could be an optional call signature that requires parameters but returns nothing.Here's how you can refine the type definition based on whether you expect the function to accept parameters and return something meaningful:
Alternatively, if you want to explicitly handle the case where
sendMessagemight be absent, you can define it separately:Consistency: Ensure that all interfaces are properly closed. In your example, the
{...}block at the end should be completed unless they contain additional definitions. Otherwise, just close the curly brace correctly:Variable/Function Naming Conventions: Make sure that variable names and function signatures adhere to consistent naming conventions within your project. This includes using descriptive names like
chatUserProfilerather than simplychatUserProfile.With these adjustments, your TypeScript code will be more robust, easier to understand, and future-proofed against changes or errors in how the
Windowobject might evolve.