FlowNodeJumpRule.vue 13.9 KB
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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501
<template>
  <div class="form-inline">
    <label class="control-label">{{ node.name }}({{ node.nodeId }})</label>
    <el-button type="primary" size="mini" @click="editNodeRules"
      >添加跳转规则</el-button
    ><br />
    <label
      v-if="!nodeDef.jumpRuleList || nodeDef.jumpRuleList.length == 0"
      class="control-label"
      style="color:#dd6161;"
      >尚未配置节点跳转规则</label
    >
    <div v-if="nodeDefCopy.jumpRuleList && nodeDefCopy.jumpRuleList.length > 0">
      <label
        style="text-align: left;"
        class="control-label  control-label-list "
        v-for="(rule, $index) in nodeDefCopy.jumpRuleList"
        :key="rule.name"
      >
        <div class="control-label-list-content">
          【{{ rule.ruleName }}】跳转至:{{
            changetargetNodeName(rule.targetNode)
          }}
        </div>
        <div class="control-label-list-set">
          <el-button size="mini" type="text" @click="setSetting(rule)"
            >编辑</el-button
          >
          <el-button
            size="mini"
            type="text"
            @click="deleteSetting(nodeDefCopy.jumpRuleList, $index)"
            >删除</el-button
          >
        </div>
      </label>
      <!-- <div class="control-label" style="text-align: right;">
        查看更多信息请编辑
      </div> -->
      <br />
    </div>
    <el-dialog
      width="40%"
      top="8vh"
      :title="titleSetting"
      :visible="dialogVisibleSetting"
      :before-close="close"
      :close-on-click-modal="false"
      append-to-body
    >
      <div style="width:100%;height: 600px;">
        <div>
          <div class="div_list">跳转规则设置</div>
          <div
            style="border: 1px solid #EBEBEB;padding:10px 24px;height:508px;"
          >
            <el-form
              v-model="curRule"
              data-vv-scope="settingSave"
              label-width="120px"
              label-position="left"
              class="elForm"
            >
              <ht-form-item label="当前节点名称"
                ><span>{{ nodeDefCopy.name }}</span></ht-form-item
              >
              <ht-form-item label="规则名称" class="is-required"
                ><ht-input
                  v-model="curRule.ruleName"
                  style="width:100%"
                  placeholder="请输入规则名称"
                  autocomplete="off"
                  validate="required"
                ></ht-input
              ></ht-form-item>
              <ht-form-item label="跳转节点名称" class="is-required">
                <ht-select
                  clearable
                  v-model="curRule.targetNode"
                  :options="
                    nodeDefList.filter(item => {
                      let result = this.filterNodeType.filter(
                        nodeType => nodeType == item.nodeType
                      )
                      return !result || result.length == 0
                    })
                  "
                  :props="{key: 'nodeId', value: 'name'}"
                  validate="required"
                />
              </ht-form-item>

              <ht-form-item class="is-required javascript-template regularExp">
                <el-tooltip
                  slot="label"
                  class="item"
                  effect="dark"
                  content="这个脚本需要使用返回语句(return)返回布尔值,返回true流程将跳转到指定的节点。"
                  placement="left-start"
                >
                  <i><i class="icon-notes"></i>规则表达式</i>
                </el-tooltip>
                <br />
                <div style="display:block;margin:10px 0">
                  <!-- 常用脚本选择对话框  -->
                  <eip-script-dialog
                    ref="eipScriptDialogCondition"
                    v-model="curRule.condition"
                    append-to-body
                  />
                  <el-button @click="showDialog('eipScriptDialogCondition')"
                    >常用脚本</el-button
                  >
                  <!-- 条件脚本 -->
                  <el-button @click="showConditionBuild" size="small"
                    >条件脚本</el-button
                  >
                  <!-- 可选变量对话框 -->
                  <FlowVarSelector
                    :defId="node.defId"
                    @node-click="varTreeOnConfirm"
                  />
                </div>

                <HtMonacoEditor
                  ref="codeEditor"
                  language="java"
                  required
                  v-model="curRule.condition"
                  height="220px"
                />
              </ht-form-item>
              <!-- <ht-form-item class="add-btn">
                <el-button
                  type="primary"
                  size="mini"
                  @click="addRule"
                  style="width:108px"
                  >新 增</el-button
                >
              </ht-form-item> -->
            </el-form>
          </div>
        </div>
        <!-- <div
          style="float: left;width:calc(40% - 40px);margin-left: 40px;height:100%;"
        >
          <div class="div_list">跳转规则列表</div>
          <el-table
            :data="nodeDefCopy.jumpRuleList"
            border
            height="528"
            ref="htTableSetting"
            @row-click="orgRowClick"
          >
            <el-table-column prop="ruleName" label="规则名称" />
            <el-table-column prop="targetNode" label="目标节点" />
            <el-table-column label="操作" width="90" class-name="default-row">
              <template v-slot="{row, $index}">
                <el-button
                  size="mini"
                  type="text"
                  @click="deleteSetting(nodeDefCopy.jumpRuleList, $index)"
                  >删除</el-button
                >
              </template>
            </el-table-column>
          </el-table>
        </div> -->
      </div>
      <div style="text-align: right; padding: 20px">
        <el-button size="small" @click="close">取消</el-button>
        <el-button type="primary" size="small" @click="addRule">保存</el-button>
      </div>
      <!-- 条件脚本对话框 -->
      <FlowConditionBuildDialog
        @onConfirm="conditionDialogConfirm"
        :defId="node.defId"
        ref="flowConditionBuildDialog"
      />
    </el-dialog>
  </div>
</template>

<script>
import req from '@/request.js'
import {mapState, mapActions} from 'vuex'
import {Message} from 'element-ui'
const eipScriptDialog = () => import('@/components/dialog/EipScriptDialog.vue')
const MessageTypeSelector = () =>
  import('@/components/flow/MessageTypeSelector.vue')
const FlowVarSelector = () => import('@/components/flow/FlowVarSelector.vue')
const FlowConditionBuildDialog = () =>
  import('@/components/flow/FlowConditionBuildDialog.vue')
export default {
  name: 'FlowNodeJumpRule',
  components: {
    MessageTypeSelector,
    eipScriptDialog,
    FlowVarSelector,
    FlowConditionBuildDialog
  },

  props: {
    //任务节点信息
    node: {
      type: Object,
      required: true
    },
    //流程配置信息
    defConfigData: {
      type: Object,
      required: true
    },
    //跳转规则配置的信息
    nodeDef: {
      type: Object,
      required: true
    },
    //跳转规则配置流程跳转节点
    nodeDefList: {
      type: Array,
      required: true
    }
  },
  data() {
    return {
      titleSetting: '设置跳转规则', //某个节点跳转规则的标题
      dialogVisibleSetting: false, //是否显示设置节点跳转规则侧边栏
      isSave: false, //判断是否可以保存
      nodeDefCopy: {}, //复制一份最开始的跳转规则配置的信息
      filterNodeType: [
        'EXCLUSIVEGATEWAY',
        'SUBPROCESS',
        'CALLACTIVITY',
        'PARALLELGATEWAY',
        'INCLUSIVEGATEWAY',
        'SUBSTARTGATEWAY',
        'SUBENDGATEWAY',
        'SUBMULTISTARTGATEWAY'
      ], // 过滤节点  分支
      curRule: {ruleName: '', targetNode: '', condition: '', isAdd: true} //初始化跳转规则信息
    }
  },
  watch: {
    nodeDef: {
      handler(val) {
        if (val) {
          this.nodeDefCopy = JSON.parse(JSON.stringify(val)) //复制一份最开始的跳转规则配置的信息
          this.nodeDefCopy.jumpRuleList || (this.nodeDefCopy.jumpRuleList = [])
        }
      },
      immediate: true,
      deep: true
    }
  },
  methods: {
    changetargetNodeName(val) {
      let name = ''
      this.nodeDefList.forEach(item => {
        if (item.nodeId == val) {
          name = item.name
        }
      })

      return name
    },
    //监听条件脚本确认事件
    conditionDialogConfirm(data) {
      this.$refs.codeEditor.insertValue(data)
    },
    //显示条件脚本对话框
    showConditionBuild() {
      this.$refs.flowConditionBuildDialog.showDialog()
    },
    //监督可选变量的返回值
    varTreeOnConfirm(data) {
      this.$refs.codeEditor.insertValue(data.pathValue)
    },
    //显示常用脚本
    showDialog(action) {
      this.$refs[action].showDialog()
    },
    //设置跳转规则
    editNodeRules() {
      this.curRule = {ruleName: '', targetNode: '', condition: '', isAdd: true} //初始化跳转规则信息
      this.isSave = false
      this.dialogVisibleSetting = true
    },
    //点击跳转规则列表某一条数据时触发
    orgRowClick(row, column, event) {
      if (column.label != '操作') {
        this.curRule = row
        this.isSave = true
      }
    },
    //保存跳转规则
    saveRule() {
      //判断是否有新增的数据
      // if (!this.isSave) {
      //   // Message.warning('请先新增跳转规则再保存')
      //   return
      // } else {
      const this_ = this
      req
        .post(
          '${bpmModel}/flow/node/v1/ruleSave?nodeId=' +
            this_.node.nodeId +
            '&defId=' +
            this_.node.defId,
          this_.nodeDefCopy.jumpRuleList
        )
        .then(function(response) {
          response = response.data
          if (response.state) {
            Message.success(response.message)
            this_.$emit('update:nodeDef', this_.nodeDefCopy) //子组件更新父组件的值
            this_.$emit('upRuleData', this_.nodeDefCopy) //更新规则数据,防止点击其他节点时,当前保存的规则数据未更新显示
            this_.dialogVisibleSetting = false
          } else {
            Message.error(response.message)
          }
        })
      // }
    },
    //新增跳转规则
    addRule() {
      const this_ = this
      this_.$validator.validateAll('settingSave').then(result => {
        if (result) {
          if (this_.curRule.isAdd) {
            delete this_.curRule.isAdd
            this_.isSave = true
            this_.nodeDefCopy.jumpRuleList.push(this_.curRule)
            this_.isSave = true
            this_.curRule = {
              ruleName: '',
              targetNode: '',
              condition: '',
              isAdd: true
            } //初始化跳转规则信息
          }
          this_.saveRule()
        } else {
          let arr = this_.$validator.errors.items.filter(
            item => item.scope == 'settingSave'
          )
          let errorLength = arr.length
          this_.$message({
            showClose: true,
            message: `有${errorLength}个字段未通过校验,请正确填写表单内容。`,
            type: 'warning'
          })
        }
      })
    },
    //关闭设置节点跳转规则列弹框
    close() {
      this.dialogVisibleSetting = false
    },
    //删除跳转规则
    deleteSetting(list, index) {
      list.splice(index, 1)

      this.isSave = true
      this.curRule = {ruleName: '', targetNode: '', condition: '', isAdd: true} //初始化跳转规则信息
      this.saveRule()
    },
    // 编辑
    setSetting(rule) {
      this.curRule = rule
      this.dialogVisibleSetting = true
    }
  },
  mounted() {
    this.$validator = this.$root.$validator
  }
}
</script>

<style lang="scss" scoped>
div >>> .el-dialog__body {
  padding: 10px 10px 10px 40px;
  color: #606266;
  font-size: 14px;
  word-break: break-all;
}
.ht_tr {
  width: 100% !important;
  background: rgb(222, 219, 219);
}
.ht_ce {
  margin-top: -10px !important;
}
.div_list {
  height: 30px;
  line-height: 30px;
  font-size: 16px;
  color: #333;
  font-weight: bold;
  padding-left: 10px;
  margin-bottom: 10px;
}
>>> label.el-checkbox {
  margin: 5px 10px 0 0;
}
.ht {
  width: 300px;
}
.form-inline {
  float: left;
  width: 100%;
}
.left-label {
  width: 18%;
  float: left;
}
.control-label {
  word-break: break-all;
  text-align: right;
  color: #545252;
  font-size: 12px;
  padding: 0px 10px !important;
  font-weight: bold;
  line-height: 35px;
}
.control-label-list {
  display: flex;
  &-content {
    width: 250px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  &-set {
    display: flex;
    ::v-deep {
      .el-button {
        padding: 0;
      }
    }
  }
}
div >>> .box-card {
  margin-bottom: 20px;
}

div >>> .box-card .clearfix {
  padding-top: 20px;
}

div >>> .el-collapse-item__header {
  height: 40px;
  line-height: 40px;
  font-size: 14px;
  font-weight: bold;
}

div >>> .el-button {
  font-size: 14px;
  padding: 7px 15px;
  margin-right: 10px;
  margin-left: 0 !important;
}
.javascript-template >>> .el-form-item__content {
  margin-left: 0 !important;
  position: static;
}
.add-btn >>> .el-form-item__content {
  margin-left: 0 !important;
  text-align: center;
}
/deep/.default-row > .cell {
  overflow: visible !important;
}
.elForm {
  ::v-deep .el-form-item__label {
    color: #888888;
  }
}
.regularExp {
  ::v-deep {
    .el-form-item__label {
      position: relative;
      &::before {
        position: absolute;

        left: 18px;
      }
    }
    .el-tooltip {
      margin-left: 25px;
    }
  }
  .icon-notes {
    position: absolute;
    left: 0;
    top: 8px;
  }
}
</style>