<template>
<div class="dataDiscovery">
<div class="container-wd bg-shadow">
<third-nav :itemsData="thirdNavItemsData" :triangleShow="false"></third-nav>
<div class="pl-30 pr-30 pb-10 pt-0 relative">
<el-form ref="searchform" :model="searchform" class="xyj-el-form">
<el-row :gutter="120" class="mt-20">
<el-col :span="8">
<el-form-item label="任务名称:" label-width="90px">
<el-input v-model.trim="searchform.serch" placeholder="请输入任务名称" class="xyj-input h30 flex-1"
@keyup.enter.native="goSearch(searchform)">
<i slot="suffix" class="el-input__icon el-icon-search" @click="goSearch(searchform)"></i>
</el-input>
<input onkeypress="if (event.keyCode == 13) showResult();" style="display:none;"/>
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="任务状态:" label-width="90px">
<el-select
v-model.number="searchform.status" clearable popper-class="xyj-dropdown" placeholder="请选择任务状态"
@change="goSearch()" class="xyj-select h30 flex-1">
<el-option v-for="item in taskStatusOptions" :key="item.value" :label="item.label" :value="item.value" />
</el-select>
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="" label-width="0px" class="text-r">
<el-button :disabled="isReadonlyByAuth" size="small" @click="showEdit('add')"> <i class="el-icon-plus mr-5"></i>新增</el-button>
<el-button :disabled="isReadonlyByAuth || !(this.batchpram.length>0)" class="btn-delete ml-20" size="small" @click="copyTask()"><img class="lmy-img" src="@/assets/image/icon-copy.png" alt="" />复制任务</el-button>
<el-button :disabled="isReadonlyByAuth || !(this.batchpram.length>0)" size="small" class="btn-delete ml-20" @click="batchRemove(batchDeltask,'任务')"><i class="el-icon-delete mr-5"></i>删除</el-button>
</el-form-item>
</el-col>
</el-row>
</el-form>
<el-table class="xyj-table" :data='tableData.tableList' ref="multipleTable" @selection-change="handleSelectionChange">
<el-table-column align="center" class="xyj-table-select" type="selection" width="60">
</el-table-column>
<el-table-column label='任务名称' min-width="100" :show-overflow-tooltip="true">
<template slot-scope="scope">
<el-button :disabled="isReadonlyByAuth" type="text" class="btn-text-two overflow" @click="handleDetail(scope.row.id)">
<span style="
display: inline-block;
text-align:left;
width: 108px;
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;">{{scope.row.taskName}}</span>
</el-button >
</template>
</el-table-column>
<el-table-column label='' width="70">
<template slot-scope="scope">
<div class="">
<el-popover trigger="hover" placement="right-start" popper-class="action-popover">
<el-button :disabled="isReadonlyByAuth || scope.row.status === 2 || scope.row.status===3" class="lmy-popover-button action-button" type="text" @click="showEdit('edit',scope.row)">
<i class="iconfont icon-bianji-zhengchang fs12"></i> 编辑
</el-button>
<el-button :disabled="isReadonlyByAuth || scope.row.status === 2 || scope.row.status === 6" class="lmy-popover-button action-button" type="text" @click="startOrStop(1,scope)">
<i class="iconfont icon-qidong-zhengchang fs12"></i> 启动
</el-button>
<el-button :disabled="isReadonlyByAuth || scope.row.status !== 2" class="lmy-popover-button action-button" type="text" @click="startOrStop(2,scope)">
<i class="iconfont icon-tingzhi fs12"></i> 停止
</el-button>
<el-button v-if="scope.row.status == 2 || scope.row.status== 6" class="lmy-popover-button action-button" type="text" @click="pauseOrRecoverWay(1,scope)">
<i class="iconfont icon-qidong-zhengchang fs12"></i> 暂停
</el-button>
<el-button v-if="scope.row.status == 3 " class="lmy-popover-button action-button" type="text" @click="pauseOrRecoverWay(2,scope)">
<i class="iconfont icon-tingzhi fs12"></i> 恢复
</el-button>
<el-button :disabled="isReadonlyByAuth || scope.row.status === 2|| scope.row.status===3" class="lmy-popover-button action-button" type="text" @click="deleteTask(scope.row.id)">
<i class="iconfont icon-shanchu-zhengchang fs12"></i> 删除
</el-button>
<div slot="reference" class="name-wrapper">
<i class="iconfont icon-sangedian-zhengchang more-action"></i>
</div>
</el-popover>
</div>
</template>
</el-table-column>
<el-table-column label='数据源名称' min-width='130' :show-overflow-tooltip="true">
<template slot-scope="scope">
<span>{{scope.row.dsName}}</span>
</template>
</el-table-column>
<el-table-column label='任务创建时间' min-width='150' :show-overflow-tooltip="true">
<template slot-scope="scope">
<span>{{scope.row.createTime | getDate}}</span>
</template>
</el-table-column>
<el-table-column label='任务开始时间' min-width='150' :show-overflow-tooltip="true">
<template slot-scope="scope">
<span v-if="scope.row.startTime">{{scope.row.startTime | getDate}}</span>
<span v-if="!scope.row.startTime">--</span>
</template>
</el-table-column>
<el-table-column label='任务运行用时' min-width='100' :show-overflow-tooltip="true">
<template slot-scope="scope">
<span>{{scope.row.duration | formatSeconds}}</span>
</template>
</el-table-column>
<el-table-column label='任务状态' min-width='100' :show-overflow-tooltip="true">
<template slot-scope="scope">
<span v-bind:class="handleTaskStatusStyle(scope.row.status)">{{scope.row.status | getTaskState}}</span>
</template>
</el-table-column>
<el-table-column label='用户' prop='creator' min-width='100' :show-overflow-tooltip="true"></el-table-column>
<el-table-column label='操作' width='130' align="center">
<template slot-scope="scope">
<el-button :disabled="isReadonlyByAuth" v-if="scope.row.status === 5" type="text" class="btn-text" @click="handleAdjust(scope.row.id,false,'confirm')">结果确认</el-button>
<el-button :disabled="isReadonlyByAuth" v-if="scope.row.status === 4" type="text" class="btn-text" @click="handleAdjust(scope.row.id,true,'adjust')">结果调整</el-button>
<el-button :disabled="isReadonlyByAuth" v-if="scope.row.status === -1||scope.row.status===3" type="text" class="btn-text" @click="handleFailureReason(scope.row.id)">查看详情</el-button>
<el-button :disabled="isReadonlyByAuth" v-if="scope.row.status === 2" type="text" class="btn-text" @click="Progress(scope)">查看进度</el-button>
</template>
</el-table-column>
</el-table>
<div class="text-r pt-20 pl-20 pr-20 relative">
<el-pagination
background
class="xyj-pagination pagination-one mar-t"
@size-change='handleSizeChange'
@current-change='handleCurrentChange'
:current-page='pageData.pageNum'
:page-sizes='[10, 20, 30, 50]'
:page-size='pageData.pageSize'
layout='total, sizes, prev, pager, next, jumper'
:total='tableData.total'>
</el-pagination>
</div>
</div>
</div>
<!-- 新增与编辑弹窗 -->
<add-task
@update-data="updateData"
@show-change="showChange"
v-if="dialogInit"
:type="dialogType"
:TaskForm="formForEdit"
:title="dialogTitle"></add-task>
</div>
</template>
<script>
import ThirdNav from '@/views/components/ThirdNav'
import { globalTable, batchRemoveCommon, pageMenusAuth, getRealTimeData } from '@/mixin/index'
import { taskList, taskStartOrStop,pauseOrRecover,failureReason, taskCopy, batchDeltask } from '@/http/htask'
import { dataDiscoveryOpts } from '@/dict/dataDesen'
import addTask from './addTaskT.vue'
export default {
mixins: [globalTable, batchRemoveCommon, pageMenusAuth, getRealTimeData],
components: {
addTask,
ThirdNav
},
data () {
return {
batchDeltask,
thirdNavItemsData: [
{
'label': '数据发现任务列表',
'value': 1
}
],
dialogType: 'add',
dialogTitle: '新建任务',
id: '',
Num: 1,
isAddTask: false,
searchform: {},
sourceTypes: [{ value: 1, label: 'MySQL' }, { value: 2, label: 'Oracle' }, { value: 3, label: 'SQLServer' },
{ value: 4, label: 'PostgreSQL' }, { value: 5, label: 'DB2' }, { value: 6, label: 'Informix' },
{ value: 7, label: 'SYBase' }, { value: 8, label: 'Hive' }, { value: 9, label: 'Hbase' }, { value: 10, label: 'DM' }],
tableData: {
tableList: [],
total: 1
},
pageData: {
pageNum: 1,
pageSize: 10
},
taskStatusOptions: dataDiscoveryOpts
}
},
watch: {
dialogType: {
handler () {
this.dialogTitle = this.dialogType === 'add' ? '新建任务' : '编辑任务'
}
},
'$route': {
handler (value) {
this.searchTask()
},
immediate: true
}
},
computed: {
},
mounted () {
this.searchTask()
},
methods: {
showEditTwo (row) {
this.dialogType = 'edit'
let editFilterTable = JSON.parse(JSON.stringify(row.filterTable)).map(item => {
return {
label: item,
key: item
}
})
this.formForEdit = JSON.parse(JSON.stringify(row))
this.formForEdit.filterTable = editFilterTable
this.dialogInit = true
},
handleSelectionChange (val) {
if (val && val.length) {
this.multipleSelection = val
this.clearTimer()
} else {
this.multipleSelection = []
this.setTimer()
}
},
deleteTask (id) {
this.multipleSelection = []
this.multipleSelection.push({ id: id })
this.batchRemove(batchDeltask, '任务')
},
setTimer () {
this.clearTimer()
this.timer = setTimeout(() => {
this.searchTask()
}, 5000)
},
clearTimer () {
if (this.timer) {
clearTimeout(this.timer)
this.timer = null
}
},
searchTask (val) {
// 通知top5列表根据任务名称跳转到任务列表
let name = this.$route.query.name
if (typeof (val) === 'undefined') {
val = {}
if (typeof (name) !== 'undefined') {
val.serch = name
// type为1-精确查询
val.type = 1
} else {
// type为0-模糊查询
val.type = 0
}
}
if (name === undefined) {
val.type = 0
}
let pr = this.getparams(val)
taskList(pr).then((res) => {
if (res.code === 0 && res.data) {
if (!this.noDataJumpFirst(res.data)) {
this.tableData.tableList = res.data.list
this.tableData.total = res.data.total
}
this.setTimer()
} else {
this.errorTips(res.message || '网络异常,请稍后再试')
}
})
},
// 根据不同任务状态显示字的不同颜色
// '已完成','未开始','执行中','待确认','失败'5种状态
handleTaskStatusStyle (item) {
if (item === -1) {
return 'failure-state'
}
},
copyTask () {
if (this.multipleSelection.length > 1) {
this.errorTips('暂不支持批量复制!')
return false
}
let param = this.multipleSelection[0].id
taskCopy(param).then(res => {
if (res.code === 0) {
this.successTips('复制任务成功!')
this.searchTask()
} else {
this.errorTips(res.message || '复制任务失败!')
}
})
},
// 详情
handleDetail (id) {
this.$router.push({ name: 'taskdetail', query: { id: id } })
},
startOrStop (flag, scope) {
taskStartOrStop(flag, scope.row.id).then(res => {
if (flag === 1) {
if (res.code === 0) {
this.successTips('启动任务成功!')
this.updateData()
} else {
this.errorTips(res.message || '启动任务失败!')
}
} else if (flag === 2) {
if (res.code === 0) {
this.successTips('停止任务成功!')
this.updateData()
} else {
this.errorTips(res.message || '停止任务失败!')
}
}
})
},
pauseOrRecoverWay (flag, scope) {
pauseOrRecover(flag, scope.row.id).then(res => {
if (flag === 1) {
if (res.code === 0) {
this.successTips('暂停任务成功!')
this.updateData()
} else {
this.errorTips(res.message || '暂停任务失败!')
}
} else if (flag === 2) {
if (res.code === 0) {
this.successTips('恢复任务成功!')
this.updateData()
} else {
this.errorTips(res.message || '恢复任务失败!')
}
}
})
},
Progress (scope) {
this.$router.push({ path: '/dataDiscovery/scan', query: { id: scope.row.id } })
},
// 失败-查看详情
handleFailureReason (id) {
failureReason(id).then(res => {
if (res.code === 0) {
this.successTips(res.data)
} else {
this.errorTips(res.message || '请求失败!')
}
})
},
// 结果调整
handleAdjust (id, val, type) {
this.$router.push({ name: 'dataConfirm', query: { id: id, isEdit: val, type } })
}
}
// beforeDestroy () {
// this.clearTimer()
// }
}
</script>
<style lang="scss">
.dataDiscovery{
.more-action{
color:#709AF9;
cursor: pointer;
}
.failure-state{
color: #E45E5E;
}
.task-btn{
font-family: MicrosoftYaHei;
font-size: 13px;
color: #6E52EE;
&:hover,&:active{
color: #a997ff;
}
}
.name-wrapper{
display: inline-block;
}
}
.grouplabel{
font-size:14px;
}
.action-popover{
min-width: 70px !important;
padding: 10px;
}
.action-button{
display: block;
font-family: "MicrosoftYaHei";
font-size: 12px;
color: #5D5D5D;
padding: 10px 0 0 0;
&:first-child{
padding-top: 0;
}
&:hover,&:active{
color: #709AF9;
img:first-child {
display: none;
}
img:last-child {
display: inline-block;
}
}
img{
margin-right: 5px;
}
.delete-action {
display: inline-block;
}
.delete-active-action {
display: none;
}
}
</style>