Files
lanzhouhailiang_one/lms/nladmin-ui/src/views/system/timing/index.vue

238 lines
10 KiB
Vue
Raw Normal View History

2022-07-06 18:32:05 +08:00
<template>
<div class="app-container">
<!--工具栏-->
<div class="head-container">
<div v-if="crud.props.searchToggle">
<!-- 搜索 -->
2022-12-06 17:57:49 +08:00
<el-input v-model="query.job_name" clearable size="mini" placeholder="输入任务名称搜索" style="width: 200px;" class="filter-item" @keyup.enter.native="toQuery" />
2022-07-06 18:32:05 +08:00
<rrOperation />
</div>
<crudOperation :permission="permission">
<!-- 任务日志 -->
<el-button
slot="right"
class="filter-item"
size="mini"
type="info"
icon="el-icon-tickets"
@click="doLog"
>日志</el-button>
</crudOperation>
<Log ref="log" />
</div>
<!--Form表单-->
<el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" append-to-body width="730px">
<el-form ref="form" :inline="true" :model="form" :rules="rules" size="mini" label-width="100px">
2022-12-06 17:57:49 +08:00
<el-form-item label="任务名称" prop="job_name">
<el-input v-model="form.job_name" style="width: 220px;" />
2022-07-06 18:32:05 +08:00
</el-form-item>
<el-form-item label="任务描述" prop="description">
<el-input v-model="form.description" style="width: 220px;" />
</el-form-item>
2022-12-06 17:57:49 +08:00
<el-form-item label="Bean名称" prop="bean_name">
<el-input v-model="form.bean_name" style="width: 220px;" />
2022-07-06 18:32:05 +08:00
</el-form-item>
2022-12-06 17:57:49 +08:00
<el-form-item label="执行方法" prop="method_name">
<el-input v-model="form.method_name" style="width: 220px;" />
2022-07-06 18:32:05 +08:00
</el-form-item>
2022-12-06 17:57:49 +08:00
<el-form-item label="Cron表达式" prop="cron_expression">
2022-08-05 13:53:58 +08:00
<!-- <el-input v-model="form.cronExpression" style="width: 220px;" />-->
2022-12-06 17:57:49 +08:00
<el-input v-model="form.cron_expression" placeholder="请输入CRON 表达式" style="width: 220px;">
2022-08-05 13:53:58 +08:00
<template slot="append">
<el-button type="primary" @click="handleShowCron">
生成表达式
<i class="el-icon-time el-icon--right" />
</el-button>
</template>
</el-input>
2022-07-06 18:32:05 +08:00
</el-form-item>
<el-form-item label="子任务ID">
2022-12-06 17:57:49 +08:00
<el-input v-model="form.sub_task" placeholder="多个用逗号隔开,按顺序执行" style="width: 220px;" />
2022-07-06 18:32:05 +08:00
</el-form-item>
2022-12-06 17:57:49 +08:00
<el-form-item label="任务负责人" prop="person_in_charge">
<el-input v-model="form.person_in_charge" style="width: 220px;" />
2022-07-06 18:32:05 +08:00
</el-form-item>
<el-form-item label="告警邮箱" prop="email">
<el-input v-model="form.email" placeholder="多个邮箱用逗号隔开" style="width: 220px;" />
</el-form-item>
<el-form-item label="失败后暂停">
2022-12-06 17:57:49 +08:00
<el-radio-group v-model="form.pause_after_failure" style="width: 220px">
<el-radio label="1"></el-radio>
<el-radio label="0"></el-radio>
2022-07-06 18:32:05 +08:00
</el-radio-group>
</el-form-item>
<el-form-item label="任务状态">
2022-12-06 17:57:49 +08:00
<el-radio-group v-model="form.is_pause" style="width: 220px">
<el-radio label="0">启用</el-radio>
<el-radio label="1">暂停</el-radio>
2022-07-06 18:32:05 +08:00
</el-radio-group>
</el-form-item>
<el-form-item label="参数内容">
<el-input v-model="form.params" style="width: 556px;" rows="4" type="textarea" />
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="text" @click="crud.cancelCU">取消</el-button>
<el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
</div>
</el-dialog>
<!--表格渲染-->
<el-table ref="table" v-loading="crud.loading" :data="crud.data" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
<el-table-column :selectable="checkboxT" type="selection" width="55" />
2022-12-06 17:57:49 +08:00
<!-- <el-table-column show-overflow-tooltip prop="job_id" label="任务ID" />-->
<el-table-column show-overflow-tooltip prop="job_name" label="任务名称" min-width="120" />
<el-table-column show-overflow-tooltip prop="bean_name" label="Bean名称" />
<el-table-column show-overflow-tooltip prop="method_name" label="执行方法" />
2022-07-06 18:32:05 +08:00
<el-table-column show-overflow-tooltip prop="params" label="参数" />
2022-12-06 17:57:49 +08:00
<el-table-column show-overflow-tooltip prop="cron_expression" label="cron表达式" min-width="100" show-tooltip-when-overflow />
<el-table-column show-overflow-tooltip prop="is_pause" width="90px" label="状态">
2022-07-06 18:32:05 +08:00
<template slot-scope="scope">
2022-12-06 17:57:49 +08:00
<el-tag :type="scope.row.is_pause ? 'warning' : 'success'">{{ scope.row.is_pause=='1' ? '已暂停' : '运行中' }}</el-tag>
2022-07-06 18:32:05 +08:00
</template>
</el-table-column>
<el-table-column show-overflow-tooltip prop="description" width="150px" label="描述" />
<el-table-column show-overflow-tooltip prop="createTime" width="136px" label="创建日期">
<template slot-scope="scope">
2022-12-06 17:57:49 +08:00
<span>{{ parseTime(scope.row.create_time) }}</span>
2022-07-06 18:32:05 +08:00
</template>
</el-table-column>
<el-table-column v-permission="['admin','timing:edit','timing:del']" label="操作" width="170px" align="center" fixed="right">
<template slot-scope="scope">
<el-button v-permission="['admin','timing:edit']" size="mini" style="margin-right: 3px;" type="text" @click="crud.toEdit(scope.row)">编辑</el-button>
2022-12-06 17:57:49 +08:00
<el-button v-permission="['admin','timing:edit']" style="margin-left: -2px" type="text" size="mini" @click="execute(scope.row.job_id)">执行</el-button>
<el-button v-permission="['admin','timing:edit']" style="margin-left: 3px" type="text" size="mini" @click="updateStatus(scope.row.job_id,scope.row.is_pause=='1' ? '恢复' : '暂停')">
{{ scope.row.is_pause=='1' ? '恢复' : '暂停' }}
2022-07-06 18:32:05 +08:00
</el-button>
<el-popover
2022-12-06 17:57:49 +08:00
:ref="scope.row.job_id"
2022-07-06 18:32:05 +08:00
v-permission="['admin','timing:del']"
placement="top"
width="200"
>
<p>确定停止并删除该任务吗</p>
<div style="text-align: right; margin: 0">
2022-12-06 17:57:49 +08:00
<el-button size="mini" type="text" @click="$refs[scope.row.job_id].doClose()">取消</el-button>
<el-button :loading="delLoading" type="primary" size="mini" @click="delMethod(scope.row.job_id)">确定</el-button>
2022-07-06 18:32:05 +08:00
</div>
<el-button slot="reference" type="text" size="mini">删除</el-button>
</el-popover>
</template>
</el-table-column>
</el-table>
<!--分页组件-->
<pagination />
2022-08-05 13:53:58 +08:00
<el-dialog title="Cron表达式生成器" :visible.sync="openCron" append-to-body class="scrollbar" destroy-on-close>
<crontab :expression="expression" @hide="openCron=false" @fill="crontabFill" />
</el-dialog>
2022-07-06 18:32:05 +08:00
</div>
</template>
<script>
import crudJob from '@/api/system/timing'
import Log from './log'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import pagination from '@crud/Pagination'
2022-08-05 13:53:58 +08:00
import Crontab from './components/crontab'
2022-07-06 18:32:05 +08:00
2022-12-06 17:57:49 +08:00
const defaultForm = { job_id: null, bean_name: null, cron_expression: null, is_pause: '0', job_name: null, method_name: null, params: null, description: null, person_in_charge: null, email: null, sub_task: null, pause_after_failure: '1', create_id: null, create_name: null, create_time: null, update_optid: null, update_optname: null, update_time: null }
2022-07-06 18:32:05 +08:00
export default {
name: 'Timing',
2022-12-06 17:57:49 +08:00
components: { Log, pagination, crudOperation, rrOperation, Crontab },
2022-07-06 18:32:05 +08:00
cruds() {
2022-12-06 17:57:49 +08:00
return CRUD({ title: '定时任务', idField: 'job_id', url: 'api/jobs', crudMethod: { ...crudJob }})
2022-07-06 18:32:05 +08:00
},
mixins: [presenter(), header(), form(defaultForm), crud()],
data() {
return {
delLoading: false,
permission: {
add: ['admin', 'timing:add'],
edit: ['admin', 'timing:edit'],
del: ['admin', 'timing:del']
},
rules: {
2022-12-06 17:57:49 +08:00
job_name: [
2022-07-06 18:32:05 +08:00
{ required: true, message: '请输入任务名称', trigger: 'blur' }
],
description: [
{ required: true, message: '请输入任务描述', trigger: 'blur' }
],
2022-12-06 17:57:49 +08:00
bean_name: [
2022-07-06 18:32:05 +08:00
{ required: true, message: '请输入Bean名称', trigger: 'blur' }
],
2022-12-06 17:57:49 +08:00
method_name: [
2022-07-06 18:32:05 +08:00
{ required: true, message: '请输入方法名称', trigger: 'blur' }
],
2022-12-06 17:57:49 +08:00
cron_expression: [
2022-07-06 18:32:05 +08:00
{ required: true, message: '请输入Cron表达式', trigger: 'blur' }
],
2022-12-06 17:57:49 +08:00
person_in_charge: [
2022-07-06 18:32:05 +08:00
{ required: true, message: '请输入负责人名称', trigger: 'blur' }
]
2022-08-05 13:53:58 +08:00
},
// 是否显示Cron表达式弹出层
openCron: false,
// 传入的表达式
expression: ''
2022-07-06 18:32:05 +08:00
}
},
methods: {
// 执行
execute(id) {
crudJob.execution(id).then(res => {
this.crud.notify('执行成功', CRUD.NOTIFICATION_TYPE.SUCCESS)
}).catch(err => {
console.log(err.response.data.message)
})
},
// 改变状态
updateStatus(id, status) {
if (status === '恢复') {
this.updateParams(id)
}
crudJob.updateIsPause(id).then(res => {
this.crud.toQuery()
this.crud.notify(status + '成功', CRUD.NOTIFICATION_TYPE.SUCCESS)
}).catch(err => {
console.log(err.response.data.message)
})
},
updateParams(id) {
console.log(id)
},
delMethod(id) {
this.delLoading = true
crudJob.del([id]).then(() => {
this.delLoading = false
this.$refs[id].doClose()
this.crud.dleChangePage(1)
this.crud.delSuccessNotify()
this.crud.toQuery()
}).catch(() => {
this.delLoading = false
this.$refs[id].doClose()
})
},
// 显示日志
doLog() {
this.$refs.log.dialog = true
this.$refs.log.doInit()
},
checkboxT(row, rowIndex) {
2022-12-06 17:57:49 +08:00
return row.job_id !== 1
2022-08-05 13:53:58 +08:00
},
/** cron表达式按钮操作 */
handleShowCron() {
2022-12-06 17:57:49 +08:00
this.expression = this.form.cron_expression
2022-08-05 13:53:58 +08:00
this.openCron = true
},
/** 确定后回传值 */
crontabFill(value) {
2022-12-06 17:57:49 +08:00
this.form.cron_expression = value
2022-07-06 18:32:05 +08:00
}
}
}
</script>