123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748 |
- <template >
- <div class="vueFlow1">
- <div id="container"></div>
- <div id="stencil"></div>
- <div id="graph-container"></div>
- <div id="minimap"></div>
- </div>
- <el-dialog title="节点信息配置" v-model="dialogVisible" width="500" v-if="dialogVisible">
- <byForm :formConfig="formConfig" :formOption="formOption" v-model="formData.data" v-loading="loading" :rules="rules" ref="byform">
- </byForm>
- <template #footer>
- <div>
- <el-button @click="dialogVisible = false" size="default">取 消</el-button>
- <el-button type="danger" @click="deleteFlowDefinitionNodeObj()" size="default">
- 删 除
- </el-button>
- <el-button type="primary" @click="submitForm" size="default">
- 确 定
- </el-button>
- </div>
- </template>
- </el-dialog>
- </template>
- <script lang="ts" setup>
- import {
- defineComponent,
- ref,
- onMounted,
- onUnmounted,
- watch,
- reactive,
- toRefs,
- computed,
- nextTick,
- 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";
- import { rectToBox } from "@vue-flow/core/dist/utils/graph";
- import { async } from "@antv/x6/lib/registry/marker/main";
- defineProps({
- title: {
- type: Object,
- default: "",
- },
- nodeObject: {
- type: String,
- default: "",
- },
- });
- const { proxy } = getCurrentInstance();
- const flowNodeObj = ref({});
- const dialogVisible = ref(false);
- const loading = ref(false);
- const byform = ref(null);
- const formData = reactive({
- data: {},
- });
- const formOption = reactive({
- inline: true,
- labelWidth: 100,
- itemWidth: 100,
- });
- const formConfig = computed(() => {
- return [
- {
- type: "input",
- prop: "nodeName",
- label: "工序名称",
- required: true,
- itemType: "text",
- },
- ];
- });
- const rules = reactive({
- nodeName: [
- {
- required: true,
- message: "请输入工序名称",
- trigger: "blur",
- },
- ],
- });
- const flowDefinitionNodeObj = ref({});
- let graph;
- const submitFormData = {
- flowInfoId: null,
- titleTemplate: null,
- tenantId: Cookies.get("tenantId"),
- nodeObject: "",
- lineObject: "",
- flowDefinitionNodeList: [],
- };
- const deleteFlowDefinitionNodeObj = () => {
- graph.removeNode(formData.data.id);
- delete flowNodeObj.value[formData.data.id];
- dialogVisible.value = false;
-
-
-
- };
- const submitForm = () => {
- byform.value.handleSubmit((valid) => {
- console.log(formData.data.nodeName, "sada");
- formData.data.cell.setData({
- title: formData.data.nodeName,
- });
- flowNodeObj.value[formData.data.id].nodeName = formData.data.nodeName;
- dialogVisible.value = false;
-
-
-
-
- });
- };
- const submitAll = () => {
- const nodeList = graph.toJSON().cells;
- submitFormData.nodeObject = JSON.stringify(nodeList);
-
- console.log(nodeList, "asda");
- const arr = nodeList
- .filter((x) => x.shape != "edge")
- .filter((y) => y.productionId);
- console.log(arr, "bbb");
- const newArr = arr.map((x) => x.productionId);
- if (new Set(newArr).size != newArr.length) {
- ElMessage({
- message: "工序不可重复",
- type: "info",
- });
- return false;
- }
- return {
- nodeObject: submitFormData.nodeObject,
- };
- };
- 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 pushRoom = (port: any) => {
-
-
-
-
-
-
-
-
-
- if (port.node.shape == "handle-btn") {
- let nodeName = "";
- if (
- port.node.store &&
- port.node.store.data &&
- port.node.store.data.data &&
- port.node.store.data.data.title
- ) {
- nodeName = port.node.store.data.data.title;
- }
- flowNodeObj.value[port.node.id] = {
- nodeName: nodeName,
- id: port.node.id,
- };
- }
- };
- const antvInit = async (data) => {
- graph = new Graph({
- height: 600,
- container: document.getElementById("graph-container")!,
- grid: true,
- panning: {
- enabled: true,
- eventTypes: "rightMouseDown",
- },
- 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",
- },
- },
- },
- },
- });
-
-
-
-
-
-
-
-
-
-
- const stencil = new Stencil({
- title: "流程图",
- target: graph,
- stencilGraphWidth: 360,
- stencilGraphHeight: 280,
- collapsable: true,
- groups: [
- {
- title: "基础流程图",
- name: "group1",
- },
- ],
- layoutOptions: {
- columns: 1,
- 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:added", ({ node }) => {});
- 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") {
- return;
- }
- if (cell.shape === "end-btn") {
- return;
- }
- if (cell.shape === "handle-btn" || cell.shape === "edge") {
-
-
-
-
-
-
-
-
- formData.data.id = cell.id;
- formData.data.cell = cell;
- console.log(cell, "sss");
- if (cell.store.data.data) {
- formData.data.nodeName = cell.store.data.data.title;
- } else if (cell.store.data) {
- formData.data.nodeName = cell.store.data.label;
- } else {
- formData.data.nodeName = "";
- }
- 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,
- },
- },
- });
- let arr = [];
- const resList = await proxy.post("/productionProcesses/page", {
- pageNum: 1,
- pageSize: 9999,
- });
- arr = resList.rows.map((x) => {
- return graph.createNode({
- shape: "handle-btn",
- label: x.name,
- productionId: x.id,
- zIndex: 100,
- attrs: {
- body: {
- rx: 20,
- ry: 26,
- },
- },
- });
- });
- stencil.load([...arr], "group1");
- if (data) {
- graph.fromJSON(data);
- } else {
- graph.addNode({
- shape: "start-btn",
- x: 300,
- y: 20,
- label: "开始",
- id: 1,
- attrs: {},
- });
- graph.addNode({
- shape: "end-btn",
- x: 300,
- y: 300,
- label: "结束",
- id: 99,
- attrs: {},
- });
- }
- };
- const getFlowInfo = (data) => {
- if (data) {
- antvInit(data);
- } else {
- antvInit();
- }
- };
- onActivated(() => {});
- onDeactivated(() => {
- console.log(window.document.getElementById("minimap").children);
- if (window.document.getElementById("minimap").children.length > 1) {
- window.document.getElementById("minimap").children[0].remove();
- }
- });
- onMounted(() => {
- if (proxy.nodeObject) {
- let data = JSON.parse(proxy.nodeObject);
- getFlowInfo(data);
- } else {
- getFlowInfo();
- }
- setTimeout(() => {
- if (window.document.getElementById("minimap").children.length > 1) {
- window.document.getElementById("minimap").children[0].remove();
- }
- }, 500);
- });
- defineExpose({
- submitAll,
- });
- </script>
- <style lang="scss" scope>
- #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;
- &::-webkit-scrollbar {
- width: 2px !important;
- height: 2px !important;
- }
- }
- .vueFlow1 {
-
- display: flex;
- justify-content: space-between;
- overflow: hidden;
- height: 600px;
- .x6-graph {
- width: 100% !important;
- }
- #stencil {
-
- position: absolute;
- top: 50px;
- left: 30px;
- z-index: 100;
- width: 190px;
- height: 600px;
- background: #fff;
- overflow: hidden;
-
- border-radius: 10px;
-
- }
- #container {
- }
- #graph-container {
- width: 100%;
-
-
-
-
- }
- }
- #stencil .x6-widget-stencil-content .x6-widget-stencil-group-content .x6-graph {
- height: 900px !important;
- }
- </style>
|