zhongshujie
2025-08-08 401ed176c9f1bdd97ccdf827d9454b11a3891f79
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
<template>
    <div class="chat-box">
        <div class="chat-box-left">
            <div class="new-chat">
                <el-icon>
                    <Plus />
                </el-icon>
                <div>New conversation</div>
            </div>
            <div class="chat-list" v-for="(item, index) in pageData.historylist">
                <div :title="item.content" @click="goAi(item)">{{ item.content }}</div>
            </div>
        </div>
        <div class="chat-box-right">
            <Header class="header"></Header>
            <!-- 聊天框内容容器 -->
            <div class="chat-box-content" ref="messagesContainer">
                <!-- 当前时间显示 -->
                <div class="chat-date">{{ currentTime }}</div>
                <!-- 底部信息展示 -->
                <div class="chat-back-info">
                    <!-- 头像 -->
                    <div class="back-avator">
                        <img src="../../assets/images/home/AI_logo.png" alt="" />
                    </div>
                    <!-- 基础图书信息 -->
                    <div class="base-book-box">
                        您好!我是您的AI智能助手,专注于小分子结构领域!我可以帮助您轻松获取与小分子结构相关的信息。您可以这样问我:“Aspirin是什么?”“xx的物理化学属性都是什么?”让小分子结构知识触手可及!
                    </div>
                </div>
                <!-- 消息列表 -->
                <div v-for="(item, index) in message" :key="index" class="chat-box-content-item">
                    <div v-if="item.type === 'user'" class="chat-date">{{ item.time }}</div>
                    <div :class="['message', item.type === 'user' ? 'user-message' : 'assistant-message']">
                        <!-- 助手头像 -->
                        <el-avatar class="assistant-avatar" :size="screenWidth > 375 ? 60 : 30"
                            :src="[item.type === 'user' ? userProfilePicture : assistantAvatar]" />
                        <!-- 消息内容 -->
                        <div :class="['message-content', item.type === 'user' ? 'user-message-content' : '']">
                            <!-- 用户消息 -->
                            <div class="user-message-text" v-if="item.type === 'user'" v-html="item.content"></div>
                            <!-- AI 图片消息 -->
                            <div :class="['message-text', 'requestText' + index].join(' ')"
                                v-if="item.type != 'user' && item.txtType == 'txt'">
                                <p class="message-text-title">
                                    AI智能助手为您找到以下的信息内容如下:
                                </p>
                                <iframe class="message-text-iframe" ref="iframeRef" v-if="item.iframeSrc != ''"
                                    :src="item.iframeSrc" frameborder="0"></iframe>
                                <div v-html="item.content"></div>
                                <p class="message-text-titleOne">以上内容由AI生成,仅供参考。</p>
                            </div>
                            <!-- 消息底部时间 -->
                            <div class="message-footer" v-if="item.type != 'user'">
                                <span class="message-time">{{ item.time }}</span>
                            </div>
                        </div>
                    </div>
                    <!-- 加载中状态 -->
                    <div v-if="loading && index == message.length - 1"
                        class="message assistant-message loading-message">
                        <el-avatar class="assistant-avatar" :size="screenWidth > 375 ? 60 : 30"
                            :src="assistantAvatar" />
                        <div :class="['message-content', item.type === 'user' ? 'user-message-content' : '']">
                            <div class="message-text-loading">
                                <span class="dot-loading">思考中...</span>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- 输入框 -->
            <div class="chat-footer">
                <!-- 输入框 -->
                <div class="chat-text">
                    <el-input type="textarea" :autosize="{ minRows: 3, maxRows: 3 }" placeholder="" v-model="inputValue"
                        @keyup.enter="handleEnter($event)" />
                </div>
                <!-- 功能选择区域 -->
                <div class="select">
                    <div class="select-right">
                        <div class="select-item">
                            <img @click="sendMsg()" :src="currentImage" alt="" />
                        </div>
                    </div>
                </div>
            </div>
            <div class="main-footer">
                Information displayed here is AI model generated and should not be considered as legal, finance or
                investment advice. You should always seek advice from a qualified <br />professional. Request
                consultation.
            </div>
        </div>
    </div>
</template>
 
<script lang="ts" setup>
import { ref, reactive, nextTick, computed, onMounted } from 'vue'
import type { aiDetails } from '@/types/aiDetails'
import current from '@/assets/images/ai/current.png'
import noCurrent from '@/assets/images/ai/noCurrent.png'
import dayjs from 'dayjs'
import Header from '@/layout/components/headerPage.vue'
import defaultImg from '../../assets/images/home/AI_logo.png'
import userIcon from '../../assets/images/ai/userImg.png'
import request from '@/plugin/axios/index'
const screenWidth = ref(window.innerWidth)
const assistantAvatar = defaultImg
const userProfilePicture = userIcon
const pageData = reactive<aiDetails>({
    historylist: [
        {
            content: "What is the quarterly water bill?",
        },
        {
            content: "How much are the council rates per quarter?",
        },
        {
            content: "What are the quarterly strata fees?",
        },
        {
            content: "What are the quarterly strata fees?",
        },
    ],
})
const inputValue = ref('')
const message = ref<any>([])
const loading = ref(false)
const autoScroll = ref(true)
const messagesContainer = ref<HTMLElement | null>(null)
const currentTime = ref(dayjs(new Date()).format('MM/DD HH:mm:ss'))
const currentImage = computed(() => {
    return inputValue.value.trim() === '' ? noCurrent : current;
});
// 从本地存储加载消息
onMounted(() => {
    // getCommonQyestuion()
    // 删除本地缓存
    localStorage.removeItem('chatMessages')
    const savedMessages = localStorage.getItem('chatMessages')
    if (savedMessages) {
        message.value = JSON.parse(savedMessages)
    }
    scrollToBottom()
    screenWidth.value = window.innerWidth
 
    window.addEventListener('message', function (event) {
        console.log(event, "event");
        if (event.data.type == 'toggleFullScreen') {
            window.open(event.data.data)
        } else if (event.data.type == 'download') {
            const link = document.createElement('a')
            link.href = event.data.data
            link.download = event.data.data
            document.body.appendChild(link)
            link.click()
            document.body.removeChild(link)
        }
    })
})
 
const scrollToBottom = async () => {
    if (!autoScroll.value) return
    await nextTick()
    if (messagesContainer.value) {
        const dom1 = document.querySelector('.dot-loading')
        const dom = document.querySelector('.requestText' + (message.value.length - 1))
        dom1?.scrollIntoView({ behavior: 'smooth', block: 'center' })
        dom?.scrollIntoView({ behavior: 'smooth', block: 'start' })
    }
}
 
 
 
interface ChatMessage {
    content: string
    type: 'user' | 'assistant'
    time: string
    txtType: 'txt' | 'List'
    currentContentIndex: 0
    isEnd: boolean
    iframeSrc: string
}
 
const handleEnter = (event: any) => {
    event.preventDefault()
    inputValue.value = inputValue.value.replace(/\n/g, '')
    // 调用发送消息的方法
    sendMsg()
}
const sendMsg = async () => {
    if (!inputValue.value.trim() || loading.value) return
    const userMessage: ChatMessage = {
        content: inputValue.value,
        type: 'user',
        time: new Date().toLocaleTimeString(),
        txtType: 'txt',
        currentContentIndex: 0,
        isEnd: false,
        iframeSrc: '',
    }
 
    message.value.push(userMessage)
    const messageToSend = inputValue.value
    inputValue.value = ''
    try {
        await getData(messageToSend) // 使用 await 等待 getData 完成
        console.log(message, "message");
 
    } catch (error) {
        console.error('发送消息失败', error)
    }
}
 
 
// 获取数据
const getData = async (messageToSend: any) => {
    loading.value = true
    try {
        const response = await request({
            url: '/v1/workflows/run',
            method: 'post',
            data: {
                inputs: {
                    question: messageToSend,
                },
                parent_message_id: null,
                response_mode: 'blocking',
                conversation_id: '',
                user: 'abc-123',
                files: [],
            },
        })
        try {
            const answerAgain = JSON.parse((response as any).data.outputs.text)
            answerAgain.msg = answerAgain.msg.replace(/\n/g, '<br>')
            console.log(answerAgain, 'answerAgain');
            answerAgain.iframeSrc = '';
            if (answerAgain.model && answerAgain.model[0].name == 'Conformer3D_COMPOUND_CID_2244') {
                answerAgain.iframeSrc = 'http://182.92.203.7:3007/showModel/?name=' + answerAgain.model[0].name;
            }
            if (answerAgain.code == 1) {
                const assistantMessage: ChatMessage = {
                    content: answerAgain.data,
                    type: 'assistant',
                    time: new Date().toLocaleTimeString(),
                    txtType: 'List',
                    currentContentIndex: 0,
                    isEnd: false,
                    iframeSrc: answerAgain.iframeSrc,
                }
                message.value.push(assistantMessage)
            } else if (answerAgain.code == 2 || answerAgain.code == 3) {
                const assistantMessage: ChatMessage = {
                    content: answerAgain.msg,
                    type: 'assistant',
                    time: new Date().toLocaleTimeString(),
                    txtType: 'txt',
                    currentContentIndex: 0,
                    isEnd: false,
                    iframeSrc: answerAgain.iframeSrc,
                }
                console.log(assistantMessage);
                message.value.push(assistantMessage)
                loading.value = false
                // 保存消息到本地存储
                localStorage.setItem('chatMessages', JSON.stringify(message.value))
            }
            console.log(message, "message");
        } catch (error) {
            console.log(error)
        }
    } catch (error) {
        const assistantMessage: ChatMessage = {
            content: '当前操作遇到一些问题,请稍后再试。',
            type: 'assistant',
            time: new Date().toLocaleTimeString(),
            txtType: 'txt',
            currentContentIndex: 0,
            isEnd: false,
            iframeSrc: "",
        }
        message.value.push(assistantMessage)
        console.error('发送消息失败', error)
    } finally {
        loading.value = false
    }
}
 
 
 
 
</script>
 
<style lang="less" scoped>
.chat-box {
    display: flex;
    height: 100%;
    width: 100%;
 
}
 
.chat-box-left {
    width: 14%;
    border-right: 1px solid #F0F0F0;
    padding: 13px 17px;
 
    .new-chat {
        height: 34px;
        background: linear-gradient(90deg, #006CB6 0%, #01644C 100%);
        border-radius: 30px 30px 30px 30px;
        margin-top: 45px;
        display: flex;
        align-items: center;
        justify-content: center;
        color: #fff;
        cursor: pointer;
 
        div {
            margin-left: 5px;
            font-weight: 400;
            font-size: 12px;
        }
    }
 
    .chat-list {
        width: 100%;
        margin-top: 28px;
 
        div {
            line-height: 1.5em;
            cursor: pointer;
            width: 100%;
            margin-top: 20px;
            overflow: hidden;
            text-wrap: nowrap;
        }
    }
}
 
.message {
    display: flex;
    margin-bottom: 24px;
    align-items: flex-start;
    animation: slideIn 0.3s ease;
    animation-fill-mode: forwards;
    max-width: 85%;
    border-radius: 12px;
    // box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    padding: 16px;
}
 
.assistant-avatar {
    width: 32px;
    height: auto;
}
 
.user-message {
    flex-direction: row-reverse;
    margin-left: auto;
}
 
.assistant-message {
    background-color: #f7fffc;
}
 
 
 
 
.chat-box-right {
    width: 86%;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
 
 
 
    .chat-box-content {
        width: 62%;
        margin: 0 auto;
        height: calc(100vh - 150px);
        display: flex;
        flex-direction: column;
        justify-content: flex-start;
        overflow: auto;
        align-items: flex-start;
 
        .chat-send {
            width: 100%;
            display: flex;
            flex-direction: column;
            justify-content: space-between;
            align-items: flex-end;
            margin-bottom: 20px;
 
            .chat-send-info {
                width: 263px;
                height: 40px;
                background: #af8b56;
                border-radius: 20px;
                line-height: 40px;
                padding: 0 20px;
                color: #fff;
            }
 
            .chat-message {
                width: 263px;
                height: 40px;
                background: #fff;
                border-radius: 20px;
                line-height: 40px;
                padding: 0 20px;
                color: #000;
            }
        }
 
        .chat-date {
            color: #999;
            width: 100%;
            text-align: center;
            margin-bottom: 30px;
            margin-top: 30px;
        }
 
        .chat-send {
            width: 100%;
            display: flex;
            justify-content: flex-end;
            margin-bottom: 20px;
 
            .chat-send-info {
                width: 263px;
                height: 40px;
                background: #af8b56;
                border-radius: 20px;
                line-height: 40px;
                padding: 0 20px;
                color: #fff;
            }
        }
 
        .chat-back-info {
            margin-bottom: 20px;
            display: flex;
            justify-content: flex-start;
            // min-height: 90px;
            padding: 16px;
 
            .back-avator {
                margin-right: 10px;
 
                img {
                    width: 32px;
                }
            }
 
            .base-book-box {
                display: flex;
                width: 800px;
                padding: 20px 47px;
                box-sizing: border-box;
                background-color: #f7fffc;
                border-radius: 20px;
                line-height: 1.5em;
            }
        }
 
        .back-item {
            width: 349px;
            height: auto;
            background: #ffffff;
            border-radius: 20px;
            margin-left: 100px;
            margin-bottom: 20px;
 
            .back-item-title {
                width: 80%;
                height: 60px;
                display: flex;
                align-items: center;
                padding: 0 10px;
                margin: auto;
                border-bottom: 1px solid #e9d8bf;
            }
 
            .hot-question {
                cursor: pointer;
 
                &:hover {
                    color: #d2a25b;
                }
            }
 
            img {
                margin-right: 10px;
            }
 
            ul li {
                list-style: none;
                margin: 20px 0 20px 0;
                display: flex;
                justify-content: flex-start;
                align-items: center;
            }
 
            .chat-change {
                display: flex;
                justify-content: flex-end;
                align-items: center;
                padding: 0 20px;
                color: #d2a25b;
                margin-bottom: 10px;
                cursor: pointer;
 
                img {
                    cursor: pointer;
                }
            }
        }
 
        .chat-box-content-item {
            width: 100%;
        }
    }
 
    .chat-box-content::-webkit-scrollbar {
        width: 1px;
    }
 
    /* 隐藏水平滚动条 */
    .chat-box-content::-webkit-scrollbar {
        height: 0;
    }
 
 
    .message-content {
        display: inline-block;
        max-width: 80%;
        background: #DEDEDE;
        margin-left: 10px;
        border-radius: 10px 0px 10px 10px;
        padding: 14px 12px;
        margin-top: 5px;
        margin-right: 10px;
    }
 
    .user-message-text {
        font-weight: 400;
        font-size: 14px;
        color: #000000;
        line-height: 1.5em;
    }
 
    .message-text {
        min-width: 600px;
        padding: 0px 40px;
        border-radius: 12px;
        word-wrap: break-word;
        line-height: 1.6;
        font-size: 0.95rem;
        transition: all 0.3s ease;
        white-space: pre-wrap;
        color: #333;
 
        .message-text-title {
            font-size: 16px;
            color: #999;
            line-height: 35px;
            padding: 0px 0 10px 0;
        }
 
        .message-text-iframe {
            width: 100%;
            height: 400px;
            margin-bottom: 10px;
        }
 
        .message-text-titleOne {
            text-align: right;
            color: #fe7313;
            font-size: 10px;
            padding-bottom: 5px;
            border-bottom: 1px solid #e9d8bf;
        }
 
        .message-text-changeOne {
            display: flex;
            align-items: center;
            justify-content: flex-end;
            padding: 10px 0 0 0;
 
            span {
                font-size: 14px;
                font-family:
                    Microsoft YaHei,
                    Microsoft YaHei-Regular;
                font-weight: 400;
                text-align: left;
                color: #d2a25b;
                line-height: 35px;
            }
        }
    }
 
    .chat-footer {
        width: 62%;
        min-width: 800px;
        border-radius: 8px 8px 8px 8px;
        border: 1px solid #E8E8E8;
        padding: 9px 13px;
        box-sizing: border-box;
        margin-bottom: 10px;
        margin-top: 14px;
    }
 
    ::v-deep(.chat-text) {
        // height: 100%;
        display: flex;
        align-items: center;
        margin-bottom: 10px;
 
        .el-textarea__inner {
            overflow: auto;
            height: 100% !important;
            border: none !important;
            outline: none !important;
            box-shadow: none !important;
            background-color: transparent !important;
            resize: none !important;
        }
 
        img {
            cursor: pointer;
            min-height: 25px;
        }
    }
 
    .select {
        width: 100%;
        display: flex;
        align-items: center;
        justify-content: space-between;
 
        .select-left,
        .select-right {
            flex: 1;
            display: flex;
            align-items: center;
            justify-content: flex-start;
 
            .upload-demo {
                height: 24px;
            }
 
            svg {
                cursor: pointer;
            }
 
            .select-item {
                display: flex;
                align-items: center;
                padding: 2px 10px;
                box-sizing: border-box;
                border: 1px solid #e9d8bf;
                border-radius: 15px;
 
                font-size: 14px;
                font-family:
                    Microsoft YaHei,
                    Microsoft YaHei-Regular;
                font-weight: 400;
                color: #e1c49a;
 
                img {
                    height: 34px;
                    cursor: pointer;
                }
            }
        }
 
        .select-right {
            display: flex;
            align-items: center;
            justify-content: flex-end;
 
            .select-item {
                border: 0;
            }
        }
    }
 
    .main-footer {
        text-align: center;
        font-weight: 400;
        font-size: 12px;
        color: #BABABA;
        line-height: 1.4em;
    }
 
}
</style>