hookehuyr

流程图的TS类型整理修复

Showing 1 changed file with 54 additions and 31 deletions
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
7 :grid="showGrid" 7 :grid="showGrid"
8 :miniMap="showMiniMap" 8 :miniMap="showMiniMap"
9 :onRef="onRef" 9 :onRef="onRef"
10 - :multipleSelect="true" 10 + :multipleSelect="showMultipleSelect"
11 :loading="state.editorLoading" 11 :loading="state.editorLoading"
12 :beforeDelete="handleBeforeDelete" 12 :beforeDelete="handleBeforeDelete"
13 :afterDelete="handleAfterDelete" 13 :afterDelete="handleAfterDelete"
...@@ -179,7 +179,7 @@ ...@@ -179,7 +179,7 @@
179 </template> 179 </template>
180 180
181 <template v-slot:toolbar> 181 <template v-slot:toolbar>
182 - <el-tooltip content="测试工具栏插槽"> 182 + <el-tooltip content="打印流程图数据结构">
183 <div class="vue-flow-editor-toolbar-item" @click="logData"> 183 <div class="vue-flow-editor-toolbar-item" @click="logData">
184 <i class="el-icon-search" /> 184 <i class="el-icon-search" />
185 </div> 185 </div>
...@@ -209,13 +209,33 @@ import axios from "./axios"; ...@@ -209,13 +209,33 @@ import axios from "./axios";
209 import $ from "jquery"; 209 import $ from "jquery";
210 import { Calendar, Search } from "@element-plus/icons-vue"; 210 import { Calendar, Search } from "@element-plus/icons-vue";
211 import SelectUserView from "./selectUserView.vue"; 211 import SelectUserView from "./selectUserView.vue";
212 +import { Function } from 'lodash';
213 +import { extend } from '@vue/shared';
212 214
213 const G6 = (window as any).G6.default as any; 215 const G6 = (window as any).G6.default as any;
214 216
215 -function delay(time) { 217 +function delay(time: number) {
216 return new Promise(resolve => setTimeout(resolve, time)); 218 return new Promise(resolve => setTimeout(resolve, time));
217 } 219 }
218 220
221 +interface myObj {
222 + source: string;
223 + id: string;
224 + label: string;
225 +}
226 +
227 +interface myEvent {
228 + item: {
229 + get(T: string): {
230 + source: any,
231 + target: any,
232 + style: any,
233 + labelCfg: any
234 + label: any
235 + }
236 + }
237 +}
238 +
219 export default { 239 export default {
220 components: { 240 components: {
221 Calendar, 241 Calendar,
...@@ -224,9 +244,9 @@ export default { ...@@ -224,9 +244,9 @@ export default {
224 }, 244 },
225 setup(props, context) { 245 setup(props, context) {
226 const state = reactive({ 246 const state = reactive({
227 - data: AppData, 247 + data: AppData, // 渲染的数据,数据格式参考G6文档
228 detailModel: null, 248 detailModel: null,
229 - editorLoading: false, 249 + editorLoading: false, // 开始编辑器的loading状态
230 selectOptions: [ 250 selectOptions: [
231 { label: "待确认", value: "0" }, 251 { label: "待确认", value: "0" },
232 { label: "填写表单", value: "1" }, 252 { label: "填写表单", value: "1" },
...@@ -344,7 +364,7 @@ export default { ...@@ -344,7 +364,7 @@ export default {
344 console.warn(name); 364 console.warn(name);
345 } 365 }
346 366
347 - const onAuthAllChange = val => { // 全选可见按钮回调 367 + const onAuthAllChange = (val: any) => { // 全选可见按钮回调
348 if (val) { 368 if (val) {
349 // 全部选中 369 // 全部选中
350 state.field_auths.forEach(ele => { 370 state.field_auths.forEach(ele => {
...@@ -357,7 +377,7 @@ export default { ...@@ -357,7 +377,7 @@ export default {
357 }); 377 });
358 } 378 }
359 }; 379 };
360 - const onAuthAllEditChange = val => { // 全选可编辑按钮回调 380 + const onAuthAllEditChange = (val: any) => { // 全选可编辑按钮回调
361 console.warn(val); 381 console.warn(val);
362 }; 382 };
363 383
...@@ -366,10 +386,10 @@ export default { ...@@ -366,10 +386,10 @@ export default {
366 state.dialogUserFormVisible = true; 386 state.dialogUserFormVisible = true;
367 }; 387 };
368 388
369 - const onCloseUserView = (status) => { 389 + const onCloseUserView = (status: boolean) => {
370 state.dialogUserFormVisible = status; 390 state.dialogUserFormVisible = status;
371 } 391 }
372 - const onConfirmUserView = (data) => { 392 + const onConfirmUserView = (data: any) => {
373 console.log(data); 393 console.log(data);
374 } 394 }
375 /******************* END *******************/ 395 /******************* END *******************/
...@@ -377,14 +397,14 @@ export default { ...@@ -377,14 +397,14 @@ export default {
377 397
378 /********** 流程图功能函数 **********/ 398 /********** 流程图功能函数 **********/
379 399
380 - let editor; 400 + let editor: { openModel: () => void; closeModel: () => void; updateModel: (arg0: any) => void; editorState: { graph: { save: () => { nodes: any; edges: any; }; }; }; };
381 401
382 /** 402 /**
383 - * Handle the event when a node is double-clicked. 403 + * 双击节点回调
384 * 404 *
385 * @param {Object} e - The event object 405 * @param {Object} e - The event object
386 */ 406 */
387 - function onDblclickNode(e) { 407 + function onDblclickNode(e: myEvent) {
388 const model = G6.Util.clone(e.item.get("model")); 408 const model = G6.Util.clone(e.item.get("model"));
389 model.style = model.style || {}; 409 model.style = model.style || {};
390 model.labelCfg = model.labelCfg || { style: {} }; 410 model.labelCfg = model.labelCfg || { style: {} };
...@@ -394,11 +414,11 @@ export default { ...@@ -394,11 +414,11 @@ export default {
394 } 414 }
395 415
396 /** 416 /**
397 - * Handles the double click event on an edge. 417 + * 双击连接线回调
398 * 418 *
399 * @param {Event} e - The event object representing the double click event. 419 * @param {Event} e - The event object representing the double click event.
400 */ 420 */
401 - function onDblClickEdge(e) { 421 + function onDblClickEdge(e: myEvent) {
402 const { source, target, style, labelCfg, label } = e.item.get("model"); 422 const { source, target, style, labelCfg, label } = e.item.get("model");
403 const model = { 423 const model = {
404 label, 424 label,
...@@ -419,8 +439,6 @@ export default { ...@@ -419,8 +439,6 @@ export default {
419 /** 439 /**
420 * Cancels the operation and closes the editor model. 440 * Cancels the operation and closes the editor model.
421 * 441 *
422 - * @param {}
423 - * @return {}
424 */ 442 */
425 function cancel() { 443 function cancel() {
426 editor.closeModel(); 444 editor.closeModel();
...@@ -429,8 +447,6 @@ export default { ...@@ -429,8 +447,6 @@ export default {
429 /** 447 /**
430 * Saves the changes made in the editor. 448 * Saves the changes made in the editor.
431 * 449 *
432 - * @param {type} paramName - description of parameter
433 - * @return {type} description of return value
434 */ 450 */
435 function save() { 451 function save() {
436 editor.updateModel(state.detailModel); 452 editor.updateModel(state.detailModel);
...@@ -438,13 +454,13 @@ export default { ...@@ -438,13 +454,13 @@ export default {
438 } 454 }
439 455
440 /** 456 /**
441 - * Handles the before delete event of the model. 457 + * 删除前校验
442 * 458 *
443 * @param {Object} model - The model object. 459 * @param {Object} model - The model object.
444 * @param {string} type - The type of the model. 460 * @param {string} type - The type of the model.
445 * @return {Promise} A promise that resolves when the event is handled. 461 * @return {Promise} A promise that resolves when the event is handled.
446 */ 462 */
447 - async function handleBeforeDelete(model, type) { 463 + async function handleBeforeDelete(model: myObj, type: string): Promise<any> {
448 if (type === "node") { 464 if (type === "node") {
449 if (model.label === "开始") { 465 if (model.label === "开始") {
450 state.editorLoading = true; 466 state.editorLoading = true;
...@@ -457,12 +473,12 @@ export default { ...@@ -457,12 +473,12 @@ export default {
457 } 473 }
458 474
459 /** 475 /**
460 - * Handles the logic after deleting a model. 476 + * 删除后动作
461 * 477 *
462 * @param {Object} model - The model being deleted. 478 * @param {Object} model - The model being deleted.
463 * @param {string} type - The type of the model being deleted. 479 * @param {string} type - The type of the model being deleted.
464 */ 480 */
465 - function handleAfterDelete(model, type) { 481 + function handleAfterDelete(model: myObj, type: string) {
466 if (type === "edge") { 482 if (type === "edge") {
467 console.log("delete edge"); 483 console.log("delete edge");
468 } else { 484 } else {
...@@ -471,13 +487,13 @@ export default { ...@@ -471,13 +487,13 @@ export default {
471 } 487 }
472 488
473 /** 489 /**
474 - * A function to handle something before adding. 490 + * 添加前校验
475 * 491 *
476 * @param {object} model - The model object. 492 * @param {object} model - The model object.
477 * @param {string} type - The type of the model. 493 * @param {string} type - The type of the model.
478 * @return {Promise} A promise that resolves to a result or rejects with an error. 494 * @return {Promise} A promise that resolves to a result or rejects with an error.
479 */ 495 */
480 - function handleBeforeAdd(model, type) { 496 + function handleBeforeAdd(model: myObj, type: string): Promise<any> {
481 if (type === "edge") { 497 if (type === "edge") {
482 if (model.source === "end-node") { 498 if (model.source === "end-node") {
483 ElNotification.error("结束节点不能输出连线其他节点"); 499 ElNotification.error("结束节点不能输出连线其他节点");
...@@ -500,18 +516,24 @@ export default { ...@@ -500,18 +516,24 @@ export default {
500 } 516 }
501 } 517 }
502 518
503 - function handleAfterAdd(model, type) { 519 + /**
520 + * 添加后动作
521 + *
522 + * @param {model} model - The model being handled.
523 + * @param {type} type - The type of the event.
524 + */
525 + function handleAfterAdd(model: myObj, type: string) {
504 if (type === "edge") { 526 if (type === "edge") {
505 console.log(`新增连接线`); 527 console.log(`新增连接线`);
506 } 528 }
507 } 529 }
508 530
509 /** 531 /**
510 - * Logs the data from the editor's graph. 532 + * 打印流程图数据结构
511 * 533 *
512 - * @return {undefined} No return value. 534 + * @return {void} No return value.
513 */ 535 */
514 - function logData() { 536 + function logData(): void {
515 let { nodes, edges } = editor.editorState.graph.save(); 537 let { nodes, edges } = editor.editorState.graph.save();
516 nodes = nodes.map( 538 nodes = nodes.map(
517 ({ data, id, label, shape, x, y, text, desc, img }) => ({ 539 ({ data, id, label, shape, x, y, text, desc, img }) => ({
...@@ -538,8 +560,9 @@ export default { ...@@ -538,8 +560,9 @@ export default {
538 return { 560 return {
539 state, 561 state,
540 562
541 - showGrid: true, 563 + showGrid: true, // 是否开启网格
542 - showMiniMap: true, 564 + showMiniMap: true, // 是否开启缩略图
565 + showMultipleSelect: true, // 编辑器是否可以多选
543 566
544 onDblclickNode, 567 onDblclickNode,
545 onDblClickEdge, 568 onDblClickEdge,
...@@ -560,7 +583,7 @@ export default { ...@@ -560,7 +583,7 @@ export default {
560 583
561 logData, 584 logData,
562 585
563 - onRef: e => (editor = e), 586 + onRef: (e: any) => (editor = e),
564 staticPath 587 staticPath
565 }; 588 };
566 } 589 }
......