Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@
<div>
<!-- 语音播放 -->
<span v-if="tts">
<el-tooltip
effect="dark"
:content="$t('chat.operation.play')"
placement="top"
v-if="!audioPlayerStatus"
>
<el-tooltip effect="dark" :content="$t('chat.operation.play')" placement="top" v-if="!audioPlayerStatus">
<el-button text @click="playAnswerText(data?.answer_text)">
<AppIcon iconName="app-video-play"></AppIcon>
</el-button>
Expand All @@ -31,22 +26,20 @@
</el-button>
</el-tooltip>
<el-divider direction="vertical" />
<el-tooltip
v-if="buttonData.improve_paragraph_id_list.length === 0"
effect="dark"
:content="$t('views.chatLog.editContent')"
placement="top"
>
<el-button text @click="editContent(data)">
<AppIcon iconName="app-edit"></AppIcon>
</el-button>
</el-tooltip>
<template v-if="permissionPrecise.chat_log_add_knowledge(id)">
<el-tooltip v-if="buttonData.improve_paragraph_id_list.length === 0" effect="dark"
:content="$t('views.chatLog.editContent')" placement="top">
<el-button text @click="editContent(data)">
<AppIcon iconName="app-edit"></AppIcon>
</el-button>
</el-tooltip>

<el-tooltip v-else effect="dark" :content="$t('views.chatLog.editMark')" placement="top">
<el-button text @click="editMark(data)">
<AppIcon iconName="app-document-active" class="primary"></AppIcon>
</el-button>
</el-tooltip>
<el-tooltip v-else effect="dark" :content="$t('views.chatLog.editMark')" placement="top">
<el-button text @click="editMark(data)">
<AppIcon iconName="app-document-active" class="primary"></AppIcon>
</el-button>
</el-tooltip>
</template>

<el-divider direction="vertical" v-if="buttonData?.vote_status !== '-1'" />
<el-button text disabled v-if="buttonData?.vote_status === '0'">
Expand All @@ -59,35 +52,31 @@
<EditContentDialog ref="EditContentDialogRef" @refresh="refreshContent" />
<EditMarkDialog ref="EditMarkDialogRef" @refresh="refreshMark" />
<!-- 先渲染,不然不能播放 -->
<audio
ref="audioPlayer"
v-for="item in audioList"
:key="item"
controls
hidden="hidden"
></audio>
<audio ref="audioPlayer" v-for="item in audioList" :key="item" controls hidden="hidden"></audio>
</div>
</div>
</template>
<script setup lang="ts">
import { onMounted, ref } from 'vue'
import { computed, onMounted, ref } from 'vue'
import { copyClick } from '@/utils/clipboard'
import EditContentDialog from '@/views/chat-log/component/EditContentDialog.vue'
import EditMarkDialog from '@/views/chat-log/component/EditMarkDialog.vue'
import { datetimeFormat } from '@/utils/time'
import applicationApi from '@/api/application/application'
import { useRoute } from 'vue-router'
import permissionMap from '@/permission'
import { MsgError } from '@/utils/message'
import { t } from '@/locales'
const route = useRoute()
const {
params: { id },
} = route as any


const props = defineProps({
data: {
type: Object,
default: () => {},
default: () => { },
},
applicationId: {
type: String,
Expand All @@ -97,6 +86,17 @@ const props = defineProps({
tts_type: String,
})

const apiType = computed(() => {
if (route.path.includes('resource-management')) {
return 'systemManage'
} else {
return 'workspace'
}
})
const permissionPrecise = computed(() => {
return permissionMap['application'][apiType.value]
})

const emit = defineEmits(['update:data'])

const audioPlayer = ref<HTMLAudioElement[] | null>(null)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some irregularities and potential issues found in the provided code:

  1. Variable Scope Issue: The audioPlayer variable is defined but never used within the script, which may indicate an unused resource.

  2. Computed Property Optimization:

    • In apiType, it would be more efficient to cache the result since route.path does not change often.
    • Consider using Vue's built-in memoization capabilities (v-memo) if performance becomes an issue.
  3. Permissions Logic Check:

    • Ensure that the permissionMap['application'][apiType.value] computation handles cases where apiType becomes undefined due to invalid routes.
  4. Code Formatting Issues:

    • While minor style improvements can make the code cleaner, they do not affect functionality.

Optimization suggestions:

  • Cache the value of apiType to avoid recalculating it multiple times during component lifecycle changes.
  • Utilize Vue’s reactivity system effectively instead of relying heavily on static values throughout complex expressions.

Example optimizations based on these points might look like:

const apiUrl = computed(() => route.path.includes('resource-management') ? 'systemManage' : 'workspace');

// Avoid direct access and pass through reactive dependencies explicitly
<el-tooltip v-if="permissionPrecise.chat_log_add_knowledge(data) && buttonData.improve_paragraph_id_list.length === 0" effect="dark">

Remember to adjust these optimizations according to the specific environment and constraints of the project.

Expand Down
Loading