FlowVarList.vue 14.1 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
<template>
  <div style="height: calc(100% - 48px); margin: 24px">
    <ht-table
      @load="loadData"
      :data="varList"
      :selectable="true"
      :nopagination="true"
      :show-export="false"
      :show-custom-column="false"
      ref="htTable"
    >
      <template v-slot:toolbar>
        <el-button
          size="mini"
          type="primary"
          icon="el-icon-plus"
          @click="operating('')"
          >添加</el-button
        >
        <el-button size="mini" icon="el-icon-delete" @click="delClick()"
          >批量删除</el-button
        >
      </template>
      <ht-table-column type="index" width="50" align="center" label="序号" />
      <ht-table-column label="变量类型" width="100">
        <template v-slot="{row}">
          <span v-if="row.nodeId == ''">全局变量</span>
          <span v-if="row.nodeId != ''">{{ row.nodeId }}</span>
        </template>
      </ht-table-column>
      <ht-table-column prop="name" align="center" label="变量名">
        <template v-slot="{row}">
          <el-link
            type="primary"
            @click="operating(row.varKey)"
            title="编辑变量"
            >{{ row.name }}</el-link
          >
        </template>
      </ht-table-column>
      <ht-table-column
        prop="varKey"
        width="150"
        align="center"
        label="变量key"
      />
      <ht-table-column
        prop="dataType"
        width="120"
        align="center"
        label="数据类型"
      />
      <ht-table-column prop="defaultVal" align="center" label="默认值" />
      <ht-table-column width="120" align="center" label="是否必需">
        <template v-slot="{row}">
          <el-tag  v-if="row.required">必填</el-tag>
          <el-tag type="info" v-if="!row.required">非必填</el-tag>
        </template>
      </ht-table-column>
      <ht-table-column width="100" label="操作" align="center">
        <template v-slot="{row}">
          <el-button
            size="mini"
            type="text"
     
            @click="remove(row.varKey)"
            >删除</el-button
          >
        </template>
      </ht-table-column>
    </ht-table>
    <ht-sidebar-dialog
      width="28%"
      :title="title"
      :visible="dialogVisibleSetting"
      :before-close="close"
      :close-on-click-modal="false"
      append-to-body
    >
      <el-form :model="data" data-vv-scope="settingSave" label-width="90px" label-position="left" class="dialog_form">
        <el-form-item label="节点:">
          <ht-select
            clearable
            v-model="data.bpmVariableDef.nodeId"
            :options="data.nodeDefList"
            :props="{key: 'nodeId', value: 'name'}"
          />
        </el-form-item>
        <el-form-item label="变量名:" required>
          <ht-input
            v-model="data.bpmVariableDef.name"
            placeholder="请输入变量名"
            autocomplete="off"
            :validate="{required: true}"
            :maxlength="50"
            :showWordLimit="true"
          ></ht-input>
        </el-form-item>
        <el-form-item label="变量key:" required
          ><ht-input
            v-model="data.bpmVariableDef.varKey"
            placeholder="请输入变量key"
            autocomplete="off"
            :validate="{
              required: true,
              regex: {
                exp: '^[a-zA-Z0-9_-]{1,50}$',
                message: '只能包含字母或数字'
              }
            }"
            :maxlength="50"
            :showWordLimit="true"
            :disabled="!isAdd"
          ></ht-input
        ></el-form-item>
        <el-form-item label="数据类型:" required>
          <ht-select
            clearable
            v-model="data.bpmVariableDef.dataType"
            :options="[
              {key: 'string', value: '字符串'},
              {key: 'int', value: '整型'},
              {key: 'float', value: '浮点型'},
              {key: 'double', value: '双精度'}
            ]"
            validate="required"
        /></el-form-item>
        <el-form-item label="是否必需:" required>
          <ht-select
            clearable
            v-model="data.bpmVariableDef.required"
            :options="[
              {key: 'true', value: '是'},
              {key: 'false', value: '否'}
            ]"
            validate="required"
        /></el-form-item>
        <el-form-item label="默认值:">
          <ht-input
            v-model="data.bpmVariableDef.defaultVal"
            placeholder="请输入默认值"
            autocomplete="off"
            :maxlength="50"
            :showWordLimit="true"
          ></ht-input
        ></el-form-item>
        <el-form-item label="变量描述:">
          <ht-input
            type="textarea"
            :rows="8"
            v-model="data.bpmVariableDef.description"
            placeholder="请输入变量描述..."
            autocomplete="off"
            :maxlength="200"
            :showWordLimit="true"
          ></ht-input
        ></el-form-item>
        <!-- <table class="form-table" cellspacing="0" cellpadding="0" border="0">
          <tbody>
            <tr>
              <th width="130px">节点:</th>
              <td>
                <ht-select
                  clearable
                  disabled
                  v-model="data.bpmVariableDef.nodeId"
                  :options="data.nodeDefList"
                  :props="{key: 'nodeId', value: 'name'}"
                />
              </td>
            </tr>
            <tr>
              <th width="130px" class="is-required">变量名:</th>
              <td>
                <ht-input
                  v-model="data.bpmVariableDef.name"
                  placeholder="请输入变量名"
                  autocomplete="off"
                  :validate="{required: true}"
                  :maxlength="50"
                  :showWordLimit="true"
                ></ht-input>
              </td>
            </tr>
            <tr>
              <th width="130px" class="is-required">变量key:</th>
              <td>
                <ht-input
                  v-model="data.bpmVariableDef.varKey"
                  placeholder="请输入变量key"
                  autocomplete="off"
                  :validate="{
                    required: true,
                    regex: {
                      exp: '^[a-zA-Z0-9_-]{1,50}$',
                      message: '只能包含字母或数字'
                    }
                  }"
                  :maxlength="50"
                  :showWordLimit="true"
                  :disabled="!isAdd"
                ></ht-input>
              </td>
            </tr>
            <tr>
              <th width="130px" class="is-required">数据类型:</th>
              <td>
                <ht-select
                  clearable
                  v-model="data.bpmVariableDef.dataType"
                  :options="[
                    {key: 'string', value: '字符串'},
                    {key: 'int', value: '整型'},
                    {key: 'float', value: '浮点型'},
                    {key: 'double', value: '双精度'}
                  ]"
                  validate="required"
                />
              </td>
            </tr>
            <tr>
              <th width="130px" class="is-required">是否必需:</th>
              <td>
                <ht-select
                  clearable
                  v-model="data.bpmVariableDef.required"
                  :options="[
                    {key: 'true', value: '是'},
                    {key: 'false', value: '否'}
                  ]"
                  validate="required"
                />
              </td>
            </tr>
            <tr>
              <th width="130px">默认值:</th>
              <td>
                <ht-input
                  v-model="data.bpmVariableDef.defaultVal"
                  placeholder="请输入默认值"
                  autocomplete="off"
                  :maxlength="50"
                  :showWordLimit="true"
                ></ht-input>
              </td>
            </tr>
            <tr>
              <th width="130px">变量描述:</th>
              <td>
                <ht-input
                  type="textarea"
                  :rows="8"
                  v-model="data.bpmVariableDef.description"
                  placeholder="请输入变量描述"
                  autocomplete="off"
                  :maxlength="200"
                  :showWordLimit="true"
                ></ht-input>
              </td>
            </tr>
          </tbody>
        </table> -->
      </el-form>
      <div slot="footer" class="dialog-footer" style="padding-right: 20px;">
        <el-button size="mini" @click="close" 
          >取 消</el-button
        >
        <el-button type="primary" size="mini" @click="save" 
          >确 认</el-button
        >
      </div>
    </ht-sidebar-dialog>
  </div>
</template>

<script>
import {Message} from 'element-ui'
import req from '@/request.js'
export default {
  name: 'FlowVarList',
  props: {
    defId: {
      type: String,
      required: true
    }
  },
  data() {
    return {
      varList: [], //列表数据
      title: '添加流程变量',
      dialogVisibleSetting: false, //是否显示添加编辑流程变量侧边栏
      data: {
        bpmVariableDef: {nodeId: '', isRequired: 'false', dataType: 'string'},
        nodeDefList: []
      }, //添加编辑流程变量时的数据
      isAdd: false
    }
  },
  methods: {
    //保存流程变量
    save() {
      const this_ = this
      this_.$validator.validateAll('settingSave').then(result => {
        if (result) {
          let isAdd = true //是否新增流程变量
          if (this_.title == '添加流程变量') {
            isAdd = true
          } else {
            isAdd = false
          }
          let param = {
            variableDef: this_.data.bpmVariableDef,
            isAdd: isAdd,
            defId: this_.defId
          }
          req.post('${bpmModel}/flow/var/v1/save', param).then(function(data) {
            data = data.data
            if (data.state) {
              Message.success((isAdd ? '添加' : '编辑') + '变量成功')
              this_.dialogVisibleSetting = false
              this_.$refs.htTable.load() //重新加载列表数据
            }
          })
        } else {
          let arr = this_.$validator.errors.items.filter(
            item => item.scope == 'settingSave'
          )
          let errorLength = arr.length
          this_.$message({
            showClose: true,
            message: `有${errorLength}个字段未通过校验,请正确填写表单内容。`,
            type: 'warning'
          })
        }
      })
    },
    //删除流程变量
    remove(key) {
      const this_ = this
      let url =
        '${bpmModel}/flow/var/v1/remove?defId=' + this_.defId + '&varKey=' + key
      this_
        .$confirm('是否确认删除?', '提示', {
          cancelButtonText: '取消',
          confirmButtonText: '确定',
          type: 'warning',
          closeOnClickModal: false
        })
        .then(() => {
          req.remove(url).then(function(rep) {
            rep = rep.data
            if (rep.state) {
              if (rep.message) {
                Message.success(rep.message)
                this_.$refs.htTable.load() //重新加载列表数据
              }
            } else {
              Message.error(rep.message)
            }
          })
        })
    },
    //批量删除
    async delClick() {
      const this_ = this
      if (this.$refs.htTable.selection.length == 0) {
        this.$message({message: '请至少选择一条记录', type: 'warning'})
        return false
      }
      let status = []
      for (const i of this.$refs.htTable.selection) {
        status.push(i.varKey)
      }
      let url =
        '${bpmModel}/flow/var/v1/remove?defId=' +
        this.defId +
        '&varKey=' +
        status.join(',')
      this_
        .$confirm('是否确认删除?', '提示', {
          cancelButtonText: '取消',
          confirmButtonText: '确定',
          type: 'warning',
          closeOnClickModal: false
        })
        .then(() => {
          req.remove(url).then(rep => {
            let res = rep.data
            if (res.state) {
              Message.success(res.message)
              this.$refs.htTable.load() //重新加载列表数据
            } else {
              Message.error(res.message)
            }
          })
        })
    },

    //添加或编辑流程变量
    operating(key) {
      this.title = key == '' ? '添加流程变量' : '编辑流程变量'
      this.isAdd = key === '' ? true : false
      this.dialogVisibleSetting = true //显示添加编辑流程变量侧边栏 req.remove(url)
      this.data = {
        bpmVariableDef: {nodeId: '', isRequired: 'false', dataType: 'string'},
        nodeDefList: []
      } //清空值
      const this_ = this
      req
        .get(
          '${bpmModel}/flow/var/v1/defVarEdit?defId=' +
            this_.defId +
            '&varKey=' +
            key
        )
        .then(function(res) {
          res = res.data
          if (res.bpmVariableDef && !res.bpmVariableDef.required) {
            res.bpmVariableDef.required = 'false'
          } else if (
            res.bpmVariableDef &&
            res.bpmVariableDef.required === true
          ) {
            res.bpmVariableDef.required = 'true'
          }
          if (this_.title == '添加流程变量') {
            this_.data.nodeDefList = res.nodeDefList
          } else {
            this_.data = res
          }
          this_.data.nodeDefList.push({nodeId: '', name: '全局变量'})
        })
    },
    //关闭侧边栏
    close() {
      this.dialogVisibleSetting = false
    },
    //页面加载显示数据
    loadData(param, cb) {
      const this_ = this
      let listUrl =
        '${bpmModel}/flow/var/v1/listJson?defId=' + this_.defId + '&nodeId='
      req
        .get(listUrl)
        .then(function(data) {
          this_.varList = data.data
        })
        .finally(() => cb())
    }
  },
  mounted() {
    this.$validator = this.$root.$validator
  }
}
</script>
<style lang="scss" scoped>
.el-main {
  padding-top: 0px;
}
.dialog_form{
  .inputs{
    width: 100%;
  }
}
</style>