Skip to content

Commit

Permalink
feat: 添加显示用于原文的选项
Browse files Browse the repository at this point in the history
  • Loading branch information
yilozt committed Mar 18, 2023
1 parent d422a80 commit 1191bff
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/locales/en-US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ export default {
deleteMessageConfirm: 'Are you sure to delete this message?',
deleteHistoryConfirm: 'Are you sure to clear this history?',
clearHistoryConfirm: 'Are you sure to clear chat history?',
preview: 'Preview',
showRawText: 'Show as raw text',
},
setting: {
setting: 'Setting',
Expand Down
2 changes: 2 additions & 0 deletions src/locales/zh-CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ export default {
deleteMessageConfirm: '是否删除此消息?',
deleteHistoryConfirm: '确定删除此记录?',
clearHistoryConfirm: '确定清空聊天记录?',
preview: '预览',
showRawText: '显示原文',
},
setting: {
setting: '设置',
Expand Down
5 changes: 3 additions & 2 deletions src/views/chat/components/Message/Text.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ interface Props {
error?: boolean
text?: string
loading?: boolean
asRawText?: boolean
}
const props = defineProps<Props>()
Expand Down Expand Up @@ -49,7 +50,7 @@ const wrapClass = computed(() => {
const text = computed(() => {
const value = props.text ?? ''
if (!props.inversion)
if (!props.asRawText)
return mdi.render(value)
return value
})
Expand All @@ -68,7 +69,7 @@ defineExpose({ textRef })
</template>
<template v-else>
<div ref="textRef" class="leading-relaxed break-words">
<div v-if="!inversion" class="markdown-body" v-html="text" />
<div v-if="!asRawText" class="markdown-body" v-html="text" />
<div v-else class="whitespace-pre-wrap" v-text="text" />
</div>
</template>
Expand Down
18 changes: 15 additions & 3 deletions src/views/chat/components/Message/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { SvgIcon } from '@/components/common'
import { copyText } from '@/utils/format'
import { useIconRender } from '@/hooks/useIconRender'
import { t } from '@/locales'
import { computed } from '@vue/reactivity'
interface Props {
dateTime?: string
Expand All @@ -29,7 +30,14 @@ const { iconRender } = useIconRender()
const textRef = ref<HTMLElement>()
const options = [
const asRawText = ref(false);
const options = computed(() => [
{
label: asRawText.value ? t('chat.preview') : t('chat.showRawText'),
key: 'toggleRenderType',
icon: iconRender({ icon: asRawText.value ? 'ic:outline-code-off' : 'ic:outline-code' })
},
{
label: t('chat.copy'),
key: 'copyText',
Expand All @@ -40,13 +48,16 @@ const options = [
key: 'delete',
icon: iconRender({ icon: 'ri:delete-bin-line' }),
},
]
])
function handleSelect(key: 'copyRaw' | 'copyText' | 'delete') {
function handleSelect(key: 'copyRaw' | 'copyText' | 'delete' | 'toggleRenderType') {
switch (key) {
case 'copyText':
copyText({ text: props.text ?? '' })
return
case 'toggleRenderType':
asRawText.value = !asRawText.value;
return
case 'delete':
emit('delete')
}
Expand Down Expand Up @@ -79,6 +90,7 @@ function handleRegenerate() {
:error="error"
:text="text"
:loading="loading"
:as-raw-text="asRawText"
/>
<div class="flex flex-col">
<button
Expand Down

0 comments on commit 1191bff

Please sign in to comment.