diff --git a/nezha-fronted/src/components/common/exportXLSX.vue b/nezha-fronted/src/components/common/exportXLSX.vue index 14c4cf753..1037652db 100644 --- a/nezha-fronted/src/components/common/exportXLSX.vue +++ b/nezha-fronted/src/components/common/exportXLSX.vue @@ -126,7 +126,6 @@ export default { }, mounted () { this.getParamsType() - console.log(this.importUrl) }, /* watch: { permissions: { @@ -144,9 +143,6 @@ export default { } this.importFile = this.importFileList[0] this.validateFile() - }, - validateFile () { - }, rollbackImport () { let url diff --git a/nezha-fronted/src/components/layout/path_navigation/PathNavigation.vue b/nezha-fronted/src/components/layout/path_navigation/PathNavigation.vue index 18c740f67..8ab4cdac2 100644 --- a/nezha-fronted/src/components/layout/path_navigation/PathNavigation.vue +++ b/nezha-fronted/src/components/layout/path_navigation/PathNavigation.vue @@ -177,10 +177,7 @@ -
- -
@@ -191,9 +188,6 @@
{{$t('overall.importTip')}}
{{$t('overall.dragFileTip')}},{{$t('overall.or')}} {{$t('overall.clickUpload')}}
- -
-
- - -
- -
-
-
-
- {{$t('overall.result.total')}}: - {{importResult&&importResult.totalNum?importResult.totalNum:0}} -
-
- {{$t('overall.result.failed')}}: - {{importResult&&importResult.failNum?importResult.failNum:0}} - {{$t('overall.result.success')}}: - {{importResult&&importResult.successNum?importResult.successNum:0}} -
-
-
{{$t('overall.result.failedDetail')}}:
-
-
- - -
-
-
-
- -
@@ -287,10 +227,8 @@ import axios from 'axios' export default { props: { show: Boolean, - exportUrl: { type: String, required: true }, params: { type: Object }, exportFileName: { type: String }, - importUrl: { type: String, required: true }, link: { type: Object }, permissions: { type: Object }, showCur: { type: Boolean, default: true }, @@ -355,7 +293,8 @@ export default { importResult: null, exportShow: false, paramsType: '', - // importUrl: '/monitor/module', + assetimportUrl: '/asset/import', + endpointimportUrl: '/monitor/endpoint/import', rightBox: { dc: { show: false @@ -524,7 +463,6 @@ export default { this.getDcData() this.getSnmpCredentialData() this.getFieldGroupData() - console.log(this.$router) }, methods: { // Datacenter @@ -552,7 +490,6 @@ export default { }, importAsset() { this.showImportBox(1) - console.log(this.importUrl) this.$emit("update:show", false); }, webTerminal() { @@ -674,6 +611,10 @@ export default { }, closeDialog: function () { this.showAgentDownload = false + this.importBox.show = false + this.importResult = null + this.importFileList = [] + this.importFile = null }, getAllDc () { this.$get('dc?pageSize=-1').then(response => { @@ -913,36 +854,69 @@ export default { showImportBox (type) { this.importBox.show = true this.importBox.type = type - if (type == 2 && (!this.showCur)) { - this.exportCur() - return - } if (type == 1) { // import this.importBox.title = this.$t('overall.importExcel') this.importBox.width = '600px' } }, + getTimeString () { + const split = '-' + const date = new Date() + const year = date.getFullYear() + const month = this.formatNum(date.getMonth() + 1) + const day = this.formatNum(date.getDate()) + const hours = this.formatNum(date.getHours()) + const minutes = this.formatNum(date.getMinutes()) + const seconds = this.formatNum(date.getSeconds()) + return year + split + month + split + day + ' ' + hours + split + minutes + split + seconds + }, + formatNum (num) { + return num > 9 ? num : '0' + num + }, importChange (file, fileList) { + // console.log(file,filelist) if (fileList.length > 0) { this.importFileList = [fileList[fileList.length - 1]] } this.importFile = this.importFileList[0] - this.validateFile() + }, + rollbackImport () { + let url + if (this.assetimportUrl.indexOf('asset') || this.assetimportUrl.indexOf('asset') > -1) { + url = '/asset/cancelImport' + } else if (this.assetimportUrl.indexOf('asset') || this.assetimportUrl.indexOf('asset') > -1) { + url = '/monitor/endpoint/cancelImport' + } else if (this.assetimportUrl.indexOf('asset') || this.assetimportUrl.indexOf('asset') > -1) { + url = '/alert/rule/cancelImport' + } else if (this.assetimportUrl.indexOf('asset') || this.assetimportUrl.indexOf('asset') > -1) { + url = '/panel/cancelImport' + } else if (this.assetimportUrl.indexOf('asset') || this.assetimportUrl.indexOf('asset') > -1) { + url = '/expression/tmpl/cancelImport' + } + this.$delete(url + '?seq=' + this.importResult.seq).then(response => { + if (response.code == 200) { + this.$message({ duration: 2000, type: 'success', message: this.$t('tip.saveSuccess') }) + this.$emit('afterImport') + } else { + this.$message.error(response.msg) + } + this.closeDialog() + }) }, downloadTemplate () { const language = localStorage.getItem('nz-language') || 'en' // 初始未选择默认 en 英文 const fileName = this.exportFileName + '-' + this.$t('overall.template') + '-' + this.getTimeString() + '.xlsx' let url = null - if (this.importUrl.indexOf('asset') > -1) { + if (this.assetimportUrl.indexOf('asset') || this.assetimportUrl.indexOf('asset') > -1) { url = '/asset/template' - } else if (this.importUrl.indexOf('rule') > -1) { + } else if (this.assetimportUrl.indexOf('asset') || this.assetimportUrl.indexOf('asset') > -1) { url = '/alert/rule/template' - } else if (this.importUrl.indexOf('panel') > -1) { + } else if (this.assetimportUrl.indexOf('asset') || this.assetimportUrl.indexOf('asset') > -1) { url = '/panel/template' - } else if (this.importUrl.indexOf('endpoint') > -1) { + } else if (this.assetimportUrl.indexOf('asset') || this.assetimportUrl.indexOf('asset') > -1) { url = '/monitor/endpoint/template' - } else if (this.importUrl.indexOf('tmpl') > -1) { + } else if (this.assetimportUrl.indexOf('asset') || this.assetimportUrl.indexOf('asset') > -1) { url = '/expression/tmpl/template' } @@ -952,6 +926,40 @@ export default { } this.exportExcel(url, param, fileName) }, + exportExcel (url, params, fileName) { + if (this.paramsType) { + params.type = this.paramsType + } + axios.get(url, { responseType: 'blob', params: params }).then(res => { + if (window.navigator.msSaveOrOpenBlob) { + // 兼容ie11 + const blobObject = new Blob([res.data]) + window.navigator.msSaveOrOpenBlob(blobObject, fileName) + } else { + const url = URL.createObjectURL(new Blob([res.data])) + const a = document.createElement('a') + document.body.appendChild(a) // 此处增加了将创建的添加到body当中 + a.href = url + a.download = fileName + a.target = '_blank' + a.click() + a.remove() // 将a标签移除 + } + }, error => { + const $self = this + const reader = new FileReader() + reader.onload = function (event) { + const responseText = reader.result + const exception = JSON.parse(responseText) + if (exception.message) { + $self.$message.error(exception.message) + } else { + console.error(error) + } + } + reader.readAsText(error.response.data) + }) + }, importExcel () { if (this.importFile && this.importFile.raw) { this.prevent_opt.import = true @@ -964,37 +972,35 @@ export default { } } form.append('language', localStorage.getItem('nz-language') ? localStorage.getItem('nz-language') : 'en') - this.$post(this.importUrl, form, { 'Content-Type': 'multipart/form-data' }).then(response => { - if (response.code == 200 && response.msg == 'success') { - this.importResult = response.data - this.$emit('afterImport') - this.importBox.type = 3 - this.importBox.width = '600px' - } else { - this.$message.error(response.msg) - } - this.prevent_opt.import = false - }) + if (this.assetimportUrl){ + this.$post(this.assetimportUrl, form, { 'Content-Type': 'multipart/form-data' }).then(response => { + if (response.code == 200 && response.msg == 'success') { + this.importResult = response.data + this.$emit('afterImport') + this.importBox.type = 3 + this.importBox.width = '600px' + } else { + this.$message.error(response.msg) + } + this.prevent_opt.import = false + }) + }else if (this.endpointimportUrl){ + this.$post(this.endpointimportUrl, form, { 'Content-Type': 'multipart/form-data' }).then(response => { + if (response.code == 200 && response.msg == 'success') { + this.importResult = response.data + this.$emit('afterImport') + this.importBox.type = 3 + this.importBox.width = '600px' + } else { + this.$message.error(response.msg) + } + this.prevent_opt.import = false + }) + } } else { this.$message.error(this.$t('tip.noImportFile')) } }, - exportCur () { - const params = Object.assign({}, this.params) - params.language = localStorage.getItem('nz-language') || 'en' - this.exportExcel(this.exportUrl, params, this.exportFileName + '-' + this.getTimeString() + '.xlsx') - this.closeDialog() - }, - exportAll () { - const params = JSON.parse(JSON.stringify(this.params)) - params.pageSize = -1 - if (this.importUrl.indexOf('panel') > -1) { - delete params.panelId - } - params.language = localStorage.getItem('nz-language') || 'en' - this.exportExcel(this.exportUrl, params, this.exportFileName + '-' + this.getTimeString() + '.xlsx') - this.closeDialog() - }, // Box 侧滑关闭事件 closeDcBox (refresh) { this.rightBox.dc.show = false