2023-07-31 09:52:57 +08:00
|
|
|
<template>
|
|
|
|
|
<div class="configSync">
|
|
|
|
|
<div @click="showDialog" v-if="type==='batch'">
|
|
|
|
|
<i class="nz-icon nz-icon-a-BatchSynchronize" style="font-size:14px;margin-right:7px;"></i>{{$t('overall.batchSync')}}
|
|
|
|
|
</div>
|
|
|
|
|
<el-dialog
|
|
|
|
|
class="configSync-dialog"
|
|
|
|
|
:title="$t('deleteButton.confirm')"
|
|
|
|
|
:visible.sync="dialogVisible"
|
|
|
|
|
@close='handleClose'
|
|
|
|
|
width="580px"
|
|
|
|
|
:append-to-body="true"
|
|
|
|
|
>
|
|
|
|
|
<div class="dialog-header" style="vertical-align:top;" >
|
|
|
|
|
<i class="nz-icon nz-icon-jinggao"></i>
|
|
|
|
|
<span>{{$t('batch.syncTip', { dataLength: idArr.length })}}</span>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="batch-sync-tree">
|
|
|
|
|
<div class="tree-header tree-body-item">
|
|
|
|
|
<el-checkbox :indeterminate="isIndeterminate" v-model="checkAll" @change="checkAllChange"></el-checkbox>
|
|
|
|
|
<div class="batch-sync-item-id">ID</div>
|
|
|
|
|
<div class="batch-sync-item-name">{{$t('overall.name')}}</div>
|
|
|
|
|
</div>
|
|
|
|
|
<el-checkbox-group v-model="idArr" @change="checkedChange">
|
|
|
|
|
<div class="tree-body">
|
|
|
|
|
<div v-for="(item,index) in batchData" :key='index' class="tree-body-item">
|
|
|
|
|
<el-checkbox :key="item.id" :label="item.id"></el-checkbox>
|
|
|
|
|
<div class="batch-sync-item-id">{{item.id}}</div>
|
|
|
|
|
<div class="batch-sync-item-name" @click="showChild(item)">
|
|
|
|
|
<i :class="selectIcon(item.type)"/>
|
|
|
|
|
<span class="text-ellipsis batch-sync-item-text" :title="item.name">{{item.name}}</span>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</el-checkbox-group>
|
|
|
|
|
</div>
|
|
|
|
|
<ul class="sync-select-list">
|
|
|
|
|
<li class="sync-select-item">
|
|
|
|
|
<el-checkbox v-model="syncBox.endpoint">{{$t('batch.syncEndpoint')}}</el-checkbox>
|
|
|
|
|
</li>
|
|
|
|
|
<li class="sync-select-item">
|
|
|
|
|
<el-checkbox v-model="syncBox.dashboard">{{$t('batch.syncDashboard')}}</el-checkbox>
|
|
|
|
|
</li>
|
|
|
|
|
</ul>
|
|
|
|
|
<div slot="footer">
|
2023-08-03 17:13:27 +08:00
|
|
|
<button class="nz-btn nz-btn-size-normal nz-btn-style-light margin-r-10" @click="dialogVisible = false">{{$t("overall.cancel")}}</button>
|
|
|
|
|
<button class="nz-btn nz-btn-size-normal nz-btn-style-normal" :class="{'nz-btn-disabled': prevent_opt.save||!idArr.length}" :disabled="prevent_opt.save||!idArr.length" @click="configSync">{{$t('overall.synchronize')}}</button>
|
2023-07-31 09:52:57 +08:00
|
|
|
</div>
|
|
|
|
|
</el-dialog>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
export default {
|
|
|
|
|
name: 'configSync',
|
|
|
|
|
data () {
|
|
|
|
|
return {
|
|
|
|
|
api: '',
|
|
|
|
|
dialogVisible: false,
|
|
|
|
|
batchData: [],
|
|
|
|
|
idArr: [],
|
|
|
|
|
syncBox: {
|
2023-08-02 14:13:21 +08:00
|
|
|
endpoint: false,
|
|
|
|
|
dashboard: false
|
2023-07-31 09:52:57 +08:00
|
|
|
},
|
|
|
|
|
checkAll: false,
|
|
|
|
|
isIndeterminate: false
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
props: {
|
|
|
|
|
type: String,
|
|
|
|
|
from: String, // 通过 from 确认删除的 icon
|
|
|
|
|
batchObjs: Array
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
showDialog () {
|
|
|
|
|
this.dialogVisible = true
|
|
|
|
|
this.batchData = this.$lodash.cloneDeep(this.batchObjs).map(item => {
|
|
|
|
|
item.type = this.from
|
|
|
|
|
return item
|
|
|
|
|
})
|
|
|
|
|
this.checkAll = true
|
|
|
|
|
this.idArr = this.batchData.map(item => item.id)
|
|
|
|
|
},
|
|
|
|
|
async configSync () {
|
|
|
|
|
this.prevent_opt.save = true
|
2023-08-02 09:52:13 +08:00
|
|
|
this.setApi()
|
2023-07-31 09:52:57 +08:00
|
|
|
const params = {
|
|
|
|
|
ids: this.idArr,
|
|
|
|
|
endpoint: this.syncBox.endpoint ? 1 : 0,
|
|
|
|
|
dashboard: this.syncBox.dashboard ? 1 : 0
|
|
|
|
|
}
|
|
|
|
|
const res = await this.$put(this.api, params)
|
|
|
|
|
if (res.code === 200) {
|
|
|
|
|
this.dialogVisible = false
|
|
|
|
|
this.$message.success(this.$t('tip.syncSuccess'))
|
2023-09-08 17:49:10 +08:00
|
|
|
this.$emit('getTableData')
|
2023-07-31 09:52:57 +08:00
|
|
|
} else {
|
|
|
|
|
this.$message.error(res.msg)
|
|
|
|
|
}
|
|
|
|
|
this.prevent_opt.save = false
|
|
|
|
|
},
|
|
|
|
|
handleClose () {
|
|
|
|
|
this.dialogVisible = false
|
2023-08-02 14:13:21 +08:00
|
|
|
this.syncBox.endpoint = false
|
|
|
|
|
this.syncBox.dashboard = false
|
2023-07-31 09:52:57 +08:00
|
|
|
},
|
|
|
|
|
checkAllChange (value) {
|
|
|
|
|
const allId = this.batchData.map(item => {
|
|
|
|
|
return item.id
|
|
|
|
|
})
|
|
|
|
|
this.idArr = value ? allId : []
|
|
|
|
|
this.isIndeterminate = false
|
|
|
|
|
},
|
|
|
|
|
checkedChange (value) {
|
|
|
|
|
const checkedCount = value.length
|
|
|
|
|
this.checkAll = checkedCount > 0
|
|
|
|
|
this.isIndeterminate = checkedCount > 0 && checkedCount < this.batchData.length
|
|
|
|
|
},
|
2023-08-02 09:52:13 +08:00
|
|
|
setApi () {
|
|
|
|
|
switch (this.from) {
|
|
|
|
|
case 'asset': this.api = '/asset/asset/sync'; break
|
|
|
|
|
case 'module': this.api = '/monitor/module/sync'; break
|
|
|
|
|
case 'endpoint': this.api = '/monitor/endpoint/sync'; break
|
|
|
|
|
}
|
|
|
|
|
},
|
2023-07-31 09:52:57 +08:00
|
|
|
selectIcon (type) {
|
|
|
|
|
switch (type) {
|
|
|
|
|
case 'asset' : return 'nz-icon monitorColor nz-icon-overview-project'
|
|
|
|
|
case 'module' : return 'nz-icon monitorColor nz-icon-overview-module'
|
|
|
|
|
case 'endpoint' : return 'nz-icon monitorColor nz-icon-overview-endpoint'
|
|
|
|
|
}
|
|
|
|
|
return ' '
|
|
|
|
|
}
|
2023-08-02 09:52:13 +08:00
|
|
|
},
|
|
|
|
|
watch: {
|
|
|
|
|
dialogVisible (n) {
|
|
|
|
|
if (!n) {
|
|
|
|
|
this.$store.dispatch('dispatchShowConfigSync', false)
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-31 09:52:57 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|