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 @@ -99,7 +99,7 @@
</div>
</template>
<script setup lang="ts">
import { nextTick, onMounted, ref } from 'vue'
import { nextTick, onMounted, ref, onBeforeUnmount } from 'vue'
import { useRoute } from 'vue-router'
import { copyClick } from '@/utils/clipboard'
import applicationApi from '@/api/application'
Expand Down Expand Up @@ -489,7 +489,7 @@ class AudioManage {
// text 处理成纯文本
text = markdownToPlainText(text)
const split = smartSplit(
props.data.answer_text,
text,
{
0: 20,
1: 50,
Expand Down Expand Up @@ -526,6 +526,11 @@ onMounted(() => {
}
})
})
onBeforeUnmount(() => {
if (audioManage.value) {
audioManage.value.pause()
}
})
</script>
<style lang="scss" scoped>
@media only screen and (max-width: 430px) {
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.

The provided code does not have any immediate irregularities or issues that need correction. However, there are a few optimizations you might consider:

  1. Debounce Copy Click: The copyClick function in the script should be debounced to prevent excessive clipboard operations during rapid clicks.
import debounce from 'lodash/debounce';

const handleCopyClick = debounce((text: string) => {
  copy(text);
}, 300);

const bindEventListeners = () => {
  document.querySelectorAll('.copy-button').forEach(button => {
    button.addEventListener('click', (e) => {
      e.preventDefault();
      const targetElement = e.target;
      let text;

      if (targetElement.tagName === 'SPAN') {
        text = targetElement.textContent || '';
      }

      if (!text || typeof text !== "string") return;

      handleCopyClick(text);
    });
  });
};

onMounted(bindEventListeners);

This will limit how often the clipboard operation is triggered when multiple clicks occur quickly.

  1. Remove Unnecessary Import for nextTick:
    Since nextTick is imported but never used within this scope, it can be removed for better readability and performance.
+// import { nextTick } from 'vue';

By making these minor adjustments, the code will perform more efficiently without compromising functionality.

Expand Down