1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| async function saveToDatabase(processName) { try { const { xml } = await modeler.saveXML({ format: true }); const { svg } = await modeler.saveSVG(); const response = await fetch('/api/processes', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ name: processName, bpmn: xml, preview: svg, createdAt: new Date().toISOString(), version: 1 }) }); if (!response.ok) { throw new Error(`服务器错误: ${response.status}`); } const data = await response.json(); console.log('✓ 流程已保存, ID:', data.id); return { success: true, processId: data.id }; } catch (err) { console.error('✗ 保存失败:', err.message); return { success: false, error: err.message }; } }
async function loadFromDatabase(processId) { try { const response = await fetch(`/api/processes/${processId}`); if (!response.ok) throw new Error('流程不存在'); const { bpmn } = await response.json(); await modeler.importXML(bpmn); modeler.get('canvas').zoom('fit-viewport'); console.log('✓ 流程已加载'); return { success: true }; } catch (err) { console.error('✗ 加载失败:', err); return { success: false, error: err.message }; } }
|