From c5235a4f7e30185495be63b09847c4d236aadb8e Mon Sep 17 00:00:00 2001 From: Yi <32430186+yilozt@users.noreply.github.com> Date: Tue, 21 Mar 2023 08:44:40 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E7=94=A8=E4=BA=8E?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E5=9B=9E=E5=A4=8D=E6=B6=88=E6=81=AF=E5=8E=9F?= =?UTF-8?q?=E6=96=87=E7=9A=84=E9=80=89=E9=A1=B9=20(#672)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 添加显示用于原文的选项 * chore: 修复暗色主题下文本颜色问题 给输入和输出气泡添加了 css 类,用来处理在暗色主题下聊天气泡的文本颜色 * feat: 用户输入不应该被渲染,防止 xss --------- Co-authored-by: ChenZhaoYu <790348264@qq.com> --- src/locales/en-US.ts | 2 + src/locales/zh-CN.ts | 2 + src/locales/zh-TW.ts | 2 + src/views/chat/components/Message/Text.vue | 9 +++- src/views/chat/components/Message/index.vue | 46 ++++++++++++++------ src/views/chat/components/Message/style.less | 11 ++++- 6 files changed, 55 insertions(+), 17 deletions(-) diff --git a/src/locales/en-US.ts b/src/locales/en-US.ts index 97cdd8cc01..bd7802173c 100644 --- a/src/locales/en-US.ts +++ b/src/locales/en-US.ts @@ -48,6 +48,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', diff --git a/src/locales/zh-CN.ts b/src/locales/zh-CN.ts index 2053407ba0..2f798f4938 100644 --- a/src/locales/zh-CN.ts +++ b/src/locales/zh-CN.ts @@ -48,6 +48,8 @@ export default { deleteMessageConfirm: '是否删除此消息?', deleteHistoryConfirm: '确定删除此记录?', clearHistoryConfirm: '确定清空聊天记录?', + preview: '预览', + showRawText: '显示原文', }, setting: { setting: '设置', diff --git a/src/locales/zh-TW.ts b/src/locales/zh-TW.ts index 07e8c7ebe0..e4b26458c0 100644 --- a/src/locales/zh-TW.ts +++ b/src/locales/zh-TW.ts @@ -48,6 +48,8 @@ export default { deleteMessageConfirm: '是否刪除此訊息?', deleteHistoryConfirm: '確定刪除此紀錄?', clearHistoryConfirm: '確定清除紀錄?', + preview: '預覽', + showRawText: '顯示原文', }, setting: { setting: '設定', diff --git a/src/views/chat/components/Message/Text.vue b/src/views/chat/components/Message/Text.vue index f273443032..61a11dbcd6 100644 --- a/src/views/chat/components/Message/Text.vue +++ b/src/views/chat/components/Message/Text.vue @@ -12,6 +12,7 @@ interface Props { error?: boolean text?: string loading?: boolean + asRawText?: boolean } const props = defineProps() @@ -43,13 +44,14 @@ const wrapClass = computed(() => { isMobile.value ? 'p-2' : 'px-3 py-2', props.inversion ? 'bg-[#d2f9d1]' : 'bg-[#f4f6f8]', props.inversion ? 'dark:bg-[#a1dc95]' : 'dark:bg-[#1e1e20]', + props.inversion ? 'message-request' : 'message-reply', { 'text-red-500': props.error }, ] }) const text = computed(() => { const value = props.text ?? '' - if (!props.inversion) + if (!props.asRawText) return mdi.render(value) return value }) @@ -68,7 +70,10 @@ defineExpose({ textRef }) diff --git a/src/views/chat/components/Message/index.vue b/src/views/chat/components/Message/index.vue index 0d462e923a..d625a8a7be 100644 --- a/src/views/chat/components/Message/index.vue +++ b/src/views/chat/components/Message/index.vue @@ -1,5 +1,5 @@