mirror of https://github.com/veops/cmdb.git
Merge pull request #580 from veops/dev_ui_240716
feat: add history export
This commit is contained in:
commit
fa9bd5a926
|
@ -11,7 +11,8 @@ export function getCIHistoryTable(params) {
|
||||||
return axios({
|
return axios({
|
||||||
url: `/v0.1/history/records/attribute`,
|
url: `/v0.1/history/records/attribute`,
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
params: params
|
params: params,
|
||||||
|
timeout: 30 * 1000
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +20,8 @@ export function getRelationTable(params) {
|
||||||
return axios({
|
return axios({
|
||||||
url: `/v0.1/history/records/relation`,
|
url: `/v0.1/history/records/relation`,
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
params: params
|
params: params,
|
||||||
|
timeout: 30 * 1000
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +29,8 @@ export function getCITypesTable(params) {
|
||||||
return axios({
|
return axios({
|
||||||
url: `/v0.1/history/ci_types`,
|
url: `/v0.1/history/ci_types`,
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
params: params
|
params: params,
|
||||||
|
timeout: 30 * 1000
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,9 @@
|
||||||
<a-button type="primary" class="ops-button-ghost" ghost @click="handleRollbackCI()">
|
<a-button type="primary" class="ops-button-ghost" ghost @click="handleRollbackCI()">
|
||||||
<ops-icon type="shishizhuangtai" />{{ $t('cmdb.ci.rollback') }}
|
<ops-icon type="shishizhuangtai" />{{ $t('cmdb.ci.rollback') }}
|
||||||
</a-button>
|
</a-button>
|
||||||
|
<a-button type="primary" class="ops-button-ghost" ghost @click="handleExport">
|
||||||
|
<ops-icon type="veops-export" />{{ $t('export') }}
|
||||||
|
</a-button>
|
||||||
</a-space>
|
</a-space>
|
||||||
<ci-rollback-form ref="ciRollbackForm" :ciIds="[ciId]" @getCIHistory="getCIHistory" />
|
<ci-rollback-form ref="ciRollbackForm" :ciIds="[ciId]" @getCIHistory="getCIHistory" />
|
||||||
<vxe-table
|
<vxe-table
|
||||||
|
@ -88,13 +91,13 @@
|
||||||
:filters="[]"
|
:filters="[]"
|
||||||
:filter-method="filterAttrMethod"
|
:filter-method="filterAttrMethod"
|
||||||
></vxe-table-column>
|
></vxe-table-column>
|
||||||
<vxe-table-column field="old" :title="$t('cmdb.history.old')">
|
<vxe-table-column :cell-type="'string'" field="old" :title="$t('cmdb.history.old')">
|
||||||
<template #default="{ row }">
|
<template #default="{ row }">
|
||||||
<span v-if="row.value_type === '6'">{{ JSON.parse(row.old) }}</span>
|
<span v-if="row.value_type === '6'">{{ JSON.parse(row.old) }}</span>
|
||||||
<span v-else>{{ row.old }}</span>
|
<span v-else>{{ row.old }}</span>
|
||||||
</template>
|
</template>
|
||||||
</vxe-table-column>
|
</vxe-table-column>
|
||||||
<vxe-table-column field="new" :title="$t('cmdb.history.new')">
|
<vxe-table-column :cell-type="'string'" field="new" :title="$t('cmdb.history.new')">
|
||||||
<template #default="{ row }">
|
<template #default="{ row }">
|
||||||
<span v-if="row.value_type === '6'">{{ JSON.parse(row.new) }}</span>
|
<span v-if="row.value_type === '6'">{{ JSON.parse(row.new) }}</span>
|
||||||
<span v-else>{{ row.new }}</span>
|
<span v-else>{{ row.new }}</span>
|
||||||
|
@ -402,6 +405,17 @@ export default {
|
||||||
this.$refs.ciRollbackForm.onOpen()
|
this.$refs.ciRollbackForm.onOpen()
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
async handleExport() {
|
||||||
|
this.$refs.xTable.exportData({
|
||||||
|
filename: this.$t('cmdb.ci.history'),
|
||||||
|
sheetName: 'Sheet1',
|
||||||
|
type: 'xlsx',
|
||||||
|
types: ['xlsx', 'csv', 'html', 'xml', 'txt'],
|
||||||
|
data: this.ciHistory,
|
||||||
|
isMerge: true,
|
||||||
|
isColgroup: true,
|
||||||
|
})
|
||||||
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
@search="handleSearch"
|
@search="handleSearch"
|
||||||
@searchFormReset="searchFormReset"
|
@searchFormReset="searchFormReset"
|
||||||
@searchFormChange="searchFormChange"
|
@searchFormChange="searchFormChange"
|
||||||
|
@export="handleExport"
|
||||||
></search-form>
|
></search-form>
|
||||||
<vxe-table
|
<vxe-table
|
||||||
ref="xTable"
|
ref="xTable"
|
||||||
|
@ -86,13 +87,13 @@
|
||||||
</template>
|
</template>
|
||||||
</vxe-column>
|
</vxe-column>
|
||||||
<vxe-column field="attr_alias" :title="$t('cmdb.history.attribute')"></vxe-column>
|
<vxe-column field="attr_alias" :title="$t('cmdb.history.attribute')"></vxe-column>
|
||||||
<vxe-column field="old" :title="$t('cmdb.history.old')"></vxe-column>
|
<vxe-column :cell-type="'string'" field="old" :title="$t('cmdb.history.old')"></vxe-column>
|
||||||
<vxe-column field="new" :title="$t('cmdb.history.new')"></vxe-column>
|
<vxe-column :cell-type="'string'" field="new" :title="$t('cmdb.history.new')"></vxe-column>
|
||||||
</vxe-table>
|
</vxe-table>
|
||||||
<pager
|
<pager
|
||||||
:current-page.sync="queryParams.page"
|
:current-page.sync="queryParams.page"
|
||||||
:page-size.sync="queryParams.page_size"
|
:page-size.sync="queryParams.page_size"
|
||||||
:page-sizes="[50, 100, 200]"
|
:page-sizes="[50, 100, 200, 500]"
|
||||||
:total="total"
|
:total="total"
|
||||||
:isLoading="loading"
|
:isLoading="loading"
|
||||||
@change="onChange"
|
@change="onChange"
|
||||||
|
@ -391,6 +392,37 @@ export default {
|
||||||
filterOption(input, option) {
|
filterOption(input, option) {
|
||||||
return option.componentOptions.children[0].text.indexOf(input) >= 0
|
return option.componentOptions.children[0].text.indexOf(input) >= 0
|
||||||
},
|
},
|
||||||
|
|
||||||
|
async handleExport(params) {
|
||||||
|
const hide = this.$message.loading(this.$t('loading'), 0)
|
||||||
|
const res = await getCIHistoryTable({
|
||||||
|
...params,
|
||||||
|
page: this.queryParams.page,
|
||||||
|
page_size: this.queryParams.page_size,
|
||||||
|
})
|
||||||
|
hide()
|
||||||
|
const data = []
|
||||||
|
res.records.forEach((item) => {
|
||||||
|
item[0].type_id = this.handleTypeId(item[0].type_id)
|
||||||
|
item[1].forEach((subItem) => {
|
||||||
|
subItem.operate_type = this.handleOperateType(subItem.operate_type)
|
||||||
|
subItem.new = subItem.new || ''
|
||||||
|
subItem.old = subItem.old || ''
|
||||||
|
const tempObj = Object.assign(subItem, item[0])
|
||||||
|
data.push(tempObj)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
this.$refs.xTable.exportData({
|
||||||
|
filename: this.$t('cmdb.history.ciChange'),
|
||||||
|
sheetName: 'Sheet1',
|
||||||
|
type: 'xlsx',
|
||||||
|
types: ['xlsx', 'csv', 'html', 'xml', 'txt'],
|
||||||
|
isMerge: true,
|
||||||
|
isColgroup: true,
|
||||||
|
data,
|
||||||
|
})
|
||||||
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
@expandChange="handleExpandChange"
|
@expandChange="handleExpandChange"
|
||||||
@search="handleSearch"
|
@search="handleSearch"
|
||||||
@searchFormReset="searchFormReset"
|
@searchFormReset="searchFormReset"
|
||||||
|
@export="handleExport"
|
||||||
></search-form>
|
></search-form>
|
||||||
<vxe-table
|
<vxe-table
|
||||||
ref="xTable"
|
ref="xTable"
|
||||||
|
@ -122,7 +123,7 @@
|
||||||
<pager
|
<pager
|
||||||
:current-page.sync="queryParams.page"
|
:current-page.sync="queryParams.page"
|
||||||
:page-size.sync="queryParams.page_size"
|
:page-size.sync="queryParams.page_size"
|
||||||
:page-sizes="[50, 100, 200]"
|
:page-sizes="[50, 100, 200, 500]"
|
||||||
:total="total"
|
:total="total"
|
||||||
:isLoading="loading"
|
:isLoading="loading"
|
||||||
@change="onChange"
|
@change="onChange"
|
||||||
|
@ -379,6 +380,58 @@ export default {
|
||||||
filterOption(input, option) {
|
filterOption(input, option) {
|
||||||
return option.componentOptions.children[0].text.indexOf(input) >= 0
|
return option.componentOptions.children[0].text.indexOf(input) >= 0
|
||||||
},
|
},
|
||||||
|
|
||||||
|
async handleExport(params) {
|
||||||
|
const hide = this.$message.loading(this.$t('loading'), 0)
|
||||||
|
const res = await getRelationTable({
|
||||||
|
...params,
|
||||||
|
page: this.queryParams.page,
|
||||||
|
page_size: this.queryParams.page_size,
|
||||||
|
})
|
||||||
|
hide()
|
||||||
|
const data = []
|
||||||
|
res.records.forEach((item) => {
|
||||||
|
item[1].forEach((subItem) => {
|
||||||
|
subItem.operate_type = this.handleOperateType(subItem.operate_type)
|
||||||
|
subItem.relation_type_id = this.handleRelationType(subItem.relation_type_id)
|
||||||
|
subItem.first = res.cis[String(subItem.first_ci_id)]
|
||||||
|
subItem.second = res.cis[String(subItem.second_ci_id)]
|
||||||
|
|
||||||
|
const tempObj = Object.assign(subItem, item[0])
|
||||||
|
|
||||||
|
tempObj.changeDescription = this.getExportChangeDescription(tempObj)
|
||||||
|
|
||||||
|
data.push(tempObj)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
this.$refs.xTable.exportData({
|
||||||
|
filename: this.$t('cmdb.history.relationChange'),
|
||||||
|
sheetName: 'Sheet1',
|
||||||
|
type: 'xlsx',
|
||||||
|
types: ['xlsx', 'csv', 'html', 'xml', 'txt'],
|
||||||
|
isMerge: true,
|
||||||
|
isColgroup: true,
|
||||||
|
data,
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
getExportChangeDescription(item) {
|
||||||
|
const first = item.first ? `${item.first.ci_type_alias}${item.first.unique_alias && item.first[item.first.unique] ? `(${item.first.unique_alias}:${item.first[item.first.unique]})` : ''}` : ''
|
||||||
|
const second = item.second ? `${item.second.ci_type_alias}${item.second.unique_alias && item.second[item.second.unique] ? `(${item.second.unique_alias}:${item.second[item.second.unique]})` : ''}` : ''
|
||||||
|
let center = ''
|
||||||
|
if (item.changeDescription === this.$t('cmdb.history.noUpdate')) {
|
||||||
|
center = item.relation_type_id
|
||||||
|
} else if (item.operate_type.includes(this.$t('update'))) {
|
||||||
|
center = item.changeArr.join(';')
|
||||||
|
} else if (item.operate_type.includes(this.$t('new'))) {
|
||||||
|
center = item.relation_type_id
|
||||||
|
} else if (item.operate_type.includes(this.$t('delete'))) {
|
||||||
|
center = item.relation_type_id
|
||||||
|
}
|
||||||
|
|
||||||
|
return `${first || ''} => ${center || ''} => ${second || ''}`
|
||||||
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
<a-select-option
|
<a-select-option
|
||||||
:value="Object.values(choice)[0]"
|
:value="Object.values(choice)[0]"
|
||||||
v-for="(choice, index) in attr.choice_value"
|
v-for="(choice, index) in attr.choice_value"
|
||||||
:key="'Search_' + attr.name + index"
|
:key="'Search_' + attr.name + Object.values(choice)[0] + index"
|
||||||
>
|
>
|
||||||
{{ Object.keys(choice)[0] }}
|
{{ Object.keys(choice)[0] }}
|
||||||
</a-select-option>
|
</a-select-option>
|
||||||
|
@ -42,7 +42,7 @@
|
||||||
hideDisabledOptions: true,
|
hideDisabledOptions: true,
|
||||||
defaultValue: [moment('00:00:00', 'HH:mm:ss'), moment('23:59:59', 'HH:mm:ss')],
|
defaultValue: [moment('00:00:00', 'HH:mm:ss'), moment('23:59:59', 'HH:mm:ss')],
|
||||||
}"
|
}"
|
||||||
v-else-if="valueTypeMap[attr.value_type] == 'date' || valueTypeMap[attr.value_type] == 'datetime'"
|
v-else-if="attr.value_type === '3'"
|
||||||
/>
|
/>
|
||||||
<a-input v-model="queryParams[attr.name]" style="width: 100%" allowClear v-else />
|
<a-input v-model="queryParams[attr.name]" style="width: 100%" allowClear v-else />
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
|
@ -85,7 +85,7 @@
|
||||||
@change="onChange"
|
@change="onChange"
|
||||||
format="YYYY-MM-DD HH:mm"
|
format="YYYY-MM-DD HH:mm"
|
||||||
:placeholder="[$t('cmdb.history.startTime'), $t('cmdb.history.endTime')]"
|
:placeholder="[$t('cmdb.history.startTime'), $t('cmdb.history.endTime')]"
|
||||||
v-else-if="valueTypeMap[item.value_type] == 'date' || valueTypeMap[item.value_type] == 'datetime'"
|
v-else-if="attr.value_type === '3'"
|
||||||
:show-time="{
|
:show-time="{
|
||||||
hideDisabledOptions: true,
|
hideDisabledOptions: true,
|
||||||
defaultValue: [moment('00:00:00', 'HH:mm:ss'), moment('23:59:59', 'HH:mm:ss')],
|
defaultValue: [moment('00:00:00', 'HH:mm:ss'), moment('23:59:59', 'HH:mm:ss')],
|
||||||
|
@ -101,6 +101,9 @@
|
||||||
<a-button type="primary" html-type="submit" @click="handleSearch">
|
<a-button type="primary" html-type="submit" @click="handleSearch">
|
||||||
{{ $t('query') }}
|
{{ $t('query') }}
|
||||||
</a-button>
|
</a-button>
|
||||||
|
<a-button :style="{ marginLeft: '8px' }" @click="handleExport">
|
||||||
|
{{ $t('export') }}
|
||||||
|
</a-button>
|
||||||
<a-button :style="{ marginLeft: '8px' }" @click="handleReset">
|
<a-button :style="{ marginLeft: '8px' }" @click="handleReset">
|
||||||
{{ $t('reset') }}
|
{{ $t('reset') }}
|
||||||
</a-button>
|
</a-button>
|
||||||
|
@ -155,6 +158,13 @@ export default {
|
||||||
this.$emit('search', this.queryParams)
|
this.$emit('search', this.queryParams)
|
||||||
},
|
},
|
||||||
|
|
||||||
|
handleExport() {
|
||||||
|
const queryParams = {
|
||||||
|
...this.queryParams
|
||||||
|
}
|
||||||
|
this.$emit('export', queryParams)
|
||||||
|
},
|
||||||
|
|
||||||
handleReset() {
|
handleReset() {
|
||||||
this.queryParams = {
|
this.queryParams = {
|
||||||
page: 1,
|
page: 1,
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
@expandChange="handleExpandChange"
|
@expandChange="handleExpandChange"
|
||||||
@search="handleSearch"
|
@search="handleSearch"
|
||||||
@searchFormReset="searchFormReset"
|
@searchFormReset="searchFormReset"
|
||||||
|
@export="handleExport"
|
||||||
></search-form>
|
></search-form>
|
||||||
<vxe-table
|
<vxe-table
|
||||||
ref="xTable"
|
ref="xTable"
|
||||||
|
@ -121,7 +122,7 @@ export default {
|
||||||
relationTypeList: null,
|
relationTypeList: null,
|
||||||
typeList: null,
|
typeList: null,
|
||||||
userList: [],
|
userList: [],
|
||||||
pageSizeOptions: ['50', '100', '200'],
|
pageSizeOptions: ['50', '100', '200', '500'],
|
||||||
isExpand: false,
|
isExpand: false,
|
||||||
current: 1,
|
current: 1,
|
||||||
pageSize: 50,
|
pageSize: 50,
|
||||||
|
@ -508,6 +509,36 @@ export default {
|
||||||
filterOption(input, option) {
|
filterOption(input, option) {
|
||||||
return option.componentOptions.children[0].text.indexOf(input) >= 0
|
return option.componentOptions.children[0].text.indexOf(input) >= 0
|
||||||
},
|
},
|
||||||
|
|
||||||
|
async handleExport(params) {
|
||||||
|
const hide = this.$message.loading(this.$t('loading'), 0)
|
||||||
|
const res = await getCITypesTable({
|
||||||
|
...params,
|
||||||
|
page: this.queryParams.page,
|
||||||
|
page_size: this.queryParams.page_size,
|
||||||
|
})
|
||||||
|
hide()
|
||||||
|
|
||||||
|
res.result.forEach((item) => {
|
||||||
|
this.handleChangeDescription(item, item.operate_type)
|
||||||
|
item.operate_type = this.handleOperateType(item.operate_type)
|
||||||
|
item.type_id = this.handleTypeId(item.type_id)
|
||||||
|
item.uid = this.handleUID(item.uid)
|
||||||
|
if (item.operate_type.includes(this.$t('update'))) {
|
||||||
|
item.changeDescription = item.changeArr.join(';')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
this.$refs.xTable.exportData({
|
||||||
|
filename: this.$t('cmdb.history.ciTypeChange'),
|
||||||
|
sheetName: 'Sheet1',
|
||||||
|
type: 'xlsx',
|
||||||
|
types: ['xlsx', 'csv', 'html', 'xml', 'txt'],
|
||||||
|
isMerge: true,
|
||||||
|
isColgroup: true,
|
||||||
|
data: res.result,
|
||||||
|
})
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in New Issue