mirror of
https://github.com/Chanzhaoyu/chatgpt-web.git
synced 2025-07-20 19:39:40 +00:00
feat: 优化删除功能
This commit is contained in:
@@ -1,9 +1,7 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { NDropdown } from 'naive-ui'
|
import { computed } from 'vue'
|
||||||
import { computed, h } from 'vue'
|
|
||||||
import { marked } from 'marked'
|
import { marked } from 'marked'
|
||||||
import includeCode from '@/utils/functions/includeCode'
|
import includeCode from '@/utils/functions/includeCode'
|
||||||
import { SvgIcon } from '@/components/common'
|
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
inversion?: boolean
|
inversion?: boolean
|
||||||
@@ -12,45 +10,8 @@ interface Props {
|
|||||||
loading?: boolean
|
loading?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Emit {
|
|
||||||
(ev: 'copy'): void
|
|
||||||
(ev: 'delete'): void
|
|
||||||
}
|
|
||||||
|
|
||||||
const props = defineProps<Props>()
|
const props = defineProps<Props>()
|
||||||
|
|
||||||
const emit = defineEmits<Emit>()
|
|
||||||
|
|
||||||
const options = [
|
|
||||||
{
|
|
||||||
label: 'Copy',
|
|
||||||
key: 'copy',
|
|
||||||
icon: renderIcon('ri:file-copy-2-line'),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'Delete',
|
|
||||||
key: 'delete',
|
|
||||||
icon: renderIcon('ri:delete-bin-6-line'),
|
|
||||||
},
|
|
||||||
]
|
|
||||||
|
|
||||||
function renderIcon(icon: string) {
|
|
||||||
return () => {
|
|
||||||
return h(SvgIcon, { icon })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleSelect(key: string | number) {
|
|
||||||
switch (key) {
|
|
||||||
case 'copy':
|
|
||||||
emit('copy')
|
|
||||||
break
|
|
||||||
case 'delete':
|
|
||||||
emit('delete')
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const wrapClass = computed(() => {
|
const wrapClass = computed(() => {
|
||||||
return [
|
return [
|
||||||
'text-wrap',
|
'text-wrap',
|
||||||
@@ -73,17 +34,15 @@ const text = computed(() => {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<NDropdown trigger="click" :options="options" @select="handleSelect">
|
<div :class="wrapClass">
|
||||||
<div :class="wrapClass">
|
<template v-if="loading">
|
||||||
<template v-if="loading">
|
<span class="w-[5px] h-[20px] block animate-blink" />
|
||||||
<span class="w-[5px] h-[20px] block animate-blink" />
|
</template>
|
||||||
</template>
|
<template v-else>
|
||||||
<template v-else>
|
<code v-if="includeCode(text)" v-highlight class="leading-relaxed" v-text="text" />
|
||||||
<code v-if="includeCode(text)" v-highlight class="leading-relaxed" v-text="text" />
|
<div v-else class="leading-relaxed break-all" v-html="text" />
|
||||||
<div v-else class="leading-relaxed break-all" v-html="text" />
|
</template>
|
||||||
</template>
|
</div>
|
||||||
</div>
|
|
||||||
</NDropdown>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style lang="less">
|
<style lang="less">
|
||||||
|
@@ -21,10 +21,6 @@ defineProps<Props>()
|
|||||||
|
|
||||||
const emit = defineEmits<Emit>()
|
const emit = defineEmits<Emit>()
|
||||||
|
|
||||||
function handleCopy() {
|
|
||||||
emit('copy')
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleDelete() {
|
function handleDelete() {
|
||||||
emit('delete')
|
emit('delete')
|
||||||
}
|
}
|
||||||
@@ -46,22 +42,28 @@ function handleRegenerate() {
|
|||||||
<span class="text-xs text-[#b4bbc4]">
|
<span class="text-xs text-[#b4bbc4]">
|
||||||
{{ dateTime }}
|
{{ dateTime }}
|
||||||
</span>
|
</span>
|
||||||
<div class="flex items-end mt-2">
|
<div class="flex items-end gap-2 mt-2" :class="[inversion ? 'flex-row-reverse' : 'flex-row']">
|
||||||
<Text
|
<Text
|
||||||
:inversion="inversion"
|
:inversion="inversion"
|
||||||
:error="error"
|
:error="error"
|
||||||
:text="text"
|
:text="text"
|
||||||
:loading="loading"
|
:loading="loading"
|
||||||
@copy="handleCopy"
|
|
||||||
@delete="handleDelete"
|
|
||||||
/>
|
/>
|
||||||
<button
|
<div class="flex flex-col">
|
||||||
v-if="!inversion"
|
<button
|
||||||
class="mb-2 ml-2 transition text-neutral-400 hover:text-neutral-800"
|
v-if="!inversion"
|
||||||
@click="handleRegenerate"
|
class="mb-2 transition text-neutral-400 hover:text-neutral-800"
|
||||||
>
|
@click="handleRegenerate"
|
||||||
<SvgIcon icon="ri:restart-line" />
|
>
|
||||||
</button>
|
<SvgIcon icon="ri:restart-line" />
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
class="mb-1 transition text-neutral-400 hover:text-neutral-800"
|
||||||
|
@click="handleDelete"
|
||||||
|
>
|
||||||
|
<SvgIcon icon="ri:delete-bin-6-line" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -2,7 +2,6 @@
|
|||||||
import { computed, onMounted, onUnmounted, ref } from 'vue'
|
import { computed, onMounted, onUnmounted, ref } from 'vue'
|
||||||
import { useRoute } from 'vue-router'
|
import { useRoute } from 'vue-router'
|
||||||
import { NButton, NInput, useDialog, useMessage } from 'naive-ui'
|
import { NButton, NInput, useDialog, useMessage } from 'naive-ui'
|
||||||
import { useClipboard } from '@vueuse/core'
|
|
||||||
import { Message } from './components'
|
import { Message } from './components'
|
||||||
import { useScroll } from './hooks/useScroll'
|
import { useScroll } from './hooks/useScroll'
|
||||||
import { useChat } from './hooks/useChat'
|
import { useChat } from './hooks/useChat'
|
||||||
@@ -17,8 +16,6 @@ const route = useRoute()
|
|||||||
const dialog = useDialog()
|
const dialog = useDialog()
|
||||||
const ms = useMessage()
|
const ms = useMessage()
|
||||||
|
|
||||||
const { copy, isSupported } = useClipboard()
|
|
||||||
|
|
||||||
const chatStore = useChatStore()
|
const chatStore = useChatStore()
|
||||||
|
|
||||||
const { isMobile } = useBasicLayout()
|
const { isMobile } = useBasicLayout()
|
||||||
@@ -199,19 +196,6 @@ async function onRegenerate(index: number) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleCopy(index: number) {
|
|
||||||
if (loading.value)
|
|
||||||
return
|
|
||||||
|
|
||||||
if (isSupported.value) {
|
|
||||||
await copy(dataSources.value[index].text)
|
|
||||||
ms.success('Copied to clipboard')
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
ms.error('Copy to clipboard is not supported')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleDelete(index: number) {
|
function handleDelete(index: number) {
|
||||||
if (loading.value)
|
if (loading.value)
|
||||||
return
|
return
|
||||||
@@ -223,6 +207,7 @@ function handleDelete(index: number) {
|
|||||||
negativeText: 'No',
|
negativeText: 'No',
|
||||||
onPositiveClick: () => {
|
onPositiveClick: () => {
|
||||||
chatStore.deleteChatByUuid(+uuid, index)
|
chatStore.deleteChatByUuid(+uuid, index)
|
||||||
|
ms.success('Message deleted successfully.')
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -305,7 +290,6 @@ onUnmounted(() => {
|
|||||||
:error="item.error"
|
:error="item.error"
|
||||||
:loading="item.loading"
|
:loading="item.loading"
|
||||||
@regenerate="onRegenerate(index)"
|
@regenerate="onRegenerate(index)"
|
||||||
@copy="handleCopy(index)"
|
|
||||||
@delete="handleDelete(index)"
|
@delete="handleDelete(index)"
|
||||||
/>
|
/>
|
||||||
<div class="flex justify-center">
|
<div class="flex justify-center">
|
||||||
|
Reference in New Issue
Block a user