<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>
|