输入框工作流调整

This commit is contained in:
2026-06-16 11:08:10 +08:00
parent 536ad8386c
commit 195d219f91

View File

@@ -1,65 +1,92 @@
<template> <template>
<div class="input-shell"> <div class="input-shell">
<div class="input-card"> <div class="input-card" :class="{ 'is-focused': isFocused }">
<!-- 已选中状态标签栏 -->
<div v-if="selectedWorkflowId !== null || selectedSkill !== 'default'" class="selected-tags">
<div v-if="selectedWorkflowId !== null" class="selected-tag workflow-tag">
<el-icon><Promotion /></el-icon>
<span>{{ commonWorkflows.find((w) => w.id === selectedWorkflowId)?.name }}</span>
<el-icon class="tag-close" @click="selectedWorkflowId = null"><Close /></el-icon>
</div>
<div v-if="selectedSkill !== 'default'" class="selected-tag skill-tag">
<el-icon><MagicStick /></el-icon>
<span>{{ skillLabels[selectedSkill] }}</span>
<el-icon class="tag-close" @click="selectedSkill = 'default'"><Close /></el-icon>
</div>
</div>
<!-- 文本输入区 -->
<el-input <el-input
v-model="message" v-model="message"
type="textarea" type="textarea"
:rows="1" :autosize="{ minRows: 1, maxRows: 6 }"
:autosize="{ minRows: 2, maxRows: 5 }" placeholder="有什么想聊的?按 Enter 发送Shift+Enter 换行"
placeholder="多说说你的偏好和要求,我会越用越懂你"
class="message-input" class="message-input"
@keydown.enter.exact="handleSend" @focus="isFocused = true"
@blur="isFocused = false"
@keydown.enter.exact.prevent="handleSend"
@keydown.enter.shift.exact="() => {}"
/> />
<!-- 底部工具栏 -->
<div class="input-toolbar"> <div class="input-toolbar">
<div class="toolbar-left"> <div class="toolbar-left">
<el-button circle class="tool-btn" @click="handleAttachment"> <!-- 上传附件 -->
<el-icon><Plus /></el-icon> <el-tooltip content="上传文件" placement="top">
</el-button> <button class="tool-icon-btn" @click="handleAttachment">
<el-dropdown trigger="click" @command="handleSkillSelect"> <el-icon><Paperclip /></el-icon>
<el-button class="pill-btn"> </button>
{{ currentSkillDisplay }} </el-tooltip>
</el-button>
<!-- 选择技能 -->
<el-dropdown trigger="click" placement="top-start" @command="handleSkillSelect">
<el-tooltip content="选择技能" placement="top">
<button class="tool-icon-btn" :class="{ active: selectedSkill !== 'default' }">
<el-icon><MagicStick /></el-icon>
<span class="tool-label">技能</span>
</button>
</el-tooltip>
<template #dropdown> <template #dropdown>
<el-dropdown-menu> <el-dropdown-menu>
<el-dropdown-item command="default">默认对话</el-dropdown-item> <el-dropdown-item command="default">
<el-dropdown-item command="code-review">代码审查</el-dropdown-item> <el-icon><CircleClose /></el-icon>不使用技能
</el-dropdown-item>
<el-dropdown-item divided command="code-review">代码审查</el-dropdown-item>
<el-dropdown-item command="refactor">代码重构</el-dropdown-item> <el-dropdown-item command="refactor">代码重构</el-dropdown-item>
<el-dropdown-item command="writing">内容写作</el-dropdown-item> <el-dropdown-item command="writing">内容写作</el-dropdown-item>
</el-dropdown-menu> </el-dropdown-menu>
</template> </template>
</el-dropdown> </el-dropdown>
</div> </div>
<div class="toolbar-right"> <div class="toolbar-right">
<el-button circle class="send-btn" :disabled="!message.trim()" @click="handleSend"> <span class="hint-text">Shift+Enter 换行</span>
<button class="send-btn" :disabled="!message.trim()" @click="handleSend">
<el-icon><Top /></el-icon> <el-icon><Top /></el-icon>
</el-button> </button>
</div>
</div> </div>
</div> </div>
<!-- 常用工作流胶囊 --> <!-- 快捷工作流胶囊输入框下方 -->
<div class="workflow-pills" v-if="commonWorkflows.length > 0"> <div v-if="commonWorkflows.length > 0" class="workflow-shortcuts">
<div <button
v-for="wf in commonWorkflows" v-for="wf in commonWorkflows"
:key="wf.id" :key="wf.id"
class="workflow-pill" class="shortcut-pill"
:class="{ active: selectedWorkflowId === wf.id }" :class="{ active: selectedWorkflowId === wf.id }"
@click="selectWorkflow(wf)" @click="toggleWorkflow(wf.id)"
> >
<el-icon class="pill-icon"> <el-icon><Promotion /></el-icon>
<component :is="wf.icon" /> {{ wf.name }}
</el-icon> </button>
<span class="pill-text">{{ wf.name }}</span>
</div>
</div>
</div> </div>
</div> </div>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ref, computed } from 'vue'; import { ref } from 'vue';
import { useRouter } from 'vue-router'; import { Top, MagicStick, Promotion, Close, CircleClose, Paperclip } from '@element-plus/icons-vue';
import { Top, Plus, MagicStick, Document, CircleCheck } from '@element-plus/icons-vue';
import { ElMessage } from 'element-plus'; import { ElMessage } from 'element-plus';
interface Emits { interface Emits {
@@ -69,14 +96,12 @@ interface Emits {
interface Workflow { interface Workflow {
id: number; id: number;
name: string; name: string;
icon: any;
prefix: string; prefix: string;
editPath: string;
} }
const emit = defineEmits<Emits>(); const emit = defineEmits<Emits>();
const router = useRouter();
const message = ref(''); const message = ref('');
const isFocused = ref(false);
const selectedSkill = ref('default'); const selectedSkill = ref('default');
const selectedWorkflowId = ref<number | null>(null); const selectedWorkflowId = ref<number | null>(null);
@@ -87,59 +112,28 @@ const skillLabels: Record<string, string> = {
writing: '内容写作', writing: '内容写作',
}; };
const currentSkillDisplay = computed(() => { const skillPrefixes: Record<string, string> = {
return selectedSkill.value === 'default' ? '选择技能' : skillLabels[selectedSkill.value];
});
const skills: Record<string, string> = {
default: '', default: '',
'code-review': '[技能:代码审查] 请帮我审查下面这段代码,找出潜在问题并给出改进建议:\n', 'code-review': '[技能:代码审查] 请帮我审查下面这段代码,找出潜在问题并给出改进建议:\n',
refactor: '[技能:代码重构] 请帮我重构下面这段代码,提升可读性和可维护性:\n', refactor: '[技能:代码重构] 请帮我重构下面这段代码,提升可读性和可维护性:\n',
writing: '[技能:内容写作] 请根据下面的需求帮我创作内容:\n', writing: '[技能:内容写作] 请根据下面的需求帮我创作内容:\n',
}; };
// 常用工作流列表
const commonWorkflows: Workflow[] = [ const commonWorkflows: Workflow[] = [
{ { id: 1, name: '审查', prefix: '[工作流:审查] 完成后请自动生成单元测试:\n' },
id: 1, { id: 2, name: '文档再编码', prefix: '[工作流:文档再编码] 请先编写接口文档,再实现代码:\n' },
name: '审查+测试', { id: 3, name: '代码重构', prefix: '[工作流:代码重构] 请帮我重构这段代码:\n' },
icon: Document, { id: 4, name: '需求分析', prefix: '[工作流:需求分析] 请帮我分析这个需求并拆解任务:\n' },
prefix: '[工作流:审查+测试] 完成后请自动生成单元测试:\n',
editPath: '/settings/workflow',
},
{
id: 2,
name: '文档再编码',
icon: Document,
prefix: '[工作流:文档再编码] 请先编写接口文档,再实现代码:\n',
editPath: '/settings/workflow',
},
{
id: 3,
name: '代码重构',
icon: Document,
prefix: '[工作流:代码重构] 请帮我重构这段代码:\n',
editPath: '/settings/workflow',
},
{
id: 4,
name: '需求分析',
icon: Document,
prefix: '[工作流:需求分析] 请帮我分析这个需求并拆解任务:\n',
editPath: '/settings/workflow',
},
]; ];
const handleSend = (event?: KeyboardEvent) => { const handleSend = () => {
if (event) event.preventDefault();
const msg = message.value.trim(); const msg = message.value.trim();
if (!msg) return; if (!msg) return;
const skillPrefix = skills[selectedSkill.value] || ''; const skillPrefix = skillPrefixes[selectedSkill.value] || '';
const workflowPrefix = selectedWorkflowId.value !== null ? commonWorkflows.find((w) => w.id === selectedWorkflowId.value)?.prefix || '' : ''; const workflowPrefix = selectedWorkflowId.value !== null ? commonWorkflows.find((w) => w.id === selectedWorkflowId.value)?.prefix || '' : '';
const finalMessage = (skillPrefix + workflowPrefix + msg).trim(); const finalMessage = (skillPrefix + workflowPrefix + msg).trim();
emit('send', finalMessage); emit('send', finalMessage);
message.value = ''; message.value = '';
// 发送后清空选择
selectedWorkflowId.value = null; selectedWorkflowId.value = null;
}; };
@@ -147,186 +141,241 @@ const handleAttachment = () => {
ElMessage.info('附件上传功能开发中...'); ElMessage.info('附件上传功能开发中...');
}; };
const handleSkillSelect = (key: string | number | object) => { const handleSkillSelect = (key: string | number | object | null) => {
selectedSkill.value = String(key); selectedSkill.value = String(key ?? 'default');
if (selectedSkill.value !== 'default') {
ElMessage.success(`已选择技能:${skillLabels[selectedSkill.value]}`);
}
}; };
const selectWorkflow = (wf: Workflow) => { const handleWorkflowSelect = (id: number | null) => {
if (selectedWorkflowId.value === wf.id) { selectedWorkflowId.value = id;
selectedWorkflowId.value = null; };
ElMessage.info('已取消工作流');
} else { const toggleWorkflow = (id: number) => {
selectedWorkflowId.value = wf.id; selectedWorkflowId.value = selectedWorkflowId.value === id ? null : id;
ElMessage.success(`已选择工作流:${wf.name}`);
}
}; };
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">
.input-shell { .input-shell {
position: relative; padding: 0 24px 24px;
z-index: 12;
margin-top: -20px;
padding: 0 0 50px;
background: transparent; background: transparent;
} }
.input-card { .input-card {
width: min(1060px, 82%); max-width: 860px;
margin: 0 auto; margin: 0 auto;
background: background: #fff;
linear-gradient(180deg, rgba(255, 255, 255, 0.98) 0%, rgba(255, 255, 255, 0.94) 100%), border: 1.5px solid #e2e8f0;
radial-gradient(120% 180% at 0% 0%, rgba(59, 130, 246, 0.15) 0%, rgba(59, 130, 246, 0) 38%), border-radius: 16px;
radial-gradient(80% 120% at 100% 100%, rgba(168, 85, 247, 0.08) 0%, rgba(168, 85, 247, 0) 38%); box-shadow: 0 2px 12px rgba(15, 23, 42, 0.07);
border: 1px solid rgba(59, 130, 246, 0.28); transition:
border-radius: 20px; border-color 0.2s,
box-shadow 0.2s;
overflow: hidden;
&.is-focused {
border-color: #93c5fd;
box-shadow: box-shadow:
0 24px 48px rgba(15, 23, 42, 0.12), 0 0 0 3px rgba(59, 130, 246, 0.12),
0 0 0 1px rgba(59, 130, 246, 0.08) inset, 0 2px 12px rgba(15, 23, 42, 0.07);
0 8px 16px rgba(37, 99, 235, 0.1); }
padding: 16px 18px 18px;
backdrop-filter: blur(16px);
} }
/* 已选标签栏 */
.selected-tags {
display: flex;
flex-wrap: wrap;
gap: 6px;
padding: 10px 14px 0;
}
.selected-tag {
display: inline-flex;
align-items: center;
gap: 4px;
padding: 3px 8px 3px 8px;
border-radius: 6px;
font-size: 12px;
font-weight: 500;
line-height: 1.4;
&.workflow-tag {
background: #eff6ff;
color: #2563eb;
border: 1px solid #bfdbfe;
}
&.skill-tag {
background: #f5f3ff;
color: #7c3aed;
border: 1px solid #ddd6fe;
}
.tag-close {
margin-left: 2px;
cursor: pointer;
opacity: 0.6;
transition: opacity 0.15s;
&:hover {
opacity: 1;
}
}
}
/* 文本域 */
.message-input { .message-input {
:deep(.el-textarea__inner) { :deep(.el-textarea__inner) {
border: none; border: none;
box-shadow: none; box-shadow: none;
resize: none; resize: none;
padding: 8px 6px 14px; padding: 14px 16px 8px;
font-size: 15px; font-size: 15px;
line-height: 1.65; line-height: 1.6;
color: #0f172a; color: #0f172a;
background: transparent; background: transparent;
min-height: 50px; min-height: 28px !important;
font-weight: 500;
&::placeholder { &::placeholder {
color: #90a1b7; color: #94a3b8;
font-weight: 400; font-weight: 400;
} }
} }
} }
/* 底部工具栏 */
.input-toolbar { .input-toolbar {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
align-items: center; align-items: center;
gap: 10px; padding: 6px 10px 10px 12px;
padding-top: 2px;
} }
.toolbar-left, .toolbar-left,
.toolbar-right { .toolbar-right {
display: flex; display: flex;
align-items: center; align-items: center;
gap: 10px; gap: 4px;
} }
.tool-btn { .tool-icon-btn {
width: 32px; display: inline-flex;
height: 32px; align-items: center;
border: 1px solid #d9e4f5; gap: 4px;
color: #5b6b84; height: 30px;
background: linear-gradient(180deg, #ffffff 0%, #f8fbff 100%); padding: 0 10px;
box-shadow: 0 2px 6px rgba(15, 23, 42, 0.06); border: none;
transition: all 0.2s ease; border-radius: 8px;
background: transparent;
color: #64748b;
font-size: 13px;
font-weight: 500;
cursor: pointer;
transition:
background 0.15s,
color 0.15s;
outline: none;
.el-icon {
font-size: 15px;
}
&:hover { &:hover {
color: #2b4d8f; background: #f1f5f9;
background: linear-gradient(135deg, #f0f7ff 0%, #e0edff 100%); color: #334155;
border-color: #bfdbfe; }
transform: translateY(-1px);
box-shadow: 0 4px 12px rgba(59, 130, 246, 0.15); &.active {
background: #eff6ff;
color: #2563eb;
} }
} }
.pill-btn { .tool-label {
height: 32px;
padding: 0 14px;
border-radius: 999px;
border: 1px solid #dbe7f7;
color: #30435f;
background: linear-gradient(180deg, #ffffff 0%, #f6f9ff 100%);
font-size: 12px; font-size: 12px;
font-weight: 600;
transition: all 0.2s ease;
&:hover {
background: linear-gradient(135deg, #f0f7ff 0%, #e0edff 100%);
border-color: #bfdbfe;
color: #1d4ed8;
} }
.hint-text {
font-size: 11px;
color: #cbd5e1;
margin-right: 6px;
user-select: none;
} }
.send-btn { .send-btn {
display: inline-flex;
align-items: center;
justify-content: center;
width: 32px; width: 32px;
height: 32px; height: 32px;
border: none; border: none;
background: linear-gradient(135deg, #60a5fa 0%, #3b82f6 50%, #2563eb 100%); border-radius: 8px;
background: #2563eb;
color: #fff; color: #fff;
box-shadow: 0 6px 16px rgba(59, 130, 246, 0.4); cursor: pointer;
transition: all 0.2s ease; transition:
background 0.15s,
transform 0.1s,
opacity 0.15s;
outline: none;
.el-icon {
font-size: 16px;
}
&:hover:not(:disabled) { &:hover:not(:disabled) {
filter: brightness(1.08); background: #1d4ed8;
transform: translateY(-1px); transform: translateY(-1px);
box-shadow: 0 8px 20px rgba(59, 130, 246, 0.5);
} }
&:disabled { &:disabled {
opacity: 0.5; background: #e2e8f0;
box-shadow: none; color: #94a3b8;
background: linear-gradient(135deg, #cbd5e1 0%, #94a3b8 100%); cursor: not-allowed;
transform: none;
} }
} }
/* 工作流胶囊样式 */ /* 快捷工作流胶囊 */
.workflow-pills { .workflow-shortcuts {
margin-top: 12px; max-width: 860px;
padding-top: 12px; margin: 10px auto 0;
border-top: 1px solid rgba(59, 130, 246, 0.15);
display: flex; display: flex;
flex-wrap: wrap; flex-wrap: wrap;
gap: 8px; gap: 8px;
} }
.workflow-pill { .shortcut-pill {
display: inline-flex; display: inline-flex;
align-items: center; align-items: center;
gap: 4px; gap: 5px;
padding: 4px 10px; height: 28px;
padding: 0 12px;
border: 1px solid #e2e8f0;
border-radius: 999px; border-radius: 999px;
border: 1px solid rgba(59, 130, 246, 0.3); background: rgba(255, 255, 255, 0.7);
background: rgba(255, 255, 255, 0.6);
cursor: pointer;
transition: all 0.2s ease;
color: #475569; color: #475569;
font-size: 12px;
font-weight: 500;
cursor: pointer;
backdrop-filter: blur(4px);
transition: all 0.15s;
outline: none;
.el-icon {
font-size: 12px;
}
&:hover { &:hover {
border-color: #3b82f6; border-color: #93c5fd;
background: rgba(59, 130, 246, 0.08); color: #2563eb;
transform: translateY(-1px); background: rgba(239, 246, 255, 0.9);
} }
&.active { &.active {
border-color: #3b82f6; border-color: #3b82f6;
background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%); background: #2563eb;
color: #ffffff; color: #fff;
box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3); box-shadow: 0 2px 8px rgba(37, 99, 235, 0.3);
}
.pill-icon {
font-size: 14px;
}
.pill-text {
font-size: 12px;
font-weight: 500;
line-height: 1.2;
} }
} }
</style> </style>