Showing
1 changed file
with
81 additions
and
91 deletions
| ... | @@ -417,6 +417,7 @@ import { staticPath } from './utils' | ... | @@ -417,6 +417,7 @@ import { staticPath } from './utils' |
| 417 | import { ElNotification, ElMessage, ElMessageBox, ElLoading } from 'element-plus' | 417 | import { ElNotification, ElMessage, ElMessageBox, ElLoading } from 'element-plus' |
| 418 | import axios from './axios' | 418 | import axios from './axios' |
| 419 | import $ from 'jquery' | 419 | import $ from 'jquery' |
| 420 | +import _ from 'lodash' | ||
| 420 | import { Calendar, Search } from '@element-plus/icons-vue' | 421 | import { Calendar, Search } from '@element-plus/icons-vue' |
| 421 | import SelectUserView from './selectUserView.vue' | 422 | import SelectUserView from './selectUserView.vue' |
| 422 | import { Function } from 'lodash' | 423 | import { Function } from 'lodash' |
| ... | @@ -587,33 +588,30 @@ export default { | ... | @@ -587,33 +588,30 @@ export default { |
| 587 | * 更新URL中的flow_id | 588 | * 更新URL中的flow_id |
| 588 | * @param flowId | 589 | * @param flowId |
| 589 | */ | 590 | */ |
| 590 | - const updateUrl = (flowId: any) => { | 591 | + // const updateUrl = (flowId: any) => { |
| 591 | - // 获取当前 URL | 592 | + // // 获取当前 URL |
| 592 | - const url = new URL(window.location.href); | 593 | + // const url = new URL(window.location.href); |
| 593 | - | 594 | + |
| 594 | - // 获取 flow_id 的值(可以是一个变量) | 595 | + // // 获取 URL 中的查询参数对象 |
| 595 | - // const flowId = 'some_value'; | 596 | + // const searchParams = url.searchParams; |
| 596 | - | 597 | + |
| 597 | - // 获取 URL 中的查询参数对象 | 598 | + // // 检查是否存在 form_id 参数 |
| 598 | - const searchParams = url.searchParams; | 599 | + // if (!searchParams.has('form_id')) { |
| 599 | - | 600 | + // // 如果不存在 form_id 参数,则添加 form_id 和 flow_id 参数 |
| 600 | - // 检查是否存在 form_id 参数 | 601 | + // searchParams.append('flow_id', flowId); |
| 601 | - if (!searchParams.has('form_id')) { | 602 | + // } else { |
| 602 | - // 如果不存在 form_id 参数,则添加 form_id 和 flow_id 参数 | 603 | + // // 如果存在 form_id 参数,则更新 flow_id 参数的值 |
| 603 | - searchParams.append('flow_id', flowId); | 604 | + // searchParams.set('flow_id', flowId); |
| 604 | - } else { | 605 | + // } |
| 605 | - // 如果存在 form_id 参数,则更新 flow_id 参数的值 | 606 | + |
| 606 | - searchParams.set('flow_id', flowId); | 607 | + // // 将更新后的查询参数设置回 URL 对象 |
| 607 | - } | 608 | + // url.search = searchParams.toString(); |
| 608 | - | 609 | + |
| 609 | - // 将更新后的查询参数设置回 URL 对象 | 610 | + // // 修改完 URL 后,更新浏览器地址栏显示的 URL |
| 610 | - url.search = searchParams.toString(); | 611 | + // window.history.replaceState(null, '', url.toString()); |
| 611 | - | 612 | + // // TODO: 到时候测试iframe的时候,看看有没有影响 |
| 612 | - // 修改完 URL 后,更新浏览器地址栏显示的 URL | 613 | + // // window.parent.location.href = window.parent.location.href + '&mod_id=' + item.id + '&width=' + item.width + '&height=' + item.height + '&bg_img=' + encodeURIComponent(item.background) + '&type=edit'; |
| 613 | - window.history.replaceState(null, '', url.toString()); | 614 | + // } |
| 614 | - // TODO: 到时候测试iframe的时候,看看有没有影响 | ||
| 615 | - // window.parent.location.href = window.parent.location.href + '&mod_id=' + item.id + '&width=' + item.width + '&height=' + item.height + '&bg_img=' + encodeURIComponent(item.background) + '&type=edit'; | ||
| 616 | - } | ||
| 617 | 615 | ||
| 618 | /** | 616 | /** |
| 619 | * 获取url参数 | 617 | * 获取url参数 |
| ... | @@ -642,9 +640,24 @@ export default { | ... | @@ -642,9 +640,24 @@ export default { |
| 642 | return params; | 640 | return params; |
| 643 | } | 641 | } |
| 644 | 642 | ||
| 643 | + /** | ||
| 644 | + * 获取缓存里的 flow_id | ||
| 645 | + */ | ||
| 646 | + const getFlowId = () => { | ||
| 647 | + let id = localStorage.getItem('flow_id') ? localStorage.getItem('flow_id') : ''; | ||
| 648 | + return id; | ||
| 649 | + } | ||
| 650 | + | ||
| 651 | + /** | ||
| 652 | + * 更新缓存里的 flow_id | ||
| 653 | + * @param id | ||
| 654 | + */ | ||
| 655 | + const updateFlowId = (id: any) => { | ||
| 656 | + localStorage.setItem('flow_id', id); | ||
| 657 | + } | ||
| 658 | + | ||
| 645 | const urlQuery = getQueryParams(location.href); | 659 | const urlQuery = getQueryParams(location.href); |
| 646 | let form_id = urlQuery.form_id? urlQuery.form_id : ''; // 表单id | 660 | let form_id = urlQuery.form_id? urlQuery.form_id : ''; // 表单id |
| 647 | - let flow_id = urlQuery.flow_id? urlQuery.flow_id : ''; // 流程id,如果是新的流程,则为空 | ||
| 648 | 661 | ||
| 649 | /** | 662 | /** |
| 650 | * 因为从外部页面到流程图页面,flow_id都需要从当前页面生成 | 663 | * 因为从外部页面到流程图页面,flow_id都需要从当前页面生成 |
| ... | @@ -654,58 +667,39 @@ export default { | ... | @@ -654,58 +667,39 @@ export default { |
| 654 | axios.get('/admin/?a=flow_version&form_id=' + form_id) | 667 | axios.get('/admin/?a=flow_version&form_id=' + form_id) |
| 655 | .then(res => { | 668 | .then(res => { |
| 656 | if (res.data.code) { | 669 | if (res.data.code) { |
| 657 | - // 流程版本列表 | 670 | + state.version_list = res.data.data;// 流程版本列表 |
| 658 | - state.version_list = res.data.data; | 671 | + let flow_id = getFlowId(); // 流程id,如果是新的流程,则为空 |
| 659 | - const urlQuery = getQueryParams(location.href); | 672 | + if (state.version_list.length) { // 从外部页面第一次跳到流程编辑页面时,flow_id不存在 |
| 660 | - let flow_id = urlQuery.flow_id? urlQuery.flow_id : ''; // 流程id,如果是新的流程,则为空 | 673 | + let index = _.findIndex(state.version_list, { status: '1' }); |
| 661 | - // 从外部页面第一次跳到流程编辑页面时,flow_id不存在 | 674 | + if (index > -1) { |
| 662 | - if (flow_id) { | 675 | + state.current_enable_version = state.version_list[index].code; // 流程版本列表显示启用项 |
| 663 | - if (state.version_list.length) { | ||
| 664 | - state.version_list.forEach((ele) => { | ||
| 665 | - if (ele.id === +flow_id) { | ||
| 666 | - // 选中的版本号 | ||
| 667 | - state.select_flow_version = ele.code; | ||
| 668 | - } | ||
| 669 | - if (ele.status === '1') { | ||
| 670 | - // 流程版本列表显示启用项 | ||
| 671 | - state.current_enable_version = ele.code; | ||
| 672 | - } | ||
| 673 | - }); | ||
| 674 | } | 676 | } |
| 675 | - } else { | ||
| 676 | - // 如果列表里没有启用的版本获取flow_id不存在时,默认选中第一个 | ||
| 677 | - if (state.version_list.length) { | ||
| 678 | - let ele = state.version_list[0]; | ||
| 679 | - flow_id = ele.id; | ||
| 680 | - updateUrl(flow_id); // 更新url | ||
| 681 | - state.select_flow_version = ele.code; // 选中的版本号 | ||
| 682 | - state.version_list.forEach((ele) => { | ||
| 683 | - if (ele.status === '1') { | ||
| 684 | - // 流程版本列表显示启用项 | ||
| 685 | - state.current_enable_version = ele.code; | ||
| 686 | - } | ||
| 687 | - }); | ||
| 688 | - console.warn(ele); | ||
| 689 | 677 | ||
| 690 | - getFlowData(flow_id); | 678 | + if (flow_id) { // 缓存里访问过 |
| 679 | + let index = _.findIndex(state.version_list, (v) => v.id == flow_id); | ||
| 680 | + if (index > -1) { | ||
| 681 | + state.select_flow_version = state.version_list[index].code; // 选中的版本号 | ||
| 682 | + } | ||
| 683 | + } else { // 如果列表里没有启用的版本获取 flow_id 不存在时,默认选中第一个 | ||
| 684 | + state.select_flow_version = state.version_list[0].code; // 选中的版本号 | ||
| 685 | + updateFlowId(state.version_list[0].id); // 更新 flow_id | ||
| 686 | + getFlowData(state.version_list[0].id);// 新的 flow_id,更新流程图 | ||
| 691 | } | 687 | } |
| 692 | - } | 688 | + } else { // 没有默认版本列表,自动新增流程 |
| 693 | - // 没有默认版本列表,自动新增流程 | 689 | + axios.post('/admin/?a=save_flow', qs.stringify({ form_id: +form_id, flow_id: '', data: JSON.stringify(AppData) })) |
| 694 | - if (!state.version_list.length) { | 690 | + .then(res => { |
| 695 | - axios.post('/admin/?a=save_flow', qs.stringify({ | 691 | + if (res.data.code) { |
| 696 | - form_id: +form_id, | 692 | + getVersionList(); // 刷新版本列表显示 |
| 697 | - flow_id: '', | 693 | + } else { |
| 698 | - data: JSON.stringify(AppData) | 694 | + ElMessage({ |
| 699 | - })) | 695 | + type: 'error', |
| 700 | - .then(res => { | 696 | + message: res.data.msg, |
| 701 | - if (res.data.code) { | 697 | + }); |
| 702 | - // 刷新版本列表显示 | 698 | + } |
| 703 | - getVersionList(); | 699 | + }) |
| 704 | - } | 700 | + .catch(err => { |
| 705 | - }) | 701 | + console.log(err); |
| 706 | - .catch(err => { | 702 | + }); |
| 707 | - console.log(err); | ||
| 708 | - }); | ||
| 709 | } | 703 | } |
| 710 | } else { | 704 | } else { |
| 711 | ElMessage({ | 705 | ElMessage({ |
| ... | @@ -718,7 +712,6 @@ export default { | ... | @@ -718,7 +712,6 @@ export default { |
| 718 | console.error(err); | 712 | console.error(err); |
| 719 | }); | 713 | }); |
| 720 | } | 714 | } |
| 721 | - | ||
| 722 | getVersionList(); | 715 | getVersionList(); |
| 723 | 716 | ||
| 724 | // TAG: 接口获取流程图数据 | 717 | // TAG: 接口获取流程图数据 |
| ... | @@ -751,6 +744,7 @@ export default { | ... | @@ -751,6 +744,7 @@ export default { |
| 751 | }); | 744 | }); |
| 752 | } | 745 | } |
| 753 | 746 | ||
| 747 | + let flow_id = getFlowId(); // flow_id 流程ID | ||
| 754 | if (flow_id) { | 748 | if (flow_id) { |
| 755 | getFlowData(flow_id); | 749 | getFlowData(flow_id); |
| 756 | } | 750 | } |
| ... | @@ -781,7 +775,7 @@ export default { | ... | @@ -781,7 +775,7 @@ export default { |
| 781 | /***************** 版本操作 ***************/ | 775 | /***************** 版本操作 ***************/ |
| 782 | const onSelectFlowVersion = (id: number, code: number, note: string) => { | 776 | const onSelectFlowVersion = (id: number, code: number, note: string) => { |
| 783 | // 切换版本信息 | 777 | // 切换版本信息 |
| 784 | - updateUrl(id); // 更新URL | 778 | + updateFlowId(id); // 更新缓存flow_id |
| 785 | getFlowData(id); // 更新流程图数据 | 779 | getFlowData(id); // 更新流程图数据 |
| 786 | state.select_flow_version = code; | 780 | state.select_flow_version = code; |
| 787 | } | 781 | } |
| ... | @@ -805,7 +799,7 @@ export default { | ... | @@ -805,7 +799,7 @@ export default { |
| 805 | .then(res => { | 799 | .then(res => { |
| 806 | if (res.data.code) { | 800 | if (res.data.code) { |
| 807 | flow_id = res.data.data; // 更新flow_id | 801 | flow_id = res.data.data; // 更新flow_id |
| 808 | - updateUrl(flow_id); // 更新url | 802 | + updateFlowId(flow_id); // 更新缓存flow_id |
| 809 | getFlowData(flow_id); | 803 | getFlowData(flow_id); |
| 810 | ElMessage({ | 804 | ElMessage({ |
| 811 | type: 'success', | 805 | type: 'success', |
| ... | @@ -855,7 +849,7 @@ export default { | ... | @@ -855,7 +849,7 @@ export default { |
| 855 | }); | 849 | }); |
| 856 | let flow_id = res.data.data; | 850 | let flow_id = res.data.data; |
| 857 | state.reloadLoading = true; // 打开loading | 851 | state.reloadLoading = true; // 打开loading |
| 858 | - updateUrl(flow_id); // 更新URL | 852 | + updateFlowId(flow_id); // 更新缓存flow_id |
| 859 | getVersionList(); // 刷新版本列表 | 853 | getVersionList(); // 刷新版本列表 |
| 860 | getFlowData(flow_id); // 更新流程图数据 | 854 | getFlowData(flow_id); // 更新流程图数据 |
| 861 | } | 855 | } |
| ... | @@ -1056,8 +1050,7 @@ export default { | ... | @@ -1056,8 +1050,7 @@ export default { |
| 1056 | const paths = []; | 1050 | const paths = []; |
| 1057 | findPathsToEndNode(edges, 'start-node', [], paths); | 1051 | findPathsToEndNode(edges, 'start-node', [], paths); |
| 1058 | 1052 | ||
| 1059 | - const urlQuery = getQueryParams(location.href); | 1053 | + let flow_id = getFlowId(); // 流程id |
| 1060 | - let flow_id = urlQuery.flow_id? urlQuery.flow_id : ''; // 流程id | ||
| 1061 | 1054 | ||
| 1062 | if (paths.length) { | 1055 | if (paths.length) { |
| 1063 | axios.post('/admin/?a=save_flow', qs.stringify({ | 1056 | axios.post('/admin/?a=save_flow', qs.stringify({ |
| ... | @@ -1068,7 +1061,7 @@ export default { | ... | @@ -1068,7 +1061,7 @@ export default { |
| 1068 | .then(res => { | 1061 | .then(res => { |
| 1069 | if (res.data.code) { | 1062 | if (res.data.code) { |
| 1070 | flow_id = res.data.data; // 更新flow_id | 1063 | flow_id = res.data.data; // 更新flow_id |
| 1071 | - updateUrl(flow_id); // 更新url | 1064 | + updateFlowId(flow_id); // 更新缓存flow_id |
| 1072 | console.log(paths); // 输出满足条件的路径结果数组 | 1065 | console.log(paths); // 输出满足条件的路径结果数组 |
| 1073 | } else { | 1066 | } else { |
| 1074 | ElMessage({ | 1067 | ElMessage({ |
| ... | @@ -1154,8 +1147,7 @@ export default { | ... | @@ -1154,8 +1147,7 @@ export default { |
| 1154 | state.statusLoading = true; | 1147 | state.statusLoading = true; |
| 1155 | state.main_attr_set = true; // 重置更多属性的显示 | 1148 | state.main_attr_set = true; // 重置更多属性的显示 |
| 1156 | 1149 | ||
| 1157 | - const urlQuery = getQueryParams(location.href); | 1150 | + let flow_id = getFlowId(); // 流程id |
| 1158 | - let flow_id = urlQuery.flow_id? urlQuery.flow_id : ''; // 流程id | ||
| 1159 | // | 1151 | // |
| 1160 | axios.get('/admin/?a=flow_node_property&node_code=' + model.id + '&flow_id=' + flow_id) | 1152 | axios.get('/admin/?a=flow_node_property&node_code=' + model.id + '&flow_id=' + flow_id) |
| 1161 | .then((res: any) => { | 1153 | .then((res: any) => { |
| ... | @@ -1383,8 +1375,7 @@ export default { | ... | @@ -1383,8 +1375,7 @@ export default { |
| 1383 | }) | 1375 | }) |
| 1384 | }); | 1376 | }); |
| 1385 | 1377 | ||
| 1386 | - const urlQuery = getQueryParams(location.href); | 1378 | + let flow_id = getFlowId(); // 流程id |
| 1387 | - let flow_id = urlQuery.flow_id? urlQuery.flow_id : ''; // 流程id | ||
| 1388 | 1379 | ||
| 1389 | // TAG: 保存表单信息 | 1380 | // TAG: 保存表单信息 |
| 1390 | axios.post('/admin/?a=save_node_property', qs.stringify({ | 1381 | axios.post('/admin/?a=save_node_property', qs.stringify({ |
| ... | @@ -1645,8 +1636,7 @@ export default { | ... | @@ -1645,8 +1636,7 @@ export default { |
| 1645 | const paths = []; | 1636 | const paths = []; |
| 1646 | findPathsToEndNode(edges, 'start-node', [], paths); | 1637 | findPathsToEndNode(edges, 'start-node', [], paths); |
| 1647 | 1638 | ||
| 1648 | - const urlQuery = getQueryParams(location.href); | 1639 | + let flow_id = getFlowId(); // 流程id |
| 1649 | - let flow_id = urlQuery.flow_id? urlQuery.flow_id : ''; // 流程id | ||
| 1650 | 1640 | ||
| 1651 | if (paths.length) { | 1641 | if (paths.length) { |
| 1652 | axios.post('/admin/?a=save_flow', qs.stringify({ | 1642 | axios.post('/admin/?a=save_flow', qs.stringify({ |
| ... | @@ -1661,7 +1651,7 @@ export default { | ... | @@ -1661,7 +1651,7 @@ export default { |
| 1661 | message: '保存流程图成功', | 1651 | message: '保存流程图成功', |
| 1662 | }); | 1652 | }); |
| 1663 | flow_id = res.data.data; // 更新flow_id | 1653 | flow_id = res.data.data; // 更新flow_id |
| 1664 | - updateUrl(flow_id); // 更新url | 1654 | + updateFlowId(flow_id); // 更新缓存flow_id |
| 1665 | console.log(paths); // 输出满足条件的路径结果数组 | 1655 | console.log(paths); // 输出满足条件的路径结果数组 |
| 1666 | } else { | 1656 | } else { |
| 1667 | ElMessage({ | 1657 | ElMessage({ | ... | ... |
-
Please register or login to post a comment