-
Notifications
You must be signed in to change notification settings - Fork 2.1k
fix: chat avatar display issue fixed #2832
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 |
---|---|---|
@@ -1,15 +1,15 @@ | ||
<template> | ||
<!-- 开场白组件 --> | ||
<div class="item-content mb-16"> | ||
<div class="avatar mr-8" v-if="prologue && application.show_avatar"> | ||
<div class="avatar mr-8" v-if="prologue && showAvatar"> | ||
<img v-if="application.avatar" :src="application.avatar" height="28px" width="28px" /> | ||
<LogoIcon v-else height="28px" width="28px" /> | ||
</div> | ||
<div | ||
class="content" | ||
v-if="prologue" | ||
:style="{ | ||
'padding-right': application.show_user_avatar ? 'var(--padding-left)' : '0' | ||
'padding-right': showUserAvatar ? 'var(--padding-left)' : '0' | ||
}" | ||
> | ||
<el-card shadow="always" class="border-r-8" style="--el-card-padding: 10px 16px 12px"> | ||
|
@@ -27,12 +27,23 @@ import { type chatType } from '@/api/type/application' | |
import { computed } from 'vue' | ||
import MdRenderer from '@/components/markdown/MdRenderer.vue' | ||
import { t } from '@/locales' | ||
import useStore from '@/stores' | ||
const props = defineProps<{ | ||
application: any | ||
available: boolean | ||
type: 'log' | 'ai-chat' | 'debug-ai-chat' | ||
sendMessage: (question: string, other_params_data?: any, chat?: chatType) => void | ||
}>() | ||
|
||
const { user } = useStore() | ||
|
||
const showAvatar = computed(() => { | ||
return user.isEnterprise() ? props.application.show_avatar : true | ||
}) | ||
const showUserAvatar = computed(() => { | ||
return user.isEnterprise() ? props.application.show_user_avatar : true | ||
}) | ||
|
||
const toQuickQuestion = (match: string, offset: number, input: string) => { | ||
return `<quick_question>${match.replace('- ', '')}</quick_question>` | ||
} | ||
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. To address your request, I'll review the provided code snippet for common issues such as syntax errors, logical inconsistencies, and potential performance improvements. Here are my findings: 1. Missing Import StatementsThe component relies on several external components and functions that need to be imported. However, there seems to be no import statements included in the code snippet. You should include them at the beginning. // Example imports:
import LogoIcon from '@/components/some/icon/LogoIcon.vue'; 2. Unused VariablesThere seem to be unused variables like const sendAnswer = (text: string) => {
// Implementation goes here
} 3. Incorrect Variable ComputationSome variable computations use incorrect properties of props or state variables. For example:
Ensure these match the actual structure and names of your props/state. 4. Logical Consistency
Optimization Suggestions
Sample Corrected Code Snippet with CommentsBelow is an updated version of the component with comments including necessary fixes and optimizations: <!-- Open scene component -->
<template>
<div class="item-content mb-16">
<div class="avatar mr-8" v-if="showAvatar && application.show_avatar">
<img v-if="application.avatar" :src="application.avatar" height="28px" width="28px" />
<LogoIcon v-else height="28px" width="28px" />
</div>
<div
class="content"
v-if="prologue"
:style="{ 'padding-right': showUserAvatar && !application.show_avatar ? 'var(--padding-left)' : '0' }"
>
<el-card shadow="always" class="border-r-8" style="--el-card-padding: 10px 16px 12px">
<!-- Component content gose here -->
</el-card>
</div>
</div>
</template>
<script setup lang="ts">
import { defineProps, computed, watchEffect } from 'vue';
import MdRenderer from '@/components/markdown/MdRenderer.vue';
import { t } from '@/locales';
// Sample imports for clarity
import LogoIcon from '@/components/some/icon/LogoIcon.vue';;
// Props definition
const props = defineProps<{
application: any;
available: boolean;
type: 'log' | 'ai-chat' | 'debug-ai-chat';
sendMessage: (question: string, other_params_data?: any, chat?: chatType) => void;
}>();
// Store usage
const { user } = useStore();
// Compute appropriate avatar visibility
const showAvatar = computed(() => {
return user.isEnterprise() ? props.application.show_avatar : true;
});
// Compute appropriate user avatar visibility based on enterprise settings
const showUserAvatar = compute(() => {
return user.isEnterprise() ? props.application.show_user_avatar : true;
});
</script>
<style scoped>
/* styles */
</style> Note: Adjusted prop names, added missing imports, cleaned up logical checks, made code cleaner without breaking functionality based on previous understanding. Make sure all imports and dependencies are correctly set up before integrating this into your project. |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,7 +63,7 @@ | |
<span> {{ chatRecord.problem_text }}</span> | ||
</div> | ||
</div> | ||
<div class="avatar ml-8" v-if="application.show_user_avatar"> | ||
<div class="avatar ml-8" v-if="showAvatar"> | ||
<el-image | ||
v-if="application.user_avatar" | ||
:src="application.user_avatar" | ||
|
@@ -81,12 +81,18 @@ | |
import { type chatType } from '@/api/type/application' | ||
import { getImgUrl, getAttrsArray, downloadByURL } from '@/utils/utils' | ||
import { onMounted, computed } from 'vue' | ||
|
||
import useStore from '@/stores' | ||
const props = defineProps<{ | ||
application: any | ||
chatRecord: chatType | ||
type: 'log' | 'ai-chat' | 'debug-ai-chat' | ||
}>() | ||
|
||
const { user } = useStore() | ||
|
||
const showAvatar = computed(() => { | ||
return user.isEnterprise() ? props.application.show_user_avatar : true | ||
}) | ||
const document_list = computed(() => { | ||
if (props.chatRecord?.upload_meta) { | ||
return props.chatRecord.upload_meta?.document_list || [] | ||
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 some potential issues:
Here are some optimization and suggestion points:
Here's a refactored version with adjustments addressing some of these concerns: <template>
<!-- ... rest of the HTML remains unchanged ... -->
</template>
<script lang="ts">
import { defineComponent, computed } from "vue";
import type {
chatType,
} from "@/api/type/application";
import { getImgUrl, getAttrsArray, downloadByURL } from "@/utils/utils";
export default defineComponent({
name: "AppMessageItem",
setup(props) {
const document_list = computed(() => {
return props.chatRecord?.upload_meta
?.document_list || [];
});
// Simplify conditional logic based on the assumption that
// user.isEnterprise() is consistent.
const showAvatar = !props.type.includes("debug");
return {
document_list,
showAvatar,
};
},
});
// Other component script sections remain unchanged ...
</script> This refactoring ensures that the avatar is shown only when necessary, removes duplicate imports, and adjusts the conditional logic accordingly. However, make sure that |
||
|
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 looks largely correct overall with minor improvements:
Template Key: The key
v-for
should reference the unique identifier of each element to avoid performance warnings.Computed Property
showAvatar
:watch
.Code Style Consistency:
Event Emits:
Here are some additional optimizations or considerations:
Computed Property Update
Instead of creating an entire new object on every change, consider using a reactive structure like Vue’s Ref or Composition API hooks (
reactive()
).This way,
showAvatar
will be recomputed dynamically based on changes touser
without needing a watch.Watchers Example
If you need more control over when the value should update, you can use watchers. This is useful if changes to nested properties affect this variable.
Improved Logic
In some places in your code, you might want to extract common logic into helper functions to improve maintainability. For example:
Final Code (Refactored)
Assuming we refactor as mentioned above, here's the updated snippet with comments:
Remember:
appState
definitions with accurate types matching your real state structure.showAvatar
might depend on different conditions not covered above.