SchedulerManager.vue 22.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 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 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715
<template>
  <el-container class="fullheight">
    <div class="xxl-job" v-if="xxlAdminAddress">
      <div class="setting__wrap">
        <div class="setting">
          <span>请通过</span>
          <el-link type="primary" :href="xxlAdminAddress" target="_blank"
            >XXLJOB任务调度中心</el-link
          >
          <span>管理定时任务</span>
        </div>
      </div>
    </div>
    <el-container v-else>
      <el-main class="main-wrap">
        <ht-table
          ref="schedulerTable"
          @load="loadData"
          :data="data"
          :pageResult="pageResult"
          :selection="true"
          quick-search-props="jobName,jobClassNname"
          :show-export="false"
          @row-click="rowClick"
        >
          <!--  定时计划没有分页和快速搜索
          :pageResult="pageResult"
          :selection="true"
          quick-search-props="jobName,className"-->
          <template v-slot:toolbar>
            <el-button
              size="small"
              @click="handleCommand({command: 'add'})"
              icon="el-icon-plus"
              type="primary"
              >添加</el-button
            >
            <el-switch
              v-model="isStandby"
              active-color="#13ce66"
              inactive-color="#ff4949"
              style="margin-left: 20px;"
              @change="changeStart()"
            ></el-switch>
          </template>
          <!-- <template v-slot:search>
            <ht-table-search-panel :divide="3">
              <ht-table-search-field label="任务名称" prop="jobName" />
              <ht-table-search-field label="任务类" prop="className" />
            </ht-table-search-panel>
          </template>-->
          <template>
            <ht-table-column
              type="index"
              width="50"
              align="center"
              label="序号"
            />
            <ht-table-column
              prop="jobName"
              label="任务名称"
              width="300"
              :show-overflow-tooltip="true"
            >
              <template slot-scope="scope">
                <el-link
                  type="primary"
                  @click="showDialog(scope.row)"
                  title="编辑"
                  >{{ scope.row.jobName }}</el-link
                >
              </template>
            </ht-table-column>
            <ht-table-column prop="jobClassNname" label="任务类" />
            <ht-table-column prop="description" label="描述" />
            <ht-table-column width="200" label="操作" align="left">
              <template v-slot="{row}">
                <el-button
                  type="text"
                  @click="handleCommand({row: row, command: 'executeJob'})"
                  >执行</el-button
                >
                <el-button
                  type="text"
                  class="copy-btn"
                  @click="handleCommand({row: row, command: 'lookLog'})"
                  >日志</el-button
                >
                <el-dropdown
                  size="mini"
                  trigger="click"
                  @command="handleCommand"
                  class="more-operate-btn__dropdown"
                >
                  <span class="more-operate-btn"
                    >更多操作<i class="el-icon-caret-bottom"></i>
                  </span>
                  <!-- <span> <i class="el-icon-caret-right"></i>执行 </span> -->
                  <el-dropdown-menu
                    slot="dropdown"
                    class="operate-dropdown__button"
                  >
                    <el-dropdown-item
                      :command="{row: row, command: 'triggersJob'}"
                      >触发器列表</el-dropdown-item
                    >
                    <!--                    <el-dropdown-item-->
                    <!--                      icon="el-icon-caret-right"-->
                    <!--                      :command="{row:row,command:'executeJob'}"-->
                    <!--                    >执行</el-dropdown-item>-->
                    <!-- <router-link to="executeJobList/com.hotent.job.job.FlowStartJob">日志</router-link>   v-link="{name: 'executeJob', params: {jobName: 'com.hotent.job.job.FlowStartJob'}}"-->
                    <!-- <el-dropdown-item
                      icon="el-icon-date"
                      :command="{row: row, command: 'lookLog'}"
                      >日志</el-dropdown-item
                    > -->
                    <el-dropdown-item
                      class="delete-drop-item"
                      :command="{row: row, command: 'delete'}"
                      >删除</el-dropdown-item
                    >
                  </el-dropdown-menu>
                </el-dropdown>
              </template>
            </ht-table-column>
          </template>
        </ht-table>

        <el-dialog
          width="70%"
          :title="schedulerTitle"
          :visible="dialogVisible"
          :before-close="handleClose"
          :close-on-click-modal="false"
        >
          <el-form
            :disabled="schedulerDisabled"
            v-model="scheduler"
            v-form="{formItemAlign: 'left'}"
            data-vv-scope="editschedulerForm"
          >
            <ht-form-item
              label="任务名"
              prop="jobName"
              label-width="120px"
              class="scheduler-input-width"
            >
              <ht-input
                v-model="scheduler.jobName"
                :validate="{required: true, max: 100}"
                placeholder="请输入任务名"
                @blur="isExist('jobName')"
                :disabled="isEdit"
                :maxlength="50"
                :showWordLimit="true"
              ></ht-input>
            </ht-form-item>
            <ht-form-item
              label="任务类"
              prop="className"
              label-width="120px"
              class="scheduler-input-width is-required"
            >
              <!-- <ht-input
                v-model="scheduler.className"
                :validate="{required:true}"
                placeholder="请输入任务类"
                @blur="isExist('className')"
                :disabled="isEdit"
              ></ht-input>-->
              <ht-input
                placeholder="请输入任务类"
                v-model="scheduler.className"
                class="input-with-select"
                :validate="{required: true}"
                :maxlength="200"
                :showWordLimit="true"
              >
                <el-button slot="append" @click="validClass()"
                  >验证任务类</el-button
                >
              </ht-input>
            </ht-form-item>
            <!-- <ht-form-item label="" prop="" label-width="120px" class="scheduler-input-width">
          <el-button size="mini">验证任务类</el-button>
            </ht-form-item>-->
            <ht-form-item
              label="任务描述"
              prop="description"
              label-width="120px"
              class="scheduler-input-width"
            >
              <ht-input
                v-model="scheduler.description"
                :validate="{required: true, max: 80}"
                placeholder="请输入任务描述"
                :maxlength="80"
                :showWordLimit="true"
              ></ht-input>
            </ht-form-item>
            <div class="obj-atter">
              <div class="obj-atter-panel">
                <div style="width: 13%;float: left">
                  <el-tooltip
                    class="item"
                    effect="dark"
                    content="任务参数"
                    placement="right-start"
                  >
                    <el-button
                      type="text"
                      class="el-icon-question"
                      style="color:#606266;"
                    >
                      <strong>对象属性管理</strong>
                    </el-button>
                  </el-tooltip>
                </div>
                <div>
                  <el-button
                    icon="el-icon-plus"
                    size="mini"
                    @click="addEntRows()"
                    plain
                    >添加</el-button
                  >
                </div>
              </div>
              <div>
                <el-table :data="parameterJson" border style="width: 100%">
                  <el-table-column prop="name" align="center">
                    <template slot="header">
                      <font color="red">*</font>参数名
                    </template>
                    <template v-slot="{row}">
                      <ht-input
                        v-model="row.name"
                        :validate="{required: true}"
                        placeholder="请输入参数名"
                        :maxlength="50"
                        :showWordLimit="true"
                      />
                    </template>
                  </el-table-column>
                  <el-table-column prop="type" align="center">
                    <template slot="header">
                      <font color="red">*</font>参数类型
                    </template>
                    <template v-slot="{row}">
                      <ht-select
                        v-model="row.type"
                        :validate="{required: true}"
                        :options="paraTypes"
                        placeholder="请选择参数类型"
                      />
                    </template>
                    <!-- <el-input v-model="row.paraType" placeholder="请输入参数类型"></el-input> -->
                  </el-table-column>
                  <el-table-column prop="value" align="center">
                    <template slot="header">
                      <font color="red">*</font>参数值
                    </template>
                    <template v-slot="{row}">
                      <ht-input
                        v-model="row.value"
                        :validate="{required: true}"
                        placeholder="请输入参数值"
                        :maxlength="50"
                        :showWordLimit="true"
                      />
                    </template>
                  </el-table-column>
                  <el-table-column label="删除" width="70" align="center">
                    <template slot-scope="scope">
                      <el-button
                        icon="el-icon-close"
                        @click="deleteEntRows(scope.row)"
                      ></el-button>
                    </template>
                  </el-table-column>
                </el-table>
              </div>
            </div>
          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button @click="dialogCancle('dialogVisible')">{{
              $t('eip.common.cancel')
            }}</el-button>
            <ht-submit-button
              v-show="!schedulerDisabled"
              :url="saveschedulerUrl"
              :model="scheduler"
              :is-submit="isSubmit"
              :request-method="requestMethod"
              scope-name="editschedulerForm"
              @before-save-data="beforeSaveData"
              @after-save-data="afterSaveData"
              >{{ $t('eip.common.save') }}</ht-submit-button
            >
          </div>
        </el-dialog>

        <!-- 加载定时计划状态-->
        <ht-load-data
          :url="getStandUrl"
          context="portal"
          @after-load-data="afterGetStand"
        ></ht-load-data>
        <!-- 加载数据 用作编辑定时计划和查看定时计划-->
        <ht-load-data
          :url="loadDataUrl"
          context="portal"
          @after-load-data="afterLoadData"
        ></ht-load-data>
        <!-- isExistUrl 验证任务名或类名是否存在计划当中了  -->
        <ht-load-data
          :url="isExistUrl"
          context="portal"
          @after-load-data="afterIsExist"
        ></ht-load-data>
        <!-- isExistUrl 验证定时计划类是否存在  -->
        <ht-load-data
          :url="validClassUrl"
          context="portal"
          @after-load-data="afterValidClass"
        ></ht-load-data>
        <!--执行定时计划  -->
        <ht-load-data
          :url="executeJobUrl"
          requestMethod="post"
          context="portal"
          @after-load-data="afterExecuteJob"
        ></ht-load-data>
      </el-main>
    </el-container>
  </el-container>
</template>
<script>
import sys from '@/api/portal.js'
export default {
  components: {},
  data() {
    return {
      schedulerDisabled: false,
      schedulerTitle: '',
      loadDataUrl: '',
      dialogVisible: false,
      data: [],
      pageResult: {
        page: 1,
        pageSize: 50,
        total: 0
      },
      isSubmit: true,
      scheduler: {},
      ent: {},
      isStandby: true,
      isExistUrl: '',
      isExistType: '',
      validClassUrl: '',
      parameterJson: [],
      paraTypes: [
        {key: 'int', value: 'int'},
        {key: 'long', value: 'long'},
        {key: 'float', value: 'float'},
        {key: 'string', value: 'string'},
        {key: 'boolean', value: 'boolean'}
      ],
      isEdit: false,
      saveschedulerUrl: '',
      executeJobUrl: '',
      getStandUrl: '',
      xxlAdminAddress: '',
      isValidateClass:false
    }
  },
  computed: {
    requestMethod: function() {
      return this.scheduler.id ? 'GET' : 'POST'
    }
  },
  mounted() {
    this.$validator = this.$root.$validator
  },
  updated() {
    if (this.isEdit) {
      this.saveschedulerUrl =
        window.context.portal +
        '/job/scheduler/v1/saveJob?jobName=' +
        encodeURI(this.scheduler.jobName)
    } else {
      this.saveschedulerUrl = window.context.portal + '/job/scheduler/v1/addJob'
    }
  },
  methods: {
    rowClick(row, column, event) {
      this.$refs.schedulerTable.$refs.htTable.toggleRowSelection(row)
    },
    //验证定时计划执行类是否存在
    validClass() {
      if (this.scheduler && this.scheduler.className) {
        this.validClassUrl =
          '/job/scheduler/v1/validClass?className=' +
          this.scheduler.className +
          '&radom=' +
          Math.random()
      } else {
        this.$message.warning('请先输入任务类再点击验证按钮')
      }
    },
    //验证任务名和类名
    isExist(type) {
      this.isExistType = type
      var name = this.scheduler.className
      if (type == 'jobName') {
        name = this.scheduler.jobName
      }
      this.isExistUrl =
        '/job/scheduler/v1/isExist?type=' + type + '&name=' + name
    },
    //切换定时计划状态
    changeStart() {
      sys.changeStart(this.isStandby).then(
        data => {
          if (data.state) {
            this.$message.success(data.message)
          } else {
            this.$message.error(data.message || '操作失败')
          }
        },
        error => {
          this.$message.error(error || '操作失败')
        }
      )
    },
    deleteEntRows(rows) {
      this.parameterJson.remove(rows)
    },
    addEntRows() {
      let temp = {
        name: '',
        type: '',
        value: '',
        relation: ''
      }
      this.parameterJson.push(temp)
    },
    beforeSaveData() {
      if (!this.scheduler.className) {
        this.$message.warning('任务类不能为空')
        this.isSubmit = false
        return
      }
      if(!this.isValidateClass){
        this.$message.warning('请先验证任务类')
        this.isSubmit = false
        return
      }
      this.scheduler.parameterJson = JSON.stringify(this.parameterJson)
      this.isSubmit = true
    },
    afterSaveData() {
      this.isEdit = false
      this.dialogVisible = false
      this.$refs.schedulerTable.load()
    },
    afterGetStand(data) {
      this.isStandby = data
    },
    afterValidClass(rep) {
      if (rep && rep.state) {
        this.isValidateClass = true
        this.$message.success(rep.message)
      }else{
        this.isValidateClass = false
      }
    },
    afterExecuteJob(rep) {
      if (rep && rep.state) {
        this.$message.success(rep.message)
      } else {
        this.$message.error(rep.message || '执行失败')
      }
      this.executeJobUrl = ''
    },
    afterIsExist(data) {
      if (data) {
        var msg =
          this.isExistType == 'jobName'
            ? '任务名称已经存在,请重新填写!'
            : '任务列表中已添加该任务类记录,不能多次添加同一任务类!'
        this.$message.error(msg)
        if (this.isExistType == 'jobName') {
          this.scheduler.jobName = ''
        } else {
          this.scheduler.className = ''
        }
      }
      this.isExistType = ''
      this.isExistUrl = ''
    },
    afterLoadData(data) {
      // 编辑定时计划
      if (this.dialogVisible) {
        this.scheduler = data
        if (this.scheduler.parameterJson) {
          this.parameterJson = JSON.parse(this.scheduler.parameterJson)
          this.parameterJson.forEach(item => {
            item.value = item.value.toString()
          })
        } else {
          this.parameterJson = []
        }
        setTimeout(() => this.$validator.validateAll('editschedulerForm'))
      }
    },
    dialogCancle(dialogVisible) {
      this.loadDataUrl = ''
      this[dialogVisible] = false
      this.isEdit = false
      setTimeout(() => (this.schedulerDisabled = false), 500)
    },
    handleClose() {
      this.loadDataUrl = ''
      this.dialogVisible = false
      this.isEdit = false
      setTimeout(() => (this.schedulerDisabled = false), 500)
    },
    showDialog(row) {
      this.dialogVisible = true
      if (row) {
        this.isEdit = true
        this.loadDataUrl = `/job/scheduler/v1/getJobDetail?name=${encodeURI(
          row.jobName
        )}`
      } else {
        this.parameterJson = []
      }
    },
    handleNodeClick(node) {},
    async loadData(param, cb) {
      let xxlInfo = await this.$http.get(
        '${portal}/base/tools/v1/getYmlValueByName?keys=xxl.job.enabled,xxl.job.admin.addresses'
      )
      if (
        xxlInfo &&
        xxlInfo.data &&
        xxlInfo.data.value &&
        xxlInfo.data.value['xxl.job.enabled'] == 'true'
      ) {
        this.xxlAdminAddress = xxlInfo.data.value['xxl.job.admin.addresses']
        return
      }
      this.getStandUrl = '/job/scheduler/v1/getStand'
      sys
        .getschedulerPageJson(param)
        .then(response => {
          this.data = response.rows
          this.pageResult = {
            page: response.page,
            pageSize: response.pageSize,
            total: response.total
          }
        })
        .finally(() => cb())
    },
    handleCommand(params) {
      switch (params.command) {
        case 'lookLog':
          //this.$router.push("/executeJobList/" + params.row.jobName);
          this.$router.push({
            name: 'executeJobList',
            params: {
              jobName: params.row.jobName,
              tobName: params.row.jobName + '定时计划日志'
            }
          })
          //this.$router.go({name: 'executeJobList', params: {jobName: 'com.hotent.job.job.FlowStartJob'}});
          break
        case 'triggersJob':
          this.$router.push({
            name: 'schedulerTriggerList',
            params: {
              jobName: encodeURI(params.row.jobName),
              tobName: '触发器列表'
            }
          })
          break
        case 'edit':
          this.parameterJson = []
          this.schedulerTitle = '编辑定时计划'
          this.showDialog(params.row)
          this.isEdit = true
          break
        case 'add':
          this.scheduler = {}
          this.parameterJson = []
          this.schedulerTitle = '添加定时计划'
          this.showDialog()
          break
        case 'get':
          this.schedulerTitle = '查看定时计划'
          this.isSubmit = false
          this.schedulerDisabled = true
          this.showDialog(params.row)
          break
        case 'delete':
          this.$confirm('是否确认删除?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          })
            .then(() => {
              sys.delJob(params.row.jobName).then(
                data => {
                  if (data.state) {
                    this.$message.success(data.message)
                    this.$refs.schedulerTable.load()
                  } else {
                    this.$message.error(data.message || '删除失败')
                  }
                },
                error => {
                  this.$message.error(error || '删除失败')
                }
              )
            })
            .catch(() => {})
          break
        case 'executeJob':
          this.executeJobUrl =
            '/job/scheduler/v1/executeJob?jobName=' + params.row.jobName
          break
        default:
          break
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.el-main {
  // padding: 0px;
}
.obj-atter {
  width: 100%;
  border: 1px solid #ddd;
  border-radius: 4px;
  //margin-left: 10px;
}
.obj-atter-panel {
  border: 1px solid #ddd;
  border-radius: 4px;
  background-color: #f4f4f5;
  height: 50px;
  line-height: 50px;
  padding: 0px 15px;
}
.scheduler-input-width .inputs {
  width: 100%;
}
/deep/.el-dialog__wrapper {
  overflow: unset !important;
}
/deep/.el-dialog__body {
  height: calc(100% - 190px);
  overflow-y: auto;
}

/deep/.el-dialog {
  height: 90%;
  min-height: 400px;
  margin-top: 3vh !important;
}
/deep/.el-dialog__body .selector-table {
  height: 100% !important;
}
/deep/.el-dialog .el-dialog__body .select-tree-div {
  height: calc(100% - 60px);
  min-height: unset;
}
@media (max-height: 960px) {
  /deep/.el-dialog__body .el-container {
    height: 100% !important;
  }
}
/deep/ .xxl-job {
  width: 100%;
  .rounters {
    color: #27b5b7;
  }
  .setting__wrap {
    display: flex;
    justify-content: center;
    align-items: center;
    height: calc(100% - 50px);
  }
  .setting {
    height: 50px;
    font-size: 24px;
    color: #e6a23c;
    line-height: 50px;
  }
}
// /deep/.el-form-item__error {
//   left: auto;
// }

/deep/ td .el-form-item__error {
  top: calc(100% - 35px);
  left: auto;
  margin-left: 8px;
}
</style>