wujingjing
2025-01-02 9bfdf795ded956021d99ae5f6662934a71163d8b
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
<template>
    <div class="playInput hl_input rounded-[22px] input-border input-shadow">
        <!-- 主场景 -->
        <SceneSwitch :isHome="isHome" @change="groupTypeChange" />
 
        <div class="assembly flex">
            <el-button
                title="输入常用语标题,可快捷调用常用语"
                class="label flex items-center cursor-pointer"
                link
                @click="commonPhrasesClick"
            >
                <img src="/static/images/wave/PlugIn.png" class="set-icon box-border" />
            </el-button>
        </div>
 
        <div class="set-input">
            <!-- @input="inputText" -->
            <el-input
                ref="inputRef"
                class="relative align-bottom set-inputAnswer"
                type="textarea"
                resize="none"
                maxlength="1024"
                :autosize="{ minRows: 1, maxRows: 8 }"
                v-elInputFocus
                show-word-limit
                @keydown="keydownInput"
                @input="inputText"
                v-model="inputValue"
                placeholder="在这里输入您的问题开始和AI对话"
            >
            </el-input>
            <InputTip ref="inputTipRef" :inputValue="inputValue" :isHome="isHome" />
        </div>
        <div class="h100 flex items-center">
            <div class="upload_img space-y">
                <div class="imgbox cursor-pointer flex items-center">
                    <el-button
                        title="清除"
                        class="cursor-pointer"
                        link
                        style="margin-left: unset"
                        @click="clearTextarea"
                        icon="ele-Close"
                        v-if="inputValue"
                    >
                    </el-button>
                    <el-button class="cursor-pointer" link>
                        <el-tooltip placement="top" content="停止生成" v-if="isTalking">
                            <div
                                class="size-[28px] stop-breathe rounded-full flex-center border-2 border-solid border-black text-black"
                                @click="emits('stopGenClick')"
                            >
                                <span class="ywifont ywicon-jieshu"></span>
                            </div>
                        </el-tooltip>
 
                        <el-tooltip v-else placement="top" content="发送">
                            <div class="size-[36px] rounded-full bg-black flex-center" @click="emits('sendClick')">
                                <img src="/static/images/wave/QueryImg.png" />
                            </div>
                        </el-tooltip>
                    </el-button>
                </div>
            </div>
        </div>
        <VoicePage
            v-model:isShow="voicePageIsShow"
            v-show="voicePageIsShow"
            @submit="(cb) => emits('sendClick', cb)"
            @updateInputValue="updateInputValue"
            :isHome="isHome"
        />
        <CommonPhrases
            v-model:isShow="isShowPhrase"
            v-show="isShowPhrase"
            :isHome="isHome"
            ref="commonPhraseRef"
            @updateInput="updateInput"
        />
    </div>
</template>
 
<script setup lang="ts">
import type { InputInstance } from 'element-plus';
import getCaretCoordinates from 'textarea-caret';
import { computed, nextTick, ref } from 'vue';
import InputTip from './inputTip/index.vue';
import CommonPhrases from './phrase/CommonPhrases.vue';
import SceneSwitch from './SceneSwitch.vue';
import VoicePage from './voicePage/VoicePage.vue';
import { useCompRef } from '/@/utils/types';
import { usePickHistory } from './hook/usePickHistory';
const emits = defineEmits(['sendClick', 'stopGenClick']);
const props = defineProps({
    isTalking: Boolean,
    isHome: Boolean,
    msgList: Array,
});
 
const voicePageIsShow = defineModel('voicePageIsShow', {
    type: Boolean,
    default: false,
});
 
const isShowPhrase = ref(false);
const inputValue = defineModel({
    type: String,
});
const inputTipRef = useCompRef(InputTip);
const inputRef = ref<InputInstance>(null);
 
const updateInputValue = (val) => {
    inputValue.value = val;
};
 
const { setUpQuestion, setDownQuestion } = usePickHistory({
    msgList: computed(() => props.msgList),
    inputValue: inputValue,
});
const keydownInput = (e) => {
    if (props.isTalking) return;
    const isEnterInput = !e.shiftKey && e.key == 'Enter';
    const isDigitalInput = e.ctrlKey && e.code.startsWith('Digit');
    const arrowUp = e.key === 'ArrowUp';
    const arrowDown = e.key === 'ArrowDown';
    if (isEnterInput || isDigitalInput || arrowUp || arrowDown) {
        e.cancelBubble = true; //ie阻止冒泡行为
        e.stopPropagation(); //Firefox阻止冒泡行为
        e.preventDefault(); //取消事件的默认动作*换行
        if (isEnterInput) {
            //以下处理发送消息代码
            emits('sendClick');
        } else if (isDigitalInput) {
            const num = Number(e.code.replace('Digit', ''));
            inputTipRef.value.applyIndexItem(num - 1);
        } else if (arrowUp) {
            setUpQuestion();
        } else if (arrowDown) {
            setDownQuestion();
        }
    }
};
 
const clearTextarea = () => {
    inputValue.value = '';
};
const inputText = (text) => {
    nextTick(() => {
        setTimeout(() => {
            const container = inputRef.value.$el;
            const textAreaEl = inputRef.value.$el.firstElementChild;
            const caret = getCaretCoordinates(textAreaEl, textAreaEl.selectionEnd);
            inputTipRef.value.triggerInputTip(text, {
                left: caret.left,
                bottom: container.offsetHeight,
            });
        }, 0);
    });
};
 
const groupTypeChange = () => {
    inputRef.value.focus();
    commonPhraseRef.value.updatePhrase();
};
const updateInput = (val) => {
    inputValue.value = val;
};
//#region ====================== 常用语功能 ======================
const commonPhraseRef = useCompRef(CommonPhrases);
// 常用语功能点击
const commonPhrasesClick = () => {
    isShowPhrase.value = true;
};
 
const addPhrase = (val) => {
    commonPhraseRef.value.addPhrase(val);
};
 
defineExpose({ addPhrase });
//#endregion
</script>
<style scoped lang="scss">
@use './index.scss';
</style>