|
| 1 | +<script lang="ts" setup> |
| 2 | +import { ref } from 'vue' |
| 3 | +import icon_quick_question from '@/assets/svg/icon_quick_question.svg' |
| 4 | +import { Close } from '@element-plus/icons-vue' |
| 5 | +import RecommendQuestion from '@/views/chat/RecommendQuestion.vue' |
| 6 | +import { ChatInfo } from '@/api/chat.ts' |
| 7 | +import RecentQuestion from '@/views/chat/RecentQuestion.vue' |
| 8 | +const visible = ref(false) |
| 9 | +const activeName = ref('recommend') |
| 10 | +const recommendQuestionRef = ref() |
| 11 | +
|
| 12 | +const getRecommendQuestions = () => { |
| 13 | + recommendQuestionRef.value.getRecommendQuestions() |
| 14 | +} |
| 15 | +const quickAsk = (question: string) => { |
| 16 | + emits('quickAsk', question) |
| 17 | +} |
| 18 | +
|
| 19 | +const onChatStop = () => { |
| 20 | + emits('stop') |
| 21 | +} |
| 22 | +
|
| 23 | +const loadingOver = () => { |
| 24 | + emits('loadingOver') |
| 25 | + visible.value = false |
| 26 | +} |
| 27 | +
|
| 28 | +const emits = defineEmits(['quickAsk', 'loadingOver', 'stop']) |
| 29 | +defineExpose({ getRecommendQuestions, id: () => props.recordId, stop }) |
| 30 | +
|
| 31 | +const props = withDefaults( |
| 32 | + defineProps<{ |
| 33 | + recordId?: number |
| 34 | + datasourceId?: number |
| 35 | + currentChat?: ChatInfo |
| 36 | + questions?: string |
| 37 | + firstChat?: boolean |
| 38 | + disabled?: boolean |
| 39 | + }>(), |
| 40 | + { |
| 41 | + recordId: undefined, |
| 42 | + datasourceId: undefined, |
| 43 | + currentChat: () => new ChatInfo(), |
| 44 | + questions: '[]', |
| 45 | + firstChat: false, |
| 46 | + disabled: false, |
| 47 | + } |
| 48 | +) |
| 49 | +</script> |
| 50 | + |
| 51 | +<template> |
| 52 | + <el-popover |
| 53 | + :title="$t('qa.quick_question')" |
| 54 | + :visible="visible" |
| 55 | + popper-class="quick_question_popover" |
| 56 | + placement="top-start" |
| 57 | + :width="320" |
| 58 | + > |
| 59 | + <el-icon class="close_icon"><Close @click="visible = false" /></el-icon> |
| 60 | + <el-tabs v-model="activeName" class="quick_question_tab"> |
| 61 | + <el-tab-pane :label="$t('qa.recommend')" name="recommend"> |
| 62 | + <RecommendQuestion |
| 63 | + ref="recommendQuestionRef" |
| 64 | + :current-chat="currentChat" |
| 65 | + :record-id="recordId" |
| 66 | + :questions="questions" |
| 67 | + :disabled="disabled" |
| 68 | + :first-chat="firstChat" |
| 69 | + position="input" |
| 70 | + @click-question="quickAsk" |
| 71 | + @stop="onChatStop" |
| 72 | + @loading-over="loadingOver" |
| 73 | + /> |
| 74 | + </el-tab-pane> |
| 75 | + <el-tab-pane v-if="datasourceId" :label="$t('qa.recently')" name="recently"> |
| 76 | + <RecentQuestion v-if="visible" :datasource-id="datasourceId" @click-question="quickAsk"> |
| 77 | + </RecentQuestion> |
| 78 | + </el-tab-pane> |
| 79 | + </el-tabs> |
| 80 | + <template #reference> |
| 81 | + <el-button plain size="small" @click="visible = true"> |
| 82 | + <el-icon size="16" class="el-icon--left"> |
| 83 | + <icon_quick_question /> |
| 84 | + </el-icon> |
| 85 | + {{ $t('qa.quick_question') }} |
| 86 | + </el-button> |
| 87 | + </template> |
| 88 | + </el-popover> |
| 89 | +</template> |
| 90 | + |
| 91 | +<style lang="less"> |
| 92 | +.quick_question_popover { |
| 93 | + .quick_question_tab { |
| 94 | + height: 230px; |
| 95 | + } |
| 96 | + .ed-tabs__content { |
| 97 | + overflow: auto; |
| 98 | + } |
| 99 | + .ed-popover__title { |
| 100 | + font-size: 14px; |
| 101 | + font-weight: 500; |
| 102 | + margin-bottom: 0; |
| 103 | + } |
| 104 | + .close_icon { |
| 105 | + position: absolute; |
| 106 | + cursor: pointer; |
| 107 | + top: 12px; |
| 108 | + right: 12px; |
| 109 | + } |
| 110 | + .ed-tabs__item { |
| 111 | + font-size: 14px; |
| 112 | + height: 38px; |
| 113 | + } |
| 114 | + .ed-tabs__active-bar { |
| 115 | + height: 2px; |
| 116 | + } |
| 117 | + .ed-tabs__nav-wrap:after { |
| 118 | + height: 0; |
| 119 | + } |
| 120 | + .ed-tabs__content { |
| 121 | + padding-top: 12px; |
| 122 | + } |
| 123 | +} |
| 124 | +</style> |
0 commit comments