Browse Source

点击首页按钮输入框回显对应信息

master
mk 6 months ago
parent
commit
7a05e115c6
  1. 45
      src/lib/components/chat/Header.svelte
  2. 6
      src/lib/components/chat/MessageInput.svelte
  3. 16
      src/lib/components/chat/Placeholder.svelte
  4. 23
      src/lib/components/common/RichTextInput.svelte
  5. BIN
      static/favicon.png

45
src/lib/components/chat/Header.svelte

@ -1,4 +1,6 @@
<script lang="ts"> <script lang="ts">
import { createEventDispatcher } from 'svelte';
const dispatch = createEventDispatcher();
let list = [ let list = [
{ {
title: '工作', title: '工作',
@ -8,12 +10,16 @@
{ {
label: '工作总结', label: '工作总结',
img: '/img/icon/work.png', img: '/img/icon/work.png',
imgActive: '/img/icon/work_active.png' imgActive: '/img/icon/work_active.png',
active: false,
placeholder:
'<p>帮我写一份用于&nbsp;例如<span style="color:#2c77f1 !important">项目进度、本周工作等</span>&nbsp;的工作总结,包括<span style="color:#2c77f1 !important">工作内容、成果、风险点等。</span></p>'
}, },
{ {
label: '工作总结', label: '文档生成',
img: '/img/icon/document.png', img: '/img/icon/document.png',
imgActive: '/img/icon/document_active.png' imgActive: '/img/icon/document_active.png',
active: false
} }
], ],
introduce: [ introduce: [
@ -26,8 +32,7 @@
{ {
label: '介绍' label: '介绍'
} }
], ]
active:true
}, },
{ {
title: '知识库', title: '知识库',
@ -37,12 +42,8 @@
{ {
label: '检索知识库', label: '检索知识库',
img: '/img/icon/knowledge.png', img: '/img/icon/knowledge.png',
imgActive: '/img/icon/knowledge_active.png' imgActive: '/img/icon/knowledge_active.png',
}, active: false
{
label: '上传文档',
img: '/img/icon/upload.png',
imgActive: '/img/icon/upload_active.png'
} }
], ],
introduce: [ introduce: [
@ -65,7 +66,8 @@
{ {
label: '历史消息', label: '历史消息',
img: '/img/icon/record.png', img: '/img/icon/record.png',
imgActive: '/img/icon/record_active.png' imgActive: '/img/icon/record_active.png',
active: false
} }
], ],
introduce: [ introduce: [
@ -81,7 +83,6 @@
] ]
} }
]; ];
</script> </script>
<div class="flex flex-col border-box header_box"> <div class="flex flex-col border-box header_box">
@ -107,12 +108,24 @@
<div class="flex mt-5.5"> <div class="flex mt-5.5">
{#each item.buttons as but, index (index)} {#each item.buttons as but, index (index)}
<button <button
class="font-medium text-black text-base mr-4 bg-white rounded-2xl px-6 py-1 box-border flex items-center border" class="font-medium text-black text-base mr-4 bg-white rounded-2xl px-6 py-1 box-border flex items-center border {but.active
? 'border-blue-500 text-blue-500'
: ''}"
on:click={() => { on:click={() => {
console.log(but, index); list.forEach((item) => {
item.buttons.forEach((c) => {
if (c.active === true && c.label !== but.label) {
c.active = false;
} else if (c.label === but.label) {
c.active = true;
}
});
});
list = [...list];
dispatch('savePlaceholder',but.placeholder || null)
}} }}
> >
<img src={but.img} alt="" class="w-5 h-5" /> <img src={but.active ? but.imgActive : but.img} alt="" class="w-5 h-5 mr-1" />
{but.label} {but.label}
</button> </button>
{/each} {/each}

6
src/lib/components/chat/MessageInput.svelte

@ -72,7 +72,6 @@
export let imageGenerationEnabled = false; export let imageGenerationEnabled = false;
export let webSearchEnabled = false; export let webSearchEnabled = false;
export let codeInterpreterEnabled = false; export let codeInterpreterEnabled = false;
$: onChange({ $: onChange({
prompt, prompt,
files, files,
@ -94,7 +93,9 @@
let dragged = false; let dragged = false;
let user = null; let user = null;
export let placeholder = '';
export let placeholder;
export let autofill;
let visionCapableModels = []; let visionCapableModels = [];
$: visionCapableModels = [...(atSelectedModel ? [atSelectedModel] : selectedModels)].filter( $: visionCapableModels = [...(atSelectedModel ? [atSelectedModel] : selectedModels)].filter(
@ -690,6 +691,7 @@
bind:this={chatInputElement} bind:this={chatInputElement}
bind:value={prompt} bind:value={prompt}
id="chat-input" id="chat-input"
{autofill}
messageInput={true} messageInput={true}
shiftEnter={!$mobile || shiftEnter={!$mobile ||
!( !(

16
src/lib/components/chat/Placeholder.svelte

@ -38,9 +38,9 @@
export let imageGenerationEnabled = false; export let imageGenerationEnabled = false;
export let codeInterpreterEnabled = false; export let codeInterpreterEnabled = false;
export let webSearchEnabled = false; export let webSearchEnabled = false;
let autofill = ''
let models = []; let models = [];
export let placeholder = null;
const selectSuggestionPrompt = async (p) => { const selectSuggestionPrompt = async (p) => {
let text = p; let text = p;
@ -85,7 +85,6 @@
} }
$: models = selectedModels.map((id) => $_models.find((m) => m.id === id)); $: models = selectedModels.map((id) => $_models.find((m) => m.id === id));
onMount(() => {}); onMount(() => {});
</script> </script>
@ -106,8 +105,12 @@
class="w-full text-3xl text-gray-800 dark:text-gray-100 font-medium text-center flex items-center gap-4 font-primary" class="w-full text-3xl text-gray-800 dark:text-gray-100 font-medium text-center flex items-center gap-4 font-primary"
> >
<div class="w-full flex flex-col justify-center items-center"> <div class="w-full flex flex-col justify-center items-center">
<div class="flex flex-row justify-center gap-3 @sm:gap-3.5 w-fit px-5 "> <div class="flex flex-row justify-center gap-3 @sm:gap-3.5 w-fit px-5">
<Header></Header> <Header
on:savePlaceholder={(val) => {
autofill = val.detail;
}}
></Header>
</div> </div>
<div class="flex mt-1 mb-2"> <div class="flex mt-1 mb-2">
@ -161,10 +164,11 @@
bind:codeInterpreterEnabled bind:codeInterpreterEnabled
bind:webSearchEnabled bind:webSearchEnabled
bind:atSelectedModel bind:atSelectedModel
{placeholder}
{autofill}
{transparentBackground} {transparentBackground}
{stopResponse} {stopResponse}
{createMessagePair} {createMessagePair}
placeholder={$i18n.t('How can I help you today?')}
on:upload={(e) => { on:upload={(e) => {
dispatch('upload', e.detail); dispatch('upload', e.detail);
}} }}

23
src/lib/components/common/RichTextInput.svelte

@ -6,7 +6,7 @@
headingStyle: 'atx' headingStyle: 'atx'
}); });
turndownService.escape = (string) => string; turndownService.escape = (string) => string;
import TextStyle from '@tiptap/extension-text-style';
import { onMount, onDestroy } from 'svelte'; import { onMount, onDestroy } from 'svelte';
import { createEventDispatcher } from 'svelte'; import { createEventDispatcher } from 'svelte';
const eventDispatch = createEventDispatcher(); const eventDispatch = createEventDispatcher();
@ -24,7 +24,7 @@
import Typography from '@tiptap/extension-typography'; import Typography from '@tiptap/extension-typography';
import StarterKit from '@tiptap/starter-kit'; import StarterKit from '@tiptap/starter-kit';
import { all, createLowlight } from 'lowlight'; import { all, createLowlight } from 'lowlight';
import Color from '@tiptap/extension-color';
import { PASTED_TEXT_CHARACTER_LIMIT } from '$lib/constants'; import { PASTED_TEXT_CHARACTER_LIMIT } from '$lib/constants';
// create a lowlight instance with all languages loaded // create a lowlight instance with all languages loaded
@ -42,10 +42,14 @@
export let messageInput = false; export let messageInput = false;
export let shiftEnter = false; export let shiftEnter = false;
export let largeTextAsFile = false; export let largeTextAsFile = false;
export let autofill = '';
let element; let element;
let editor; let editor;
$: {
if (editor && autofill !== editor.getHTML()) {
setContent(autofill); // 更新编辑器内容
}
}
const options = { const options = {
throwOnError: false throwOnError: false
}; };
@ -105,6 +109,7 @@
export const setContent = (content) => { export const setContent = (content) => {
editor.commands.setContent(content); editor.commands.setContent(content);
editor.commands.focus();
}; };
const selectTemplate = () => { const selectTemplate = () => {
@ -163,6 +168,8 @@
element: element, element: element,
extensions: [ extensions: [
StarterKit, StarterKit,
TextStyle,
Color.configure({ types: ['textStyle'] }),
CodeBlockLowlight.configure({ CodeBlockLowlight.configure({
lowlight lowlight
}), }),
@ -188,12 +195,11 @@
] ]
: []) : [])
], ],
content: content,// content: content, //
editable: true,
autofocus: messageInput ? true : false, autofocus: messageInput ? true : false,
onTransaction: () => { onTransaction: () => {
// force re-render so `editor.isActive` works as expected // force re-render so `editor.isActive` works as expected
editor = editor;
if (!raw) { if (!raw) {
let newValue = turndownService let newValue = turndownService
.turndown( .turndown(
@ -332,7 +338,6 @@
} }
} }
}); });
if (messageInput) { if (messageInput) {
selectTemplate(); selectTemplate();
} }
@ -375,4 +380,4 @@
} }
</script> </script>
<div bind:this={element} class="relative w-full min-w-full h-full min-h-fit {className}" /> <div bind:this={element} class="relative ccccc min-w-full h-full min-h-fit {className}" />

BIN
static/favicon.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.4 KiB

After

Width:  |  Height:  |  Size: 15 KiB

Loading…
Cancel
Save