原型
This commit is contained in:
91
江西城市生命线-可交互原型/frontend/src/stores/agent.js
Normal file
91
江西城市生命线-可交互原型/frontend/src/stores/agent.js
Normal file
@@ -0,0 +1,91 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref, computed } from 'vue'
|
||||
|
||||
export const useAgentStore = defineStore('agent', () => {
|
||||
// 智能体列表
|
||||
const agents = ref([
|
||||
{
|
||||
id: 'default',
|
||||
name: '泰豪AI助手',
|
||||
description: '通用AI智能助手,可以回答各类问题',
|
||||
icon: '🤖',
|
||||
color: '#7c3aed',
|
||||
category: 'office',
|
||||
usage: 25000
|
||||
},
|
||||
{
|
||||
id: 'xiaohongshu',
|
||||
name: '小红书文案生成',
|
||||
description: '一键生成爆款小红书文案,支持多种风格,自动添加热门话题标签',
|
||||
icon: '📕',
|
||||
color: '#ff2442',
|
||||
category: 'content',
|
||||
usage: 12580
|
||||
},
|
||||
{
|
||||
id: 'contract',
|
||||
name: '泰豪合同助手',
|
||||
description: '智能合同审核、条款分析、风险提示,提高合同处理效率',
|
||||
icon: '📄',
|
||||
color: '#7c3aed',
|
||||
category: 'business',
|
||||
usage: 8320
|
||||
},
|
||||
{
|
||||
id: 'video',
|
||||
name: '泰豪短视频助手',
|
||||
description: '短视频脚本创作、文案优化、热门话题推荐',
|
||||
icon: '🎬',
|
||||
color: '#10b981',
|
||||
category: 'content',
|
||||
usage: 5640
|
||||
},
|
||||
{
|
||||
id: 'email',
|
||||
name: '邮件写作助手',
|
||||
description: '商务邮件、会议邀请、工作汇报等各类邮件智能生成',
|
||||
icon: '✉️',
|
||||
color: '#6366f1',
|
||||
category: 'office',
|
||||
usage: 7230
|
||||
},
|
||||
{
|
||||
id: 'translate',
|
||||
name: '多语言翻译',
|
||||
description: '支持中英日韩等多语言互译,专业术语精准翻译',
|
||||
icon: '🌐',
|
||||
color: '#14b8a6',
|
||||
category: 'office',
|
||||
usage: 11200
|
||||
}
|
||||
])
|
||||
|
||||
// 当前选中的智能体ID
|
||||
const currentAgentId = ref('default')
|
||||
|
||||
// 当前智能体
|
||||
const currentAgent = computed(() => {
|
||||
return agents.value.find(a => a.id === currentAgentId.value) || agents.value[0]
|
||||
})
|
||||
|
||||
// 设置当前智能体
|
||||
const setCurrentAgent = (agentId) => {
|
||||
const agent = agents.value.find(a => a.id === agentId)
|
||||
if (agent) {
|
||||
currentAgentId.value = agentId
|
||||
}
|
||||
}
|
||||
|
||||
// 添加新智能体
|
||||
const addAgent = (agent) => {
|
||||
agents.value.push(agent)
|
||||
}
|
||||
|
||||
return {
|
||||
agents,
|
||||
currentAgentId,
|
||||
currentAgent,
|
||||
setCurrentAgent,
|
||||
addAgent
|
||||
}
|
||||
})
|
||||
99
江西城市生命线-可交互原型/frontend/src/stores/chat.js
Normal file
99
江西城市生命线-可交互原型/frontend/src/stores/chat.js
Normal file
@@ -0,0 +1,99 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref } from 'vue'
|
||||
import axios from 'axios'
|
||||
|
||||
const api = axios.create({
|
||||
baseURL: '/api',
|
||||
timeout: 30000
|
||||
})
|
||||
|
||||
export const useChatStore = defineStore('chat', () => {
|
||||
const messages = ref([])
|
||||
const isLoading = ref(false)
|
||||
const currentSession = ref(null)
|
||||
|
||||
// Mock responses for when backend is not available
|
||||
const mockResponses = {
|
||||
'城市生命线': '城市生命线是指城市中维持城市正常运转的关键基础设施系统,包括供水、供电、供气、通信、交通等系统。这些系统如同城市的"生命线",一旦发生故障,将对城市运行和居民生活产生重大影响。',
|
||||
'关键设施': '城市生命线关键设施包括:\n1. 供水系统:水厂、管网、加压站\n2. 供电系统:变电站、配电网\n3. 供气系统:门站、调压站、管网\n4. 通信系统:基站、光纤网络\n5. 交通系统:道路、桥梁、隧道',
|
||||
'消防安全': '消防安全隐患常见问题及处理措施:\n1. 消防通道堵塞 - 立即清理,保持畅通\n2. 灭火器过期 - 及时更换检修\n3. 电气线路老化 - 专业检测更换\n4. 易燃物品堆放 - 规范存储管理\n5. 消防设施损坏 - 定期检查维护',
|
||||
'排水': '如何平衡排水能力和生态环境保护:\n1. 采用海绵城市理念,增加透水面积\n2. 建设生态调蓄池,减缓雨水径流\n3. 推广透水铺装,促进雨水下渗\n4. 保护自然水系,维护生态平衡\n5. 雨污分流改造,提高污水处理效率'
|
||||
}
|
||||
|
||||
const getMockResponse = (input) => {
|
||||
for (const [key, value] of Object.entries(mockResponses)) {
|
||||
if (input.includes(key)) {
|
||||
return value
|
||||
}
|
||||
}
|
||||
return `您好!关于"${input}"的问题,我正在为您查询相关资料。作为城市生命线智能助手,我可以帮助您:\n\n1. 查询城市生命线相关知识\n2. 识别潜在安全隐患\n3. 编制应急预案\n4. 撰写公文报告\n\n请问还有什么可以帮助您的?`
|
||||
}
|
||||
|
||||
const sendMessage = async (content) => {
|
||||
isLoading.value = true
|
||||
try {
|
||||
const response = await api.post('/chat/send', {
|
||||
content,
|
||||
role: 'user',
|
||||
sessionId: currentSession.value
|
||||
})
|
||||
return response.data
|
||||
} catch (error) {
|
||||
console.log('Backend not available, using mock response')
|
||||
// Return mock response when backend is not available
|
||||
return {
|
||||
id: Date.now().toString(),
|
||||
content: getMockResponse(content),
|
||||
role: 'assistant',
|
||||
timestamp: new Date().toISOString()
|
||||
}
|
||||
} finally {
|
||||
isLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const getHistory = async () => {
|
||||
try {
|
||||
const response = await api.get('/chat/history')
|
||||
messages.value = response.data
|
||||
return response.data
|
||||
} catch (error) {
|
||||
console.log('Backend not available')
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
const getSuggestions = async () => {
|
||||
try {
|
||||
const response = await api.get('/chat/suggestions')
|
||||
return response.data
|
||||
} catch (error) {
|
||||
return [
|
||||
'城市生命线关键设施有哪些?',
|
||||
'消防安全隐患常见问题以及处理措施有哪些?',
|
||||
'如何平衡排水能力和生态环境保护?'
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
const newChat = async () => {
|
||||
try {
|
||||
await api.post('/chat/new')
|
||||
messages.value = []
|
||||
currentSession.value = Date.now().toString()
|
||||
} catch (error) {
|
||||
messages.value = []
|
||||
currentSession.value = Date.now().toString()
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
messages,
|
||||
isLoading,
|
||||
currentSession,
|
||||
sendMessage,
|
||||
getHistory,
|
||||
getSuggestions,
|
||||
newChat
|
||||
}
|
||||
})
|
||||
140
江西城市生命线-可交互原型/frontend/src/stores/workflow.js
Normal file
140
江西城市生命线-可交互原型/frontend/src/stores/workflow.js
Normal file
@@ -0,0 +1,140 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref, computed } from 'vue'
|
||||
|
||||
export const useWorkflowStore = defineStore('workflow', () => {
|
||||
// 节点列表
|
||||
const nodes = ref([])
|
||||
|
||||
// 连接线列表
|
||||
const connections = ref([])
|
||||
|
||||
// 选中的节点ID
|
||||
const selectedNodeId = ref(null)
|
||||
|
||||
// 节点ID计数器
|
||||
let nodeIdCounter = 1
|
||||
|
||||
// 节点类型定义
|
||||
const nodeTypes = [
|
||||
{ type: 'start', label: '开始', icon: '▶', color: '#10b981', category: 'control' },
|
||||
{ type: 'end', label: '结束', icon: '⏹', color: '#ef4444', category: 'control' },
|
||||
{ type: 'llm', label: 'LLM 模型', icon: '🤖', color: '#7c3aed', category: 'ai' },
|
||||
{ type: 'knowledge', label: '知识库', icon: '📚', color: '#3b82f6', category: 'ai' },
|
||||
{ type: 'condition', label: '条件判断', icon: '⋔', color: '#f59e0b', category: 'logic' },
|
||||
{ type: 'code', label: '代码执行', icon: '{ }', color: '#6366f1', category: 'logic' },
|
||||
{ type: 'http', label: 'HTTP 请求', icon: '🌐', color: '#14b8a6', category: 'integration' },
|
||||
{ type: 'variable', label: '变量赋值', icon: '𝑥=', color: '#8b5cf6', category: 'logic' },
|
||||
{ type: 'template', label: '模板转换', icon: '📝', color: '#ec4899', category: 'transform' },
|
||||
{ type: 'loop', label: '循环', icon: '↻', color: '#f97316', category: 'logic' }
|
||||
]
|
||||
|
||||
// 添加节点
|
||||
const addNode = (type, position) => {
|
||||
const nodeType = nodeTypes.find(n => n.type === type)
|
||||
if (!nodeType) return null
|
||||
|
||||
const newNode = {
|
||||
id: `node_${nodeIdCounter++}`,
|
||||
type: type,
|
||||
label: nodeType.label,
|
||||
icon: nodeType.icon,
|
||||
color: nodeType.color,
|
||||
x: position.x,
|
||||
y: position.y,
|
||||
width: 180,
|
||||
height: 60,
|
||||
inputs: type !== 'start' ? [{ id: 'in_1', label: '输入' }] : [],
|
||||
outputs: type !== 'end' ? [{ id: 'out_1', label: '输出' }] : []
|
||||
}
|
||||
|
||||
nodes.value.push(newNode)
|
||||
return newNode
|
||||
}
|
||||
|
||||
// 更新节点位置
|
||||
const updateNodePosition = (nodeId, x, y) => {
|
||||
const node = nodes.value.find(n => n.id === nodeId)
|
||||
if (node) {
|
||||
node.x = x
|
||||
node.y = y
|
||||
}
|
||||
}
|
||||
|
||||
// 删除节点
|
||||
const deleteNode = (nodeId) => {
|
||||
const index = nodes.value.findIndex(n => n.id === nodeId)
|
||||
if (index > -1) {
|
||||
nodes.value.splice(index, 1)
|
||||
// 删除相关连接
|
||||
connections.value = connections.value.filter(
|
||||
c => c.sourceNodeId !== nodeId && c.targetNodeId !== nodeId
|
||||
)
|
||||
}
|
||||
if (selectedNodeId.value === nodeId) {
|
||||
selectedNodeId.value = null
|
||||
}
|
||||
}
|
||||
|
||||
// 添加连接
|
||||
const addConnection = (sourceNodeId, sourcePortId, targetNodeId, targetPortId) => {
|
||||
// 检查是否已存在相同连接
|
||||
const exists = connections.value.some(
|
||||
c => c.sourceNodeId === sourceNodeId &&
|
||||
c.sourcePortId === sourcePortId &&
|
||||
c.targetNodeId === targetNodeId &&
|
||||
c.targetPortId === targetPortId
|
||||
)
|
||||
if (exists) return null
|
||||
|
||||
const newConnection = {
|
||||
id: `conn_${Date.now()}`,
|
||||
sourceNodeId,
|
||||
sourcePortId,
|
||||
targetNodeId,
|
||||
targetPortId
|
||||
}
|
||||
connections.value.push(newConnection)
|
||||
return newConnection
|
||||
}
|
||||
|
||||
// 删除连接
|
||||
const deleteConnection = (connectionId) => {
|
||||
const index = connections.value.findIndex(c => c.id === connectionId)
|
||||
if (index > -1) {
|
||||
connections.value.splice(index, 1)
|
||||
}
|
||||
}
|
||||
|
||||
// 选中节点
|
||||
const selectNode = (nodeId) => {
|
||||
selectedNodeId.value = nodeId
|
||||
}
|
||||
|
||||
// 清空画布
|
||||
const clearCanvas = () => {
|
||||
nodes.value = []
|
||||
connections.value = []
|
||||
selectedNodeId.value = null
|
||||
nodeIdCounter = 1
|
||||
}
|
||||
|
||||
// 获取节点
|
||||
const getNode = (nodeId) => {
|
||||
return nodes.value.find(n => n.id === nodeId)
|
||||
}
|
||||
|
||||
return {
|
||||
nodes,
|
||||
connections,
|
||||
selectedNodeId,
|
||||
nodeTypes,
|
||||
addNode,
|
||||
updateNodePosition,
|
||||
deleteNode,
|
||||
addConnection,
|
||||
deleteConnection,
|
||||
selectNode,
|
||||
clearCanvas,
|
||||
getNode
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user