| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659 |
- <template>
- <section class="chat-input-area" :class="{ 'is-desktop': isDesktop }">
- <div class="chat-input-box">
- <div v-if="uploadedFiles.length > 0" class="attachments-area">
- <div v-for="file in uploadedFiles" :key="file.id" class="attachment-item"
- :class="file.isImage ? 'is-image' : 'is-file'">
- <img v-if="file.isImage && file.url" :src="file.url" class="attachment-image-preview" :alt="file.name" />
- <div v-else class="file-icon">{{ getFileExtension(file.name) }}</div>
- <div class="file-info">
- <div class="file-name">{{ file.name }}</div>
- <div class="file-progress" :class="{ error: file.status === 'error' }">
- {{ getFileStatusText(file) }}
- </div>
- <div v-if="file.status === 'uploading'" class="file-progress-bar">
- <div class="file-progress-bar-fill" :style="{ width: `${file.progress}%` }"></div>
- </div>
- </div>
- <button type="button" class="attachment-delete-btn" aria-label="移除附件" @click="emit('removeFile', file.id)">
- ×
- </button>
- <div v-if="file.status === 'uploading'" class="attachment-progress-overlay">
- <div class="progress-spinner"></div>
- </div>
- </div>
- </div>
- <div class="textarea-wrapper">
- <textarea ref="textareaRef" :value="modelValue" :rows="resolvedMinRows" placeholder="说出您的需求,我来为您解答"
- @input="handleInput" @keydown="handleKeydown"></textarea>
- </div>
- <div class="input-actions-bar">
- <div class="actions-left">
- <!-- 上传入口:附件先传到 OSS,再随请求体的 `pictures` / `files` 字段发给后端 -->
- <button type="button" class="action-btn" aria-label="上传图片" @click="emit('imageUpload')"
- @mouseenter="showActionTip($event, '上传图片')" @mouseleave="hideActionTip">
- <svg width="18" height="18" viewBox="0 0 18 18" fill="none">
- <path
- d="M2 18c-.55 0-1.02-.2-1.41-.59A1.93 1.93 0 0 1 0 16V2C0 1.45.2.98.59.59A1.93 1.93 0 0 1 2 0h14c.55 0 1.02.2 1.41.59.39.39.59.86.59 1.41v14c0 .55-.2 1.02-.59 1.41-.39.39-.86.59-1.41.59H2Zm0-2h14V2H2v14Zm1-2h12v-1.41L11.25 7l-3 4-2.25-3-3 4.59V14Z"
- fill="currentColor" />
- </svg>
- </button>
- <button type="button" class="action-btn" aria-label="上传附件" @click="emit('fileUpload')"
- @mouseenter="showActionTip($event, '上传附件')" @mouseleave="hideActionTip">
- <svg width="13" height="20" viewBox="0 0 13 20" fill="none">
- <path
- d="M12.5 13.75c0 1.73-.61 3.21-1.83 4.43C9.46 19.39 7.98 20 6.25 20s-3.21-.61-4.43-1.82A6.02 6.02 0 0 1 0 13.75V4.5c0-1.25.44-2.31 1.31-3.19A4.34 4.34 0 0 1 4.5 0c1.25 0 2.31.44 3.19 1.31A4.34 4.34 0 0 1 9 4.5v8.75c0 .77-.27 1.42-.8 1.95-.53.53-1.18.8-1.95.8s-1.42-.27-1.95-.8c-.53-.53-.8-1.18-.8-1.95V4h2v9.25c0 .22.07.4.21.54.14.14.32.21.54.21s.4-.07.54-.21c.14-.14.21-.32.21-.54V4.5c-.02-.7-.26-1.29-.74-1.78A2.37 2.37 0 0 0 4.5 2c-.7 0-1.29.24-1.78.73A2.42 2.42 0 0 0 2 4.5v9.25c-.02 1.18.39 2.19 1.23 3.01.83.83 1.84 1.24 3.02 1.24 1.17 0 2.16-.41 2.98-1.24.82-.82 1.24-1.83 1.27-3.01V4h2v9.75Z"
- fill="currentColor" />
- </svg>
- </button>
- <button v-if="VOICE_INPUT_VISIBLE" type="button" class="action-btn"
- :class="{ 'voice-active': isVoiceInputMode }" :aria-pressed="isVoiceInputMode"
- :disabled="isVoiceInputStarting" aria-label="语音输入" @click="emit('voiceToggle')"
- @mouseenter="showActionTip($event, '语音输入')" @mouseleave="hideActionTip">
- <svg width="14" height="19" viewBox="0 0 14 19" fill="none">
- <path
- d="M7 12c-.83 0-1.54-.29-2.13-.88A2.9 2.9 0 0 1 4 9V3c0-.83.29-1.54.87-2.13A2.9 2.9 0 0 1 7 0c.83 0 1.54.29 2.13.87C9.71 1.46 10 2.17 10 3v6c0 .83-.29 1.54-.87 2.12A2.9 2.9 0 0 1 7 12Zm-1 7v-3.08a7.04 7.04 0 0 1-4.3-2.32A6.91 6.91 0 0 1 0 9h2c0 1.38.49 2.56 1.46 3.54A4.82 4.82 0 0 0 7 14c1.38 0 2.56-.49 3.54-1.46A4.82 4.82 0 0 0 12 9h2c0 1.75-.57 3.28-1.7 4.6A7.04 7.04 0 0 1 8 15.92V19H6Zm1-9c.28 0 .52-.1.71-.29.19-.19.29-.43.29-.71V3c0-.28-.1-.52-.29-.71A.97.97 0 0 0 7 2a.97.97 0 0 0-.71.29A.97.97 0 0 0 6 3v6c0 .28.1.52.29.71.19.19.43.29.71.29Z"
- fill="currentColor" />
- </svg>
- </button>
- </div>
- <div class="actions-right">
- <!-- <DeepseekButton v-model="deepThinkValue" /> -->
- <!-- 测试用 MOCK 按钮组(资料 / 问卷 / 流测 / 回放 / 打字 / Scope / 测试输入):
- 要恢复只需取消下一段注释(事件、处理函数与 showTestActions 开关都还在) -->
- <!--
- <div v-if="showTestActions" class="mock-stream-test-actions">
- <button type="button" class="mock-stream-test-action" :disabled="isGenerating"
- @click="emit('testRefLinks')">
- 资料
- </button>
- <button type="button" class="mock-stream-test-action" :disabled="isGenerating"
- @click="emit('testQuestionCard')">
- 问卷
- </button>
- <button type="button" class="mock-stream-test-action" :disabled="isGenerating"
- @click="emit('testMockStream')">
- 流测
- </button>
- <button type="button" class="mock-stream-test-action" :disabled="isGenerating" @click="emit('testReplay')">
- 回放
- </button>
- <button type="button" class="mock-stream-test-action" :disabled="isGenerating"
- @click="emit('testTypewriter')">
- 打字
- </button>
- <button type="button" class="mock-stream-test-action" :disabled="isGenerating"
- @click="emit('testScopeMerge')">
- Scope
- </button>
- <button type="button" class="mock-stream-test-action" :disabled="isGenerating" @click="emit('testInput')">
- 测试输入
- </button>
- </div>
- -->
- <button type="button" class="send-btn" :class="{
- active: modelValue.trim().length > 0 && !isGenerating,
- 'is-generating': isGenerating,
- }" :disabled="!modelValue.trim().length && !isGenerating"
- @click="isGenerating ? emit('stop') : emit('send')">
- <svg v-if="isGenerating" width="14" height="14" viewBox="0 0 16 16" fill="none">
- <rect x="3" y="3" width="10" height="10" rx="2" fill="currentColor" />
- </svg>
- <svg v-else width="19" height="16" viewBox="0 0 19 16" fill="none">
- <path d="M0 16V0l19 8-19 8Zm2-3 11.85-5L2 3v3.5L8 8 2 9.5V13Z" fill="currentColor" />
- </svg>
- </button>
- </div>
- </div>
- </div>
- <Teleport to="body">
- <div v-if="actionTip.visible" class="action-name-tip"
- :style="{ left: `${actionTip.x}px`, top: `${actionTip.y}px` }">{{ actionTip.text }}</div>
- </Teleport>
- </section>
- </template>
- <script setup lang="ts">
- import { computed, nextTick, onBeforeUnmount, onMounted, reactive, ref, watch } from 'vue';
- import type { BusinessAssistantUploadedFile } from './business-assistant/shared';
- const props = defineProps<{
- modelValue: string;
- uploadedFiles: BusinessAssistantUploadedFile[];
- isGenerating: boolean;
- isDeepThink: boolean;
- isVoiceInputMode: boolean;
- isVoiceInputStarting: boolean;
- isDesktop?: boolean;
- minRows?: number;
- showTestActions?: boolean;
- showMockStreamTestButton?: boolean;
- }>();
- const showTestActions = computed(() => props.showTestActions === true);
- const showMockStreamTestButton = computed(() => props.showMockStreamTestButton === true);
- /**
- * 语音输入入口是否显示。
- *
- * 2026-10-28 用户需要调试语音链路 → 恢复为按安全上下文判断:
- * HTTPS/localhost 显示,HTTP 隐藏(HTTP 下 getUserMedia 本来也不能用)。
- * 入口全仓库只有这一处;ASR 逻辑与内部实现在 src/asr/。
- */
- const VOICE_INPUT_VISIBLE = typeof window !== "undefined" && window.isSecureContext;
- const emit = defineEmits<{
- 'update:modelValue': [value: string];
- 'update:isDeepThink': [value: boolean];
- send: [];
- stop: [];
- imageUpload: [];
- fileUpload: [];
- voiceToggle: [];
- removeFile: [id: string];
- paste: [event: ClipboardEvent];
- testReplay: [];
- testTypewriter: [];
- testScopeMerge: [];
- testInput: [];
- testMockStream: [];
- testRefLinks: [];
- testQuestionCard: [];
- }>();
- const ACTION_TIP_DELAY = 300;
- const actionTip = reactive({ visible: false, text: '', x: 0, y: 0 });
- let actionTipTimer: number | null = null;
- let actionTipEl: HTMLElement | null = null;
- const clearActionTipTimer = () => {
- if (actionTipTimer !== null) {
- window.clearTimeout(actionTipTimer);
- actionTipTimer = null;
- }
- };
- const placeActionTip = (el: HTMLElement) => {
- const rect = el.getBoundingClientRect();
- actionTip.x = rect.left + rect.width / 2;
- actionTip.y = rect.top;
- };
- const showActionTip = (event: MouseEvent, text: string) => {
- if (!props.isDesktop) return;
- const el = event.currentTarget as HTMLElement | null;
- if (!el) return;
- clearActionTipTimer();
- actionTipEl = el;
- placeActionTip(el);
- actionTip.text = text;
- actionTipTimer = window.setTimeout(() => {
- actionTipTimer = null;
- if (actionTipEl) placeActionTip(actionTipEl);
- actionTip.visible = true;
- }, ACTION_TIP_DELAY);
- };
- const hideActionTip = () => {
- clearActionTipTimer();
- actionTipEl = null;
- actionTip.visible = false;
- actionTip.text = '';
- };
- onBeforeUnmount(hideActionTip);
- const deepThinkValue = computed({
- get: () => props.isDeepThink,
- set: (value: boolean) => emit('update:isDeepThink', value),
- });
- const textareaRef = ref<HTMLTextAreaElement | null>(null);
- const maxRows = 4;
- const resolvedMinRows = computed(() => {
- const minRows = Number(props.minRows ?? 1);
- if (!Number.isFinite(minRows)) {
- return 1;
- }
- return Math.max(1, Math.min(maxRows, Math.round(minRows)));
- });
- const scrollTextareaToBottom = async () => {
- await nextTick();
- const textarea = textareaRef.value;
- if (!textarea) {
- return;
- }
- textarea.scrollTop = textarea.scrollHeight;
- };
- const syncTextareaHeight = async () => {
- await nextTick();
- const textarea = textareaRef.value;
- if (!textarea) {
- return;
- }
- const styles = window.getComputedStyle(textarea);
- const lineHeight = Number.parseFloat(styles.lineHeight) || Number.parseFloat(styles.fontSize) * 1.6 || 24;
- const paddingY = (Number.parseFloat(styles.paddingTop) || 0) + (Number.parseFloat(styles.paddingBottom) || 0);
- const borderY = (Number.parseFloat(styles.borderTopWidth) || 0) + (Number.parseFloat(styles.borderBottomWidth) || 0);
- const minHeight = lineHeight * resolvedMinRows.value + paddingY + borderY;
- const maxHeight = lineHeight * maxRows + paddingY + borderY;
- textarea.style.height = "auto";
- const nextHeight = Math.max(minHeight, Math.min(textarea.scrollHeight, maxHeight));
- textarea.style.height = `${Math.ceil(nextHeight)}px`;
- textarea.style.overflowY = textarea.scrollHeight > maxHeight ? "auto" : "hidden";
- };
- watch(
- () => [props.modelValue, props.isVoiceInputMode, resolvedMinRows.value],
- ([, isVoiceInputMode]) => {
- void syncTextareaHeight();
- if (!isVoiceInputMode) {
- return;
- }
- void scrollTextareaToBottom();
- },
- { flush: 'post' },
- );
- onMounted(() => {
- void syncTextareaHeight();
- });
- const handleInput = (event: Event) => {
- emit('update:modelValue', (event.target as HTMLTextAreaElement).value);
- };
- const insertNewLineAtCursor = (textarea: HTMLTextAreaElement) => {
- const value = textarea.value;
- const start = textarea.selectionStart ?? value.length;
- const end = textarea.selectionEnd ?? value.length;
- const nextValue = `${value.slice(0, start)}\n${value.slice(end)}`;
- emit('update:modelValue', nextValue);
- void nextTick(() => {
- const currentTextarea = textareaRef.value;
- if (!currentTextarea) {
- return;
- }
- currentTextarea.selectionStart = currentTextarea.selectionEnd = start + 1;
- });
- };
- const handleKeydown = (event: KeyboardEvent) => {
- if (event.key !== 'Enter' || event.isComposing) {
- return;
- }
- if (event.ctrlKey || event.metaKey || (props.isDesktop && (event.shiftKey || event.altKey))) {
- event.preventDefault();
- const textarea = event.target as HTMLTextAreaElement;
- insertNewLineAtCursor(textarea);
- return;
- }
- event.preventDefault();
- if (!props.modelValue.trim() || props.isGenerating) {
- return;
- }
- emit('send');
- };
- const getFileExtension = (name: string) => name.split('.').pop()?.toUpperCase() || 'FILE';
- const getFileStatusText = (file: BusinessAssistantUploadedFile) => {
- if (file.status === 'uploading') {
- return `正在上传... ${file.progress}%`;
- }
- if (file.status === 'error') {
- return file.errorMsg || '上传失败';
- }
- return `${(file.size / 1024 / 1024).toFixed(2)} MB`;
- };
- </script>
- <style scoped>
- .chat-input-area {
- width: 100%;
- padding: 0 16px 16px;
- overflow: hidden;
- }
- .chat-input-box {
- width: 100%;
- display: flex;
- flex-direction: column;
- align-items: stretch;
- justify-content: flex-start;
- gap: 0;
- box-sizing: border-box;
- background: #ffffff;
- border: 1px solid #c7c4d84d;
- border-radius: 16px;
- box-shadow: 0 4px 17.5px #00000008;
- }
- .textarea-wrapper {
- padding: 12px 20px;
- display: flex;
- align-items: center;
- justify-content: center;
- overflow: hidden;
- }
- .textarea-wrapper textarea {
- width: 100%;
- overflow-y: auto;
- overscroll-behavior: contain;
- border: 0 !important;
- outline: 0 !important;
- resize: none;
- background: transparent !important;
- color: #141b2b;
- font-family: "HarmonyOS Sans SC", sans-serif;
- font-size: 16px;
- font-weight: normal;
- line-height: 1.6;
- display: block;
- padding: 0 0 0.59px 0 !important;
- box-shadow: none !important;
- }
- .textarea-wrapper textarea::placeholder {
- color: #777587;
- }
- .input-actions-bar {
- display: flex;
- align-items: center;
- justify-content: space-between;
- padding: 0 12px 12px;
- }
- .actions-left,
- .actions-right {
- display: flex;
- align-items: center;
- }
- .actions-left {
- gap: 4px;
- }
- .actions-right {
- gap: 8px;
- height: 40px;
- }
- .mock-stream-test-actions {
- display: flex;
- align-items: center;
- gap: 4px;
- }
- .mock-stream-test-action {
- height: 28px;
- border: 1px solid rgba(53, 37, 205, 0.18);
- border-radius: 7px;
- padding: 0 7px;
- background: rgba(53, 37, 205, 0.06);
- color: #3525cd;
- font-size: 11px;
- line-height: 1;
- cursor: pointer;
- white-space: nowrap;
- }
- .mock-stream-test-action:disabled {
- cursor: not-allowed;
- opacity: 0.45;
- }
- .action-btn {
- border: 0;
- border-radius: 8px;
- padding: 8px;
- background: transparent;
- color: #464555;
- display: flex;
- align-items: center;
- justify-content: center;
- cursor: pointer;
- }
- .chat-input-area.is-desktop .action-btn:hover {
- background: #e3e3e3;
- }
- .action-name-tip {
- position: fixed;
- z-index: 4000;
- max-width: 280px;
- padding: 8px 10px;
- border-radius: 8px;
- background: #141b2b;
- color: #ffffff;
- font-size: 12px;
- font-weight: 500;
- line-height: 1.5;
- box-shadow: 0 8px 20px rgba(20, 27, 43, 0.18);
- pointer-events: none;
- transform: translate(-50%, calc(-100% - 8px));
- white-space: nowrap;
- }
- .action-btn:active {
- background: #e3e3e3;
- color: #3525cd;
- }
- .action-btn:disabled {
- cursor: not-allowed;
- opacity: 0.55;
- }
- .action-btn.voice-active {
- background: rgba(53, 37, 205, 0.1);
- color: #3525cd;
- }
- :deep(.toggle-btn.zhaoshang-theme-btn) {
- height: 40px;
- padding: 0 12px;
- gap: 8px;
- border-color: #e3e1eb;
- }
- :deep(.toggle-btn.zhaoshang-theme-btn .zhaoshang-toggle-text) {
- display: inline-flex;
- min-width: 40px;
- margin-right: 0;
- color: #464555;
- font-size: 14px;
- font-weight: 500;
- line-height: 1.6;
- }
- :deep(.toggle-btn.zhaoshang-theme-btn .zhaoshang-switch) {
- width: 36px;
- height: 20px;
- }
- .send-btn {
- width: 40px;
- height: 40px;
- border: 0;
- border-radius: 8px;
- display: flex;
- align-items: center;
- justify-content: center;
- background: #3525cd;
- color: #ffffff;
- opacity: 0.5;
- cursor: pointer;
- transition: opacity 0.2s ease;
- }
- .send-btn.active {
- opacity: 1;
- }
- .send-btn.is-generating {
- background: #e2e8f0;
- color: #64748b;
- opacity: 1;
- }
- .send-btn:disabled {
- cursor: not-allowed;
- }
- .attachments-area {
- display: flex;
- gap: 10px;
- overflow-x: auto;
- padding: 12px 12px 0;
- }
- .attachment-item {
- position: relative;
- flex: 0 0 auto;
- min-width: 118px;
- max-width: 220px;
- min-height: 68px;
- display: flex;
- align-items: center;
- gap: 10px;
- padding: 10px;
- border: 1px solid rgba(199, 196, 216, 0.3);
- border-radius: 12px;
- background: #fff;
- }
- .attachment-item.is-image {
- min-width: 68px;
- width: 68px;
- padding: 0;
- overflow: hidden;
- }
- .attachment-image-preview {
- width: 100%;
- height: 68px;
- object-fit: cover;
- }
- .file-icon {
- width: 40px;
- height: 40px;
- border-radius: 8px;
- background: rgba(53, 37, 205, 0.1);
- color: #3525cd;
- font-size: 10px;
- display: flex;
- align-items: center;
- justify-content: center;
- flex-shrink: 0;
- }
- .file-info {
- min-width: 0;
- flex: 1;
- }
- .file-name {
- color: #141b2b;
- font-size: 13px;
- font-weight: 500;
- overflow: hidden;
- text-overflow: ellipsis;
- white-space: nowrap;
- }
- .file-progress {
- margin-top: 2px;
- color: #464555;
- font-size: 12px;
- }
- .file-progress.error {
- color: #f97c7c;
- }
- .file-progress-bar {
- height: 4px;
- margin-top: 6px;
- overflow: hidden;
- border-radius: 999px;
- background: rgba(53, 37, 205, 0.08);
- }
- .file-progress-bar-fill {
- height: 100%;
- border-radius: inherit;
- background: #3525cd;
- }
- .attachment-delete-btn {
- position: absolute;
- top: 5px;
- right: 5px;
- z-index: 2;
- width: 22px;
- height: 22px;
- border: 0;
- border-radius: 50%;
- background: rgba(255, 255, 255, 0.88);
- color: #464555;
- display: flex;
- align-items: center;
- justify-content: center;
- }
- .attachment-progress-overlay {
- position: absolute;
- inset: 0;
- z-index: 1;
- display: flex;
- align-items: center;
- justify-content: center;
- background: rgba(255, 255, 255, 0.65);
- }
- .progress-spinner {
- width: 22px;
- height: 22px;
- border-radius: 50%;
- border: 2px solid rgba(53, 37, 205, 0.2);
- border-top-color: #3525cd;
- animation: spin 1s linear infinite;
- }
- @keyframes spin {
- to {
- transform: rotate(360deg);
- }
- }
- </style>
|