<template> <app-container> <!--筛选条件--> <search-area size="small" @search="search"> <search-item> <el-input v-model.trim="listQuery.condition" size="small" placeholder="任务名/启动类" clearable/> </search-item> </search-area> <!--查询结果Table显示--> <normal-table :data="list" :total="total" :columns="columns" :query="listQuery" :list-loading="listLoading" @change="changePage"> <template slot="btns"> <el-button v-if="hasPerm('/job/add')" size="small" icon="el-icon-plus" @click="add">新增</el-button> </template> <template slot="columns"> <el-table-column label="任务状态" prop="status" align="center" > <template slot-scope="scope"> <div slot="reference" class="name-wrapper"> <el-tag :type="getTag(scope.row).type" size="medium">{{ getTag(scope.row).text }}</el-tag> </div> </template> </el-table-column> <el-table-column label="任务控制" align="center"> <template slot-scope="scope"> <el-button v-if="scope.row.status==='0' ||scope.row.status==='3'" type="text" size="small" title="启动" @click="start(scope.row)">启动</el-button> <el-button v-if="scope.row.status==='1' " type="text" size="small" title="暂停" @click="pause(scope.row)" >暂停</el-button> <el-button v-if="scope.row.status==='2' " type="text" size="small" title="恢复" @click="resume(scope.row)" >恢复</el-button> <el-button v-if="scope.row.status!='0' & scope.row.status!='3'" type="text" size="small" title="停止" @click="stop(scope.row)" >停止</el-button> </template> </el-table-column> <el-table-column label="执行状态" prop="isSuccess" align="center" > <template slot-scope="scope"> <div slot="reference" class="name-wrapper"> <el-tag v-if="scope.row.isSuccess==='1'" type="success" size="medium">成功</el-tag> <el-tag v-if="scope.row.isSuccess==='0' && !scope.row.completeTime" type="danger" size="medium">失败</el-tag> <el-button v-if="scope.row.isSuccess==='0'&&(scope.row.completeTime==='null'||scope.row.completeTime)" :loading="true" size="small" circle /> </div> </template> </el-table-column> <el-table-column label="执行时间" prop="lastTime" align="center" width="160" /> <el-table-column v-if="showOperate" label="操作" width="160" align="center"> <template slot-scope="scope"> <el-button v-if="hasPerm('/job/update')&&!scope.row.isSystem" type="text" size="small" @click="edit(scope.row)">修改</el-button> <el-button v-if="hasPerm('/job/delete')&&!scope.row.isSystem" type="text" size="small" @click="del(scope.row)">删除</el-button> </template> </el-table-column> </template> </normal-table> <edit-Job v-show="dialogFormVisible" ref="editJob" @watchChild="fetchData"/> </app-container> </template> <script> import { getListPage, del, operation } from '@/api/common/job' import editJob from './editJob' export default { name: 'ListJob', components: { editJob }, data() { return { listQuery: { condition: '', offset: 1, limit: 20, sort: '', order: '' }, // 筛选条件 tags: [ { text: '未启动', value: '0', type: 'info' }, { text: '运行中', value: '1', type: 'success' }, { text: '暂停', value: '2', type: 'warning' }, { text: '停止', value: '3', type: 'danger' } ], columns: [ { text: '任务名称', value: 'jobName', align: 'center' }, { text: 'cron表达式', value: 'cronExpression', align: 'center' }, { text: '分片数', value: 'shardingCount', align: 'center', width: '80' }, { text: '分片参数', value: 'shardingParameter', align: 'center', width: '160' } ], // 显示列 list: [], // 列表数据 total: 0, // 数据总数 listLoading: true, // 加载动画 fullscreenLoading: false, // 全屏加载动画 dialogFormVisible: false // 是否显示编辑框 } }, computed: { 'showOperate': function(row) { // 判断是否显示操作列,如果编辑和删除的权限都没有则不显示操作列 return this.hasPerm('/job/update') || this.hasPerm('/job/delete') } }, created() { this.fetchData()// 获取数据 }, activated() { this.fetchData()// 获取数据 }, methods: { // 打开详情对话框 detail(row) { this.$refs.detailwell.initDialog(true, row) }, // 新增字典 add() { this.dialogFormVisible = true this.$refs.editJob.initDialog('create', this.dialogFormVisible) }, // 编辑字典信息 edit(row) { this.dialogFormVisible = true this.editShow = true this.$refs.editJob.initDialog('update', this.dialogFormVisible, row) }, getTag(row) { return this.tags.find(tag => tag.value === row.status) }, // 删除 del(row) { this.$confirm( '确定删除吗?', '确认操作', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' } ).then(() => { del(row.id).then(response => { if (response.code === 200) { this.$message.success('删除成功') this.fetchData() } }) }) }, start(row) { this.$confirm( '确定启动吗?', '确认操作', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' } ).then(() => { operation(row.jobName, 'start').then(response => { if (response.code === 200) { this.$message.success('启动成功') this.fetchData() } }) }) }, stop(row) { this.$confirm( '确定停止吗?', '确认操作', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' } ).then(() => { operation(row.jobName, 'stop').then(response => { if (response.code === 200) { this.$message.success('停止成功') this.fetchData() } }) }) }, pause(row) { this.$confirm( '确定暂停吗?', '确认操作', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' } ).then(() => { operation(row.jobName, 'pause').then(response => { if (response.code === 200) { this.$message.success('暂停成功') this.fetchData() } }) }) }, resume(row) { this.$confirm( '确定恢复吗?', '确认操作', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' } ).then(() => { operation(row.jobName, 'resume').then(response => { if (response.code === 200) { this.$message.success('恢复成功') this.fetchData() } }) }) }, // 查询数据 search() { this.fetchData(false) }, // 获取字典数据 fetchData(isNowPage = true) { this.listLoading = true if (!isNowPage) { // 是否显示当前页,否则跳转第一页 this.listQuery.offset = 1 } getListPage(this.listQuery).then(response => { this.list = response.data.rows this.total = parseInt(response.data.total) this.listLoading = false }) }, indexMethod(index) { return this.listQuery.limit * (this.listQuery.offset - 1) + index + 1 }, // 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写 changePage(val) { if (val && val.size) { this.listQuery.limit = val.size } if (val && val.page) { this.listQuery.offset = val.page } this.fetchData() } } } </script> <style rel="stylesheet/scss" lang="scss" scoped> $tableTitleHeight:46px; .table{ margin-bottom: 20px; } .pagination-container{ margin-bottom: 50px; } .table-title{ background-color:rgba(243, 243, 243, 1); height: $tableTitleHeight; .title-header{ line-height:$tableTitleHeight; color: #606266; font-size: 15px; i{ margin-left: 5px; margin-right: 5px; } } } .edit_btns{ .edit_btn{ float:right; margin:7px 3px;//为了需要居中显示margin-top和bottom要用$tableTitleHeight减去按钮原高度除以2 } } </style>