2021-04-27 16:26:22 +08:00
< template >
2022-07-08 18:06:31 +08:00
< div >
2023-02-22 18:32:54 +08:00
< el-dropdown trigger = "click" :size = "size" class = "nz-el-dropdown" v-if = "type!=='integration'" >
2022-07-08 18:06:31 +08:00
< button id = "more" :class = "triggerButtonClass" :title = "$t('overall.more')" >
< i class = "nz-icon nz-icon-more2" > < / i >
< / button >
2022-12-27 13:46:56 +08:00
< el-dropdown-menu slot = "dropdown" class = "right-box-select-top right-public-box-dropdown-top nz-el-dropdown-menu" >
2022-12-27 16:17:50 +08:00
< el-dropdown-item v-if = "showLock" v-has="'main_edit'" >
2023-03-22 10:14:11 +08:00
< div @click ="editPanel" id = "edit-bottom-dashboard" > < i class = "nz-icon nz-icon-edit" > < / i > { { $t ( 'dashboard.dashboard.editDashboardTitle' ) } } < / div >
2022-07-08 18:06:31 +08:00
< / el-dropdown-item >
2022-12-27 16:17:50 +08:00
< el-dropdown-item v-if = "showLock" v-has="'main_edit'" >
2022-07-08 18:06:31 +08:00
< div @click ="panelLock=!panelLock" id = "panel-lock" > < i : class = "{'nz-icon nz-icon-lock':!panelLock,'nz-icon nz-icon-unlock':panelLock}" > < / i > { { ! panelLock ? $t ( "overall.locked" ) : $t ( "overall.unlocked" ) } } < / div >
< / el-dropdown-item >
<!-- import 、 export之前的内容 -- >
2022-12-21 14:05:37 +08:00
< template >
< slot name = "before" > < / slot >
< / template >
2022-07-08 18:06:31 +08:00
< el-dropdown-item v-has = "permissions.import" v-if="importUrl" >
< div id = "chart-import" @click ="showImportBox(1)" > < i class = "nz-icon nz-icon-upload" > < / i > { { $t ( 'overall.importExcel' ) } } < / div >
< / el-dropdown-item >
< el-dropdown-item v-has = "permissions.export" v-if="exportUrl" >
< div id = "chart-export" @click ="showImportBox(2)" > < i class = "nz-icon nz-icon-download1" > < / i > { { $t ( 'overall.exportExcel' ) } } < / div >
< / el-dropdown-item >
<!-- import 、 export之后的内容 -- >
2022-12-21 14:05:37 +08:00
< template >
< slot name = "after" > < / slot >
< / template >
2022-07-08 18:06:31 +08:00
< / el-dropdown-menu >
2023-02-22 18:32:54 +08:00
< / el-dropdown >
2021-04-27 16:26:22 +08:00
2023-02-22 18:32:54 +08:00
< slot v-else > < / slot >
2022-10-31 12:35:18 +08:00
2023-02-22 18:32:54 +08:00
< el-dialog
: close - on - click - modal = "importBox.type!=3"
destroy - on - close
: show - close = "true"
: title = "importBox.title"
: visible . sync = "importBox.show"
width = "580px"
: append - to - body = "true"
@ close = "closeDialog"
: class = "{'import-failContent-dialog':importBox.type==3}"
class = "nz-dialog" >
<!-- 新版导入 -- >
< div v-if = "importBox.type == 1" >
< div class = "upload-body" >
2023-08-02 14:30:20 +08:00
< el-upload :id = "id+'-xlsx-input-file'" ref = "uploadExcel" :auto-upload = "false" :file-list = "importFileList" :on-change = "importChange" :accept = "!onlyJson?'.xlsx,.xls,.csv,.json':'.json'" action = "" class = "import-upload" drag >
2023-02-22 18:32:54 +08:00
< i class = "el-icon-upload" > < / i >
< div class = "el-upload__text" > { { $t ( 'overall.dragFileTip' ) } } , { { $t ( 'overall.or' ) } } & nbsp ; < em > { { $t ( 'overall.clickUpload' ) } } < / em > < / div >
2023-08-02 14:30:20 +08:00
< div class = "el-upload__tip" > { { ! onlyJson ? $t ( 'overall.importSupport' ) : $t ( 'overall.supportJson' ) } } < / div >
2023-02-22 18:32:54 +08:00
< / el-upload >
< / div >
2023-08-02 14:30:20 +08:00
< div class = "import-select" v-if = "!isTopo" >
2023-02-22 18:32:54 +08:00
< div class = "exists" >
< span > { { $t ( 'overall.existed' ) } } < / span >
< el-select v-model = "importBox.existed" :popper-append-to-body="false" style="flex:1" size="medium" popper-class="select-auto" >
< el-option
v - for = "item in existedArr"
: key = "item.value"
: label = "item.name"
: value = "item.value" >
< / el-option >
< / el-select >
2022-08-08 16:52:08 +08:00
< / div >
2023-02-22 18:32:54 +08:00
< ul class = "import-select-list" >
< li class = "import-select-item" >
< el-checkbox v-model = "importBox.ignoreError" > {{ $ t ( ' overall.ignoreError ' ) }} < / el -checkbox >
< / li >
< li v-if = "showSyncDashboard" class="import-select-item" >
< el-checkbox v-model = "importBox.syncDashboard" > {{ $ t ( ' overall.syncDashboard ' ) }} < / el -checkbox >
< / li >
< li v-if = "showSyncEndpoint" class="import-select-item" >
< el-checkbox v-model = "importBox.syncEndpoint" > {{ $ t ( ' overall.syncEndpoint ' ) }} < / el -checkbox >
< / li >
< / ul >
< / div >
2023-08-02 14:30:20 +08:00
< div class = "footer" : style = "isTopo? 'marginTop:15px' : ''" >
2023-02-22 18:32:54 +08:00
< div class = "el-message-box__btns" style = "text-align: right;" >
< el-popover
2023-08-02 14:30:20 +08:00
v - if = "!onlyJson"
2023-02-22 18:32:54 +08:00
placement = "bottom-start"
trigger = "click" >
< div class = "template-pop" >
< p style = "margin-bottom:8px" > { { $t ( 'overall.selectTemplate' ) } } < / p >
< el-radio-group v-model = "importBox.templateFormat" size="small" >
< el-radio-button :label = "item.value" v-for = "(item,index) in formatArr" :key="index" @click.native="downloadTemplate(item.value)" > {{ item.name }} < / el -radio -button >
< / el-radio-group >
< / div >
< button slot = "reference" :id = "id+'-xlsx-import-template'" class = "nz-btn el-button el-button--default el-button--small" >
< span > { { $t ( 'upload.template' ) } } < / span >
< i class = "el-icon-arrow-down el-icon--right" > < / i >
2022-08-08 16:52:08 +08:00
< / button >
2023-02-22 18:32:54 +08:00
< / el-popover >
< button :id = "id+'-xlsx-import-add'" :class = "{'nz-btn-disabled':prevent_opt.import}" :disabled = "prevent_opt.import" class = "nz-btn el-button el-button--default el-button--small" @click ="importExcel" >
< span > { { $t ( 'overall.importExcel' ) } } < / span >
< / button >
< button :id = "id+'-xlsx-import-esc'" class = "nz-btn el-button el-button--default el-button--small" @click ="closeDialog" >
< span > { { $t ( 'overall.cancel' ) } } < / span >
< / button >
2022-08-08 16:52:08 +08:00
< / div >
< / div >
2023-02-22 18:32:54 +08:00
< / div >
2022-09-14 17:05:23 +08:00
2023-02-22 18:32:54 +08:00
<!-- 导出 -- >
< div v-else-if = "importBox.type == 2" >
< div class = "upload-body" style = "height: 200px" >
< div class = "export-box" >
< span class = "export-title" > { { $t ( 'export.records' ) } } < / span >
< el-radio-group v-model = "importBox.record" size="small" >
2023-08-02 14:30:20 +08:00
< el-radio-button :label = "item.value" v-for = "(item,index) in recordArr" :key="index" :disabled="(item.value==='records'&&!deleteObjs.length) || (item.value==='all'&&(assetOrEndpoint || isTopo))" >
2023-02-22 18:32:54 +08:00
{ { item . name } }
< span v-if = "item.value==='records'&&deleteObjs.length" > ( {{ deleteObjs.length }} ) < / span >
< / el-radio-button >
< / el-radio-group >
2022-07-08 18:06:31 +08:00
< / div >
2023-02-22 18:32:54 +08:00
< div class = "export-box" >
< span class = "export-title" > { { $t ( 'export.fileFormat' ) } } < / span >
< el-radio-group v-model = "importBox.format" size="small" >
2023-08-02 14:30:20 +08:00
< el-radio-button :label = "item.value" v-for = "(item,index) in formatArr" :key="index" :disabled="onlyJson&&item.name!='JSON'" > {{ item.name }} < / el -radio -button >
2023-02-22 18:32:54 +08:00
< / el-radio-group >
2021-11-02 15:47:17 +08:00
< / div >
2021-04-27 16:26:22 +08:00
< / div >
2023-02-22 18:32:54 +08:00
< div class = "footer" >
< div class = "el-message-box__btns" >
< button :id = "id+'-xlsx-import-export'" class = "nz-btn el-button--small nz-btn-style-normal" @click ="exportData" >
< span style = "text-transform:Capitalize" > { { $t ( 'overall.exportExcel' ) } } < / span >
< / button >
< button :id = "id+'-xlsx-import-close'" class = "nz-btn el-button el-button--small el-button--default" @click ="closeDialog" >
< span > { { $t ( 'overall.close' ) } } < / span >
< / button >
< / div >
< / div >
< / div >
2022-08-08 16:52:08 +08:00
2023-02-22 18:32:54 +08:00
<!-- 导入结果 ( 展示导出失败记录 ) -- >
< div v-if = "importBox.type==3" >
< div class = "upload-body result-body" >
<!-- 失败提示 -- >
< div v-if = "importResult&&importResult.failNum" >
<!-- success number -- >
< div class = "result-title-top" >
< div class = "result-number" >
< span >
< i class = "nz-icon nz-icon-import-success" / >
{ { $t ( 'overall.result.successful' ) } }
< / span >
< span > { { importResult . successNum } } < / span >
< / div >
< div class = "result-number" style = "padding-left:20px;" >
< span >
< i class = "nz-icon nz-icon-New" / >
{ { $t ( 'overall.result.newQuantity' ) } }
< / span >
< span > { { importResult . addNum } } < / span >
< / div >
< div class = "result-number" style = "padding-left:20px;" >
< span >
< i class = "nz-icon nz-icon-Update" / >
{ { $t ( 'overall.result.updates' ) } }
< / span >
< span > { { importResult . updateNum } } < / span >
< / div >
<!-- fail number -- >
< div class = "result-number fail" >
< span >
< i class = "nz-icon nz-icon-import-failed" / >
{ { $t ( 'overall.result.fail' ) } }
< / span >
< span > { { importResult . failNum } } < / span >
2021-11-01 16:46:12 +08:00
< / div >
2023-02-22 18:32:54 +08:00
< / div >
< div >
< div v-if = "importResult&&importResult.failDetail" class="result-detail" >
< div style = "height: 100%; overflow: auto" >
< template v-for = "(item, index) in importResult.failDetail" >
< div :key = "index" class = "import-result-block" >
< div class = "import-result-item" >
< span class = "import-result-item-left" > • < / span >
< div class = "import-result-item-right" >
< span class = "line-num" > { { $t ( 'overall.result.line' , [ item . lineNo ] ) } } < / span >
< span class = "line-content" :title = "item.errorMsg" > { { item . errorMsg } } < / span >
2022-07-08 18:06:31 +08:00
< / div >
2021-11-01 16:46:12 +08:00
< / div >
2023-02-22 18:32:54 +08:00
< / div >
< / template >
2021-11-01 16:46:12 +08:00
< / div >
2023-02-22 18:32:54 +08:00
< i class = "nz-icon nz-icon-override" @click ="copyFailDetail(importResult.failDetail)" > < / i >
2021-04-27 16:26:22 +08:00
< / div >
< / div >
2023-02-22 18:32:54 +08:00
< / div >
<!-- 成功提示 -- >
< div v-else class = "result-success-box" >
< div style = "height:80px;line-height:80px;" >
< i class = "nz-icon nz-icon-import-success" style = "margin-right:0" / >
< / div >
< div style = "margin-top:30px" >
< div class = "success-number" >
< span >
{ { $t ( 'overall.result.importedRecords' ) } }
< / span >
< span > { { importResult . successNum } } < / span >
2022-07-08 18:06:31 +08:00
< / div >
2023-02-22 18:32:54 +08:00
< div class = "success-number" style = "margin-top:8px" >
< span >
< i class = "nz-icon nz-icon-New" / >
{ { $t ( 'overall.result.newRecords' ) } }
< / span >
< span > { { importResult . addNum } } < / span >
< / div >
< div class = "success-number" style = "margin-top:4px" >
< span >
< i class = "nz-icon nz-icon-Update" / >
{ { $t ( 'overall.result.updatedRecords' ) } }
< / span >
< span > { { importResult . updateNum } } < / span >
2022-07-08 18:06:31 +08:00
< / div >
2021-11-01 16:46:12 +08:00
< / div >
< / div >
2023-02-22 18:32:54 +08:00
< / div >
< div class = "footer" >
< div class = "el-message-box__btns" >
< button v-if = "importResult&&importResult.failNum" :id="id+'-xlsx-import-downloadFail'" class="nz-btn el-button el-button--small nz-btn-style-error" @click="downloadFail" >
< span > { { $t ( 'overall.result.downloadFail' ) } } < / span >
< / button >
< button :id = "id+'-xlsx-import-close'" class = "nz-btn el-button el-button--small el-button--default" @click ="closeDialog" >
< span > { { $t ( 'overall.close' ) } } < / span >
< / button >
2021-04-27 16:26:22 +08:00
< / div >
< / div >
2023-02-22 18:32:54 +08:00
< / div >
2022-10-28 12:58:17 +08:00
2023-02-22 18:32:54 +08:00
< / el-dialog >
2022-07-08 18:06:31 +08:00
< transition name = "right-box" >
< panel-box v-if = "rightBox.panel.show" ref="panelBox" :obj="panel" @close="closePanelBox" :isBottom="true" :panelType="params.from" > < / panel -box >
< / transition >
< / div >
2021-04-27 16:26:22 +08:00
< / template >
< script >
import axios from 'axios'
2022-07-08 18:06:31 +08:00
import panelBox from '@/components/common/rightBox/panelBox'
2022-08-08 16:52:08 +08:00
import bus from '@/libs/bus'
2021-04-27 16:26:22 +08:00
let timeout
export default {
name : 'topToolMoreOptions' ,
2022-07-08 18:06:31 +08:00
components : {
panelBox
} ,
2021-04-27 16:26:22 +08:00
props : {
size : {
type : String ,
2021-08-25 10:39:26 +08:00
default : 'medium'
2021-04-27 16:26:22 +08:00
} ,
exportUrl : { type : String , default : '' } ,
params : { type : Object } ,
2021-06-17 15:01:13 +08:00
params2 : { type : Object } ,
2021-04-27 16:26:22 +08:00
exportFileName : { type : String } ,
importUrl : { type : String , default : '' } , // 为空时不显示导入按钮
link : { type : Object } , // 为空时不显示导出按钮
permissions : { type : Object } ,
showCur : { type : Boolean , default : true } ,
id : { type : String , default : 'export' } ,
triggerButtonClass : { // 触发下拉事件的按钮的class
type : String ,
default : 'top-tool-btn'
2021-05-13 19:02:23 +08:00
} ,
showLock : {
type : Boolean , default : false
2021-07-19 17:04:46 +08:00
} ,
paramsType : {
type : String ,
default : ''
2021-11-02 15:47:17 +08:00
} ,
2023-08-02 14:30:20 +08:00
isTopo : {
type : Boolean , default : false
} ,
2022-05-24 15:04:46 +08:00
deleteObjs : Array ,
2023-08-02 14:30:20 +08:00
type : String ,
onlyJson : {
type : Boolean , default : false
}
2022-09-22 10:19:30 +08:00
} ,
computed : {
language ( ) { return this . $store . getters . getLanguage } ,
2022-11-29 14:55:10 +08:00
// 判断是否是dashboard
isDashboard ( ) {
2023-07-25 11:28:24 +08:00
return this . exportUrl === '/visual/dashboard/export'
2022-10-31 12:35:18 +08:00
} ,
2023-03-08 17:29:25 +08:00
// asset, endpoint dashboard导出选项不支持 all data
assetOrEndpoint ( ) {
return this . paramsType === 'asset' || this . paramsType === 'endpoint'
} ,
2022-09-05 15:09:04 +08:00
// 是否同步更新关联的dashboard
2022-08-08 16:52:08 +08:00
showSyncDashboard ( ) {
2022-09-16 15:26:50 +08:00
// asset endpoint model
const arr = [ '/asset/asset/import' , '/monitor/endpoint/import' , '/asset/model/import' ]
2022-09-05 15:09:04 +08:00
return arr . some ( item => item === this . importUrl )
2022-08-08 16:52:08 +08:00
} ,
2022-09-05 15:09:04 +08:00
// 是否同步更新关联的endpoint
2022-08-08 16:52:08 +08:00
showSyncEndpoint ( ) {
2022-09-14 17:05:23 +08:00
// asset module
2022-09-14 10:15:35 +08:00
const arr = [ '/asset/asset/import' , '/monitor/module/import' ]
2022-09-05 15:09:04 +08:00
return arr . some ( item => item === this . importUrl )
2022-08-08 16:52:08 +08:00
}
2021-11-09 10:17:12 +08:00
} ,
2021-04-27 16:26:22 +08:00
data ( ) {
return {
2022-08-08 16:52:08 +08:00
importBox : {
show : false ,
title : this . $t ( 'overall.importExcel' ) ,
type : 1 ,
record : 'all' ,
format : 1 ,
templateFormat : 1 , // 模板格式
2022-09-05 15:09:04 +08:00
existed : 0 , // 已存在的内容处理方式
2022-09-14 10:15:35 +08:00
ignoreError : 0 , // 遇到错误是否继续导入
syncDashboard : 0 , // 是否同步更新关联的dashboard
syncEndpoint : 0 // 是否同步更新关联的endpoint
2022-08-08 16:52:08 +08:00
} ,
existedArr : [
{ name : this . $t ( 'overall.error' ) , value : 0 } ,
{ name : this . $t ( 'overall.override' ) , value : 1 } ,
{ name : this . $t ( 'overall.ignore' ) , value : 2 }
] ,
2021-04-27 16:26:22 +08:00
importFile : null ,
importFileList : [ ] ,
importResult : null ,
exportShow : false ,
2021-11-01 16:46:12 +08:00
panelLock : true ,
2021-11-02 15:47:17 +08:00
recordArr : [
{ name : this . $t ( 'overall.allData' ) , value : 'all' } ,
{ name : this . $t ( 'overall.selectRecords' ) , value : 'records' } ,
{ name : this . $t ( 'overall.current' ) , value : 'current' }
] ,
formatArr : [
{ name : 'XLSX' , value : 1 } ,
{ name : 'CSV' , value : 2 } ,
{ name : 'JSON' , value : 3 }
2022-05-24 15:04:46 +08:00
] ,
2022-07-08 18:06:31 +08:00
suffix : '.xlsx' ,
2023-03-02 11:34:42 +08:00
faildSuffix : '.xlsx' ,
2022-07-08 18:06:31 +08:00
panel : { } ,
rightBox : { // 面板弹出框相关
panel : { show : false } ,
loading : false
}
2021-04-27 16:26:22 +08:00
}
} ,
mounted ( ) {
2021-07-19 17:04:46 +08:00
// this.getParamsType()
2021-04-27 16:26:22 +08:00
} ,
methods : {
2022-10-25 16:57:54 +08:00
// 复制失败记录
copyFailDetail ( data ) {
let txt = ''
data . forEach ( ( item , index ) => {
txt += '• ' + this . $t ( 'overall.result.line' , [ item . lineNo ] ) + ' ' + item . errorMsg + ( index + 1 < data . length ? '\n' : '' )
} )
this . $copyText ( txt ) . then ( ( ) => {
this . $message . success ( { message : this . $t ( 'overall.copySuccess' ) } )
} )
} ,
2021-04-27 16:26:22 +08:00
importChange ( file , fileList ) {
if ( fileList . length > 0 ) {
this . importFileList = [ fileList [ fileList . length - 1 ] ]
}
this . importFile = this . importFileList [ 0 ]
2023-03-02 11:34:42 +08:00
const arr = this . importFile . name . split ( '.' )
this . faildSuffix = '.' + arr [ arr . length - 1 ] // 获取文件后缀名
2021-04-27 16:26:22 +08:00
this . validateFile ( )
} ,
validateFile ( ) {
} ,
rollbackImport ( ) {
let url
2021-07-20 10:16:28 +08:00
if ( this . importUrl . indexOf ( '/asset/model' ) > - 1 ) {
url = '/asset/model/cancelImport'
} else if ( this . importUrl . indexOf ( 'asset' ) > - 1 ) {
2021-05-14 17:09:57 +08:00
url = '/asset/asset/cancelImport'
2021-04-27 16:26:22 +08:00
} else if ( this . importUrl . indexOf ( 'endpoint' ) > - 1 ) {
url = '/monitor/endpoint/cancelImport'
2021-08-03 15:32:22 +08:00
} else if ( this . importUrl . indexOf ( 'module' ) > - 1 ) {
url = '/monitor/module/cancelImport'
2021-04-27 16:26:22 +08:00
} else if ( this . importUrl . indexOf ( 'rule' ) > - 1 ) {
url = '/alert/rule/cancelImport'
2023-03-15 15:39:06 +08:00
} else if ( this . importUrl . indexOf ( 'dashboard' ) > - 1 ) {
url = 'visual/dashboard/cancelImport'
2021-04-27 16:26:22 +08:00
} else if ( this . importUrl . indexOf ( 'tmpl' ) > - 1 ) {
url = '/expression/tmpl/cancelImport'
2021-07-20 10:16:28 +08:00
} else if ( this . importUrl . indexOf ( 'dc/cabinet' ) > - 1 ) {
url = '/dc/cabinet/cancelImport'
} else if ( this . importUrl . indexOf ( 'dc' ) > - 1 ) {
url = '/dc/cancelImport'
2022-03-03 10:33:29 +08:00
} else if ( this . importUrl . indexOf ( '/ipam/subnet' ) > - 1 ) {
url = '/ipam/subnet/cancelImport'
2022-03-18 16:23:41 +08:00
} else if ( this . importUrl . indexOf ( '/ipam/ip' ) > - 1 ) {
url = '/ipam/ip/cancelImport'
2021-04-27 16:26:22 +08:00
}
this . $delete ( url + '?seq=' + this . importResult . seq ) . then ( response => {
if ( response . code == 200 ) {
2021-05-25 10:26:13 +08:00
const linkId = this . link ? this . link . id : ''
2021-04-27 16:26:22 +08:00
this . $message ( { duration : 2000 , type : 'success' , message : this . $t ( 'tip.saveSuccess' ) } )
2021-05-25 10:26:13 +08:00
this . $emit ( 'afterImport' , linkId )
2021-04-27 16:26:22 +08:00
} else {
this . $message . error ( response . msg )
}
this . closeDialog ( )
} )
} ,
importExcel ( ) {
2023-08-02 14:30:20 +08:00
if ( this . isTopo ) {
this . importTopo ( )
return
}
2021-04-27 16:26:22 +08:00
if ( this . importFile && this . importFile . raw ) {
this . prevent _opt . import = true
const form = new FormData ( )
2022-10-25 16:57:54 +08:00
form . append ( 'file' , this . importFile . raw )
2022-11-29 14:55:10 +08:00
form . append ( 'existed' , this . importBox . existed )
form . append ( 'ignoreError' , Number ( this . importBox . ignoreError ) )
2022-08-08 16:52:08 +08:00
if ( this . showSyncDashboard ) {
2022-09-05 15:09:04 +08:00
form . append ( 'syncDashboard' , Number ( this . importBox . syncDashboard ) )
2022-08-08 16:52:08 +08:00
}
if ( this . showSyncEndpoint ) {
2022-09-05 15:09:04 +08:00
form . append ( 'syncEndpoint' , Number ( this . importBox . syncEndpoint ) )
2022-08-08 16:52:08 +08:00
}
2021-04-27 16:26:22 +08:00
if ( this . paramsType ) {
form . append ( 'type' , this . paramsType )
2021-05-21 23:10:15 +08:00
if ( this . paramsType === 'asset' || this . paramsType === 'endpoint' ) {
2021-04-27 16:26:22 +08:00
form . append ( 'linkId' , this . link ? this . link . id : '' )
}
}
2021-07-20 10:16:28 +08:00
if ( this . importUrl . indexOf ( 'dc/cabinet' ) > - 1 ) {
form . append ( 'dcIds' , this . params . dcIds )
}
2021-11-04 17:18:37 +08:00
// form.append('language', localStorage.getItem('nz-language') ? localStorage.getItem('nz-language') : 'en')
2021-04-27 16:26:22 +08:00
this . $post ( this . importUrl , form , { 'Content-Type' : 'multipart/form-data' } ) . then ( response => {
if ( response . code == 200 && response . msg == 'success' ) {
2022-10-25 16:57:54 +08:00
this . importBox . type = 3
this . importBox . title = this . $t ( 'overall.importResult' )
2021-04-27 16:26:22 +08:00
this . importResult = response . data
2021-05-25 10:26:13 +08:00
const linkId = this . link ? this . link . id : ''
this . $emit ( 'afterImport' , linkId )
2021-04-27 16:26:22 +08:00
} else {
this . $message . error ( response . msg )
}
this . prevent _opt . import = false
} )
} else {
this . $message . error ( this . $t ( 'tip.noImportFile' ) )
}
} ,
2023-08-02 14:30:20 +08:00
importTopo ( ) {
if ( this . importFile && this . importFile . raw ) {
let reader = new FileReader ( ) // 新建一个FileReader
reader . readAsText ( this . importFile . raw , 'UTF-8' ) // 读取文件
reader . onload = ( evt ) => { // 读取完文件之后会回来这里
let fileString = evt . target . result // 读取文件内容
fileString = JSON . parse ( fileString )
console . log ( fileString )
if ( ! fileString . topo ) {
this . $message . error ( this . $t ( 'IMPORT_FORMAT_ERROR' , { 0 : '' } ) )
return
}
try {
2023-08-02 15:27:50 +08:00
fileString . topo . pens . forEach ( item => {
item . imageId = ''
} )
console . log ( fileString )
2023-08-02 14:30:20 +08:00
this . $post ( this . importUrl , fileString ) . then ( response => {
if ( response . code == 200 && response . msg == 'success' ) {
this . $message . success ( this . $t ( 'overall.result.success' ) )
this . importBox . show = false
this . $emit ( 'afterImport' )
} else {
this . $message . error ( response . msg )
}
this . prevent _opt . import = false
reader = null
} )
} catch ( e ) {
2023-08-02 15:27:50 +08:00
this . $message . error ( this . $t ( 'IMPORT_FORMAT_ERROR' , { 0 : '' } ) )
2023-08-02 14:30:20 +08:00
}
}
} else {
this . $message . error ( this . $t ( 'tip.noImportFile' ) )
}
} ,
2021-04-27 16:26:22 +08:00
exportMenuHandler ( show ) {
if ( show ) {
clearTimeout ( timeout )
this . exportShow = true
} else {
timeout = setTimeout ( ( ) => {
this . exportShow = false
} , 700 )
}
} ,
closeDialog ( ) {
this . importBox . show = false
2021-12-20 11:05:41 +08:00
setTimeout ( ( ) => {
this . $nextTick ( ( ) => {
this . importResult = null
this . importFileList = [ ]
this . importFile = null
2022-10-28 12:58:17 +08:00
this . importBox . type = 1
2021-12-20 11:05:41 +08:00
this . importBox . record = 'all'
2022-05-24 15:04:46 +08:00
this . importBox . format = 1
2022-08-08 16:52:08 +08:00
this . importBox . templateFormat = 1 // 模板格式
2022-10-25 16:57:54 +08:00
this . importBox . existed = 0 // 已存在的内容处理方式
2022-09-14 10:15:35 +08:00
this . importBox . ignoreError = 0 // 遇到错误是否继续导入
this . importBox . syncDashboard = 0 // 是否同步更新关联的dashboard
this . importBox . syncEndpoint = 0 // 是否同步更新关联的endpoint
2021-12-20 11:05:41 +08:00
} )
2021-12-20 16:58:58 +08:00
} , 200 )
2021-04-27 16:26:22 +08:00
} ,
2022-08-08 16:52:08 +08:00
downloadTemplate : bus . debounce ( function ( templateFormat ) {
2021-04-27 16:26:22 +08:00
const language = localStorage . getItem ( 'nz-language' ) || 'en' // 初始未选择默认 en 英文
2022-09-05 15:09:04 +08:00
// 导出模板后缀
let suffix = '.xlsx'
2022-09-16 09:50:02 +08:00
if ( templateFormat == 1 ) {
2022-09-05 15:09:04 +08:00
suffix = '.xlsx'
2022-09-16 09:50:02 +08:00
} else if ( templateFormat == 2 ) {
2022-09-05 15:09:04 +08:00
suffix = '.csv'
2022-09-16 09:50:02 +08:00
} else if ( templateFormat == 3 ) {
2022-09-05 15:09:04 +08:00
suffix = '.json'
}
const fileName = this . exportFileName + '-' + this . $t ( 'overall.template' ) + '-' + this . getTimeString ( ) + suffix
2021-04-27 16:26:22 +08:00
let url = null
2022-08-08 16:52:08 +08:00
const param = { language : language , format : templateFormat }
2021-07-20 10:16:28 +08:00
if ( this . importUrl . indexOf ( '/asset/model' ) > - 1 ) {
url = '/asset/model/template'
} else if ( this . importUrl . indexOf ( 'asset' ) > - 1 ) {
2021-05-14 17:09:57 +08:00
url = '/asset/asset/template'
2021-05-21 22:55:51 +08:00
param . type = 'asset'
2023-03-15 15:39:06 +08:00
} else if ( this . importUrl . indexOf ( 'dashboard' ) > - 1 ) {
url = 'visual/dashboard/template'
2021-07-19 17:04:46 +08:00
param . type = this . paramsType
} else if ( this . importUrl . indexOf ( 'endpoint' ) > - 1 ) {
2021-04-27 16:26:22 +08:00
url = '/monitor/endpoint/template'
2021-05-21 22:55:51 +08:00
param . type = 'endpoint'
2021-08-03 15:32:22 +08:00
} else if ( this . importUrl . indexOf ( 'module' ) > - 1 ) {
url = '/monitor/module/template'
param . type = 'module'
2021-04-27 16:26:22 +08:00
} else if ( this . importUrl . indexOf ( 'tmpl' ) > - 1 ) {
url = '/expression/tmpl/template'
2021-06-30 16:42:54 +08:00
} else if ( this . importUrl . indexOf ( 'alert' ) > - 1 ) {
url = '/alert/rule/template'
2021-07-20 10:16:28 +08:00
} else if ( this . importUrl . indexOf ( 'dc/cabinet' ) > - 1 ) {
url = '/dc/cabinet/template'
} else if ( this . importUrl . indexOf ( 'dc' ) > - 1 ) {
url = '/dc/template'
2022-03-21 18:05:33 +08:00
} else if ( this . importUrl . indexOf ( 'ipam/subnet' ) > - 1 ) {
2022-03-03 10:33:29 +08:00
url = '/ipam/subnet/template'
2022-03-21 18:05:33 +08:00
} else if ( this . importUrl . indexOf ( 'ipam/ip' ) > - 1 ) {
url = '/ipam/ip/template'
2022-08-08 09:09:08 +08:00
} else if ( this . importUrl . indexOf ( 'record/rule' ) > - 1 ) {
url = '/record/rule/template'
2021-04-27 16:26:22 +08:00
}
if ( ! url ) {
console . error ( 'no interface support' )
}
this . exportExcel ( url , param , fileName )
2022-08-08 16:52:08 +08:00
} , 50 ) ,
2021-04-27 16:26:22 +08:00
formatJson ( filterVal , jsonData ) {
return jsonData . map ( v => filterVal . map ( j => v [ j ] ) )
} ,
exportCur ( ) {
2021-05-18 10:12:47 +08:00
const params = JSON . parse ( JSON . stringify ( this . params ) )
2021-07-19 17:04:46 +08:00
if ( this . params2 ) {
Object . keys ( this . params2 ) . forEach ( key => {
if ( params [ key ] ) {
if ( params [ key ] . prototype . toString . call ( val ) === '[object Object]' ) {
Object . assign ( params [ key ] , this . params2 [ key ] )
} else if ( params [ key ] . prototype . toString . call ( val ) === '[object Array]' ) {
2021-06-17 15:01:13 +08:00
params [ key ] . concat ( this . params2 [ key ] )
}
} else {
params [ key ] = this . params2 [ key ]
}
} )
}
2023-03-15 15:39:06 +08:00
if ( this . exportUrl . indexOf ( 'dashboard' ) > - 1 ) {
2021-07-20 10:16:28 +08:00
if ( this . paramsType !== 'template' ) {
params . pageSize = - 1
}
2021-05-13 15:26:25 +08:00
delete params . start _time
delete params . end _time
delete params . id
delete params . searchName
2022-12-01 10:44:09 +08:00
delete params . value
2023-03-15 15:39:06 +08:00
params . ids = params . dashboardId
delete params . dashboardId
2021-05-13 15:26:25 +08:00
}
2021-04-27 16:26:22 +08:00
params . language = localStorage . getItem ( 'nz-language' ) || 'en'
2021-11-02 15:47:17 +08:00
params . format = this . importBox . format
2021-11-04 17:00:58 +08:00
delete params . statistics
2022-05-24 15:04:46 +08:00
this . exportExcel ( this . exportUrl , params , this . exportFileName + '-' + this . getTimeString ( ) + this . suffix )
2021-04-27 16:26:22 +08:00
this . closeDialog ( )
} ,
exportAll ( ) {
const params = JSON . parse ( JSON . stringify ( this . params ) )
2021-07-19 17:04:46 +08:00
if ( this . params2 ) {
Object . keys ( this . params2 ) . forEach ( key => {
if ( params [ key ] ) {
if ( params [ key ] . prototype . toString . call ( val ) === '[object Object]' ) {
Object . assign ( params [ key ] , this . params2 [ key ] )
} else if ( params [ key ] . prototype . toString . call ( val ) === '[object Array]' ) {
2021-06-17 15:01:13 +08:00
params [ key ] . concat ( this . params2 [ key ] )
}
} else {
params [ key ] = this . params2 [ key ]
}
} )
}
2021-04-27 16:26:22 +08:00
params . pageSize = - 1
2023-03-15 15:39:06 +08:00
if ( this . exportUrl . indexOf ( 'dashboard' ) > - 1 ) {
2021-05-13 15:26:25 +08:00
delete params . start _time
delete params . end _time
delete params . id
delete params . searchName
2022-12-01 10:44:09 +08:00
delete params . value
2023-03-15 15:39:06 +08:00
delete params . dashboardId
2021-04-27 16:26:22 +08:00
}
// if (this.importUrl.indexOf('endpoint') > -1){
// delete params.moduleId
// }
params . language = localStorage . getItem ( 'nz-language' ) || 'en'
2021-11-02 15:47:17 +08:00
params . format = this . importBox . format
2021-11-04 17:00:58 +08:00
delete params . statistics
2022-05-24 15:04:46 +08:00
this . exportExcel ( this . exportUrl , params , this . exportFileName + '-' + this . getTimeString ( ) + this . suffix )
2021-04-27 16:26:22 +08:00
this . closeDialog ( )
} ,
2021-11-09 10:17:12 +08:00
exportRecords ( ) {
2021-11-02 15:47:17 +08:00
const params = JSON . parse ( JSON . stringify ( this . params ) )
if ( this . params2 ) {
Object . keys ( this . params2 ) . forEach ( key => {
if ( params [ key ] ) {
if ( params [ key ] . prototype . toString . call ( val ) === '[object Object]' ) {
Object . assign ( params [ key ] , this . params2 [ key ] )
} else if ( params [ key ] . prototype . toString . call ( val ) === '[object Array]' ) {
params [ key ] . concat ( this . params2 [ key ] )
}
} else {
params [ key ] = this . params2 [ key ]
}
} )
}
params . pageSize = - 1
2023-03-15 15:39:06 +08:00
if ( this . exportUrl . indexOf ( 'dashboard' ) > - 1 ) {
2021-11-02 15:47:17 +08:00
delete params . start _time
delete params . end _time
delete params . id
delete params . searchName
2022-12-01 10:44:09 +08:00
delete params . value
2023-03-15 15:39:06 +08:00
delete params . dashboardId
2021-11-02 15:47:17 +08:00
}
// if (this.importUrl.indexOf('endpoint') > -1){
// delete params.moduleId
// }
params . language = localStorage . getItem ( 'nz-language' ) || 'en'
params . format = this . importBox . format
params . ids = this . deleteObjs . map ( item => item . id ) . join ( ',' )
2021-11-04 17:00:58 +08:00
delete params . statistics
2022-05-24 15:04:46 +08:00
this . exportExcel ( this . exportUrl , params , this . exportFileName + '-' + this . getTimeString ( ) + this . suffix )
2021-11-02 15:47:17 +08:00
this . closeDialog ( )
} ,
exportData ( ) {
2022-05-24 15:04:46 +08:00
if ( this . importBox . format == 1 ) {
this . suffix = '.xlsx'
} else if ( this . importBox . format == 2 ) {
this . suffix = '.csv'
} else if ( this . importBox . format == 3 ) {
this . suffix = '.json'
} else if ( this . importBox . format == 4 ) {
this . suffix = '.pdf'
this . $emit ( 'export' , 'PDF' )
return
} else if ( this . importBox . format == 5 ) {
this . suffix = '.html'
this . $emit ( 'export' , 'Html' )
return
}
2021-11-02 15:47:17 +08:00
if ( this . importBox . record === 'all' ) {
this . exportAll ( )
} else if ( this . importBox . record === 'current' ) {
this . exportCur ( )
} else if ( this . importBox . record === 'records' ) {
this . exportRecords ( )
}
} ,
2021-04-27 16:26:22 +08:00
exportExcel ( url , params , fileName ) {
if ( this . paramsType ) {
params . type = this . paramsType
}
2023-03-08 17:29:25 +08:00
if ( this . assetOrEndpoint ) {
2021-05-18 10:12:47 +08:00
delete params . from
}
2021-04-27 16:26:22 +08:00
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 )
} )
} ,
2022-10-25 16:57:54 +08:00
// 导出失败记录
downloadFail ( ) {
const result = this . importResult . failContent
const raw = window . atob ( result )
const uInt8Array = new Uint8Array ( raw . length )
for ( let i = 0 ; i < raw . length ; i ++ ) {
uInt8Array [ i ] = raw . charCodeAt ( i )
}
const link = document . createElement ( 'a' )
2022-12-01 10:44:09 +08:00
const blob = new Blob ( [ uInt8Array ] )
2022-10-25 16:57:54 +08:00
link . style . display = 'none'
link . href = URL . createObjectURL ( blob )
2023-03-02 11:34:42 +08:00
link . setAttribute ( 'download' , 'failed_records' + '-' + this . getTimeString ( ) + this . faildSuffix )
2022-10-25 16:57:54 +08:00
document . body . appendChild ( link )
link . click ( )
document . body . removeChild ( link )
} ,
2021-04-27 16:26:22 +08:00
showImportBox ( type ) {
this . importBox . show = true
this . importBox . type = type
2023-03-08 17:29:25 +08:00
2023-08-02 14:30:20 +08:00
if ( this . assetOrEndpoint || this . isTopo ) {
2023-03-08 17:29:25 +08:00
this . importBox . record = 'current'
}
2022-11-29 14:55:10 +08:00
// isDashboard 只支持JSON
if ( this . isDashboard ) {
this . importBox . format = 3
}
2023-08-02 14:30:20 +08:00
if ( this . onlyJson ) {
this . importBox . format = 3
}
2021-04-27 16:26:22 +08:00
if ( type == 2 && ( ! this . showCur ) ) {
this . exportCur ( )
return
}
if ( type == 1 ) { // import
this . importBox . title = this . $t ( 'overall.importExcel' )
} else if ( type == 2 ) { // export
this . importBox . title = this . $t ( 'overall.exportExcel' )
}
} ,
getTimeString ( ) {
const split = '-'
const date = new Date ( )
const year = date . getFullYear ( )
2022-09-14 17:05:23 +08:00
const month = String ( date . getMonth ( ) + 1 ) . padStart ( 2 , '0' )
const day = String ( date . getDate ( ) ) . padStart ( 2 , '0' )
const hours = String ( date . getHours ( ) ) . padStart ( 2 , '0' )
const minutes = String ( date . getMinutes ( ) ) . padStart ( 2 , '0' )
const seconds = String ( date . getSeconds ( ) ) . padStart ( 2 , '0' )
2021-04-27 16:26:22 +08:00
return year + split + month + split + day + ' ' + hours + split + minutes + split + seconds
} ,
2022-07-08 18:06:31 +08:00
editPanel ( ) {
2023-03-15 15:39:06 +08:00
this . $get ( 'visual/dashboard/' + this . params . dashboardId ) . then ( res => {
2022-07-08 18:06:31 +08:00
if ( res . code === 200 ) {
this . panel = res . data
2023-06-20 16:59:46 +08:00
if ( ! this . $lodash . get ( this . panel , 'param.report' , '' ) ) {
2022-07-08 18:06:31 +08:00
this . panel = {
... this . panel ,
param : {
report : {
enable : false ,
range : {
unit : 'day'
} ,
schedule : {
type : '2' ,
repeat : 1 ,
nums : [ ] ,
stime : '' ,
etime : ''
} ,
receivers : [ ]
} ,
2023-03-28 09:16:24 +08:00
chartShare : 'none' ,
defaultTimeRange : 4 ,
refresh : 0
2022-07-08 18:06:31 +08:00
}
}
}
this . panel . param . report . schedule . type = this . panel . param . report . schedule . type + ''
2023-06-20 16:59:46 +08:00
const startTime = this . $lodash . get ( this . panel , 'param.report.schedule.stime' , '' )
2022-07-08 18:06:31 +08:00
if ( startTime !== '' ) {
this . panel . param . report . schedule . stime = this . utcTimeToTimezoneStr ( this . panel . param . report . schedule . stime , 'YYYY-MM-DD HH:mm:ss' )
} else {
this . panel . param . report . schedule . stime = ''
}
2023-06-20 16:59:46 +08:00
const endTime = this . $lodash . get ( this . panel , 'param.report.schedule.etime' , '' )
2022-07-08 18:06:31 +08:00
if ( endTime !== '' ) {
this . panel . param . report . schedule . etime = this . utcTimeToTimezoneStr ( this . panel . param . report . schedule . etime , 'YYYY-MM-DD HH:mm:ss' )
} else {
this . panel . param . report . schedule . etime = ''
}
this . rightBox . panel . show = true
}
} )
// this.panel = Object.assign({}, u)panelType
} ,
closePanelBox ( refresh ) {
this . rightBox . panel . show = false
if ( refresh ) {
this . $emit ( 'afterImport' )
}
2022-08-08 16:52:08 +08:00
}
2021-05-13 19:02:23 +08:00
} ,
watch : {
panelLock : {
immediate : true ,
handler ( n ) {
this . $emit ( 'panelLockChange' , n )
}
}
2021-04-27 16:26:22 +08:00
}
}
< / script >