1.1.14 • Published 5 years ago

jkstack-flow-chart v1.1.14

Weekly downloads
62
License
-
Repository
-
Last release
5 years ago

自定义流程图

功能

  • 新增节点,新增可新增条件节点和流程节点
  • 删除节点
  • 修改节点,点击查看后弹出抽屉进行节点属性的编辑
  • 多选,按住shift键合并生成控制节点
  • 反选,流程节点可反选,菜单中选择反选目标节点
  • 保存位置,拖拽后保存位置
  • 缩放和画布拖拽
  • 实现流程节点的颜色配置(失败/成功/正常/开始/结束)
  • 流程图中是否可以点击mask关闭抽屉
  • 流程图界面的mask颜色配置
  • 流程图界面的宽高配置
  • 抽屉的宽度配置
  • 返回了节点选择改变的事件
  • 返回了更新节点数据的方法
  • 返回了切换抽屉状态的方法
  • 返回了获取当前流程图数据的方法
  • 新增删除反选按钮是否展示的配置
  • 新增菜单中条件节点的配置
  • 新增菜单中选项文案的配置
  • 删除节点的方法
  • 所有前置节点的方法

安装

推荐使用 npm 的方式安装,它能更好地和 webpack 打包工具配合使用

npm i jkstack-flow-chart

引入

根据需要可以选择再文件中引入,或者全局引入

1.文件引入,在使用得vue文件中引入
<script>
import FlowChart from 'jkstack-flow-chart' // 引入组件
import 'jkstack-flow-chart/dist/flow-chart.css' // 引入组件样式

export default {
  components: {
    FlowChart
  }
}
</script>
2.全局引入,在main.js中全局引入
import FlowChart from 'jkstack-flow-chart' // 引入组件
import 'jkstack-flow-chart/dist/flow-chart.css' // 引入组件样式

Vue.use(FlowChart)

快速上手

<template>
  <div id="app">
    <FlowChart
      ref="flowChart"
      :data="data"
      :height="height"
      :width="width"
      :closeSideBarClickMask="false"
      :maskColor="maskColor"
      :statusColor ="statusColor"
      addFlowNodeText="流程节点"
      addSwitchNodeText="条件节点"
      :showDelBtn="true"
      :showAddBtn="true"
      :showBackBtn="false"
      :shoViewBtn="false"
      :addShowSwitchNode="false"
      @node-selected="nodeSelecSted"
      @node-add="nodeAdd"
      @node-delete="nodeDel"
    >
    <!-- 插槽 -->
      <template v-slot:sideBar>
        <div class="rightMsg">
          <div v-if="selectedNodes.type === 'flowNode'">
            <div class="title">流程节点</div>
            <input type="text" v-model="selectedNodes.label" placeholder="请输入标题">
            <input type="text" v-model="selectedNodes.propertyOne" placeholder="节点属性">
            <input type="text" v-model="selectedNodes.propertyTwo" placeholder="节点属性">
            <input type="text" v-model="selectedNodes.propertyThree" placeholder="节点属性">
            <input type="text" v-model="type" placeholder="各个项目中所存储的参数(类型)">
            <input type="text" v-model="tell" placeholder="各个项目中所存储的参数(方式)">
            <input type="text" v-model="people" placeholder="各个项目中所存储的参数(对象)">
            <Button @click="saveNodeData">保存节点数据</Button>
            <Button @click="closeSidebar">取消</Button>
          </div>
          <div v-if="selectedNodes.type === 'switchNode'">
            <div class="title">条件节点</div>
            <input type="text" v-model="type" placeholder="各个项目中所存储的参数(类型)">
            <input type="text" v-model="tell" placeholder="各个项目中所存储的参数(方式)">
            <input type="text" v-model="people" placeholder="各个项目中所存储的参数(对象)">
            <Button @click="saveNodeData">保存节点数据</Button>
            <Button @click="closeSidebar">取消</Button>
          </div>
          <div v-if="selectedNodes.type === 'controlNode'">
            <div class="title">控制节点</div>
            <input type="text" v-model="type" placeholder="各个项目中所存储的参数(类型)">
            <input type="text" v-model="tell" placeholder="各个项目中所存储的参数(方式)">
            <input type="text" v-model="people" placeholder="各个项目中所存储的参数(对象)">
            <Button @click="saveNodeData">保存节点数据</Button>
            <Button @click="closeSidebar">取消</Button>
          </div>
        </div>
      </template>
    </FlowChart>
    <button @click="getData">保存流程图数据</button>
  </div>
</template>

<script>
import FlowChart from './components/FlowChart.vue' // 引入组件
// import FlowChart from 'jkstack-flow-chart' // 引入组件
// import 'jkstack-flow-chart/dist/flow-chart.css' // 引入组件

export default {
  name: 'App',
  components: {
    FlowChart
  },
  data () {
    return {
      selectedNodes: {},
      statusColor: { // 状态颜色得配置
        success: { color: '#67C23A' }, // 成功
        error: { color: '#F56C6C' }, // 失败
        normal: { color: '#409EFF' }, // 正常
        start: { color: '#909399' }, // 开始
        end: { color: '#909399' } // 结束
      },
      width: 1500, // 宽度
      height: 600, // 高度
      maskColor: 'rgba(255, 255, 255, 0.7)', // mask颜色
      data: {}, // 流程图数据
      type: '', // 各个项目中所需存储得字段
      tell: '', // 各个项目中所需存储得字段
      people: '' // 各个项目中所需存储得字段
    }
  },
  methods: {
    // 选择节点事件
    nodeSelecSted (node) {
      this.selectedNodes = node // 拿到当前点击得节点数据
    },
    // 新增节点事件
    nodeAdd (node) {
      console.log('新增', node)
      this.selectedNodes = node
    },
    // 删除节点事件
    nodeDel (node) {
      console.log('删除', node)
    },
    // 保存节点数据
    saveNodeData () {
      if (this.selectedNodes) {
        this.selectedNodes.task = { // *各个项目需求中所存储得内容请放进task对象
          type: this.type,
          tell: this.tell,
          people: this.people
        }
        this.$refs.flowChart.updateItem(this.selectedNodes) // 更新图表节点方法调用,传入更改后得节点信息
        this.$refs.flowChart.toggleSidebar() // 调用更改抽屉状态的方法
      }
    },
    // 更改抽屉关闭/打开状态
    closeSidebar () {
      this.$refs.flowChart.toggleSidebar()
    },
    // 获取流程图数据保存
    getData () {
      console.log(this.$refs.flowChart.getData()) // 获取流程图中数据调用getData()方法
    }
  }
}
</script>

<style lang="scss" scoped>
#app{
  width: 1500px;
  border:1px solid #fff;
  border-radius: 5px;
  margin: 20px auto;
}
.rightMsg{
  padding: 20px;
  box-sizing: border-box;
}
.title{
  font-size: 15px;
  margin-bottom: 10px;
  color: #666;
}
input{
  width: 100%;
  border: 1px solid #efefef;
  line-height: 35px;
  padding: 0 10px;
  box-sizing: border-box;
  border-radius: 8px;
  font-size: 14px;
  outline: none;
}
textarea{
  width: 100%;
  border: 1px solid #efefef;
  line-height: 35px;
  padding: 10px;
  box-sizing: border-box;
  border-radius: 8px;
  font-family: '微软雅黑';
  font-size: 14px;
  outline: none;
}
button{
  width: 120px;
  height: 45px;
  line-height: 45px;
  text-align: center;
  background: #3388FF;
  color: #fff;
  border: none;
  border-radius: 5px;
  font-size: 16px;
  margin: 10px 20px;
}
</style>

API

FlowChart Attributes
参数说明类型默认值
width指定画布宽度,单位为 'px'number1200
height指定画布高度,单位为 'px'number600
sliderWidth指定抽屉宽度,单位为 'px'number400
data显示的图表数据 配置项object{nodes: [], edges: []}
closeSideBarClickMask是否可以通过点击 mask 关闭抽屉booleantrue
maskColormask遮罩层的颜色stringrgba(0,0,0,0.3)
statusColor节点状态颜色 (success/error/normal/start/end)object默认值
showBackBtn是否展示反选按钮booleantrue
showAddBtn是否展示新增按钮booleantrue
showDelBtn是否展示删除按钮booleantrue
showViewBtn是否展示查看按钮booleantrue
addFlowNodeText新增菜单中新增流程节点得文案string新建流程节点
addShowSwitchNode新增菜单中是否展示‘新增条件节点’booleantrue
addSwitchNodeText新增菜单中新增条件节点得文案string新建条件节点
节点状态颜色默认值
statusColor: {
  success: { color: '#67C23A' }, 
  error: { color: '#F56C6C' }, 
  normal: { color: '#409EFF' }, 
  start: { color: '#909399' }, 
  end: { color: '#909399' }
}
FlowChart Events
事件名说明参数
node-selected当用户手动点击当前节点查看按钮触发的事件node
node-add当用户手动点击新增节点和合并控制节点时触发的事件node
node-delete当用户手动删除节点时触发的事件-
FlowChart Methods
方法名说明参数
deleteItem用于删除关联的节点nodeId
updateItem用于更新节点数据node
getAllPreNodeList用于返回所有前置节点nodeId
fitViewcanvas适应视口padding: top, right, bottom, left
toggleSidebar用于切换抽屉的状态-
getData用于用户获取当前数据-
FlowChart Slot
slot name说明
sideBar抽屉的内容,如果需要编辑当前节点,需要自定义 dom ,并且提交数据的时候调用 updateItem 方法更新节点信息|
data
  • 数据格式如下,分为nodes(节点)和edges(关系),
data: {
      nodes: [
        {
          id: 'start',
          type: 'flowNode',
          label: '开始',
          state: 'start',
          x: 100,
          y: 100,
          propertyOne: '节点属性',
          propertyTwo: '节点属性',
          propertyThree: '节点属性',
          task: {}
        },
        {
          id: 'xxx1',
          type: 'switchNode',
          label: '第一个节点',
          state: 'normal',
          x: 480,
          y: 100,
          propertyOne: '节点属性',
          propertyTwo: '节点属性',
          propertyThree: '节点属性',
          task: {}
        },
        {
          id: 'xxx2',
          type: 'controlNode',
          label: '第二个节点',
          state: 'normal',
          x: 480,
          y: 140,
          propertyOne: '节点属性',
          propertyTwo: '节点属性',
          propertyThree: '节点属性',
          task: {}
        }
      ],
      edges: [
        {
          source: "start",
          target: "xxx1",
          type: "customEdge"
        },
        {
          source: "xxx1",
          target: "xxx2",
          type: "customBackEdge"
        }
      ]
  }

节点(nodes)

属性说明备注
id节点得唯一标识不可更改
type节点类型(流程节点:flowNode/条件节点:switchNode/控制节点:controlNode)不可更改
label节点标题-
state节点状态(成功:success/异常:error/正常:normal/开始:start/结束:end)-
x相对canvas得X坐标不可更改
y相对canvas得y坐标不可更改
propertyOne/propertyTwo/propertyThree节点属性-
task根据需求所需绑定该节点得属性,请添加进task,避免组件与业务混淆-
anchorPoints节点入口/数组不可更改
style节点样式/对象不可更改

边(edges)

属性说明备注
source源ID不可更改
target目标ID不可更改
targetAnchor源坐标索引值不可更改
sourceAnchor目标坐标索引值不可更改
type类型(自定义边:customEdge/自定义反选边:customBackEdge)不可更改
style边样式不可更改
startPoint源出口坐标不可更改
endPoint目标入口坐标不可更改
1.1.14

5 years ago

1.1.13

5 years ago

1.1.12

5 years ago

1.1.11

5 years ago

1.1.9

5 years ago

1.1.10

5 years ago

1.1.8

5 years ago

1.1.7

5 years ago

1.1.6

5 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

1.0.0-alpha.1

5 years ago

1.0.0-alpha.0

5 years ago