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/views/report/Report.vue

364 lines
10 KiB
Vue
Raw Normal View History

<template>
2023-03-09 10:14:05 +08:00
<div class="cn-report">
<div class="cn-report-left">
<loading :loading="builtinLeftLoading"></loading>
2023-03-09 10:14:05 +08:00
<div class="cn-report-left-title">
{{$t('report.category')}}
</div>
2023-03-09 10:14:05 +08:00
<div class="cn-report-left-menu" :class="{'cn-active': !builtinId}" @click="builtinTabs(null)">
{{$t('dns.all')}}
</div>
2023-03-09 10:14:05 +08:00
<div class="cn-report-left-menu" :class="{'cn-active': builtinId === item.id}" v-for="item in builtinReportLeftMenu" :key="item.id" @click="builtinTabs(item.id)">
{{item.name}}
</div>
</div>
2023-03-09 10:14:05 +08:00
<div class="cn-report-right">
<cn-data-list
ref="dataList"
:tableId="tableId"
v-model:custom-table-title="tools.customTableTitle"
:api="url"
:from="fromRoute.builtinReport"
:layout="['search']"
@search="search"
>
2023-03-10 20:50:54 +08:00
<template #top-tool-left>
<button id="account-add" class="top-tool-btn margin-r-10 top-tool-btn--create"
@click="add">
<i class="cn-icon-xinjian cn-icon"></i>
<span>{{$t('overall.create')}}</span>
</button>
<button id="report-edit" class="top-tool-btn margin-r-10" :disabled="disableEdit"
@click="editReport">
<i class="cn-icon-edit cn-icon"></i>
<span>{{$t('overall.edit')}}</span>
</button>
<button id="report-delete" class="top-tool-btn margin-r-10" :disabled="disableDelete"
2023-03-10 20:50:54 +08:00
@click="delBatch">
<i class="cn-icon-delete cn-icon"></i>
<span>{{$t('overall.delete')}}</span>
</button>
</template>
<template #default>
<loading :loading="loading"></loading>
2023-03-09 10:14:05 +08:00
<report-table
ref="dataTable"
:api="url"
:isNoData="isNoData"
:custom-table-title="tools.customTableTitle"
:category-list="builtinReportLeftMenu"
:height="mainTableHeight"
:table-data="tableData"
:category-id="builtinId"
@delete="del"
@edit="edit"
2022-06-06 17:37:01 +08:00
@download="download"
@preview="preview"
@orderBy="tableDataSort"
@reload="getTableData"
@selectionChange="selectionChange"
/>
</template>
<template #pagination>
<pagination ref="pagination" :page-obj="pageObj" :tableData="tableData" :table-id="tableId" @pageNo='pageNo' @pageSize='pageSize'></pagination>
</template>
</cn-data-list>
<el-drawer
v-model="rightBox.show"
direction="rtl"
2023-07-02 22:38:59 +08:00
custom-class="common-right-box"
:size="700"
:with-header="false"
destroy-on-close>
2022-06-08 15:31:41 +08:00
<report-box
:object="object"
2022-06-08 15:31:41 +08:00
:category-list="builtinReportLeftMenu"
2022-06-08 18:32:52 +08:00
:current-category-id="builtinId"
@close="closeRightBox"
/>
</el-drawer>
</div>
</div>
</template>
<script>
import axios from 'axios'
2023-03-09 10:14:05 +08:00
import ReportTable from '@/components/table/report/ReportTable'
import cnDataList from '@/components/table/CnDataList'
import dataListMixin from '@/mixins/data-list'
import { api } from '@/utils/api'
2022-09-09 19:35:58 +08:00
import { urlParamsHandler, overwriteUrl } from '@/utils/tools'
2022-06-08 15:31:41 +08:00
import ReportBox from '@/components/rightBox/report/ReportBox'
import Loading from '@/components/common/Loading'
import { ref } from 'vue'
import { useRoute } from 'vue-router'
export default {
name: 'Report',
data () {
return {
builtinReportLeftMenu: [], // 左侧列表菜单数据
builtinColor: false,
// builtinId: '',
2022-06-06 17:37:01 +08:00
url: api.reportTemp,
blankObject: {
id: '',
name: '',
2022-06-06 17:37:01 +08:00
type: '',
2022-06-08 18:32:52 +08:00
source: 'session_record_cn',
2022-06-06 17:37:01 +08:00
cTime: '',
uTime: '',
remark: '',
2022-06-06 17:37:01 +08:00
config: {
isRepeat: 0,
2022-06-08 15:31:41 +08:00
isScheduler: 0,
2022-06-06 17:37:01 +08:00
cronExpression: '',
startTime: '',
endTime: '',
2022-06-08 18:32:52 +08:00
queryParam: {},
2022-06-06 17:37:01 +08:00
schedulerConfig: {
2022-06-08 15:31:41 +08:00
type: 'day',
weekDates: [],
months: [],
monthDates: [],
monthWeekDates: [],
2022-06-06 17:37:01 +08:00
interval: 1
},
timeConfig: {
2022-06-08 15:31:41 +08:00
type: 'yesterday',
offset: 1,
2022-06-08 18:32:52 +08:00
unit: 'hour'
2022-06-06 17:37:01 +08:00
}
},
schedulerStart: '',
schedulerEnd: '',
2022-06-17 15:56:48 +08:00
categoryId: '',
categoryParams: []
},
checkWeekListData: [
2022-06-06 17:37:01 +08:00
'report.sunday',
2022-06-08 15:31:41 +08:00
'report.monday',
2022-06-06 17:37:01 +08:00
'report.tuesday',
'report.wednesday',
'report.thursday',
'report.friday',
'report.saturday'
],
checkMonthsListData: [
2022-06-06 17:37:01 +08:00
'report.january',
'report.february',
'report.march',
'report.april',
'report.may',
'report.june',
'report.july',
'report.august',
'report.september',
'report.october',
'report.november',
'report.december'
],
2023-03-09 10:14:05 +08:00
tableId: 'reportTable',
builtinLeftLoading: false,
// builtinRightLoading: false,
isInit: true
}
},
/**
* 添加vue3的setup目的是添加/获取地址栏的参数
*/
setup () {
const { query } = useRoute()
const builtinId = ref(parseInt(query.categoryId) || '')
const urlPageNo = ref(parseInt(query.pageNo) || 1)
return {
builtinId,
urlPageNo
}
},
mixins: [dataListMixin],
components: {
Loading,
cnDataList,
2023-03-09 10:14:05 +08:00
ReportTable,
2022-06-08 15:31:41 +08:00
ReportBox
},
2022-09-09 19:35:58 +08:00
mounted () {
this.$nextTick(() => {
this.queryGetTempData()
})
2022-09-09 19:35:58 +08:00
},
watch: {
builtinId (n) {
const { query } = this.$route
let newUrl = urlParamsHandler(window.location.href, query, {
categoryId: n,
pageNo: 1,
pageSize: 20
})
// 点击“全部”或者首次进入界面时,不显示左侧菜单栏参数
const newQuery = JSON.parse(JSON.stringify(query)) // 深拷贝路由数据
if (n === null) {
delete newQuery.categoryId
} else {
delete newQuery.startTime
delete newQuery.endTime
delete newQuery.expandId
delete newQuery.expandPage
delete newQuery.pageNo
delete newQuery.pageSize
2022-09-09 19:35:58 +08:00
}
newUrl = urlParamsHandler(window.location.href, query, newQuery, 'clean')
2022-09-09 19:35:58 +08:00
overwriteUrl(newUrl)
}
},
methods: {
queryGetTempData () {
this.builtinLeftLoading = true
axios.get(api.reportCategory, { params: { pageSize: 999 } }).then(res => {
if (res.status === 200) {
this.builtinReportLeftMenu = res.data.data.list.map(c => {
2022-06-08 18:32:52 +08:00
return {
...c,
config: c.config ? JSON.parse(c.config) : {}
}
})
if (this.builtinId !== '') {
this.builtinTabs(this.builtinId, 'init')
2022-09-09 19:35:58 +08:00
} else {
this.getTableData()
2022-09-09 19:35:58 +08:00
}
2022-06-08 18:32:52 +08:00
}
this.builtinLeftLoading = false
2022-06-08 18:32:52 +08:00
})
},
2023-05-11 11:45:39 +08:00
tableDataSort (orderBy) {
this.searchLabel.orderBy = orderBy
this.getTableData(this.searchLabel)
},
2022-06-08 18:32:52 +08:00
getTableData (params) {
this.searchLabel = null
2022-06-08 18:32:52 +08:00
if (params) {
this.searchLabel = { ...this.searchLabel, ...params }
}
this.searchLabel = { ...this.searchLabel, ...this.pageObj }
// this.tools.loading = true
// this.builtinRightLoading = true
// this.loading = true
this.isNoData = false
// this.tableData = []
this.toggleLoading(true)
2022-06-08 18:32:52 +08:00
delete this.searchLabel.total
let listUrl = this.url
if (this.listUrl) {
listUrl = this.listUrl
}
2022-09-09 19:35:58 +08:00
if (this.builtinId !== '') {
this.searchLabel.categoryId = this.builtinId
}
2022-09-09 19:35:58 +08:00
if (!this.isInit) {
axios.get(listUrl, { params: this.searchLabel }).then(response => {
if (response.status === 200) {
for (let i = 0; i < response.data.data.list.length; i++) {
response.data.data.list[i].status = response.data.data.list[i].status + ''
2022-06-08 18:32:52 +08:00
}
this.$nextTick(() => {
this.tableData = response.data.data.list.map(item => {
return {
...item,
config: item.config ? JSON.parse(item.config) : {}
}
})
this.pageObj.total = response.data.data.total
2023-08-29 15:35:22 +08:00
this.isNoData = !this.tableData || this.tableData.length === 0
2023-03-08 17:57:01 +08:00
})
2022-09-09 19:35:58 +08:00
// TODO 回到顶部
} else {
this.isNoData = true
2022-09-09 19:35:58 +08:00
}
}).finally(() => {
this.toggleLoading(false)
2022-09-09 19:35:58 +08:00
})
}
this.isInit = false
},
2022-09-09 19:35:58 +08:00
/**
* 点击左侧tab页
*/
builtinTabs (id, flag) {
this.builtinId = id
if (flag === undefined) {
this.pageObj.pageNo = 1
this.pageObj.pageSize = 20
}
this.getTableData({ categoryId: id })
2022-06-06 17:37:01 +08:00
},
edit (u) {
2022-06-08 15:31:41 +08:00
this.initConfig(u)
this.object = u
this.rightBox.show = true
},
2023-03-10 20:50:54 +08:00
editReport () {
if (this.batchDeleteObjs.length === 0) {
this.$alert(this.$t('tip.pleaseSelectForEdit'), {
2023-03-10 20:50:54 +08:00
confirmButtonText: this.$t('tip.yes'),
type: 'warning'
}).catch(() => {})
} else {
const curRecord = this.batchDeleteObjs[0]
2023-03-10 20:50:54 +08:00
this.initConfig(curRecord)
this.object = curRecord
this.rightBox.show = true
}
},
2022-06-08 15:31:41 +08:00
initConfig (u) {
if (!u.config) {
u.config = {
isRepeat: 0,
cronExpression: '',
startTime: '',
endTime: '',
2022-06-08 18:32:52 +08:00
queryParam: {},
2022-06-08 15:31:41 +08:00
schedulerConfig: {
type: 'day',
weekDates: [],
months: [],
monthDates: [],
monthWeekDates: [],
interval: 1
},
timeConfig: {
type: 'yesterday',
offset: 1,
unit: ''
}
2022-06-06 17:37:01 +08:00
}
2022-06-08 15:31:41 +08:00
} else if (!u.config.schedulerConfig) {
u.config.schedulerConfig = {
type: 'day',
weekDates: [],
months: [],
monthDates: [],
monthWeekDates: [],
interval: 1
}
} else if (!u.config.timeConfig) {
u.config.timeConfig = {
type: 'yesterday',
offset: 1,
unit: ''
}
}
}
}
}
</script>