This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
cyber-narrator-cn-ui/src/components/table/report/reportTestTable.vue

326 lines
11 KiB
Vue
Raw Normal View History

<template>
<el-table
2022-06-08 15:31:41 +08:00
id="reportTable"
ref="dataTable"
:data="tableData"
:height="height"
2022-06-08 18:32:52 +08:00
:expand-row-keys="expandedIds"
row-key="id"
border
2022-06-08 15:31:41 +08:00
tooltip-effect="light"
@header-dragend="dragend"
@sort-change="tableDataSort"
2022-06-06 17:37:01 +08:00
@expand-change="dropExpandChange"
@selection-change="selectionChange"
>
2022-06-08 15:31:41 +08:00
<el-table-column type="expand" width="30">
<template #default="props">
2022-06-06 17:37:01 +08:00
<div class="down">
<loading :loading="loadingDown"></loading>
<div class="block drop-down-time">
<el-date-picker
v-model="value"
size="small"
:format="format"
type="datetimerange"
range-separator="To"
2022-06-08 15:31:41 +08:00
:start-placeholder="$t('detections.startTime')"
:end-placeholder="$t('detections.endTime')"
@change="datePickerChange(props.row)"
2022-06-06 17:37:01 +08:00
/>
</div>
<div class="expand">
<div class="expand-cell" v-for="(item, index) in downDataList" :key="index">
<div class="expand-right">
<div class="demo-progress">
2022-06-08 15:31:41 +08:00
<el-progress type="circle" :percentage="item.percent * 100" :color="item.percent === 1 ? '#21bf9a' : '#50b3ef'">
<template #default="{ percentage }">
<span style="font-size: 0.875rem;">{{ percentage }}%</span>
</template>
</el-progress>
</div>
</div>
2022-06-06 17:37:01 +08:00
<div class="expand-left">
<div class="expand-name"><i class="cn-icon cn-icon-user"></i>{{ username }}</div>
<div class="expand-time">
<div>{{ $t('report.creationTime') }}</div>
<div>{{dateFormatByAppearance(item.ctime)}}</div>
</div>
2022-06-06 17:37:01 +08:00
<div class="expand-icon">
<div class="table-operation-item--no-border" @click="tableOperation(['download', item])">
<loading :loading="loadingTableId === item.id"></loading>
<svg class="icon" aria-hidden="true" :class="{'table-operation-all-loading': loadingTableId}">
<use xlink:href="#cn-icon-download2"></use>
</svg>
</div>
<div class="table-operation-item--no-border" @click="tableOperation(['preview', item])">
<loading :loading="loadingPreviewId === item.id"></loading>
<svg class="icon" aria-hidden="true" :class="{'table-operation-all-loading': loadingPreviewId}">
<use xlink:href="#cn-icon-preview"></use>
</svg>
</div>
<div class="table-operation-item--no-border" @click="downDeleteQueryChange(item, props)">
<svg class="icon" aria-hidden="true">
<use xlink:href="#cn-icon-shanchu"></use>
</svg>
</div>
</div>
</div>
</div>
2022-06-06 17:37:01 +08:00
</div>
<div class="cn-detection__footer">
<chart-detection-pagination
ref="pagination"
:page-obj="pageObj"
@pageJump="pageJump"
></chart-detection-pagination>
</div>
</div>
</template>
</el-table-column>
<el-table-column
:resizable="false"
align="center"
type="selection"
2022-06-08 15:31:41 +08:00
width="30">
</el-table-column>
<el-table-column
v-for="(item, index) in customTableTitles"
:key="`col-${index}`"
:fixed="item.fixed"
:label="item.label"
:min-width="`${item.minWidth}`"
:prop="item.prop"
:resizable="true"
2022-06-08 15:31:41 +08:00
:show-overflow-tooltip="item.prop === 'timePlan'"
:sort-orders="['ascending', 'descending']"
:sortable="item.sortable"
:width="`${item.width}`"
>
<template #header>
<span class="data-column__span">{{item.label}}</span>
<div class="col-resize-area"></div>
</template>
<template #default="scope" :column="item">
2022-06-06 17:37:01 +08:00
<span v-if="item.prop === 'timeLimit'">
2022-06-08 15:31:41 +08:00
{{handleTimeRange(scope.row)}}
</span>
2022-06-08 15:31:41 +08:00
<span v-else-if="item.prop === 'timePlan'">
{{(scope.row.config && scope.row.config.schedulerConfig) || '-'}}
</span>
2022-06-08 15:31:41 +08:00
<span v-else-if="item.prop === 'userName'">
{{(scope.row.sysUser && scope.row.sysUser.name) || '-'}}
</span>
<span v-else-if="item.prop === 'lastExecutionTime'">
{{scope.row.lastTime ? dateFormatByAppearance(scope.row.lastTime) : '-'}}
</span>
<span v-else>{{scope.row[item.prop] || '-'}}</span>
</template>
</el-table-column>
<el-table-column
:resizable="false"
:width="operationWidth"
fixed="right">
<template #header>
<div class="table-operation-title">{{$t('overall.option')}}</div>
</template>
<template #default="scope">
2022-06-06 17:37:01 +08:00
<div class="table-operation-items">
<button class="table-operation-item" @click="tableOperation(['edit', scope.row])"><i class="cn-icon cn-icon-bianji"></i></button>
<button class="table-operation-item" @click="tableOperation(['delete', scope.row])"><i class="cn-icon cn-icon-shanchu"></i></button>
</div>
</template>
</el-table-column>
</el-table>
<div class="table-operation-all">
<el-checkbox v-model="checkboxAll" @change="selectAll(tableData)"></el-checkbox>
<div class="table-operation-all-span">
<span>{{ $t('overall.all') }}</span>
<div class="table-operation-back-down" :class="{'table-operation-all-checkbox': batchDow, 'table-operation-all-loading': loading}" @click="tableOperation(['delete', this.checkboxIds])">
<loading :loading="loading"></loading>
<span>{{$t('report.batchDeletion')}}</span>
</div>
</div>
</div>
</template>
<script>
import table from '@/mixins/table'
import Loading from '@/components/common/Loading'
2022-06-06 17:37:01 +08:00
import { del, get } from '@/utils/http'
import { api } from '@/utils/api'
import { storageKey } from '@/utils/constants'
import { ref } from 'vue'
2022-06-08 18:32:52 +08:00
import { dateFormatToUTC } from '@/utils/date-util'
2022-06-06 17:37:01 +08:00
import chartDetectionPagination from '@/views/charts/charts/chartDetectionPagination'
export default {
name: 'builtinReportTable',
mixins: [table],
components: {
2022-06-06 17:37:01 +08:00
Loading,
chartDetectionPagination
},
2022-06-06 17:37:01 +08:00
inject: ['reload'],
data () {
return {
2022-06-06 17:37:01 +08:00
format: localStorage.getItem(storageKey.dateFormat),
username: localStorage.getItem(storageKey.username),
tableTitle: [ // 原始table列
{
label: 'ID',
prop: 'id',
2022-06-06 17:37:01 +08:00
show: true,
2022-06-08 15:31:41 +08:00
width: 40
}, {
label: this.$t('config.user.name'),
prop: 'name',
show: true,
2022-06-08 15:31:41 +08:00
minWidth: 200,
sortable: 'custom'
}, {
label: this.$t('report.timeLimit'),
prop: 'timeLimit',
2022-06-08 15:31:41 +08:00
show: true,
minWidth: 110
}, {
label: this.$t('report.timePlan'),
2022-06-08 15:31:41 +08:00
prop: 'timePlan',
show: true,
minWidth: 110
}, {
label: this.$t('report.operationUserName'),
2022-06-06 17:37:01 +08:00
prop: 'userName',
show: true,
2022-06-08 15:31:41 +08:00
minWidth: 70
}, {
label: this.$t('report.resultCount'),
2022-06-08 15:31:41 +08:00
prop: 'total',
show: true,
2022-06-08 15:31:41 +08:00
minWidth: 50
2022-06-08 18:32:52 +08:00
}, {
label: this.$t('report.lastExecutionTime'),
2022-06-08 15:31:41 +08:00
prop: 'lastTime',
show: true,
2022-06-08 15:31:41 +08:00
width: 170,
sortable: 'custom'
}
],
checkboxAll: false,
checkboxIds: '',
batchDow: false,
builtinId: '',
indeterminate: false,
loading: false,
2022-06-06 17:37:01 +08:00
loadingDown: false,
loadingTableId: '',
loadingPreviewId: '',
2022-06-06 17:37:01 +08:00
downDataList: [],
pageObj: {
pageNo: 1,
2022-06-08 15:31:41 +08:00
pageSize: 20,
2022-06-06 17:37:01 +08:00
total: 0,
resetPageNo: true
2022-06-08 15:31:41 +08:00
},
expandedIds: []
}
},
computed: {
handleTimeRange () {
return function (row) {
let str = ''
if (row.config && row.config.timeConfig && row.config.timeConfig.type) {
str += row.config.timeConfig.type
if (row.config.timeConfig.offset) {
str += ` ${row.config.timeConfig.offset} ${row.config.timeConfig.unit}`
}
}
return str
2022-06-06 17:37:01 +08:00
}
}
},
methods: {
getJobStatus (report) {
if (report.state === 1 && report.upload === 1) {
return this.$t('overall.completed')
} else {
return this.$t('overall.inProgress')
}
},
selectionChange (objs) {
this.$emit('selectionChange', objs)
this.checkboxIds = objs.map(item => { return item.id }).join(',')
this.checkboxAll = objs.length > 0 || objs.length === this.tableData.length
this.batchDow = objs.length > 0
},
selectAll (objs) {
if (objs) {
objs.forEach(item => {
this.$refs.dataTable.toggleAllSelection(item)
})
} else {
this.$refs.dataTable.clearSelection()
}
2022-06-06 17:37:01 +08:00
},
2022-06-08 15:31:41 +08:00
dropExpandChange (row, expandedRows) {
this.expandedIds = []
if (expandedRows.length > 0 && row) {
this.expandedIds.push(row.id)
this.datePickerChange(row)
2022-06-06 17:37:01 +08:00
}
},
2022-06-08 15:31:41 +08:00
datePickerChange (row) {
const param = {
tempId: row.id,
2022-06-08 18:32:52 +08:00
startTime: dateFormatToUTC(this.value[0]),
endTime: dateFormatToUTC(this.value[1]),
2022-06-08 15:31:41 +08:00
...this.pageObj
2022-06-06 17:37:01 +08:00
}
2022-06-08 15:31:41 +08:00
this.dropDownQueryChange(param)
2022-06-06 17:37:01 +08:00
},
2022-06-08 15:31:41 +08:00
dropDownQueryChange (param) {
2022-06-06 17:37:01 +08:00
this.loadingDown = true
2022-06-08 15:31:41 +08:00
this.downDataList = []
get(api.reportJob, param).then(res => {
2022-06-06 17:37:01 +08:00
if (res.code === 200) {
this.downDataList = res.data.list
2022-06-08 15:31:41 +08:00
this.pageObj.total = res.data.total
this.$nextTick(() => {
this.$refs.dataTable.doLayout()
})
2022-06-06 17:37:01 +08:00
}
this.loadingDown = false
})
},
downDeleteQueryChange (row, props) {
this.$confirm(this.$t('tip.confirmDelete'), {
confirmButtonText: this.$t('tip.yes'),
cancelButtonText: this.$t('tip.no'),
type: 'warning'
}).then(() => {
del(api.reportJob + '?ids=' + row.id).then(response => {
if (response.code === 200) {
this.delFlag = true
this.$message({ duration: 2000, type: 'success', message: this.$t('tip.deleteSuccess') })
this.dropDownQueryChange({ tempId: props.row.id })
} else {
this.$message.error(response.msg)
}
})
})
},
pageJump (val) {
2022-06-08 18:32:52 +08:00
this.pageObj.pageNo = val
if (this.expandedIds.length > 0) {
this.datePickerChange({ id: this.expandedIds[0] })
}
2022-06-06 17:37:01 +08:00
}
},
setup () {
const value = ref('')
return {
value
}
}
}
</script>