feat: 首页开发
This commit is contained in:
@@ -42,7 +42,13 @@
|
||||
<!-- 底部:输入框 -->
|
||||
<div class="input-section">
|
||||
<div class="input-wrapper">
|
||||
<textarea class="input-textarea" placeholder="描述任务,/ 调用技能与工具,@调用知识库"></textarea>
|
||||
<textarea
|
||||
v-model="inputText"
|
||||
class="input-textarea"
|
||||
placeholder="描述任务,/ 调用技能与工具,@调用知识库"
|
||||
:disabled="isCreating"
|
||||
@keydown="handleKeydown"
|
||||
></textarea>
|
||||
<div class="input-toolbar">
|
||||
<div class="toolbar-left">
|
||||
<button class="toolbar-btn file-btn">
|
||||
@@ -53,7 +59,7 @@
|
||||
<button class="toolbar-btn symbol-btn">@</button>
|
||||
</div>
|
||||
<div class="toolbar-right">
|
||||
<button class="send-btn">
|
||||
<button class="send-btn" :disabled="!inputText.trim() || isCreating" @click="handleSend">
|
||||
<el-icon><Promotion /></el-icon>
|
||||
</button>
|
||||
</div>
|
||||
@@ -64,7 +70,50 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref } from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
import { useHistoryStore } from '@/stores/history';
|
||||
import { Document, Plus, Promotion } from '@element-plus/icons-vue';
|
||||
|
||||
const router = useRouter();
|
||||
const historyStore = useHistoryStore();
|
||||
const inputText = ref('');
|
||||
const isCreating = ref(false);
|
||||
|
||||
// 处理发送消息
|
||||
async function handleSend() {
|
||||
const text = inputText.value.trim();
|
||||
if (!text || isCreating.value) return;
|
||||
|
||||
isCreating.value = true;
|
||||
try {
|
||||
// 创建会话,title 使用用户输入的文本
|
||||
const session = await historyStore.createSession(text);
|
||||
console.log('创建会话成功:', session);
|
||||
|
||||
// 清空输入框
|
||||
inputText.value = '';
|
||||
|
||||
// 跳转到对话页面
|
||||
router.push({
|
||||
path: '/chat',
|
||||
query: { sessionId: session.id },
|
||||
});
|
||||
} catch (err) {
|
||||
console.error('创建会话失败:', err);
|
||||
} finally {
|
||||
isCreating.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 处理键盘事件
|
||||
function handleKeydown(e) {
|
||||
// Enter 发送,Shift+Enter 换行
|
||||
if (e.key === 'Enter' && !e.shiftKey) {
|
||||
e.preventDefault();
|
||||
handleSend();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
Reference in New Issue
Block a user