fix: import路径修改

This commit is contained in:
@changcode
2021-05-10 11:43:49 +08:00
parent 10f0d4f7cf
commit 03657068ab
2 changed files with 108 additions and 106 deletions

View File

@@ -126,7 +126,6 @@ export default {
}, },
mounted () { mounted () {
this.getParamsType() this.getParamsType()
console.log(this.importUrl)
}, },
/* watch: { /* watch: {
permissions: { permissions: {
@@ -144,9 +143,6 @@ export default {
} }
this.importFile = this.importFileList[0] this.importFile = this.importFileList[0]
this.validateFile() this.validateFile()
},
validateFile () {
}, },
rollbackImport () { rollbackImport () {
let url let url

View File

@@ -177,10 +177,7 @@
</transition> </transition>
<!--web--> <!--web-->
<el-dropdown> <el-dropdown>
<el-dropdown-menu></el-dropdown-menu>
<div id="header-open-cli" @click="cli"> <div id="header-open-cli" @click="cli">
<!-- <div class="header-menu__item"><i class="nz-icon nz-icon-terminal"></i></div>-->
<!-- <span v-show="$store.state.consoleCount>0" class="right-tip">{{$store.state.consoleCount<=10?$store.state.consoleCount:'10+'}}</span>-->
</div> </div>
</el-dropdown> </el-dropdown>
<!--import--> <!--import-->
@@ -191,9 +188,6 @@
<div slot="tip" class="el-upload__tip" >{{$t('overall.importTip')}}</div> <div slot="tip" class="el-upload__tip" >{{$t('overall.importTip')}}</div>
<i class="nz-icon nz-icon-upload"></i> <i class="nz-icon nz-icon-upload"></i>
<div class="el-upload__text">{{$t('overall.dragFileTip')}}{{$t('overall.or')}}&nbsp;<em>{{$t('overall.clickUpload')}}</em></div> <div class="el-upload__text">{{$t('overall.dragFileTip')}}{{$t('overall.or')}}&nbsp;<em>{{$t('overall.clickUpload')}}</em></div>
<!--<button type="button" class="nz-btn nz-btn-size-normal nz-btn-style-normal">
<span class="top-tool-btn-txt" >{{$t('overall.upload')}}</span>
</button>-->
</el-upload> </el-upload>
</div> </div>
<div slot="footer" class="footer"> <div slot="footer" class="footer">
@@ -210,60 +204,6 @@
</div> </div>
</div> </div>
</div> </div>
<div v-if="importBox.type == 2">
<div class="upload-body">
<button @click="exportCur" class="el-button el-button--default el-button--small" :id="id+'-xlsx-export-current'">
<span>{{$t('overall.exportCur')}}</span>
</button>
<button @click="exportAll" class="el-button el-button--default el-button--small" :id="id+'-xlsx-export-all'">
<span>{{$t('overall.exportAll')}}</span>
</button>
</div>
<div slot="footer" class="footer">
</div>
</div>
<div v-if="importBox.type==3">
<div class="upload-body result-body">
<div>
<span class="result-title">{{$t('overall.result.total')}}:</span>
<span>{{importResult&&importResult.totalNum?importResult.totalNum:0}}</span>
</div>
<div>
<span class="result-title">{{$t('overall.result.failed')}}:</span>
<span>{{importResult&&importResult.failNum?importResult.failNum:0}}</span>
<span class="result-title">{{$t('overall.result.success')}}:</span>
<span>{{importResult&&importResult.successNum?importResult.successNum:0}}</span>
</div>
<div>
<div class="result-title">{{$t('overall.result.failedDetail')}}:</div>
<div class="result-detail" v-if="importResult&&importResult.failDetail">
<div style="height: 100%; overflow: auto;">
<!-- <ul>
<li v-for="(item,index) in importResult.failDetail"><span>{{item.lineNo}}</span>:<span>{{item.errorMsg}}</span> </li>
</ul>-->
<template v-for="(item, index) in importResult.failDetail">
<div :key="index" class="import-result-block">
<div class="import-result-item">
<div class="line-num">{{$t('overall.result.line',[item.lineNo])}}</div>
<div>{{item.errorMsg}}</div>
</div>
</div>
</template>
</div>
</div>
</div>
</div>
<div slot="footer" class="footer">
<div class="el-message-box__btns">
<button @click="rollbackImport" class="nz-btn nz-btn-size-normal-new nz-btn-style-error-new" :id="id+'-xlsx-import-rollback'">
<span>{{$t('overall.rollbackImport')}}</span>
</button>
<!--<button @click="closeDialog" class="el-button el-button&#45;&#45;default el-button&#45;&#45;small">-->
<!--<span>{{$t('overall.cancel')}}</span>-->
<!--</button>-->
</div>
</div>
</div>
</el-dialog> </el-dialog>
</div> </div>
</template> </template>
@@ -287,10 +227,8 @@ import axios from 'axios'
export default { export default {
props: { props: {
show: Boolean, show: Boolean,
exportUrl: { type: String, required: true },
params: { type: Object }, params: { type: Object },
exportFileName: { type: String }, exportFileName: { type: String },
importUrl: { type: String, required: true },
link: { type: Object }, link: { type: Object },
permissions: { type: Object }, permissions: { type: Object },
showCur: { type: Boolean, default: true }, showCur: { type: Boolean, default: true },
@@ -355,7 +293,8 @@ export default {
importResult: null, importResult: null,
exportShow: false, exportShow: false,
paramsType: '', paramsType: '',
// importUrl: '/monitor/module', assetimportUrl: '/asset/import',
endpointimportUrl: '/monitor/endpoint/import',
rightBox: { rightBox: {
dc: { dc: {
show: false show: false
@@ -524,7 +463,6 @@ export default {
this.getDcData() this.getDcData()
this.getSnmpCredentialData() this.getSnmpCredentialData()
this.getFieldGroupData() this.getFieldGroupData()
console.log(this.$router)
}, },
methods: { methods: {
// Datacenter // Datacenter
@@ -552,7 +490,6 @@ export default {
}, },
importAsset() { importAsset() {
this.showImportBox(1) this.showImportBox(1)
console.log(this.importUrl)
this.$emit("update:show", false); this.$emit("update:show", false);
}, },
webTerminal() { webTerminal() {
@@ -674,6 +611,10 @@ export default {
}, },
closeDialog: function () { closeDialog: function () {
this.showAgentDownload = false this.showAgentDownload = false
this.importBox.show = false
this.importResult = null
this.importFileList = []
this.importFile = null
}, },
getAllDc () { getAllDc () {
this.$get('dc?pageSize=-1').then(response => { this.$get('dc?pageSize=-1').then(response => {
@@ -913,36 +854,69 @@ export default {
showImportBox (type) { showImportBox (type) {
this.importBox.show = true this.importBox.show = true
this.importBox.type = type this.importBox.type = type
if (type == 2 && (!this.showCur)) {
this.exportCur()
return
}
if (type == 1) { // import if (type == 1) { // import
this.importBox.title = this.$t('overall.importExcel') this.importBox.title = this.$t('overall.importExcel')
this.importBox.width = '600px' 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) { importChange (file, fileList) {
// console.log(file,filelist)
if (fileList.length > 0) { if (fileList.length > 0) {
this.importFileList = [fileList[fileList.length - 1]] this.importFileList = [fileList[fileList.length - 1]]
} }
this.importFile = this.importFileList[0] 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 () { downloadTemplate () {
const language = localStorage.getItem('nz-language') || 'en' // 初始未选择默认 en 英文 const language = localStorage.getItem('nz-language') || 'en' // 初始未选择默认 en 英文
const fileName = this.exportFileName + '-' + this.$t('overall.template') + '-' + this.getTimeString() + '.xlsx' const fileName = this.exportFileName + '-' + this.$t('overall.template') + '-' + this.getTimeString() + '.xlsx'
let url = null let url = null
if (this.importUrl.indexOf('asset') > -1) { if (this.assetimportUrl.indexOf('asset') || this.assetimportUrl.indexOf('asset') > -1) {
url = '/asset/template' 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' 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' 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' 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' url = '/expression/tmpl/template'
} }
@@ -952,6 +926,40 @@ export default {
} }
this.exportExcel(url, param, fileName) 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 () { importExcel () {
if (this.importFile && this.importFile.raw) { if (this.importFile && this.importFile.raw) {
this.prevent_opt.import = true this.prevent_opt.import = true
@@ -964,37 +972,35 @@ export default {
} }
} }
form.append('language', localStorage.getItem('nz-language') ? localStorage.getItem('nz-language') : 'en') 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 (this.assetimportUrl){
if (response.code == 200 && response.msg == 'success') { this.$post(this.assetimportUrl, form, { 'Content-Type': 'multipart/form-data' }).then(response => {
this.importResult = response.data if (response.code == 200 && response.msg == 'success') {
this.$emit('afterImport') this.importResult = response.data
this.importBox.type = 3 this.$emit('afterImport')
this.importBox.width = '600px' this.importBox.type = 3
} else { this.importBox.width = '600px'
this.$message.error(response.msg) } else {
} this.$message.error(response.msg)
this.prevent_opt.import = false }
}) 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 { } else {
this.$message.error(this.$t('tip.noImportFile')) 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 侧滑关闭事件 // Box 侧滑关闭事件
closeDcBox (refresh) { closeDcBox (refresh) {
this.rightBox.dc.show = false this.rightBox.dc.show = false