chat-app/src/components/talk/message/TextMessage.vue

86 lines
1.7 KiB
Vue
Raw Normal View History

2024-11-22 01:06:37 +00:00
<script lang="ts" setup>
import { textReplaceEmoji } from '@/utils/emojis'
import { textReplaceLink, textReplaceMention } from '@/utils/strings'
import { ITalkRecordExtraText, ITalkRecord } from '@/types/chat'
const props = defineProps<{
extra: ITalkRecordExtraText
data: ITalkRecord
maxWidth?: boolean
source?: 'panel' | 'forward' | 'history'
}>()
const float = props.data.float
let textContent = props.extra?.content || ''
textContent = textReplaceLink(textContent)
if (props.data.talk_type == 2) {
textContent = textReplaceMention(textContent, '#1890ff')
}
textContent = textReplaceEmoji(textContent)
</script>
<template>
<div
class="im-message-text"
:class="{
left: float == 'left',
right: float == 'right',
maxwidth: maxWidth,
'radius-reset': source != 'panel'
}"
>
<pre v-html="textContent" />
</div>
</template>
<style lang="less" scoped>
.im-message-text {
min-width: 30px;
min-height: 30px;
2024-11-22 09:00:03 +00:00
padding: 22rpx 30rpx;
color: #1A1A1A;
background: #FFFFFF;
2024-11-22 01:06:37 +00:00
border-radius: 0px 10px 10px 10px;
&.right {
2024-11-22 09:00:03 +00:00
background-color: #46299D;
color: #FFFFFF;
2024-11-22 01:06:37 +00:00
border-radius: 10px 0px 10px 10px;
}
&.maxwidth {
2024-11-22 09:00:03 +00:00
max-width: 486rpx;
2024-11-22 01:06:37 +00:00
}
&.radius-reset {
border-radius: 0;
}
pre {
white-space: pre-wrap;
overflow: hidden;
word-break: break-word;
word-wrap: break-word;
2024-11-22 09:00:03 +00:00
font-size: 32rpx;
2024-11-22 01:06:37 +00:00
font-family: 'PingFang SC', 'Microsoft YaHei', 'Alibaba PuHuiTi 2.0 45';
2024-11-22 09:00:03 +00:00
line-height: 44rpx;
2024-11-22 01:06:37 +00:00
:deep(.emoji) {
vertical-align: text-bottom;
2024-11-22 09:00:03 +00:00
margin: 0 10rpx;
width: 44rpx;
height: 44rpx;
2024-11-22 01:06:37 +00:00
}
:deep(a) {
color: #2196f3;
text-decoration: revert;
}
}
}
</style>