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 8990e0f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 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
19 changes: 15 additions & 4 deletions src/views/chat/components/Message/index.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang='ts'>
import { ref } from 'vue'
import { computed, ref } from 'vue'
import { NDropdown } from 'naive-ui'
import AvatarComponent from './Avatar.vue'
import TextComponent from './Text.vue'
Expand Down Expand Up @@ -29,7 +29,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 +47,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 +89,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 8990e0f

Please sign in to comment.