123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991 |
- <template>
- <div class="vueFlow">
- <div id="container"></div>
- <div id="stencil"></div>
- <div id="graph-container"></div>
- <div id="minimap"></div>
- </div>
- <el-button @click="submitAll" type="primary">保存</el-button>
- <el-dialog
- title="节点信息配置"
- v-model="dialogVisible"
- width="500"
- v-loading="loading"
- >
- <byForm
- :formConfig="formType === 'handle-btn' ? formConfig : branchBtnConfig"
- :formOption="formOption"
- v-model="formData.data"
- :rules="rules"
- ref="byform"
- >
- </byForm>
- <template #footer>
- <el-button @click="dialogVisible = false" size="large"
- >取 消</el-button
- >
- <el-button
- type="danger"
- @click="deleteFlowDefinitionNodeObj()"
- size="large"
- :loading="submitLoading"
- >
- 删 除
- </el-button>
- <el-button
- type="primary"
- @click="submitForm('byform')"
- size="large"
- :loading="submitLoading"
- >
- 确 定
- </el-button>
- </template>
- </el-dialog>
- <el-dialog
- title="节点信息配置"
- v-model="startModalType"
- width="500"
- v-loading="loading"
- >
- <div>
- 节点后执行方法
- <el-input style="margin-top:10px" v-model="handlingMethod"></el-input>
- </div>
- <template #footer>
- <el-button @click="startModalType = false" size="large">取 消</el-button>
- <el-button
- type="primary"
- @click="startModalType = false"
- size="large"
- :loading="submitLoading"
- >
- 确 定
- </el-button>
- </template>
- </el-dialog>
- </template>
- <script lang="ts" setup>
- import {
- ref,
- onMounted,
- reactive,
- computed,
- getCurrentInstance,
- onDeactivated,
- onActivated,
- } from "vue";
- import byForm from "@/components/byForm/index";
- import { Graph, Shape } from "@antv/x6";
- import { Stencil } from "@antv/x6-plugin-stencil";
- import { Transform } from "@antv/x6-plugin-transform";
- import { Selection } from "@antv/x6-plugin-selection";
- import { Snapline } from "@antv/x6-plugin-snapline";
- import { Keyboard } from "@antv/x6-plugin-keyboard";
- import { Clipboard } from "@antv/x6-plugin-clipboard";
- import { register } from "@antv/x6-vue-shape";
- import { History } from "@antv/x6-plugin-history";
- import Cookies from "js-cookie";
- import { ElMessage, ElMessageBox } from "element-plus";
- import startBtn from "./startBtn.vue";
- import endBtn from "./endBtn.vue";
- import handleBtn from "./handleBtn.vue";
- import branchBtn from "./branchBtn.vue";
- import { MiniMap } from "@antv/x6-plugin-minimap";
- import useTagsViewStore from "@/store/modules/tagsView";
- defineProps({
- title: {
- type: Object,
- default: "",
- },
- });
- const { proxy } = getCurrentInstance();
- const internalInstance = getCurrentInstance();
- const dialogVisible = ref(false);
- const modalType = ref("add");
- const loading = ref(false);
- const submitLoading = ref(false);
- let formType = ref(1);
- const formData = reactive({
- data: {
- userName: "",
- password: "",
- },
- });
- const startModalType = ref(false);
- const handlingMethod = ref("");
- const byform = ref(null);
- const flowDefinitionNodeObj = ref({});
- const rules = reactive({
- nodeName: [
- {
- required: true,
- message: "请输入节点名称",
- trigger: "blur",
- },
- ],
- handleObjectType: [
- {
- required: true,
- message: "办理人类型不能为空",
- trigger: "blur",
- },
- ],
- handleObjectId: [
- {
- required: true,
- message: "办理人不能为空",
- trigger: "blur",
- },
- ],
- });
- const branchBtnConfig = computed(() => {
- return [
- {
- type: "input",
- prop: "nodeName",
- label: "节点名称",
- required: true,
- itemType: "text",
- },
- ];
- });
- const formConfig = computed(() => {
- return [
- {
- type: "input",
- prop: "nodeName",
- label: "节点名称",
- required: true,
- itemType: "text",
- },
- {
- type: "select",
- prop: "handleObjectType",
- label: "办理人",
- placeholder: "请选择办理人类型",
- required: true,
- itemWidth: 30,
- fn: (e) => {
- gethandleObjectList(e);
- },
-
- data: [
- {
- label: "用户",
- value: 1,
- },
- {
- label: "部门负责人",
- value: 2,
- },
- {
- label: "部门总监",
- value: 3,
- },
- {
- label: "岗位",
- value: 4,
- },
- {
- label: "角色",
- value: 5,
- },
- ],
- },
-
-
-
-
-
-
-
- {
- type: "select",
- label: " ",
- itemWidth: 30,
- prop: "handleObjectId",
- placeholder: "请选择办理人",
- data: [],
- },
- {
- type: "input",
- prop: "handlingMethod",
- label: "节点后置执行方法",
- required: true,
- itemType: "text",
- },
- {
- type: "input",
- prop: "jumpCondition",
- label: "条件表达式",
- required: true,
- itemType: "text",
- },
- {
- type: "checkbox",
- prop: "nodeButtonSet",
- label: "节点按钮",
-
- data: [
- {
- label: "通过",
- value: 1,
- disabled: true,
- },
- {
- label: "驳回",
- value: 2,
- },
- {
- label: "返回上一步",
- value: 3,
- },
- {
- label: "退回到发起人",
- value: 4,
- },
- ],
- },
- {
- type: "radio",
- prop: "jobNumber11",
- label: "审批意见必填",
- data: [
- {
- label: "是",
- value: 1,
- },
- {
- label: "否",
- value: 0,
- },
- ],
- },
- ];
- });
- const formOption = reactive({
- inline: true,
- labelWidth: 100,
- itemWidth: 100,
- });
- let graph;
- const submitForm = () => {
- byform.value.handleSubmit((valid) => {
- flowDefinitionNodeObj.value[formData.data.id] = formData.data;
- dialogVisible.value = false;
- formData.data.cell.setData({
- title: formData.data.nodeName,
- });
- });
- };
- const submitFormData = {
- flowInfoId: null,
- titleTemplate: null,
- tenantId: Cookies.get("tenantId"),
- nodeObject: "",
- lineObject: "",
- flowDefinitionNodeList: [],
- };
- const submitAll = () => {
- if (proxy.title == "") {
- ElMessage({
- message: "请输入流程标题",
- type: "warning",
- });
- return;
- }
- submitFormData.titleTemplate = proxy.title;
- const nodeList = graph.toJSON().cells;
- submitFormData.nodeObject = JSON.stringify(nodeList);
- submitFormData.lineObject = JSON.stringify(flowDefinitionNodeObj.value);
- const isStart = false;
- for (let i = 0; i < nodeList.length; i++) {
- const element = nodeList[i];
- //是办理节点
- if (
- element.shape != "start-btn" &&
- element.shape != "edge" &&
- element.shape != "end-btn"
- ) {
- if (!flowDefinitionNodeObj.value[element.id]) {
- ElMessage({
- message: "有节点未配置,请检查节点",
- type: "warning",
- });
- return;
- }
- submitFormData.flowDefinitionNodeList.push({
- ...flowDefinitionNodeObj.value[element.id],
- nodeType: element.shape == "branch-btn" ? 3 : 2,
- });
- }
- if (element.shape == "end-btn") {
- submitFormData.flowDefinitionNodeList.push({
- ...flowDefinitionNodeObj.value[element.id],
- });
- }
- if (element.shape == "start-btn") {
- submitFormData.flowDefinitionNodeList.push({
- nodeName: "开始",
- nodeType: 1,
- id: 1,
- parentId: 0,
- nodeButtonSet: [1],
- handlingMethod: handlingMethod.value,
- });
- }
- //说明是线
- if (element.shape == "edge") {
- if (!flowDefinitionNodeObj.value[element.target.cell]) {
- ElMessage({
- message: "有节点未配置,请检查节点",
- type: "warning",
- });
- return;
- }
- flowDefinitionNodeObj.value[element.target.cell].id = element.target.cell;
- flowDefinitionNodeObj.value[element.target.cell].parentId =
- element.source.cell;
- submitFormData.flowDefinitionNodeList = [];
- }
- }
- addVersion();
- };
- //选取一个随机不重复的正整数id
- const randomId = () => {
- const id = Math.floor(Math.random() * 100000000000000000);
- if (flowDefinitionNodeObj.value[id]) {
- randomId();
- } else {
- return id;
- }
- };
- const addVersion = () => {
- const idObg = {};
- for (let i = 0; i < submitFormData.flowDefinitionNodeList.length; i++) {
- const element = submitFormData.flowDefinitionNodeList[i];
- if (element.parentId == null && element.nodeName == "结束") {
- ElMessage({
- message: "有结束节点未连线,请配置",
- type: "warning",
- });
- return;
- }
- if (isNaN(element.id)) {
- if (idObg[element.id]) {
- element.id = idObg[element.id];
- } else {
- const id = randomId();
- idObg[element.id] = id;
- element.id = id;
- }
- }
- if (isNaN(element.parentId) && element.nodeName != "开始") {
- if (idObg[element.parentId]) {
- element.parentId = idObg[element.parentId];
- } else {
- const id = randomId();
- idObg[element.parentId] = id;
- element.parentId = id;
- }
- }
- //nodeButtonSet转成字符串类型,用逗号隔开
- if (element.nodeButtonSet) {
- element.nodeButtonSet = element.nodeButtonSet.join(",");
- }
- }
- proxy.post("/flowDefinition/addVersion", submitFormData).then((res) => {
- ElMessage({
- message: "保存成功",
- type: "success",
- });
- useTagsViewStore().delView(router.currentRoute.value);
- history.go(-1);
- });
- };
- const changeId = (arr) => {
- for (let i = 0; i < arr.length; i++) {
- const element = arr[i];
- element.id = parseInt(element.id);
- element.parentId = parseInt(element.parentId);
- }
- };
- const deleteFlowDefinitionNodeObj = (id) => {
- graph.removeNode(formData.data.id);
- delete flowDefinitionNodeObj.value[id];
- dialogVisible.value = false;
- };
- const gethandleObjectList = (e) => {
- formData.data.handleObjectId = "";
- if (e === 1) {
- proxy
- .get(
- "/tenantUser/list?pageNum=1&pageSize=1000&tenantId=" +
- submitFormData.tenantId,
- {}
- )
- .then((res) => {
- formConfig.value[2].data = res.rows.map((item) => {
- return {
- label: item.nickName,
- value: item.userId,
- };
- });
- });
- }
- if (e === 3 || e === 2) {
- proxy
- .get(
- "/tenantDept/list?pageNum=1&pageSize=1000&tenantId=" +
- submitFormData.tenantId,
- {}
- )
- .then((res) => {
- formConfig.value[2].data = res.data.map((item) => {
- return {
- label: item.deptName,
- value: item.deptId,
- };
- });
- });
- }
- if (e === 4) {
- }
- if (e === 5) {
- proxy
- .get(
- "/tenantRole/list?pageNum=1&pageSize=1000&tenantId=" +
- submitFormData.tenantId,
- {}
- )
- .then((res) => {
- formConfig.value[2].data = res.rows.map((item) => {
- return {
- label: item.roleName,
- value: item.roleId,
- };
- });
- });
- }
- };
- const getTenantDept = () => {};
- getTenantDept();
- const recursive = (data) => {
- data.map((item) => {
- item.label = item.deptName;
- item.id = item.deptId;
- if (item.children) {
- recursive(item.children);
- } else {
- item.children = [];
- }
- });
- };
- const pushRoom = (port: any) => {
- if (port.node.shape == "end-btn") {
- flowDefinitionNodeObj.value[port.node.id] = {
- nodeName: "结束",
- nodeType: 99,
- id: port.id,
- nodeButtonSet: "",
- parentId: null,
- };
- }
- };
- const antvInit = (data) => {
- graph = new Graph({
- height: 600,
- container: document.getElementById("graph-container")!,
- grid: true,
- onPortRendered: pushRoom,
- mousewheel: {
- enabled: true,
- zoomAtMousePosition: true,
- modifiers: "ctrl",
- minScale: 0.5,
- maxScale: 3,
- },
- connecting: {
- allowLoop: false,
-
- connector: {
- name: "rounded",
- args: {
- radius: 8,
- },
- },
- anchor: "center",
- connectionPoint: "anchor",
- allowBlank: false,
- snap: {
- radius: 20,
- },
- createEdge() {
- return new Shape.Edge({
- attrs: {
- line: {
- stroke: "#A2B1C3",
- strokeWidth: 2,
- targetMarker: {
- name: "block",
- width: 12,
- height: 8,
- },
- },
- },
- zIndex: 0,
- });
- },
- validateConnection({ targetMagnet }) {
- return !!targetMagnet;
- },
- },
- highlighting: {
- magnetAdsorbed: {
- name: "stroke",
- args: {
- attrs: {
- fill: "#5F95FF",
- stroke: "#5F95FF",
- },
- },
- },
- },
- });
- graph.use(
- new MiniMap({
- container: document.getElementById("minimap"),
- })
- );
- const stencil = new Stencil({
- title: "流程图",
- target: graph,
- stencilGraphWidth: 360,
- stencilGraphHeight: 280,
- collapsable: true,
- groups: [
- {
- title: "基础流程图",
- name: "group1",
- },
- ],
- layoutOptions: {
- columns: 2,
- columnWidth: 170,
- rowHeight: 100,
- },
- });
- document.getElementById("stencil")!.appendChild(stencil.container);
-
- graph
- .use(
- new Transform({
- resizing: true,
- rotating: true,
- })
- )
- .use(
- new Selection({
- enabled: true,
- rubberband: true,
- showNodeSelectionBox: true,
- })
- )
- .use(
- new Snapline({
- enabled: true,
- })
- )
- .use(
- new Keyboard({
- enabled: true,
- })
- )
- .use(
- new Clipboard({
- enabled: true,
- })
- )
- .use(
- new History({
- enabled: true,
- })
- );
-
- const showPorts = (ports: NodeListOf<SVGElement>, show: boolean) => {
- for (let i = 0, len = ports.length; i < len; i += 1) {
- ports[i].style.visibility = show ? "visible" : "hidden";
- }
- };
- graph.on("node:mouseenter", () => {
- const container = document.getElementById("graph-container")!;
- const ports = container.querySelectorAll(
- ".x6-port-body"
- ) as NodeListOf<SVGElement>;
- showPorts(ports, true);
- });
- graph.on("node:mouseleave", () => {
- const container = document.getElementById("graph-container")!;
- const ports = container.querySelectorAll(
- ".x6-port-body"
- ) as NodeListOf<SVGElement>;
- showPorts(ports, false);
- });
-
- graph.on("cell:click", ({ e, x, y, cell, view }) => {
- if (cell.shape === "start-btn") {
- startModalType.value = true;
- return;
- }
- if (cell.shape === "end-btn" || cell.shape === "edge") {
- ElMessageBox.confirm("是否删除", "提示", {
- confirmButtonText: "确定",
- cancelButtonText: "取消",
- type: "warning",
- }).then(() => {
- graph.removeNode(cell.id);
-
- });
- return;
- }
- formType.value = cell.shape;
- if (flowDefinitionNodeObj.value[cell.id]) {
- formData.data = flowDefinitionNodeObj.value[cell.id];
- formData.data.cell = cell;
- } else {
- formData.data = {
- id: cell.id,
- cell: cell,
- nodeButtonSet: [1],
- };
- }
- dialogVisible.value = true;
- });
-
- const ports = {
- groups: {
- top: {
- position: "top",
- attrs: {
- circle: {
- r: 4,
- magnet: true,
- stroke: "#5F95FF",
- strokeWidth: 1,
- fill: "#fff",
- style: {
- visibility: "hidden",
- },
- },
- },
- },
- right: {
- position: "right",
- attrs: {
- circle: {
- r: 4,
- magnet: true,
- stroke: "#5F95FF",
- strokeWidth: 1,
- fill: "#fff",
- style: {
- visibility: "hidden",
- },
- },
- },
- },
- bottom: {
- position: "bottom",
- attrs: {
- circle: {
- r: 4,
- magnet: true,
- stroke: "#5F95FF",
- strokeWidth: 1,
- fill: "#fff",
- style: {
- visibility: "hidden",
- },
- },
- },
- },
- left: {
- position: "left",
- attrs: {
- circle: {
- r: 4,
- magnet: true,
- stroke: "#5F95FF",
- strokeWidth: 1,
- fill: "#fff",
- style: {
- visibility: "hidden",
- },
- },
- },
- },
- },
- items: [
- {
- group: "top",
- },
- {
- group: "right",
- },
- {
- group: "bottom",
- },
- {
- group: "left",
- },
- ],
- };
- Graph.registerNode(
- "custom-rect",
- {
- inherit: "rect",
- width: 66,
- height: 36,
- attrs: {
- body: {
- strokeWidth: 1,
- stroke: "#5F95FF",
- fill: "#EFF4FF",
- },
- text: {
- fontSize: 12,
- fill: "#262626",
- },
- },
- ports: { ...ports },
- },
- true
- );
- register({
- shape: "start-btn",
- width: 150,
- height: 90,
- component: startBtn,
- effect: ["title"],
- ports: { ...ports },
- data: {
- title: 80,
- },
- });
- register({
- shape: "handle-btn",
- width: 150,
- height: 90,
- effect: ["title"],
- component: handleBtn,
- ports: { ...ports },
- });
- register({
- shape: "branch-btn",
- width: 150,
- height: 90,
- effect: ["title"],
- component: branchBtn,
- ports: { ...ports },
- });
- register({
- shape: "end-btn",
- width: 150,
- height: 90,
- effect: ["title"],
- component: endBtn,
- ports: { ...ports },
- });
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- const r2 = graph.createNode({
- shape: "handle-btn",
- label: "办理",
- zIndex: 100,
- attrs: {
- body: {
- rx: 40,
- ry: 46,
- },
- },
- });
- const r3 = graph.createNode({
- shape: "branch-btn",
- label: "分支",
- zIndex: 100,
- attrs: {
- body: {
- rx: 40,
- ry: 46,
- },
- },
- });
- const r4 = graph.createNode({
- shape: "end-btn",
- label: "结束",
- zIndex: 100,
- attrs: {
- body: {
- rx: 20,
- ry: 26,
- },
- },
- });
- stencil.load([r2, r3, r4], "group1");
-
-
-
-
-
-
-
- if (data) {
- graph.fromJSON(data);
- } else {
- graph.addNode({
- shape: "start-btn",
- x: 500,
- y: 20,
- label: "开始",
- id: 1,
- attrs: {},
- });
- }
- };
- const getFlowInfo = () => {
- proxy
- .post("/flowDefinition/getDetails", { id: submitFormData.id })
- .then((res) => {
- if (res.lineObject) {
- flowDefinitionNodeObj.value = JSON.parse(res.lineObject);
- for (const key in flowDefinitionNodeObj.value) {
- if (flowDefinitionNodeObj.value[key].nodeButtonSet) {
- flowDefinitionNodeObj.value[key].nodeButtonSet =
- flowDefinitionNodeObj.value[key].nodeButtonSet.map((item) => {
- return item * 1;
- });
- }
- }
- }
- if (res.nodeObject) {
- antvInit(JSON.parse(res.nodeObject));
- } else {
- antvInit();
- }
- for (const key in flowDefinitionNodeObj.value) {
-
- setTimeout(() => {
- if (
- flowDefinitionNodeObj.value[key].nodeName != "结束" &&
- flowDefinitionNodeObj.value[key].cell != "开始"
- ) {
- let htmlNode = document.querySelector(
- "g[data-cell-id='" + key + "']"
- );
-
- htmlNode.getElementsByClassName("title")[0].innerHTML =
- flowDefinitionNodeObj.value[key].nodeName;
- }
- }, 2000);
- }
- dialogVisible.value = false;
- });
- };
- const router = useRouter();
- onActivated(() => {});
- onDeactivated(() => {
- if (window.document.getElementById("minimap").children.length > 1) {
- window.document.getElementById("minimap").children[0].remove();
- }
- });
- onMounted(() => {
-
- submitFormData.flowInfoId = router.currentRoute.value.query.flowInfoId;
- submitFormData.id = router.currentRoute.value.query.id;
- submitFormData.tenantId = router.currentRoute.value.query.tenantId;
- if (submitFormData.flowInfoId) {
- getFlowInfo();
- }
- setTimeout(() => {
- if (window.document.getElementById("minimap").children.length > 1) {
- window.document.getElementById("minimap").children[0].remove();
- }
- }, 500);
- });
- </script>
- <style lang="scss">
- #minimap .x6-widget-minimap {
- border: 1px solid #dcdcdc;
- }
- .x6-widget-stencil-group-title {
- display: none !important;
- }
- .x6-widget-stencil-title {
- display: none;
- }
- .x6-widget-stencil-content {
- top: 0 !important;
- }
- .vueFlow {
- position: relative;
- display: flex;
- justify-content: space-between;
- overflow: hidden;
- height: 600px;
- .x6-graph {
- width: 100% !important;
- }
- #stencil {
- position: fixed;
- top: 250px;
- left: 40px;
- z-index: 100;
- width: 360px;
- height: 500px;
- background: #fff;
- overflow: hidden;
- background: #eee;
- border-radius: 20px;
- }
- #container {
- }
- #graph-container {
- width: 100%;
- position: absolute;
- right: 0;
- top: 0;
- }
- }
- </style>
|