RuleWorkflow.vue 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507
  1. <script setup>
  2. import { ref, computed, watch, onMounted, onUnmounted, nextTick, markRaw } from 'vue'
  3. import { VueFlow, useVueFlow } from '@vue-flow/core'
  4. import { Background } from '@vue-flow/background'
  5. import { Controls } from '@vue-flow/controls'
  6. import { MiniMap } from '@vue-flow/minimap'
  7. import { ElMessage, ElMessageBox } from 'element-plus'
  8. import { ArrowLeft, Grid, Connection, Close } from '@element-plus/icons-vue'
  9. import '@vue-flow/core/dist/style.css'
  10. import '@vue-flow/core/dist/theme-default.css'
  11. import '@vue-flow/controls/dist/style.css'
  12. import '@vue-flow/minimap/dist/style.css'
  13. import SourceNode from './nodes/SourceNode.vue'
  14. import ActionNode from './nodes/ActionNode.vue'
  15. import ElementNode from './nodes/ElementNode.vue'
  16. import NodePanel from './panels/NodePanel.vue'
  17. import PropertyPanel from './panels/PropertyPanel.vue'
  18. const props = defineProps({
  19. projectId: { type: Number, required: true },
  20. attachments: { type: Array, default: () => [] },
  21. elements: { type: Array, default: () => [] },
  22. rules: { type: Array, default: () => [] },
  23. targetRule: { type: Object, default: null }, // 编辑的目标规则
  24. targetElement: { type: Object, default: null }, // 目标要素(单要素模式)
  25. workflowTitle: { type: String, default: '新建规则' } // 工作流标题
  26. })
  27. const emit = defineEmits(['save', 'close'])
  28. // 使用 markRaw 避免组件被响应式化
  29. const nodeTypes = {
  30. source: markRaw(SourceNode),
  31. action: markRaw(ActionNode),
  32. element: markRaw(ElementNode)
  33. }
  34. const nodes = ref([])
  35. const edges = ref([])
  36. const selectedNode = ref(null)
  37. const selectedEdge = ref(null)
  38. const selectedNodes = ref([])
  39. // 撤销重做
  40. const historyStack = ref([])
  41. const historyIndex = ref(-1)
  42. const maxHistory = 50
  43. // 右键菜单
  44. const contextMenu = ref({ visible: false, x: 0, y: 0, type: '', target: null })
  45. // 工作流验证
  46. const validationErrors = ref([])
  47. const showValidation = ref(false)
  48. // 复制粘贴
  49. const clipboard = ref(null)
  50. // 规则预览
  51. const showPreview = ref(false)
  52. const previewRules = ref([])
  53. const expandedRuleIdx = ref(null)
  54. const {
  55. onConnect,
  56. addEdges,
  57. onNodesChange,
  58. onEdgesChange,
  59. onNodeClick,
  60. onEdgeClick,
  61. onPaneClick,
  62. onNodeContextMenu,
  63. onEdgeContextMenu,
  64. onPaneContextMenu,
  65. project,
  66. fitView,
  67. getSelectedNodes,
  68. removeNodes,
  69. removeEdges
  70. } = useVueFlow()
  71. // 历史记录
  72. function saveHistory() {
  73. const state = {
  74. nodes: JSON.parse(JSON.stringify(nodes.value)),
  75. edges: JSON.parse(JSON.stringify(edges.value))
  76. }
  77. if (historyIndex.value < historyStack.value.length - 1) {
  78. historyStack.value = historyStack.value.slice(0, historyIndex.value + 1)
  79. }
  80. historyStack.value.push(state)
  81. if (historyStack.value.length > maxHistory) {
  82. historyStack.value.shift()
  83. } else {
  84. historyIndex.value++
  85. }
  86. }
  87. function undo() {
  88. if (historyIndex.value > 0) {
  89. historyIndex.value--
  90. const state = historyStack.value[historyIndex.value]
  91. nodes.value = JSON.parse(JSON.stringify(state.nodes))
  92. edges.value = JSON.parse(JSON.stringify(state.edges))
  93. selectedNode.value = null
  94. selectedEdge.value = null
  95. ElMessage.info('已撤销')
  96. }
  97. }
  98. function redo() {
  99. if (historyIndex.value < historyStack.value.length - 1) {
  100. historyIndex.value++
  101. const state = historyStack.value[historyIndex.value]
  102. nodes.value = JSON.parse(JSON.stringify(state.nodes))
  103. edges.value = JSON.parse(JSON.stringify(state.edges))
  104. selectedNode.value = null
  105. selectedEdge.value = null
  106. ElMessage.info('已重做')
  107. }
  108. }
  109. const canUndo = computed(() => historyIndex.value > 0)
  110. const canRedo = computed(() => historyIndex.value < historyStack.value.length - 1)
  111. // 连接验证
  112. onConnect((params) => {
  113. if (validateConnection(params)) {
  114. saveHistory()
  115. addEdges([{
  116. ...params,
  117. id: `edge-${Date.now()}`,
  118. animated: true,
  119. style: { stroke: '#409eff', strokeWidth: 2 }
  120. }])
  121. } else {
  122. ElMessage.warning('无效的连接:请检查节点类型')
  123. }
  124. })
  125. onNodeClick(({ node }) => {
  126. selectedNode.value = node
  127. selectedEdge.value = null
  128. hideContextMenu()
  129. })
  130. onEdgeClick(({ edge }) => {
  131. selectedEdge.value = edge
  132. selectedNode.value = null
  133. hideContextMenu()
  134. })
  135. onPaneClick(() => {
  136. selectedNode.value = null
  137. selectedEdge.value = null
  138. hideContextMenu()
  139. })
  140. // 右键菜单
  141. onNodeContextMenu(({ event, node }) => {
  142. event.preventDefault()
  143. selectedNode.value = node
  144. showContextMenu(event.clientX, event.clientY, 'node', node)
  145. })
  146. onEdgeContextMenu(({ event, edge }) => {
  147. event.preventDefault()
  148. selectedEdge.value = edge
  149. showContextMenu(event.clientX, event.clientY, 'edge', edge)
  150. })
  151. onPaneContextMenu(({ event }) => {
  152. event.preventDefault()
  153. showContextMenu(event.clientX, event.clientY, 'pane', null)
  154. })
  155. function showContextMenu(x, y, type, target) {
  156. contextMenu.value = { visible: true, x, y, type, target }
  157. }
  158. function hideContextMenu() {
  159. contextMenu.value.visible = false
  160. }
  161. function handleContextMenuAction(action) {
  162. const { type, target } = contextMenu.value
  163. hideContextMenu()
  164. switch (action) {
  165. case 'delete':
  166. if (type === 'node') handleDeleteNode(target.id)
  167. else if (type === 'edge') handleDeleteEdge(target.id)
  168. break
  169. case 'copy':
  170. if (type === 'node') copyNode(target)
  171. break
  172. case 'paste':
  173. pasteNode()
  174. break
  175. case 'duplicate':
  176. if (type === 'node') duplicateNode(target)
  177. break
  178. }
  179. }
  180. function validateConnection(params) {
  181. const sourceNode = nodes.value.find(n => n.id === params.source)
  182. const targetNode = nodes.value.find(n => n.id === params.target)
  183. if (!sourceNode || !targetNode) return false
  184. if (params.source === params.target) return false
  185. // 检查是否已存在连接
  186. const existingEdge = edges.value.find(e =>
  187. e.source === params.source && e.target === params.target
  188. )
  189. if (existingEdge) return false
  190. // 验证连接规则
  191. if (sourceNode.type === 'source' && targetNode.type === 'element') return true
  192. if (sourceNode.type === 'source' && targetNode.type === 'action') return true
  193. if (sourceNode.type === 'action' && targetNode.type === 'element') return true
  194. if (sourceNode.type === 'action' && targetNode.type === 'action') return true
  195. return false
  196. }
  197. function onDragOver(event) {
  198. event.preventDefault()
  199. event.dataTransfer.dropEffect = 'move'
  200. }
  201. function onDrop(event) {
  202. event.preventDefault()
  203. const dataStr = event.dataTransfer.getData('application/vueflow')
  204. if (!dataStr) return
  205. saveHistory()
  206. const data = JSON.parse(dataStr)
  207. const position = project({ x: event.clientX - 220, y: event.clientY - 60 })
  208. const newNode = {
  209. id: `node-${Date.now()}`,
  210. type: data.nodeType,
  211. position,
  212. data: {
  213. ...data,
  214. label: data.label || data.nodeType
  215. }
  216. }
  217. nodes.value.push(newNode)
  218. setTimeout(() => {
  219. selectedNode.value = newNode
  220. }, 50)
  221. }
  222. function handleNodeUpdate(nodeId, newData) {
  223. saveHistory()
  224. const node = nodes.value.find(n => n.id === nodeId)
  225. if (node) {
  226. node.data = { ...node.data, ...newData }
  227. }
  228. }
  229. function handleDeleteNode(nodeId) {
  230. saveHistory()
  231. nodes.value = nodes.value.filter(n => n.id !== nodeId)
  232. edges.value = edges.value.filter(e => e.source !== nodeId && e.target !== nodeId)
  233. selectedNode.value = null
  234. }
  235. function handleDeleteEdge(edgeId) {
  236. saveHistory()
  237. edges.value = edges.value.filter(e => e.id !== edgeId)
  238. selectedEdge.value = null
  239. }
  240. // 复制粘贴
  241. function copyNode(node) {
  242. clipboard.value = JSON.parse(JSON.stringify(node))
  243. ElMessage.success('已复制节点')
  244. }
  245. function pasteNode() {
  246. if (!clipboard.value) {
  247. ElMessage.warning('剪贴板为空')
  248. return
  249. }
  250. saveHistory()
  251. const newNode = {
  252. ...clipboard.value,
  253. id: `node-${Date.now()}`,
  254. position: {
  255. x: clipboard.value.position.x + 50,
  256. y: clipboard.value.position.y + 50
  257. }
  258. }
  259. nodes.value.push(newNode)
  260. selectedNode.value = newNode
  261. ElMessage.success('已粘贴节点')
  262. }
  263. function duplicateNode(node) {
  264. saveHistory()
  265. const newNode = {
  266. ...JSON.parse(JSON.stringify(node)),
  267. id: `node-${Date.now()}`,
  268. position: {
  269. x: node.position.x + 50,
  270. y: node.position.y + 50
  271. }
  272. }
  273. nodes.value.push(newNode)
  274. selectedNode.value = newNode
  275. }
  276. // 工作流验证
  277. function validateWorkflow() {
  278. const errors = []
  279. // 检查孤立节点
  280. const connectedNodeIds = new Set()
  281. edges.value.forEach(e => {
  282. connectedNodeIds.add(e.source)
  283. connectedNodeIds.add(e.target)
  284. })
  285. nodes.value.forEach(node => {
  286. if (!connectedNodeIds.has(node.id)) {
  287. errors.push({ type: 'warning', nodeId: node.id, message: `节点 "${node.data.label}" 未连接` })
  288. }
  289. })
  290. // 检查来源节点配置
  291. nodes.value.filter(n => n.type === 'source').forEach(node => {
  292. if (node.data.subType === 'attachment' && !node.data.sourceNodeId) {
  293. errors.push({ type: 'error', nodeId: node.id, message: `来源节点 "${node.data.label}" 未选择附件` })
  294. }
  295. })
  296. // 检查输出节点配置
  297. nodes.value.filter(n => n.type === 'element').forEach(node => {
  298. if (!node.data.elementKey) {
  299. errors.push({ type: 'error', nodeId: node.id, message: `输出节点 "${node.data.label}" 未选择要素` })
  300. }
  301. })
  302. // 检查动作节点配置
  303. nodes.value.filter(n => n.type === 'action').forEach(node => {
  304. const actionType = node.data.actionType || node.data.subType
  305. if (['summary', 'ai_extract'].includes(actionType) && !node.data.prompt) {
  306. errors.push({ type: 'warning', nodeId: node.id, message: `动作节点 "${node.data.label}" 建议配置提示词` })
  307. }
  308. })
  309. // 检查完整的数据流
  310. const elementNodes = nodes.value.filter(n => n.type === 'element')
  311. elementNodes.forEach(elemNode => {
  312. const hasInput = edges.value.some(e => e.target === elemNode.id)
  313. if (!hasInput) {
  314. errors.push({ type: 'error', nodeId: elemNode.id, message: `输出节点 "${elemNode.data.label}" 没有输入连接` })
  315. }
  316. })
  317. validationErrors.value = errors
  318. showValidation.value = true
  319. if (errors.length === 0) {
  320. ElMessage.success('工作流验证通过')
  321. } else {
  322. const errorCount = errors.filter(e => e.type === 'error').length
  323. const warningCount = errors.filter(e => e.type === 'warning').length
  324. ElMessage.warning(`发现 ${errorCount} 个错误,${warningCount} 个警告`)
  325. }
  326. return errors.filter(e => e.type === 'error').length === 0
  327. }
  328. function highlightNode(nodeId) {
  329. const node = nodes.value.find(n => n.id === nodeId)
  330. if (node) {
  331. selectedNode.value = node
  332. // 滚动到节点位置
  333. }
  334. }
  335. function handleSave() {
  336. if (!validateWorkflow()) {
  337. ElMessageBox.confirm('工作流存在错误,是否仍要保存?', '验证警告', {
  338. confirmButtonText: '继续保存',
  339. cancelButtonText: '返回修改',
  340. type: 'warning'
  341. }).then(() => {
  342. showRulePreview()
  343. }).catch(() => {})
  344. } else {
  345. showRulePreview()
  346. }
  347. }
  348. function showRulePreview() {
  349. const rules = generateRulesFromWorkflow()
  350. if (rules.length === 0) {
  351. ElMessage.warning('没有可保存的规则,请确保有完整的数据流(来源 → 输出)')
  352. return
  353. }
  354. previewRules.value = rules
  355. showPreview.value = true
  356. }
  357. function generateRulesFromWorkflow() {
  358. const rules = []
  359. const elementNodes = nodes.value.filter(n => n.type === 'element')
  360. function traceDataFlow(nodeId, visited = new Set()) {
  361. if (visited.has(nodeId)) return { sources: [], actions: [] }
  362. visited.add(nodeId)
  363. const node = nodes.value.find(n => n.id === nodeId)
  364. if (!node) return { sources: [], actions: [] }
  365. if (node.type === 'source') {
  366. return { sources: [node], actions: [] }
  367. }
  368. if (node.type === 'action') {
  369. const inEdges = edges.value.filter(e => e.target === nodeId)
  370. let allSources = []
  371. let allActions = [node]
  372. for (const edge of inEdges) {
  373. const upstream = traceDataFlow(edge.source, visited)
  374. allSources = [...allSources, ...upstream.sources]
  375. allActions = [...allActions, ...upstream.actions]
  376. }
  377. return { sources: allSources, actions: allActions }
  378. }
  379. return { sources: [], actions: [] }
  380. }
  381. for (const elementNode of elementNodes) {
  382. if (!elementNode.data.elementKey) continue
  383. const incomingEdges = edges.value.filter(e => e.target === elementNode.id)
  384. if (incomingEdges.length === 0) continue
  385. let allSources = []
  386. let allActions = []
  387. for (const edge of incomingEdges) {
  388. const { sources, actions } = traceDataFlow(edge.source)
  389. allSources = [...allSources, ...sources]
  390. allActions = [...allActions, ...actions]
  391. }
  392. const uniqueSources = [...new Map(allSources.map(s => [s.id, s])).values()]
  393. const uniqueActions = [...new Map(allActions.map(a => [a.id, a])).values()]
  394. const directInputNode = nodes.value.find(n => n.id === incomingEdges[0].source)
  395. let primaryAction = directInputNode?.type === 'action' ? directInputNode : uniqueActions[0]
  396. const actionType = primaryAction?.data?.actionType || primaryAction?.data?.subType || 'quote'
  397. rules.push({
  398. elementKey: elementNode.data.elementKey,
  399. elementName: elementNode.data.elementName || elementNode.data.label,
  400. actionType: actionType,
  401. actionLabel: getActionLabel(actionType),
  402. prompt: primaryAction?.data?.prompt || '',
  403. sources: uniqueSources.map(s => ({
  404. name: s.data.sourceName || s.data.label,
  405. type: s.data.subType,
  406. locatorType: s.data.locatorType
  407. })),
  408. actionsCount: uniqueActions.length
  409. })
  410. }
  411. return rules
  412. }
  413. function confirmSave() {
  414. showPreview.value = false
  415. doSave()
  416. }
  417. function doSave() {
  418. const workflowData = {
  419. nodes: nodes.value,
  420. edges: edges.value
  421. }
  422. emit('save', workflowData)
  423. }
  424. function handleClear() {
  425. ElMessageBox.confirm('确定要清空画布吗?此操作不可撤销。', '确认清空', {
  426. confirmButtonText: '确定',
  427. cancelButtonText: '取消',
  428. type: 'warning'
  429. }).then(() => {
  430. saveHistory()
  431. nodes.value = []
  432. edges.value = []
  433. selectedNode.value = null
  434. selectedEdge.value = null
  435. ElMessage.success('画布已清空')
  436. }).catch(() => {})
  437. }
  438. function handleFitView() {
  439. fitView({ padding: 0.2 })
  440. }
  441. // 快捷键
  442. function handleKeydown(event) {
  443. // 忽略输入框中的快捷键
  444. if (['INPUT', 'TEXTAREA'].includes(event.target.tagName)) return
  445. const isMac = navigator.platform.toUpperCase().indexOf('MAC') >= 0
  446. const ctrlKey = isMac ? event.metaKey : event.ctrlKey
  447. switch (event.key) {
  448. case 'Delete':
  449. case 'Backspace':
  450. if (selectedNode.value) {
  451. handleDeleteNode(selectedNode.value.id)
  452. } else if (selectedEdge.value) {
  453. handleDeleteEdge(selectedEdge.value.id)
  454. }
  455. event.preventDefault()
  456. break
  457. case 'z':
  458. if (ctrlKey && event.shiftKey) {
  459. redo()
  460. event.preventDefault()
  461. } else if (ctrlKey) {
  462. undo()
  463. event.preventDefault()
  464. }
  465. break
  466. case 'y':
  467. if (ctrlKey) {
  468. redo()
  469. event.preventDefault()
  470. }
  471. break
  472. case 'c':
  473. if (ctrlKey && selectedNode.value) {
  474. copyNode(selectedNode.value)
  475. event.preventDefault()
  476. }
  477. break
  478. case 'v':
  479. if (ctrlKey) {
  480. pasteNode()
  481. event.preventDefault()
  482. }
  483. break
  484. case 'd':
  485. if (ctrlKey && selectedNode.value) {
  486. duplicateNode(selectedNode.value)
  487. event.preventDefault()
  488. }
  489. break
  490. case 's':
  491. if (ctrlKey) {
  492. handleSave()
  493. event.preventDefault()
  494. }
  495. break
  496. case 'Escape':
  497. selectedNode.value = null
  498. selectedEdge.value = null
  499. hideContextMenu()
  500. break
  501. case 'a':
  502. if (ctrlKey) {
  503. // 全选节点
  504. event.preventDefault()
  505. }
  506. break
  507. }
  508. }
  509. // VueFlow 初始化完成后调用
  510. const flowInitialized = ref(false)
  511. function onFlowInit() {
  512. console.log('VueFlow initialized, nodes:', nodes.value.length)
  513. flowInitialized.value = true
  514. // 延迟 fitView 确保节点已渲染
  515. setTimeout(() => {
  516. console.log('Calling fitView with nodes:', nodes.value.length)
  517. if (nodes.value.length > 0) {
  518. fitView({ padding: 0.2, maxZoom: 1, includeHiddenNodes: true })
  519. }
  520. }, 200)
  521. }
  522. onMounted(() => {
  523. // 如果有目标规则,加载该规则的工作流
  524. if (props.targetRule) {
  525. loadSingleRuleAsWorkflow(props.targetRule)
  526. } else if (props.targetElement) {
  527. // 新建规则模式:预置目标要素节点
  528. initWithTargetElement(props.targetElement)
  529. }
  530. // 新建模式(无 targetRule 和 targetElement):空白画布,不加载任何规则
  531. // 保存初始状态
  532. saveHistory()
  533. // 注册快捷键
  534. window.addEventListener('keydown', handleKeydown)
  535. })
  536. onUnmounted(() => {
  537. window.removeEventListener('keydown', handleKeydown)
  538. })
  539. // 加载单个规则为工作流(编辑模式)
  540. function loadSingleRuleAsWorkflow(rule) {
  541. console.log('loadSingleRuleAsWorkflow:', rule)
  542. const newNodes = []
  543. const newEdges = []
  544. const y = 150
  545. const elementId = `element-${rule.id}`
  546. const sourceId = `source-${rule.id}`
  547. const actionId = `action-${rule.id}`
  548. let lastNodeId = null
  549. let xPos = 50
  550. const nodeSpacing = 250 // 节点间距
  551. // 1. 添加来源节点
  552. // 对于 use_entity_value(人工录入)类型,添加一个"人工录入"来源节点
  553. if (rule.actionType === 'use_entity_value') {
  554. newNodes.push({
  555. id: sourceId,
  556. type: 'source',
  557. position: { x: xPos, y },
  558. data: {
  559. nodeType: 'source',
  560. subType: 'manual',
  561. label: '人工录入',
  562. sourceName: '人工录入',
  563. sourceText: '用户手工输入的值'
  564. }
  565. })
  566. lastNodeId = sourceId
  567. xPos += nodeSpacing
  568. } else if (rule.inputs && rule.inputs.length > 0) {
  569. // 其他类型:从 inputs 获取来源
  570. const input = rule.inputs[0]
  571. newNodes.push({
  572. id: sourceId,
  573. type: 'source',
  574. position: { x: xPos, y },
  575. data: {
  576. nodeType: 'source',
  577. subType: input.inputType || 'attachment',
  578. label: input.sourceName || input.inputName || '来源',
  579. sourceNodeId: input.sourceNodeId,
  580. sourceName: input.sourceName || input.inputName,
  581. sourceText: input.sourceText
  582. }
  583. })
  584. lastNodeId = sourceId
  585. xPos += nodeSpacing
  586. }
  587. // 2. 添加动作节点(如果不是 quote 和 use_entity_value 类型)
  588. if (rule.actionType && rule.actionType !== 'quote' && rule.actionType !== 'use_entity_value') {
  589. let prompt = ''
  590. try {
  591. prompt = rule.actionConfig ? JSON.parse(rule.actionConfig).prompt : ''
  592. } catch (e) {}
  593. newNodes.push({
  594. id: actionId,
  595. type: 'action',
  596. position: { x: xPos, y },
  597. data: {
  598. nodeType: 'action',
  599. subType: rule.actionType,
  600. label: getActionLabel(rule.actionType),
  601. actionType: rule.actionType,
  602. prompt: prompt
  603. }
  604. })
  605. // 连接来源到动作
  606. if (lastNodeId) {
  607. newEdges.push({
  608. id: `edge-${lastNodeId}-${actionId}`,
  609. source: lastNodeId,
  610. target: actionId,
  611. animated: true,
  612. style: { stroke: '#409eff', strokeWidth: 2 }
  613. })
  614. }
  615. lastNodeId = actionId
  616. xPos += nodeSpacing
  617. }
  618. // 3. 添加输出节点(目标要素)
  619. newNodes.push({
  620. id: elementId,
  621. type: 'element',
  622. position: { x: xPos, y },
  623. data: {
  624. nodeType: 'element',
  625. label: rule.elementKey,
  626. elementKey: rule.elementKey,
  627. elementName: getElementName(rule.elementKey)
  628. }
  629. })
  630. // 连接到输出节点
  631. if (lastNodeId) {
  632. newEdges.push({
  633. id: `edge-${lastNodeId}-${elementId}`,
  634. source: lastNodeId,
  635. target: elementId,
  636. animated: true,
  637. style: { stroke: '#67c23a', strokeWidth: 2 }
  638. })
  639. }
  640. console.log('Setting nodes:', newNodes.length, 'edges:', newEdges.length)
  641. nodes.value = newNodes
  642. edges.value = newEdges
  643. console.log('After set - nodes:', nodes.value.length, 'edges:', edges.value.length)
  644. }
  645. // 新建规则模式:预置目标要素节点
  646. function initWithTargetElement(element) {
  647. const elementId = `element-new-${Date.now()}`
  648. nodes.value = [{
  649. id: elementId,
  650. type: 'element',
  651. position: { x: 400, y: 150 },
  652. data: {
  653. nodeType: 'element',
  654. label: element.elementName || element.elementKey,
  655. elementKey: element.elementKey,
  656. elementName: element.elementName || element.elementKey
  657. }
  658. }]
  659. edges.value = []
  660. setTimeout(() => fitView({ padding: 0.3 }), 100)
  661. }
  662. function loadRulesAsWorkflow(rules) {
  663. const newNodes = []
  664. const newEdges = []
  665. let xOffset = 100
  666. let yOffset = 100
  667. rules.forEach((rule, index) => {
  668. const y = yOffset + index * 150
  669. if (rule.inputs && rule.inputs.length > 0) {
  670. const input = rule.inputs[0]
  671. const sourceId = `source-${rule.id}-${index}`
  672. newNodes.push({
  673. id: sourceId,
  674. type: 'source',
  675. position: { x: xOffset, y },
  676. data: {
  677. nodeType: 'source',
  678. subType: input.inputType || 'attachment',
  679. label: input.sourceName || input.inputName || '来源',
  680. sourceNodeId: input.sourceNodeId,
  681. sourceName: input.sourceName || input.inputName,
  682. sourceText: input.sourceText
  683. }
  684. })
  685. if (rule.actionType && rule.actionType !== 'quote') {
  686. const actionId = `action-${rule.id}-${index}`
  687. newNodes.push({
  688. id: actionId,
  689. type: 'action',
  690. position: { x: xOffset + 200, y },
  691. data: {
  692. nodeType: 'action',
  693. subType: rule.actionType,
  694. label: getActionLabel(rule.actionType),
  695. actionType: rule.actionType,
  696. prompt: rule.actionConfig ? JSON.parse(rule.actionConfig).prompt : ''
  697. }
  698. })
  699. newEdges.push({
  700. id: `edge-${sourceId}-${actionId}`,
  701. source: sourceId,
  702. target: actionId,
  703. animated: true,
  704. style: { stroke: '#409eff', strokeWidth: 2 }
  705. })
  706. const elementId = `element-${rule.id}-${index}`
  707. newNodes.push({
  708. id: elementId,
  709. type: 'element',
  710. position: { x: xOffset + 400, y },
  711. data: {
  712. nodeType: 'element',
  713. label: rule.elementKey,
  714. elementKey: rule.elementKey,
  715. elementName: getElementName(rule.elementKey)
  716. }
  717. })
  718. newEdges.push({
  719. id: `edge-${actionId}-${elementId}`,
  720. source: actionId,
  721. target: elementId,
  722. animated: true,
  723. style: { stroke: '#409eff', strokeWidth: 2 }
  724. })
  725. } else {
  726. const elementId = `element-${rule.id}-${index}`
  727. newNodes.push({
  728. id: elementId,
  729. type: 'element',
  730. position: { x: xOffset + 250, y },
  731. data: {
  732. nodeType: 'element',
  733. label: rule.elementKey,
  734. elementKey: rule.elementKey,
  735. elementName: getElementName(rule.elementKey)
  736. }
  737. })
  738. newEdges.push({
  739. id: `edge-${sourceId}-${elementId}`,
  740. source: sourceId,
  741. target: elementId,
  742. animated: true,
  743. style: { stroke: '#67c23a', strokeWidth: 2 }
  744. })
  745. }
  746. }
  747. })
  748. nodes.value = newNodes
  749. edges.value = newEdges
  750. setTimeout(() => fitView({ padding: 0.2 }), 100)
  751. }
  752. function getActionLabel(actionType) {
  753. const labels = {
  754. quote: '引用',
  755. summary: 'AI 总结',
  756. ai_extract: 'AI 提取',
  757. table_extract: '表格提取'
  758. }
  759. return labels[actionType] || actionType
  760. }
  761. function getElementName(elementKey) {
  762. const elem = props.elements.find(e => e.elementKey === elementKey)
  763. return elem ? elem.elementName : elementKey
  764. }
  765. function getActionTagType(actionType) {
  766. const types = {
  767. quote: 'success',
  768. summary: 'warning',
  769. ai_extract: '',
  770. table_extract: 'info'
  771. }
  772. return types[actionType] || 'info'
  773. }
  774. defineExpose({
  775. handleSave,
  776. handleClear,
  777. handleFitView,
  778. undo,
  779. redo,
  780. validateWorkflow
  781. })
  782. </script>
  783. <template>
  784. <div class="rule-workflow" @click="hideContextMenu">
  785. <div class="workflow-toolbar">
  786. <div class="toolbar-left">
  787. <el-button text circle @click="$emit('close')" title="返回" class="back-button">
  788. <el-icon :size="20"><ArrowLeft /></el-icon>
  789. </el-button>
  790. <el-divider direction="vertical" />
  791. <div class="workflow-title">{{ workflowTitle }}</div>
  792. <el-divider direction="vertical" />
  793. <el-button-group>
  794. <el-button :disabled="!canUndo" @click="undo" title="撤销 (Ctrl+Z)" :icon="'RefreshLeft'">
  795. 撤销
  796. </el-button>
  797. <el-button :disabled="!canRedo" @click="redo" title="重做 (Ctrl+Y)" :icon="'RefreshRight'">
  798. 重做
  799. </el-button>
  800. </el-button-group>
  801. <el-divider direction="vertical" />
  802. <el-button @click="handleFitView" title="适应视图" :icon="'FullScreen'">适应</el-button>
  803. <el-button @click="validateWorkflow" title="验证工作流" :icon="'CircleCheck'">验证</el-button>
  804. <el-button type="danger" plain @click="handleClear" :icon="'Delete'">清空</el-button>
  805. </div>
  806. <div class="toolbar-right">
  807. <span class="workflow-stats">
  808. <el-icon><Grid /></el-icon>
  809. <span>{{ nodes.length }} 节点</span>
  810. <span class="stats-divider">·</span>
  811. <el-icon><Connection /></el-icon>
  812. <span>{{ edges.length }} 连线</span>
  813. </span>
  814. <el-tag v-if="validationErrors.length > 0" type="warning" size="small">
  815. {{ validationErrors.filter(e => e.type === 'error').length }} 错误
  816. </el-tag>
  817. <el-divider direction="vertical" />
  818. <el-button type="primary" @click="handleSave" title="保存 (Ctrl+S)" :icon="'Check'">
  819. 保存规则
  820. </el-button>
  821. <el-button text circle @click="$emit('close')" title="关闭" class="close-button">
  822. <el-icon :size="18"><Close /></el-icon>
  823. </el-button>
  824. </div>
  825. </div>
  826. <!-- 验证结果面板 -->
  827. <div class="validation-panel" v-if="showValidation && validationErrors.length > 0">
  828. <div class="validation-header">
  829. <span>验证结果</span>
  830. <el-button text size="small" @click="showValidation = false">✕</el-button>
  831. </div>
  832. <div class="validation-list">
  833. <div
  834. v-for="(err, idx) in validationErrors"
  835. :key="idx"
  836. class="validation-item"
  837. :class="err.type"
  838. @click="highlightNode(err.nodeId)"
  839. >
  840. <span class="validation-icon">{{ err.type === 'error' ? '❌' : '⚠️' }}</span>
  841. <span class="validation-msg">{{ err.message }}</span>
  842. </div>
  843. </div>
  844. </div>
  845. <div class="workflow-container">
  846. <NodePanel
  847. :attachments="attachments"
  848. :elements="elements"
  849. class="workflow-node-panel"
  850. />
  851. <div class="workflow-canvas" @dragover="onDragOver" @drop="onDrop">
  852. <VueFlow
  853. v-model:nodes="nodes"
  854. v-model:edges="edges"
  855. :node-types="nodeTypes"
  856. :default-viewport="{ zoom: 1, x: 0, y: 0 }"
  857. :min-zoom="0.2"
  858. :max-zoom="2"
  859. class="vue-flow-wrapper"
  860. @init="onFlowInit"
  861. >
  862. <Background pattern-color="#aaa" :gap="16" />
  863. <Controls position="bottom-left" />
  864. <MiniMap position="bottom-right" />
  865. </VueFlow>
  866. <!-- 右键菜单 -->
  867. <div
  868. v-if="contextMenu.visible"
  869. class="context-menu"
  870. :style="{ left: contextMenu.x + 'px', top: contextMenu.y + 'px' }"
  871. @click.stop
  872. >
  873. <template v-if="contextMenu.type === 'node'">
  874. <div class="context-menu-item" @click="handleContextMenuAction('copy')">
  875. 📋 复制 <span class="shortcut">Ctrl+C</span>
  876. </div>
  877. <div class="context-menu-item" @click="handleContextMenuAction('duplicate')">
  878. 📑 复制节点 <span class="shortcut">Ctrl+D</span>
  879. </div>
  880. <div class="context-menu-divider"></div>
  881. <div class="context-menu-item danger" @click="handleContextMenuAction('delete')">
  882. 🗑️ 删除 <span class="shortcut">Delete</span>
  883. </div>
  884. </template>
  885. <template v-else-if="contextMenu.type === 'edge'">
  886. <div class="context-menu-item danger" @click="handleContextMenuAction('delete')">
  887. 🗑️ 删除连线 <span class="shortcut">Delete</span>
  888. </div>
  889. </template>
  890. <template v-else>
  891. <div class="context-menu-item" @click="handleContextMenuAction('paste')" :class="{ disabled: !clipboard }">
  892. 📋 粘贴 <span class="shortcut">Ctrl+V</span>
  893. </div>
  894. <div class="context-menu-divider"></div>
  895. <div class="context-menu-item" @click="handleFitView">
  896. 📐 适应视图
  897. </div>
  898. </template>
  899. </div>
  900. </div>
  901. <PropertyPanel
  902. :selected-node="selectedNode"
  903. :selected-edge="selectedEdge"
  904. :attachments="attachments"
  905. :elements="elements"
  906. class="workflow-property-panel"
  907. @update-node="handleNodeUpdate"
  908. @delete-node="handleDeleteNode"
  909. @delete-edge="handleDeleteEdge"
  910. />
  911. </div>
  912. <!-- 快捷键提示 -->
  913. <div class="shortcuts-hint">
  914. <span>快捷键: Ctrl+S 保存 | Ctrl+Z 撤销 | Ctrl+Y 重做 | Delete 删除 | Ctrl+C/V 复制粘贴</span>
  915. </div>
  916. <!-- 规则预览弹窗 -->
  917. <el-dialog
  918. v-model="showPreview"
  919. title="📋 规则预览"
  920. width="700"
  921. :close-on-click-modal="false"
  922. >
  923. <div class="preview-content">
  924. <p class="preview-desc">将创建以下 <strong>{{ previewRules.length }}</strong> 条规则:</p>
  925. <div class="preview-list">
  926. <div
  927. v-for="(rule, idx) in previewRules"
  928. :key="idx"
  929. class="preview-item"
  930. :class="{ expanded: expandedRuleIdx === idx }"
  931. >
  932. <div class="preview-header" @click="expandedRuleIdx = expandedRuleIdx === idx ? null : idx">
  933. <span class="preview-index">{{ idx + 1 }}</span>
  934. <span class="preview-element">{{ rule.elementName }}</span>
  935. <el-tag size="small" :type="getActionTagType(rule.actionType)">
  936. {{ rule.actionLabel }}
  937. </el-tag>
  938. <span class="preview-sources-count" v-if="rule.sources.length > 0">
  939. 📎 {{ rule.sources.length }}
  940. </span>
  941. <span class="preview-expand-icon">{{ expandedRuleIdx === idx ? '▼' : '▶' }}</span>
  942. </div>
  943. <div class="preview-body" v-show="expandedRuleIdx === idx">
  944. <div class="preview-row">
  945. <span class="preview-label">要素标识:</span>
  946. <code class="preview-value">{{ rule.elementKey }}</code>
  947. </div>
  948. <div class="preview-row" v-if="rule.sources.length > 0">
  949. <span class="preview-label">数据来源:</span>
  950. <span class="preview-value">
  951. <el-tag v-for="(src, i) in rule.sources" :key="i" size="small" type="info" class="source-tag">
  952. 📎 {{ src.name }}
  953. </el-tag>
  954. </span>
  955. </div>
  956. <div class="preview-row" v-if="rule.prompt">
  957. <span class="preview-label">提示词:</span>
  958. <span class="preview-value preview-prompt">{{ rule.prompt }}</span>
  959. </div>
  960. </div>
  961. </div>
  962. </div>
  963. </div>
  964. <template #footer>
  965. <el-button @click="showPreview = false">取消</el-button>
  966. <el-button type="primary" @click="confirmSave">
  967. 确认保存 ({{ previewRules.length }} 条规则)
  968. </el-button>
  969. </template>
  970. </el-dialog>
  971. </div>
  972. </template>
  973. <style scoped>
  974. .rule-workflow {
  975. display: flex;
  976. flex-direction: column;
  977. height: 100vh;
  978. background: #f5f7fa;
  979. }
  980. .workflow-toolbar {
  981. display: flex;
  982. justify-content: space-between;
  983. align-items: center;
  984. padding: 14px 20px;
  985. background: linear-gradient(135deg, #ffffff 0%, #fafbfc 100%);
  986. border-bottom: 1.5px solid #e8ecf0;
  987. box-shadow: 0 1px 3px rgba(0, 0, 0, 0.02);
  988. }
  989. .toolbar-left {
  990. display: flex;
  991. align-items: center;
  992. gap: 10px;
  993. }
  994. .workflow-title {
  995. font-size: 16px;
  996. font-weight: 700;
  997. color: #1f2937;
  998. letter-spacing: 0.3px;
  999. }
  1000. .back-button {
  1001. width: 36px;
  1002. height: 36px;
  1003. border-radius: 10px;
  1004. transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  1005. &:hover {
  1006. background: linear-gradient(135deg, #f0f7ff 0%, #e6f0ff 100%);
  1007. transform: translateX(-2px);
  1008. }
  1009. }
  1010. .close-button {
  1011. width: 36px;
  1012. height: 36px;
  1013. border-radius: 10px;
  1014. transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  1015. &:hover {
  1016. background: #fee;
  1017. color: #f56c6c;
  1018. }
  1019. }
  1020. .toolbar-right {
  1021. display: flex;
  1022. align-items: center;
  1023. gap: 12px;
  1024. }
  1025. .workflow-stats {
  1026. display: flex;
  1027. align-items: center;
  1028. gap: 8px;
  1029. font-size: 13px;
  1030. color: #606266;
  1031. padding: 6px 12px;
  1032. background: #f5f7fa;
  1033. border-radius: 8px;
  1034. font-weight: 500;
  1035. .el-icon {
  1036. font-size: 16px;
  1037. color: #909399;
  1038. }
  1039. .stats-divider {
  1040. color: #d0d7de;
  1041. margin: 0 4px;
  1042. }
  1043. }
  1044. .workflow-container {
  1045. display: flex;
  1046. flex: 1;
  1047. overflow: hidden;
  1048. }
  1049. .workflow-node-panel {
  1050. width: 280px;
  1051. flex-shrink: 0;
  1052. background: white;
  1053. border-right: 1px solid #e4e7ed;
  1054. overflow-y: auto;
  1055. }
  1056. .workflow-canvas {
  1057. flex: 1;
  1058. position: relative;
  1059. }
  1060. .vue-flow-wrapper {
  1061. width: 100%;
  1062. height: 100%;
  1063. }
  1064. .workflow-property-panel {
  1065. width: 300px;
  1066. flex-shrink: 0;
  1067. background: white;
  1068. border-left: 1px solid #e4e7ed;
  1069. overflow-y: auto;
  1070. }
  1071. :deep(.vue-flow__node) {
  1072. cursor: grab;
  1073. }
  1074. :deep(.vue-flow__node:active) {
  1075. cursor: grabbing;
  1076. }
  1077. :deep(.vue-flow__edge-path) {
  1078. stroke-width: 2;
  1079. }
  1080. :deep(.vue-flow__handle) {
  1081. width: 12px;
  1082. height: 12px;
  1083. border-radius: 50%;
  1084. background: #409eff;
  1085. border: 2px solid white;
  1086. }
  1087. :deep(.vue-flow__handle-left) {
  1088. left: -6px;
  1089. }
  1090. :deep(.vue-flow__handle-right) {
  1091. right: -6px;
  1092. }
  1093. /* 验证面板 */
  1094. .validation-panel {
  1095. background: #fef0f0;
  1096. border-bottom: 1px solid #fbc4c4;
  1097. padding: 8px 16px;
  1098. }
  1099. .validation-header {
  1100. display: flex;
  1101. justify-content: space-between;
  1102. align-items: center;
  1103. font-size: 13px;
  1104. font-weight: 500;
  1105. color: #f56c6c;
  1106. margin-bottom: 8px;
  1107. }
  1108. .validation-list {
  1109. display: flex;
  1110. flex-wrap: wrap;
  1111. gap: 8px;
  1112. }
  1113. .validation-item {
  1114. display: flex;
  1115. align-items: center;
  1116. gap: 4px;
  1117. padding: 4px 10px;
  1118. border-radius: 4px;
  1119. font-size: 12px;
  1120. cursor: pointer;
  1121. transition: all 0.2s;
  1122. }
  1123. .validation-item.error {
  1124. background: #fef0f0;
  1125. color: #f56c6c;
  1126. border: 1px solid #fbc4c4;
  1127. }
  1128. .validation-item.warning {
  1129. background: #fdf6ec;
  1130. color: #e6a23c;
  1131. border: 1px solid #f5dab1;
  1132. }
  1133. .validation-item:hover {
  1134. transform: translateY(-1px);
  1135. box-shadow: 0 2px 6px rgba(0,0,0,0.1);
  1136. }
  1137. .validation-icon {
  1138. font-size: 12px;
  1139. }
  1140. .validation-msg {
  1141. max-width: 300px;
  1142. white-space: nowrap;
  1143. overflow: hidden;
  1144. text-overflow: ellipsis;
  1145. }
  1146. /* 右键菜单 */
  1147. .context-menu {
  1148. position: fixed;
  1149. background: white;
  1150. border-radius: 8px;
  1151. box-shadow: 0 4px 16px rgba(0,0,0,0.15);
  1152. min-width: 180px;
  1153. padding: 6px 0;
  1154. z-index: 1000;
  1155. }
  1156. .context-menu-item {
  1157. display: flex;
  1158. align-items: center;
  1159. justify-content: space-between;
  1160. padding: 10px 16px;
  1161. font-size: 13px;
  1162. color: #303133;
  1163. cursor: pointer;
  1164. transition: background 0.15s;
  1165. }
  1166. .context-menu-item:hover {
  1167. background: #f5f7fa;
  1168. }
  1169. .context-menu-item.danger {
  1170. color: #f56c6c;
  1171. }
  1172. .context-menu-item.danger:hover {
  1173. background: #fef0f0;
  1174. }
  1175. .context-menu-item.disabled {
  1176. color: #c0c4cc;
  1177. cursor: not-allowed;
  1178. }
  1179. .context-menu-item.disabled:hover {
  1180. background: transparent;
  1181. }
  1182. .context-menu-item .shortcut {
  1183. font-size: 11px;
  1184. color: #909399;
  1185. margin-left: 20px;
  1186. }
  1187. .context-menu-divider {
  1188. height: 1px;
  1189. background: #e4e7ed;
  1190. margin: 6px 0;
  1191. }
  1192. /* 快捷键提示 */
  1193. .shortcuts-hint {
  1194. padding: 8px 16px;
  1195. background: #f5f7fa;
  1196. border-top: 1px solid #e4e7ed;
  1197. font-size: 11px;
  1198. color: #909399;
  1199. text-align: center;
  1200. }
  1201. /* 工具栏分隔线 */
  1202. .toolbar-left :deep(.el-divider--vertical) {
  1203. height: 20px;
  1204. margin: 0 8px;
  1205. }
  1206. /* 规则预览弹窗 */
  1207. .preview-content {
  1208. max-height: 60vh;
  1209. overflow-y: auto;
  1210. }
  1211. .preview-desc {
  1212. margin-bottom: 16px;
  1213. color: #606266;
  1214. font-size: 14px;
  1215. }
  1216. .preview-list {
  1217. display: flex;
  1218. flex-direction: column;
  1219. gap: 12px;
  1220. }
  1221. .preview-item {
  1222. border: 1px solid #e4e7ed;
  1223. border-radius: 8px;
  1224. overflow: hidden;
  1225. }
  1226. .preview-header {
  1227. display: flex;
  1228. align-items: center;
  1229. gap: 10px;
  1230. padding: 12px 16px;
  1231. background: #f5f7fa;
  1232. cursor: pointer;
  1233. transition: background 0.2s;
  1234. }
  1235. .preview-header:hover {
  1236. background: #ebeef5;
  1237. }
  1238. .preview-item.expanded .preview-header {
  1239. border-bottom: 1px solid #e4e7ed;
  1240. }
  1241. .preview-sources-count {
  1242. font-size: 12px;
  1243. color: #909399;
  1244. }
  1245. .preview-expand-icon {
  1246. margin-left: auto;
  1247. font-size: 10px;
  1248. color: #909399;
  1249. }
  1250. .preview-index {
  1251. width: 24px;
  1252. height: 24px;
  1253. display: flex;
  1254. align-items: center;
  1255. justify-content: center;
  1256. background: #409eff;
  1257. color: white;
  1258. border-radius: 50%;
  1259. font-size: 12px;
  1260. font-weight: 500;
  1261. }
  1262. .preview-element {
  1263. flex: 1;
  1264. font-size: 14px;
  1265. font-weight: 500;
  1266. color: #303133;
  1267. }
  1268. .preview-body {
  1269. padding: 12px 16px;
  1270. }
  1271. .preview-row {
  1272. display: flex;
  1273. align-items: flex-start;
  1274. gap: 12px;
  1275. margin-bottom: 8px;
  1276. }
  1277. .preview-row:last-child {
  1278. margin-bottom: 0;
  1279. }
  1280. .preview-label {
  1281. flex-shrink: 0;
  1282. width: 70px;
  1283. font-size: 12px;
  1284. color: #909399;
  1285. }
  1286. .preview-value {
  1287. flex: 1;
  1288. font-size: 13px;
  1289. color: #303133;
  1290. }
  1291. .preview-value code {
  1292. background: #f5f7fa;
  1293. padding: 2px 6px;
  1294. border-radius: 4px;
  1295. font-family: monospace;
  1296. font-size: 12px;
  1297. }
  1298. .preview-prompt {
  1299. background: #fdf6ec;
  1300. padding: 6px 10px;
  1301. border-radius: 4px;
  1302. font-size: 12px;
  1303. line-height: 1.5;
  1304. color: #e6a23c;
  1305. }
  1306. .source-tag {
  1307. margin-right: 6px;
  1308. margin-bottom: 4px;
  1309. }
  1310. </style>