diff --git a/src/utils/copy.ts b/src/utils/copy.ts
new file mode 100644
index 0000000000..6fd32d8b7a
--- /dev/null
+++ b/src/utils/copy.ts
@@ -0,0 +1,18 @@
+export function copyToClip(text: string) {
+ return new Promise((resolve, reject) => {
+ try {
+ const input: HTMLTextAreaElement = document.createElement('textarea')
+ input.setAttribute('readonly', 'readonly')
+ input.value = text
+ document.body.appendChild(input)
+ input.select()
+ if (document.execCommand('copy'))
+ document.execCommand('copy')
+ document.body.removeChild(input)
+ resolve(text)
+ }
+ catch (error) {
+ reject(error)
+ }
+ })
+}
diff --git a/src/views/chat/components/Message/Text.vue b/src/views/chat/components/Message/Text.vue
index c9f969b835..4f2bb5554c 100644
--- a/src/views/chat/components/Message/Text.vue
+++ b/src/views/chat/components/Message/Text.vue
@@ -1,11 +1,12 @@
diff --git a/src/views/chat/components/Message/index.vue b/src/views/chat/components/Message/index.vue
index 541dde1e25..d08cb04910 100644
--- a/src/views/chat/components/Message/index.vue
+++ b/src/views/chat/components/Message/index.vue
@@ -1,13 +1,13 @@
diff --git a/src/views/chat/hooks/useCopyCode.ts b/src/views/chat/hooks/useCopyCode.ts
deleted file mode 100644
index 8816b5dd38..0000000000
--- a/src/views/chat/hooks/useCopyCode.ts
+++ /dev/null
@@ -1,24 +0,0 @@
-import { onMounted, onUpdated } from 'vue'
-import { copyText } from '@/utils/format'
-
-export function useCopyCode() {
- function copyCodeBlock() {
- const codeBlockWrapper = document.querySelectorAll('.code-block-wrapper')
- codeBlockWrapper.forEach((wrapper) => {
- const copyBtn = wrapper.querySelector('.code-block-header__copy')
- const codeBlock = wrapper.querySelector('.code-block-body')
- if (copyBtn && codeBlock) {
- copyBtn.addEventListener('click', () => {
- if (navigator.clipboard?.writeText)
- navigator.clipboard.writeText(codeBlock.textContent ?? '')
- else
- copyText({ text: codeBlock.textContent ?? '', origin: true })
- })
- }
- })
- }
-
- onMounted(() => copyCodeBlock())
-
- onUpdated(() => copyCodeBlock())
-}
diff --git a/src/views/chat/index.vue b/src/views/chat/index.vue
index c66ddaea72..27f220ca8f 100644
--- a/src/views/chat/index.vue
+++ b/src/views/chat/index.vue
@@ -8,7 +8,6 @@ import html2canvas from 'html2canvas'
import { Message } from './components'
import { useScroll } from './hooks/useScroll'
import { useChat } from './hooks/useChat'
-import { useCopyCode } from './hooks/useCopyCode'
import { useUsingContext } from './hooks/useUsingContext'
import HeaderComponent from './components/Header/index.vue'
import { HoverButton, SvgIcon } from '@/components/common'
@@ -27,8 +26,6 @@ const ms = useMessage()
const chatStore = useChatStore()
-useCopyCode()
-
const { isMobile } = useBasicLayout()
const { addChat, updateChat, updateChatSome, getChatByUuidAndIndex } = useChat()
const { scrollRef, scrollToBottom, scrollToBottomIfAtBottom } = useScroll()