ny
昨天 282fbc6488f4e8ceb5fda759f963ee88fbf7b999
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<script lang="ts" setup>
import { computed, nextTick, onMounted, reactive, ref, unref } from 'vue';
 
import { JnpfBpmn } from '@jnpf/bpmn';
 
import { MinusOutlined, PlusOutlined } from '@ant-design/icons-vue';
 
import FlowButton from './propPanel/components/FlowButton.vue';
 
interface State {
  defaultZoom: number;
}
interface ComType {
  updateCanRedoAndUndo: () => any;
}
const props = defineProps(['flowInfo', 'nodeList', 'flowState', 'versionList', 'type', 'openPreview', 'isPreview', 'noShowScale', 'lineKeyList']);
const emit = defineEmits(['viewSubFlow', 'addVersion']);
defineExpose({ getElement, getBpmn });
const state = reactive<State>({
  defaultZoom: 1, // 流程图缩放比例 100%
});
const jnpfBpmnRef: any = ref(null);
const flowButtonRef = ref<Nullable<ComType>>(null);
const getBpmnBindValue = computed(() => ({
  flowXml: props.flowInfo?.flowXml,
  flowNodes: props.flowInfo?.flowNodes || {},
  nodeList: props.nodeList || [],
  type: props.type,
  isPreview: !!props.isPreview,
  disabled: !!props.isPreview || props.flowState === undefined || props.flowState !== 0,
  openPreview: props.openPreview,
  lineKeyList: props.lineKeyList,
}));
const getBindValue = computed(() => ({ ...props, element: getElement(), bpmn: getBpmn() }));
 
function getElement() {
  return unref(jnpfBpmnRef)?.getElement();
}
function getBpmn() {
  return unref(jnpfBpmnRef)?.getBpmn();
}
function viewSubFlow(data) {
  emit('viewSubFlow', data);
}
/**
 * 控制流程图缩放,缩放介于50% - 220%
 * @param { boolean } isPlus - 是否放大
 */
function changeScale(isPlus?) {
  if ((isPlus && state.defaultZoom > 2) || (!isPlus && state.defaultZoom < 0.6)) return;
  state.defaultZoom = Math.floor(state.defaultZoom * 100 + (isPlus ? 10 : -10)) / 100;
  getBpmn().get('canvas').zoom(state.defaultZoom);
}
function handleAddVersion() {
  emit('addVersion');
}
// 监听bpmn时间
function handleInitListeners() {
  const bpmn = getBpmn();
  // 监听撤回重做
  bpmn?.on('commandStack.changed', () => {
    nextTick(() => (unref(flowButtonRef) as ComType)?.updateCanRedoAndUndo());
  });
}
onMounted(() => {
  handleInitListeners();
});
</script>
 
<template>
  <div class="center-container">
    <FlowButton ref="flowButtonRef" v-bind="getBindValue" v-if="!isPreview" @add-version="handleAddVersion" />
    <template v-if="isPreview">
      <div class="tips">
        <div class="tips-item"><span class="icon past">●</span>已完成</div>
        <div class="tips-item"><span class="icon curr">●</span>进行中</div>
        <div class="tips-item"><span class="icon error">●</span>异常</div>
        <div class="tips-item"><span class="icon">●</span>无/未处理</div>
      </div>
      <div class="scale-slider" v-if="!noShowScale">
        <MinusOutlined class="btn" @click="changeScale()" />
        <span class="num">{{ `${Math.floor(state.defaultZoom * 100)}%` }}</span>
        <PlusOutlined class="btn" @click="changeScale(true)" />
      </div>
    </template>
    <div class="center-container-center">
      <JnpfBpmn v-bind="getBpmnBindValue" ref="jnpfBpmnRef" @view-sub-flow="viewSubFlow" />
    </div>
  </div>
</template>
<style lang="scss">
@use '../style/index.scss' as *;
</style>