Skip to content

Commit

Permalink
perf: 沙盒可复读自己的消息
Browse files Browse the repository at this point in the history
  • Loading branch information
XasYer committed Nov 21, 2024
1 parent 69a5c1a commit 0a617ef
Showing 1 changed file with 34 additions and 3 deletions.
37 changes: 34 additions & 3 deletions src/views/Bot/sandbox/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,23 @@
<div>
<el-text tag="b"> {{ msg.name }} </el-text>
</div>
<component :is="msg.message" />
<div class="flex items-center">
<component :is="msg.message" />

<el-button
v-if="!msg.bot"
circle
type="info"
class="ml-[10px]"
@click="handleAgainMsg(msg)"
>
<Iconify
icon="mdi:plus-one"
:width="23"
:height="24"
/>
</el-button>
</div>
</div>
</div>
<div v-if="msg.poke" class="flex-c">
Expand Down Expand Up @@ -185,6 +201,7 @@ import { createWS } from "@/api/utils";
import { buildPrefixUUID, openLink } from "@pureadmin/utils";
import { Link } from "@element-plus/icons-vue";
import Menu from "./components/menu.vue";
import { IconifyIconOnline as Iconify } from "@/components/ReIcon";
defineOptions({
name: "sandbox"
Expand Down Expand Up @@ -297,6 +314,7 @@ type msgDataType = {
msgId?: string;
bot?: boolean;
message?: DefineComponent;
rawMessage?: string;
poke?: {
operatorId: string;
targetId: string;
Expand Down Expand Up @@ -369,9 +387,16 @@ const sendWsMessage = (content: string, push: boolean = true) => {
target.push({
name: selectUser.value,
msgId,
rawMessage: content,
message: defineComponent({
render() {
return h("div", { class: "message", innerHTML: input });
return h("div", {
class: "message",
innerHTML: input,
style: {
maxWidth: `${bodyWidth.value}px`
}
});
}
})
});
Expand All @@ -380,6 +405,12 @@ const sendWsMessage = (content: string, push: boolean = true) => {
}
};
const handleAgainMsg = (msg: msgDataType) => {
if (msg.rawMessage) {
sendWsMessage(msg.rawMessage, true);
}
};
const setScrollToBottom = () => {
nextTick(() => {
const bottom = messageScrollbarRef.value.wrapRef.scrollHeight;
Expand Down Expand Up @@ -444,7 +475,7 @@ onMounted(() => {
window.addEventListener("resize", updateWidth);
bodyWidth.value =
(cardRef.value.$el.clientWidth - 140 - (isCollapse.value ? 60 : 200)) *
(isCollapse.value ? 1 : 0.8);
(isCollapse.value ? 1.1 : 0.8);
socket.value = createWS("sandbox", {
onopen(ev) {
socket.value.send(
Expand Down

0 comments on commit 0a617ef

Please sign in to comment.