Showing
3 changed files
with
218 additions
and
186 deletions
| ... | @@ -222,36 +222,39 @@ | ... | @@ -222,36 +222,39 @@ |
| 222 | </template> | 222 | </template> |
| 223 | 223 | ||
| 224 | <script lang="ts"> | 224 | <script lang="ts"> |
| 225 | -import { reactive, onMounted, watch, nextTick } from "vue"; | 225 | +import { reactive, onMounted, watch, nextTick } from 'vue' |
| 226 | -import { AppData } from "./data.js"; | 226 | +import { AppData } from './data.js' |
| 227 | -import { staticPath } from "./utils"; | 227 | +import { staticPath } from './utils' |
| 228 | -import { ElNotification } from "element-plus"; | 228 | +import { ElNotification } from 'element-plus' |
| 229 | -import axios from "./axios"; | 229 | +import axios from './axios' |
| 230 | -import $ from "jquery"; | 230 | +import $ from 'jquery' |
| 231 | -import { Calendar, Search } from "@element-plus/icons-vue"; | 231 | +import { Calendar, Search } from '@element-plus/icons-vue' |
| 232 | -import SelectUserView from "./selectUserView.vue"; | 232 | +import SelectUserView from './selectUserView.vue' |
| 233 | -import { Function } from 'lodash'; | 233 | +import { Function } from 'lodash' |
| 234 | -import { extend } from '@vue/shared'; | 234 | +import { extend } from '@vue/shared' |
| 235 | - | 235 | + |
| 236 | -const G6 = (window as any).G6.default as any; | 236 | +const G6 = (window as any).G6.default as any |
| 237 | 237 | ||
| 238 | function delay(time: number) { | 238 | function delay(time: number) { |
| 239 | - return new Promise(resolve => setTimeout(resolve, time)); | 239 | + return new Promise((resolve) => setTimeout(resolve, time)) |
| 240 | } | 240 | } |
| 241 | 241 | ||
| 242 | interface myObj { | 242 | interface myObj { |
| 243 | - source: string; | 243 | + source: string |
| 244 | - id: string; | 244 | + id: string |
| 245 | - label: string; | 245 | + label: string |
| 246 | - control: string; | 246 | + control: string |
| 247 | + target: string | ||
| 247 | } | 248 | } |
| 248 | 249 | ||
| 249 | interface myEvent { | 250 | interface myEvent { |
| 250 | item: { | 251 | item: { |
| 251 | - get(T: string): { | 252 | + get( |
| 252 | - source: any, | 253 | + T: string, |
| 253 | - target: any, | 254 | + ): { |
| 254 | - style: any, | 255 | + source: any |
| 256 | + target: any | ||
| 257 | + style: any | ||
| 255 | labelCfg: any | 258 | labelCfg: any |
| 256 | label: any | 259 | label: any |
| 257 | } | 260 | } |
| ... | @@ -262,7 +265,7 @@ export default { | ... | @@ -262,7 +265,7 @@ export default { |
| 262 | components: { | 265 | components: { |
| 263 | Calendar, | 266 | Calendar, |
| 264 | Search, | 267 | Search, |
| 265 | - SelectUserView | 268 | + SelectUserView, |
| 266 | }, | 269 | }, |
| 267 | setup(props, context) { | 270 | setup(props, context) { |
| 268 | const state = reactive({ | 271 | const state = reactive({ |
| ... | @@ -270,32 +273,32 @@ export default { | ... | @@ -270,32 +273,32 @@ export default { |
| 270 | detailModel: null, | 273 | detailModel: null, |
| 271 | editorLoading: false, // 开始编辑器的loading状态 | 274 | editorLoading: false, // 开始编辑器的loading状态 |
| 272 | selectOptions: [ | 275 | selectOptions: [ |
| 273 | - { label: "待确认", value: "0" }, | 276 | + { label: '待确认', value: '0' }, |
| 274 | - { label: "填写表单", value: "1" }, | 277 | + { label: '填写表单', value: '1' }, |
| 275 | - { label: "部门负责人审批", value: "2" }, | 278 | + { label: '部门负责人审批', value: '2' }, |
| 276 | - { label: "总经理审批", value: "3" } | 279 | + { label: '总经理审批', value: '3' }, |
| 277 | ], | 280 | ], |
| 278 | menuData: [ | 281 | menuData: [ |
| 279 | { | 282 | { |
| 280 | - label: "流程节点", | 283 | + label: '流程节点', |
| 281 | menus: [ | 284 | menus: [ |
| 282 | - { label: "开始", shape: "ellipse", id: "start-node" }, | 285 | + { label: '开始', shape: 'ellipse', id: 'start-node' }, |
| 283 | - { label: "结束", shape: "ellipse", id: "end-node" }, | 286 | + { label: '结束', shape: 'ellipse', id: 'end-node' }, |
| 284 | - { label: "审批节点", busType: "123" }, | 287 | + { label: '审批节点', busType: '123' }, |
| 285 | - { label: "判断节点", shape: "diamond" } | 288 | + { label: '判断节点', shape: 'diamond' }, |
| 286 | - ] | 289 | + ], |
| 287 | }, | 290 | }, |
| 288 | { | 291 | { |
| 289 | - label: "其他形状节点", | 292 | + label: '其他形状节点', |
| 290 | menus: [ | 293 | menus: [ |
| 291 | - { label: "矩形节点", shape: "rect" }, | 294 | + { label: '矩形节点', shape: 'rect' }, |
| 292 | - { label: "圆形节点", shape: "circle" }, | 295 | + { label: '圆形节点', shape: 'circle' }, |
| 293 | - { label: "椭圆节点", shape: "ellipse" }, | 296 | + { label: '椭圆节点', shape: 'ellipse' }, |
| 294 | - { label: "菱形节点", shape: "diamond" }, | 297 | + { label: '菱形节点', shape: 'diamond' }, |
| 295 | - { label: "三角形节点", shape: "triangle" }, | 298 | + { label: '三角形节点', shape: 'triangle' }, |
| 296 | - { label: "星形节点", shape: "star" } | 299 | + { label: '星形节点', shape: 'star' }, |
| 297 | - ] | 300 | + ], |
| 298 | - } | 301 | + }, |
| 299 | ], | 302 | ], |
| 300 | // activityConfig: { | 303 | // activityConfig: { |
| 301 | // advertisement: { | 304 | // advertisement: { |
| ... | @@ -319,130 +322,142 @@ export default { | ... | @@ -319,130 +322,142 @@ export default { |
| 319 | // }, | 322 | // }, |
| 320 | controlConfig: { | 323 | controlConfig: { |
| 321 | start: { | 324 | start: { |
| 322 | - id: "start-node", | 325 | + id: 'start-node', |
| 323 | - text: "开始", | 326 | + text: '开始', |
| 324 | - desc: "开始", | 327 | + desc: '开始', |
| 325 | - color: "#9283ed", | 328 | + color: '#9283ed', |
| 326 | - img: "https://cdn.ipadbiz.cn/oa/advertisement-node.svg" | 329 | + img: 'https://cdn.ipadbiz.cn/oa/advertisement-node.svg', |
| 327 | }, | 330 | }, |
| 328 | flow: { | 331 | flow: { |
| 329 | - text: "流程节点", | 332 | + text: '流程节点', |
| 330 | - desc: "流程节点", | 333 | + desc: '流程节点', |
| 331 | - color: "#ed8383", | 334 | + color: '#ed8383', |
| 332 | - img: "https://cdn.ipadbiz.cn/oa/coupon-node.svg" | 335 | + img: 'https://cdn.ipadbiz.cn/oa/coupon-node.svg', |
| 333 | }, | 336 | }, |
| 334 | end: { | 337 | end: { |
| 335 | - id: "end-node", | 338 | + id: 'end-node', |
| 336 | - text: "结束", | 339 | + text: '结束', |
| 337 | - desc: "结束", | 340 | + desc: '结束', |
| 338 | - color: "#92dba8", | 341 | + color: '#92dba8', |
| 339 | - img: "https://cdn.ipadbiz.cn/oa/crowd-node.svg" | 342 | + img: 'https://cdn.ipadbiz.cn/oa/crowd-node.svg', |
| 340 | - } | 343 | + }, |
| 341 | }, | 344 | }, |
| 342 | dialogUserFormVisible: false, | 345 | dialogUserFormVisible: false, |
| 343 | - activeName: "node", | 346 | + activeName: 'node', |
| 344 | - attr_radio: "基础属性", | 347 | + attr_radio: '基础属性', |
| 345 | auth_all_checked: false, | 348 | auth_all_checked: false, |
| 346 | auth_all_edit: false, | 349 | auth_all_edit: false, |
| 347 | field_auths: [ | 350 | field_auths: [ |
| 348 | { | 351 | { |
| 349 | - name: "字段1", | 352 | + name: '字段1', |
| 350 | visible: { | 353 | visible: { |
| 351 | checked: true, | 354 | checked: true, |
| 352 | - disabled: false | 355 | + disabled: false, |
| 353 | }, | 356 | }, |
| 354 | editable: { | 357 | editable: { |
| 355 | checked: false, | 358 | checked: false, |
| 356 | - disabled: true | 359 | + disabled: true, |
| 357 | - } | 360 | + }, |
| 358 | }, | 361 | }, |
| 359 | { | 362 | { |
| 360 | - name: "字段2", | 363 | + name: '字段2', |
| 361 | visible: { | 364 | visible: { |
| 362 | checked: true, | 365 | checked: true, |
| 363 | - disabled: false | 366 | + disabled: false, |
| 364 | }, | 367 | }, |
| 365 | editable: { | 368 | editable: { |
| 366 | checked: false, | 369 | checked: false, |
| 367 | - disabled: false | 370 | + disabled: false, |
| 368 | - } | 371 | + }, |
| 369 | }, | 372 | }, |
| 370 | { | 373 | { |
| 371 | - name: "字段3", | 374 | + name: '字段3', |
| 372 | visible: { | 375 | visible: { |
| 373 | checked: true, | 376 | checked: true, |
| 374 | - disabled: false | 377 | + disabled: false, |
| 375 | }, | 378 | }, |
| 376 | editable: { | 379 | editable: { |
| 377 | checked: false, | 380 | checked: false, |
| 378 | - disabled: false | 381 | + disabled: false, |
| 379 | - } | 382 | + }, |
| 380 | - } | 383 | + }, |
| 381 | ], | 384 | ], |
| 382 | - }); | 385 | + }) |
| 383 | 386 | ||
| 384 | onMounted(() => { | 387 | onMounted(() => { |
| 385 | - document.title = '可视化流程设计器'; | 388 | + document.title = '可视化流程设计器' |
| 386 | - // // 显示提示框的标志位 | 389 | + // // 显示提示框的标志位 |
| 387 | - // var showConfirmation = true; | 390 | + // var showConfirmation = true; |
| 388 | - // // 监听 beforeunload 事件 | 391 | + // // 监听 beforeunload 事件 |
| 389 | - // window.addEventListener('beforeunload', function (event) { | 392 | + // window.addEventListener('beforeunload', function (event) { |
| 390 | - // if (showConfirmation) { | 393 | + // if (showConfirmation) { |
| 391 | - // // 取消事件的默认行为(弹出确认对话框) | 394 | + // // 取消事件的默认行为(弹出确认对话框) |
| 392 | - // event.preventDefault(); | 395 | + // event.preventDefault(); |
| 393 | - // // Chrome 和 Firefox 需要返回一个值以显示确认对话框 | 396 | + // // Chrome 和 Firefox 需要返回一个值以显示确认对话框 |
| 394 | - // event.returnValue = ''; | 397 | + // event.returnValue = ''; |
| 395 | - // // 显示自定义的提示信息 | 398 | + // // 显示自定义的提示信息 |
| 396 | - // var confirmationMessage = '确定要离开此页面吗?'; | 399 | + // var confirmationMessage = '确定要离开此页面吗?'; |
| 397 | - // (event || window.event).returnValue = confirmationMessage; // 兼容旧版浏览器 | 400 | + // (event || window.event).returnValue = confirmationMessage; // 兼容旧版浏览器 |
| 398 | - // return confirmationMessage; | 401 | + // return confirmationMessage; |
| 399 | - // } | 402 | + // } |
| 400 | - // }); | 403 | + // }); |
| 401 | - // // 监听 unload 事件 | 404 | + // // 监听 unload 事件 |
| 402 | - // window.addEventListener('unload', function () { | 405 | + // window.addEventListener('unload', function () { |
| 403 | - // // 设置标志位为 false,避免在刷新页面时再次显示提示框 | 406 | + // // 设置标志位为 false,避免在刷新页面时再次显示提示框 |
| 404 | - // showConfirmation = false; | 407 | + // showConfirmation = false; |
| 405 | - // }); | 408 | + // }); |
| 406 | - }); | 409 | + }) |
| 407 | 410 | ||
| 408 | function handleActiveChange(name) { | 411 | function handleActiveChange(name) { |
| 409 | - console.warn(name); | 412 | + console.warn(name) |
| 410 | } | 413 | } |
| 411 | 414 | ||
| 412 | - const onAuthAllChange = (val: any) => { // 全选可见按钮回调 | 415 | + const onAuthAllChange = (val: any) => { |
| 416 | + // 全选可见按钮回调 | ||
| 413 | if (val) { | 417 | if (val) { |
| 414 | // 全部选中 | 418 | // 全部选中 |
| 415 | - state.field_auths.forEach(ele => { | 419 | + state.field_auths.forEach((ele) => { |
| 416 | - ele.visible.checked = true; | 420 | + ele.visible.checked = true |
| 417 | - }); | 421 | + }) |
| 418 | } else { | 422 | } else { |
| 419 | // 全部取消选中 | 423 | // 全部取消选中 |
| 420 | - state.field_auths.forEach(ele => { | 424 | + state.field_auths.forEach((ele) => { |
| 421 | - ele.visible.checked = false; | 425 | + ele.visible.checked = false |
| 422 | - }); | 426 | + }) |
| 423 | } | 427 | } |
| 424 | - }; | 428 | + } |
| 425 | - const onAuthAllEditChange = (val: any) => { // 全选可编辑按钮回调 | 429 | + const onAuthAllEditChange = (val: any) => { |
| 426 | - console.warn(val); | 430 | + // 全选可编辑按钮回调 |
| 427 | - }; | 431 | + console.warn(val) |
| 432 | + } | ||
| 428 | 433 | ||
| 429 | /****** 用户选择控件弹框 ******/ | 434 | /****** 用户选择控件弹框 ******/ |
| 430 | - const openUserForm = () => { // 打开设置用户弹框 | 435 | + const openUserForm = () => { |
| 431 | - state.dialogUserFormVisible = true; | 436 | + // 打开设置用户弹框 |
| 432 | - }; | 437 | + state.dialogUserFormVisible = true |
| 438 | + } | ||
| 433 | 439 | ||
| 434 | const onCloseUserView = (status: boolean) => { | 440 | const onCloseUserView = (status: boolean) => { |
| 435 | - state.dialogUserFormVisible = status; | 441 | + state.dialogUserFormVisible = status |
| 436 | } | 442 | } |
| 437 | const onConfirmUserView = (data: any) => { | 443 | const onConfirmUserView = (data: any) => { |
| 438 | - console.log(data); | 444 | + console.log(data) |
| 439 | } | 445 | } |
| 440 | /******************* END *******************/ | 446 | /******************* END *******************/ |
| 441 | 447 | ||
| 442 | - | ||
| 443 | /********** 流程图功能函数 **********/ | 448 | /********** 流程图功能函数 **********/ |
| 444 | 449 | ||
| 445 | - let editor: { openModel: () => void; closeModel: () => void; updateModel: (arg0: any) => void; editorState: { graph: { save: () => { nodes: any; edges: any; }; }; }; }; | 450 | + let editor: { |
| 451 | + openModel: () => void | ||
| 452 | + closeModel: () => void | ||
| 453 | + updateModel: (arg0: any) => void | ||
| 454 | + editorState: { | ||
| 455 | + graph: { | ||
| 456 | + removeItem: any | ||
| 457 | + save: () => { nodes: any; edges: any } | ||
| 458 | + } | ||
| 459 | + } | ||
| 460 | + } | ||
| 446 | 461 | ||
| 447 | /** | 462 | /** |
| 448 | * 双击节点回调 | 463 | * 双击节点回调 |
| ... | @@ -450,23 +465,23 @@ export default { | ... | @@ -450,23 +465,23 @@ export default { |
| 450 | * @param {Object} e - The event object | 465 | * @param {Object} e - The event object |
| 451 | */ | 466 | */ |
| 452 | function onDblClickNode(e: myEvent) { | 467 | function onDblClickNode(e: myEvent) { |
| 453 | - const model = G6.Util.clone(e.item.get("model")); | 468 | + const model = G6.Util.clone(e.item.get('model')) |
| 454 | - model.style = model.style || {}; | 469 | + model.style = model.style || {} |
| 455 | - model.labelCfg = model.labelCfg || { style: {} }; | 470 | + model.labelCfg = model.labelCfg || { style: {} } |
| 456 | 471 | ||
| 457 | - model.data = model.data ? model.data : {}; | 472 | + model.data = model.data ? model.data : {} |
| 458 | - state.detailModel = model; | 473 | + state.detailModel = model |
| 459 | - editor.openModel(); | 474 | + editor.openModel() |
| 460 | } | 475 | } |
| 461 | 476 | ||
| 462 | function onClickNode(e: myEvent) { | 477 | function onClickNode(e: myEvent) { |
| 463 | - const model = G6.Util.clone(e.item.get("model")); | 478 | + const model = G6.Util.clone(e.item.get('model')) |
| 464 | - model.style = model.style || {}; | 479 | + model.style = model.style || {} |
| 465 | - model.labelCfg = model.labelCfg || { style: {} }; | 480 | + model.labelCfg = model.labelCfg || { style: {} } |
| 466 | 481 | ||
| 467 | - model.data = model.data ? model.data : {}; | 482 | + model.data = model.data ? model.data : {} |
| 468 | - state.detailModel = model; | 483 | + state.detailModel = model |
| 469 | - editor.openModel(); | 484 | + editor.openModel() |
| 470 | } | 485 | } |
| 471 | 486 | ||
| 472 | /** | 487 | /** |
| ... | @@ -475,7 +490,7 @@ export default { | ... | @@ -475,7 +490,7 @@ export default { |
| 475 | * @param {Event} e - The event object representing the double click event. | 490 | * @param {Event} e - The event object representing the double click event. |
| 476 | */ | 491 | */ |
| 477 | function onDblClickEdge(e: myEvent) { | 492 | function onDblClickEdge(e: myEvent) { |
| 478 | - const { source, target, style, labelCfg, label } = e.item.get("model"); | 493 | + const { source, target, style, labelCfg, label } = e.item.get('model') |
| 479 | const model = { | 494 | const model = { |
| 480 | label, | 495 | label, |
| 481 | source, | 496 | source, |
| ... | @@ -483,13 +498,13 @@ export default { | ... | @@ -483,13 +498,13 @@ export default { |
| 483 | style: style || {}, | 498 | style: style || {}, |
| 484 | labelCfg: labelCfg || { style: {} }, | 499 | labelCfg: labelCfg || { style: {} }, |
| 485 | type: null, | 500 | type: null, |
| 486 | - id: null | 501 | + id: null, |
| 487 | - }; | 502 | + } |
| 488 | - model.type = e.item.get("type"); | 503 | + model.type = e.item.get('type') |
| 489 | - model.id = e.item.get("id"); | 504 | + model.id = e.item.get('id') |
| 490 | 505 | ||
| 491 | - state.detailModel = model; | 506 | + state.detailModel = model |
| 492 | - editor.openModel(); | 507 | + editor.openModel() |
| 493 | } | 508 | } |
| 494 | 509 | ||
| 495 | /** | 510 | /** |
| ... | @@ -497,7 +512,7 @@ export default { | ... | @@ -497,7 +512,7 @@ export default { |
| 497 | * | 512 | * |
| 498 | */ | 513 | */ |
| 499 | function cancel() { | 514 | function cancel() { |
| 500 | - editor.closeModel(); | 515 | + editor.closeModel() |
| 501 | } | 516 | } |
| 502 | 517 | ||
| 503 | /** | 518 | /** |
| ... | @@ -505,8 +520,8 @@ export default { | ... | @@ -505,8 +520,8 @@ export default { |
| 505 | * | 520 | * |
| 506 | */ | 521 | */ |
| 507 | function save() { | 522 | function save() { |
| 508 | - editor.updateModel(state.detailModel); | 523 | + editor.updateModel(state.detailModel) |
| 509 | - editor.closeModel(); | 524 | + editor.closeModel() |
| 510 | } | 525 | } |
| 511 | 526 | ||
| 512 | /** | 527 | /** |
| ... | @@ -516,14 +531,17 @@ export default { | ... | @@ -516,14 +531,17 @@ export default { |
| 516 | * @param {string} type - The type of the model. | 531 | * @param {string} type - The type of the model. |
| 517 | * @return {Promise} A promise that resolves when the event is handled. | 532 | * @return {Promise} A promise that resolves when the event is handled. |
| 518 | */ | 533 | */ |
| 519 | - async function handleBeforeDelete(model: myObj, type: string): Promise<any> { | 534 | + async function handleBeforeDelete( |
| 520 | - if (type === "node") { | 535 | + model: myObj, |
| 521 | - if (model.label === "开始") { | 536 | + type: string, |
| 522 | - state.editorLoading = true; | 537 | + ): Promise<any> { |
| 523 | - await delay(1000); | 538 | + if (type === 'node') { |
| 524 | - state.editorLoading = false; | 539 | + if (model.label === '开始') { |
| 525 | - ElNotification.error("不可以删除【开始】节点"); | 540 | + state.editorLoading = true |
| 526 | - return Promise.reject("reject"); | 541 | + await delay(1000) |
| 542 | + state.editorLoading = false | ||
| 543 | + ElNotification.error('不可以删除【开始】节点') | ||
| 544 | + return Promise.reject('reject') | ||
| 527 | } | 545 | } |
| 528 | } | 546 | } |
| 529 | } | 547 | } |
| ... | @@ -535,10 +553,10 @@ export default { | ... | @@ -535,10 +553,10 @@ export default { |
| 535 | * @param {string} type - The type of the model being deleted. | 553 | * @param {string} type - The type of the model being deleted. |
| 536 | */ | 554 | */ |
| 537 | function handleAfterDelete(model: myObj, type: string) { | 555 | function handleAfterDelete(model: myObj, type: string) { |
| 538 | - if (type === "edge") { | 556 | + if (type === 'edge') { |
| 539 | - console.log("delete edge"); | 557 | + console.log('delete edge') |
| 540 | } else { | 558 | } else { |
| 541 | - console.log("after delete", model.label, { ...model }); | 559 | + console.log('after delete', model.label, { ...model }) |
| 542 | } | 560 | } |
| 543 | } | 561 | } |
| 544 | 562 | ||
| ... | @@ -550,22 +568,33 @@ export default { | ... | @@ -550,22 +568,33 @@ export default { |
| 550 | * @return {Promise} A promise that resolves to a result or rejects with an error. | 568 | * @return {Promise} A promise that resolves to a result or rejects with an error. |
| 551 | */ | 569 | */ |
| 552 | function handleBeforeAdd(model: myObj, type: string): Promise<any> { | 570 | function handleBeforeAdd(model: myObj, type: string): Promise<any> { |
| 553 | - if (type === "edge") { | 571 | + const source = model.source; |
| 554 | - if (model.source === "end-node") { | 572 | + const target = model.target; |
| 555 | - ElNotification.error("结束节点不能输出连线其他节点"); | 573 | + let { nodes, edges } = editor.editorState.graph.save(); |
| 556 | - return Promise.reject("reject"); | 574 | + |
| 575 | + if (type === 'edge') { | ||
| 576 | + if (model.source === 'end-node') { | ||
| 577 | + ElNotification.error('结束节点不能输出连线其他节点') | ||
| 578 | + return Promise.reject('reject') | ||
| 579 | + } | ||
| 580 | + for (let index = 0; index < edges.length; index++) { | ||
| 581 | + const element = edges[index] | ||
| 582 | + if (element.source === source && element.target === target) { | ||
| 583 | + ElNotification.error('不可以重复添加连线') | ||
| 584 | + return Promise.reject('reject') | ||
| 585 | + } | ||
| 557 | } | 586 | } |
| 558 | } | 587 | } |
| 559 | - if (type === "node") { | 588 | + if (type === 'node') { |
| 560 | - if (model.control === "start" || model.control === "end") { | 589 | + if (model.control === 'start' || model.control === 'end') { |
| 561 | - const data = editor.editorState.graph.save(); | 590 | + const data = editor.editorState.graph.save() |
| 562 | for (let i = 0; i < data.nodes.length; i++) { | 591 | for (let i = 0; i < data.nodes.length; i++) { |
| 563 | - const node = data.nodes[i]; | 592 | + const node = data.nodes[i] |
| 564 | if (node.control === model.control) { | 593 | if (node.control === model.control) { |
| 565 | ElNotification.error( | 594 | ElNotification.error( |
| 566 | - `只能有一个${model.control === "start" ? "开始" : "结束"}节点` | 595 | + `只能有一个${model.control === 'start' ? '开始' : '结束'}节点`, |
| 567 | - ); | 596 | + ) |
| 568 | - return Promise.reject("reject"); | 597 | + return Promise.reject('reject') |
| 569 | } | 598 | } |
| 570 | } | 599 | } |
| 571 | } | 600 | } |
| ... | @@ -579,15 +608,18 @@ export default { | ... | @@ -579,15 +608,18 @@ export default { |
| 579 | * @param {type} type - The type of the event. | 608 | * @param {type} type - The type of the event. |
| 580 | */ | 609 | */ |
| 581 | function handleAfterAdd(model: myObj, type: string) { | 610 | function handleAfterAdd(model: myObj, type: string) { |
| 582 | - console.log('handleAfterAdd', model); | 611 | + // console.log('handleAfterAdd', model); |
| 583 | 612 | ||
| 584 | // TODO: 因为resize会重新绘制,所以可能需要保存操作 | 613 | // TODO: 因为resize会重新绘制,所以可能需要保存操作 |
| 585 | if (type === 'node') { | 614 | if (type === 'node') { |
| 586 | - console.log(`新增节点`); | 615 | + console.log(`新增节点`) |
| 587 | } | 616 | } |
| 588 | - if (type === "edge") { | 617 | + if (type === 'edge') { |
| 589 | - console.log(`新增连接线`); | 618 | + console.log(`新增连接线`) |
| 590 | } | 619 | } |
| 620 | + | ||
| 621 | + state.data.nodes = editor.editorState.graph.save().nodes | ||
| 622 | + state.data.edges = editor.editorState.graph.save().edges | ||
| 591 | } | 623 | } |
| 592 | 624 | ||
| 593 | /** | 625 | /** |
| ... | @@ -597,8 +629,8 @@ export default { | ... | @@ -597,8 +629,8 @@ export default { |
| 597 | */ | 629 | */ |
| 598 | function onDragEndNode(e: myEvent) { | 630 | function onDragEndNode(e: myEvent) { |
| 599 | // TODO:可能需要接口保存相应位置,避免拖动窗口时数据丢失 | 631 | // TODO:可能需要接口保存相应位置,避免拖动窗口时数据丢失 |
| 600 | - const model = e.item.get("model"); | 632 | + const model = e.item.get('model') |
| 601 | - console.log("onDragEndNode", model); | 633 | + console.log('onDragEndNode', model) |
| 602 | } | 634 | } |
| 603 | 635 | ||
| 604 | /** | 636 | /** |
| ... | @@ -607,18 +639,18 @@ export default { | ... | @@ -607,18 +639,18 @@ export default { |
| 607 | * @return {void} No return value. | 639 | * @return {void} No return value. |
| 608 | */ | 640 | */ |
| 609 | function logData(): void { | 641 | function logData(): void { |
| 610 | - let { nodes, edges } = editor.editorState.graph.save(); | 642 | + let { nodes, edges } = editor.editorState.graph.save() |
| 611 | // console.log("nodes", nodes); | 643 | // console.log("nodes", nodes); |
| 612 | // console.log("edges", edges); | 644 | // console.log("edges", edges); |
| 613 | // 使用时需要把自定义节点的类型带过去 activity/control | 645 | // 使用时需要把自定义节点的类型带过去 activity/control |
| 614 | - nodes.forEach((node: { [x: string]: string; shape: string; }) => { | 646 | + nodes.forEach((node: { [x: string]: string; shape: string }) => { |
| 615 | - if (node.shape === "activity") { | 647 | + if (node.shape === 'activity') { |
| 616 | - node['shape'] = 'activity_' + node['activity']; | 648 | + node['shape'] = 'activity_' + node['activity'] |
| 617 | } | 649 | } |
| 618 | - if (node.shape === "control") { | 650 | + if (node.shape === 'control') { |
| 619 | - node['shape'] = 'control_' + node['control']; | 651 | + node['shape'] = 'control_' + node['control'] |
| 620 | } | 652 | } |
| 621 | - }); | 653 | + }) |
| 622 | 654 | ||
| 623 | nodes = nodes.map( | 655 | nodes = nodes.map( |
| 624 | ({ data, id, label, shape, x, y, text, desc, img }) => ({ | 656 | ({ data, id, label, shape, x, y, text, desc, img }) => ({ |
| ... | @@ -630,18 +662,18 @@ export default { | ... | @@ -630,18 +662,18 @@ export default { |
| 630 | y, | 662 | y, |
| 631 | text, | 663 | text, |
| 632 | desc, | 664 | desc, |
| 633 | - img | 665 | + img, |
| 634 | - }) | 666 | + }), |
| 635 | - ); | 667 | + ) |
| 636 | edges = edges.map(({ source, sourceAnchor, target, targetAnchor }) => ({ | 668 | edges = edges.map(({ source, sourceAnchor, target, targetAnchor }) => ({ |
| 637 | source, | 669 | source, |
| 638 | sourceAnchor, | 670 | sourceAnchor, |
| 639 | target, | 671 | target, |
| 640 | - targetAnchor | 672 | + targetAnchor, |
| 641 | - })); | 673 | + })) |
| 642 | // console.log(JSON.stringify({ nodes, edges }, null, 2)); | 674 | // console.log(JSON.stringify({ nodes, edges }, null, 2)); |
| 643 | - console.log(nodes); | 675 | + console.log(nodes) |
| 644 | - console.log(edges); | 676 | + console.log(edges) |
| 645 | } | 677 | } |
| 646 | 678 | ||
| 647 | /** | 679 | /** |
| ... | @@ -652,8 +684,8 @@ export default { | ... | @@ -652,8 +684,8 @@ export default { |
| 652 | */ | 684 | */ |
| 653 | function toolbarButtonHandler(buttons: any[]): Array<any> { | 685 | function toolbarButtonHandler(buttons: any[]): Array<any> { |
| 654 | // TAG:测试隐藏缩略图 | 686 | // TAG:测试隐藏缩略图 |
| 655 | - let map = buttons.filter(item => item.key !== "miniMapSwitcher"); | 687 | + let map = buttons.filter((item) => item.key !== 'miniMapSwitcher') |
| 656 | - return map; | 688 | + return map |
| 657 | } | 689 | } |
| 658 | 690 | ||
| 659 | return { | 691 | return { |
| ... | @@ -686,10 +718,10 @@ export default { | ... | @@ -686,10 +718,10 @@ export default { |
| 686 | toolbarButtonHandler, | 718 | toolbarButtonHandler, |
| 687 | 719 | ||
| 688 | onRef: (e: any) => (editor = e), | 720 | onRef: (e: any) => (editor = e), |
| 689 | - staticPath | 721 | + staticPath, |
| 690 | - }; | 722 | + } |
| 691 | - } | 723 | + }, |
| 692 | -}; | 724 | +} |
| 693 | </script> | 725 | </script> |
| 694 | 726 | ||
| 695 | <style lang="scss"> | 727 | <style lang="scss"> | ... | ... |
| 1 | /* | 1 | /* |
| 2 | * @Date: 2023-10-27 09:29:48 | 2 | * @Date: 2023-10-27 09:29:48 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2023-11-15 15:56:03 | 4 | + * @LastEditTime: 2023-11-15 16:16:04 |
| 5 | * @FilePath: /vue-flow-editor/doc/data.js | 5 | * @FilePath: /vue-flow-editor/doc/data.js |
| 6 | * @Description: 初始化结构,数据都是固定的 | 6 | * @Description: 初始化结构,数据都是固定的 |
| 7 | */ | 7 | */ | ... | ... |
| ... | @@ -130,7 +130,7 @@ export function dragEdge(G6, option: OptionType) { | ... | @@ -130,7 +130,7 @@ export function dragEdge(G6, option: OptionType) { |
| 130 | async _addEdge() { | 130 | async _addEdge() { |
| 131 | if (this.origin.targetNode) { | 131 | if (this.origin.targetNode) { |
| 132 | const addModel = { | 132 | const addModel = { |
| 133 | - clazz: 'flow', | 133 | + class: 'flow', |
| 134 | source: this.origin.sourceNode.get('id'), | 134 | source: this.origin.sourceNode.get('id'), |
| 135 | target: this.origin.targetNode.get('id'), | 135 | target: this.origin.targetNode.get('id'), |
| 136 | sourceAnchor: this.origin.sourceAnchor, | 136 | sourceAnchor: this.origin.sourceAnchor, |
| ... | @@ -159,4 +159,4 @@ export function dragEdge(G6, option: OptionType) { | ... | @@ -159,4 +159,4 @@ export function dragEdge(G6, option: OptionType) { |
| 159 | } | 159 | } |
| 160 | } | 160 | } |
| 161 | }); | 161 | }); |
| 162 | -} | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 162 | +} | ... | ... |
-
Please register or login to post a comment