wujingjing
2024-11-06 8523de3e77f8b71cce8f90ed3f1b7d2885d9806b
src/components/chat/components/playBar/PlayBar.vue
@@ -1,10 +1,11 @@
<template>
   <div class="playInput hl_input rounded-b-[22px] input-border input-shadow" :class="{ 'rounded-t-[22px]': !currentGroupTypeIsShow }">
   <div class="playInput hl_input rounded-[22px] input-border input-shadow">
      <!-- 应用场景 -->
      <div v-if="!currentGroupTypeIsShow" class="application-scenarios absolute bottom-[114%] left-4">
      <div class="application-scenarios absolute bottom-[114%] left-4">
         <div class="flex-items-center space-x-2">
            <div
               class="border border-gray-400 border-solid h-8 flex-items-center px-3 py-2 rounded-2xl cursor-pointer space-x-1 hover:bg-[#c5e0ff] hover:text-[#1c86ff]"
               class="border border-gray-400 border-solid h-8 flex-items-center px-3 py-2 rounded-2xl cursor-pointer space-x-1 hover:bg-[#cae3ff]"
               :class="{ 'bg-[#c5e0ff]': activeGroupType === item, '!text-[#1c86ff]': activeGroupType === item }"
               v-for="item in groupTypeList"
               @click="groupTypeClick(item)"
            >
@@ -14,8 +15,7 @@
         </div>
      </div>
      <!-- 当前应用场景 -->
      <div
         v-else
      <!-- <div
         class="bg-[#f9fafb] rounded-t-[22px] absolute bottom-[100%] left-0 w-full input-border h-11 flex-items-center justify-between text-[14px]"
         style="padding: 4px 4px 4px 18px; border-bottom: none"
      >
@@ -29,9 +29,14 @@
               class="ywifont ywicon-guanbi mr-3 rounded-sm p-1 hover:bg-[#eaebec] cursor-pointer"
            ></span>
         </el-tooltip>
      </div>
      </div> -->
      <div class="assembly flex">
         <el-button title="插件菜单" class="label flex items-center cursor-pointer" link>
         <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>
@@ -44,8 +49,10 @@
            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"
@@ -103,24 +110,44 @@
         @updateInputValue="updateInputValue"
         :isHome="isHome"
      />
      <CommonPhrases
         v-model:isShow="isShowPhrase"
         v-show="isShowPhrase"
         :isHome="isHome"
         ref="commonPhrasesRef"
         @updateCommonChatInput="updateCommonChatInput"
      />
   </div>
</template>
<script setup lang="ts">
import { onClickOutside } from '@vueuse/core';
import type { InputInstance } from 'element-plus';
import { ElMessage } from 'element-plus';
import _ from 'lodash';
import getCaretCoordinates from 'textarea-caret';
import { computed, nextTick, ref, triggerRef } from 'vue';
import { computed, nextTick, ref, toRefs, watch } from 'vue';
import InfoDetail from './InfoDetail.vue';
import CommonPhrases from './phrase/CommonPhrases.vue';
import VoicePage from './voicePage/VoicePage.vue';
import { getMetricsNames, querySimilarityHistory } from '/@/api/ai/chat';
import { onClickOutside } from '@vueuse/core';
import _ from 'lodash';
import { activeGroupType, groupTypeList, groupTypeMapIcon } from '/@/stores/chatRoom';
const emits = defineEmits(['sendClick']);
const props = defineProps(['isTalking', 'isHome']);
const emits = defineEmits(['sendClick', 'showUpChatClick', 'showDownChatClick']);
const props = defineProps({
   isTalking: Boolean,
   isHome: Boolean,
   setCommonQuestionInfo: {
      type: Object,
      default: {},
   },
});
const { setCommonQuestionInfo } = toRefs(props);
const voicePageIsShow = defineModel('voicePageIsShow', {
   type: Boolean,
   default: false,
});
const isShowPhrase = defineModel('isShowPhrase', {
   type: Boolean,
   default: false,
});
@@ -139,7 +166,9 @@
   if (props.isTalking) return;
   const isEnterInput = !e.shiftKey && e.key == 'Enter';
   const isDigitalInput = e.ctrlKey && e.code.startsWith('Digit') && tipIsShow.value;
   if (isEnterInput || isDigitalInput) {
   const arrowUp = e.key === 'ArrowUp';
   const arrowDown = e.key === 'ArrowDown';
   if (isEnterInput || isDigitalInput || arrowUp || arrowDown) {
      e.cancelBubble = true; //ie阻止冒泡行为
      e.stopPropagation(); //Firefox阻止冒泡行为
      e.preventDefault(); //取消事件的默认动作*换行
@@ -153,6 +182,10 @@
            inputValue.value = mapValue;
            triggerShow.value = false;
         }
      } else if (arrowUp) {
         emits('showUpChatClick');
      } else if (arrowDown) {
         emits('showDownChatClick');
      }
   }
};
@@ -174,6 +207,7 @@
onClickOutside(tipEleRef, () => {
   triggerShow.value = false;
});
const inputText = (text) => {
   nextTick(() => {
      setTimeout(() => {
@@ -213,6 +247,7 @@
   lastIsFinish = false;
   const res = await querySimilarityHistory({
      question: text,
      group_type: activeGroupType.value,
   });
   lastIsFinish = true;
   const handleValues = res?.values ?? [];
@@ -404,11 +439,10 @@
//#region ====================== 当前应用场景 ======================
const currentGroupTypeIsShow = computed(() => !!activeGroupType.value);
const groupTypeClick = (item) => {
   activeGroupType.value = item;
   inputRef.value.focus();
   commonPhrasesRef.value.getCommonPhrases();
};
// 关闭当前 groupType 面板
@@ -416,6 +450,30 @@
   activeGroupType.value = null;
};
//#endregion
//#region ====================== 常用语功能 ======================
const commonPhrasesRef = ref(null);
const commonPhrasesClick = () => {
   isShowPhrase.value = true;
};
onClickOutside(commonPhrasesRef, () => {
   isShowPhrase.value = false;
});
const updateCommonChatInput = (val) => {
   inputValue.value = val;
   isShowPhrase.value = false;
};
watch(setCommonQuestionInfo, (val) => {
   if (!props.isHome) {
      let obj = {
         id: val?.historyId,
         question: val?.content.values,
      };
      commonPhrasesRef.value.commonChatByUser(obj);
      isShowPhrase.value = true;
   }
});
//#endregion
</script>
<style scoped lang="scss">
.set-waterTitle {