From 61e178530f2a02752de11f210e99633627050bf2 Mon Sep 17 00:00:00 2001 From: wang-liang0615 Date: Thu, 3 Aug 2023 16:54:27 +0800 Subject: [PATCH] =?UTF-8?q?ci=20=E6=89=B9=E9=87=8F=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E5=92=8C=E5=88=A0=E9=99=A4=E7=9A=84=E5=BC=82=E6=AD=A5=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmdb-ui/src/modules/cmdb/api/ci.js | 10 +- cmdb-ui/src/modules/cmdb/views/ci/index.vue | 128 ++++++++------- .../modules/cmdb/views/tree_views/index.vue | 150 +++++++++--------- 3 files changed, 155 insertions(+), 133 deletions(-) diff --git a/cmdb-ui/src/modules/cmdb/api/ci.js b/cmdb-ui/src/modules/cmdb/api/ci.js index 343340f..92214ee 100644 --- a/cmdb-ui/src/modules/cmdb/api/ci.js +++ b/cmdb-ui/src/modules/cmdb/api/ci.js @@ -25,18 +25,20 @@ export function addCI(params) { }) } -export function updateCI(id, params) { +export function updateCI(id, params, isShowMessage = true) { return axios({ url: urlPrefix + `/ci/${id}`, method: 'PUT', - data: params + data: params, + isShowMessage }) } -export function deleteCI(ciId) { +export function deleteCI(ciId, isShowMessage = true) { return axios({ url: urlPrefix + `/ci/${ciId}`, - method: 'DELETE' + method: 'DELETE', + isShowMessage }) } diff --git a/cmdb-ui/src/modules/cmdb/views/ci/index.vue b/cmdb-ui/src/modules/cmdb/views/ci/index.vue index a7bf46a..1399b80 100644 --- a/cmdb-ui/src/modules/cmdb/views/ci/index.vue +++ b/cmdb-ui/src/modules/cmdb/views/ci/index.vue @@ -522,76 +522,88 @@ export default { const that = this this.$confirm({ title: '警告', - content: '确认要批量修改吗 ?', - onOk() { - that.loading = true - that.loadTip = '正在批量修改 ...' - const payload = {} - Object.keys(values).forEach((key) => { - if (values[key] || values[key] === 0) { - payload[key] = values[key] - } - // 字段值支持置空 - // 目前存在字段值不支持置空,由后端返回 - if (values[key] === undefined || values[key] === null) { - payload[key] = null - } - }) - const promises = that.selectedRowKeys.map((ciId) => { - return updateCI(ciId, payload).then((res) => { - return 'ok' - }) - }) - Promise.all(promises) - .then((res) => { - that.$message.success('批量修改成功') - that.$refs.create.visible = false - }) - .catch((e) => { - console.log(e) - }) - .finally(() => { - that.loading = false - that.loadTip = '' - that.selectedRowKeys = [] - that.$refs.xTable.getVxetableRef().clearCheckboxRow() - that.$refs.xTable.getVxetableRef().clearCheckboxReserve() - that.reloadData() - }) + content: '确认要批量修改吗?', + async onOk() { + that.batchUpdateAsync(values) }, }) }, + async batchUpdateAsync(values) { + let successNum = 0 + let errorNum = 0 + this.loading = true + this.loadTip = `正在批量修改...` + const payload = {} + Object.keys(values).forEach((key) => { + if (values[key] || values[key] === 0) { + payload[key] = values[key] + } + // 字段值支持置空 + // 目前存在字段值不支持置空,由后端返回 + if (values[key] === undefined || values[key] === null) { + payload[key] = null + } + }) + this.$refs.create.visible = false + for (let i = 0; i < this.selectedRowKeys.length; i++) { + await updateCI(this.selectedRowKeys[i], payload, false) + .then(() => { + successNum += 1 + }) + .catch((err) => { + errorNum += 1 + }) + .finally(() => { + this.loadTip = `正在批量修改,共${this.selectedRowKeys.length}个,成功${successNum}个,失败${errorNum}个` + }) + } + this.loading = false + this.loadTip = '' + this.selectedRowKeys = [] + this.$refs.xTable.getVxetableRef().clearCheckboxRow() + this.$refs.xTable.getVxetableRef().clearCheckboxReserve() + this.reloadData() + }, batchDelete() { const that = this this.$confirm({ title: '警告', content: '确认删除?', onOk() { - that.loading = true - that.loadTip = '正在删除 ...' - const promises = that.selectedRowKeys.map((ciId) => { - return deleteCI(ciId).then((res) => { - return 'ok' - }) - }) - Promise.all(promises) - .then((res) => { - that.$message.success('删除成功') - }) - .catch((e) => { - console.log(e) - }) - .finally(() => { - that.loading = false - that.loadTip = '' - that.selectedRowKeys = [] - that.$refs.xTable.getVxetableRef().clearCheckboxRow() - that.$refs.xTable.getVxetableRef().clearCheckboxReserve() - that.reloadData() - }) + that.batchDeleteAsync() }, }) }, + async batchDeleteAsync() { + let successNum = 0 + let errorNum = 0 + this.loading = true + this.loadTip = `正在删除...` + for (let i = 0; i < this.selectedRowKeys.length; i++) { + await deleteCI(this.selectedRowKeys[i], false) + .then(() => { + successNum += 1 + }) + .catch((err) => { + errorNum += 1 + }) + .finally(() => { + this.loadTip = `正在删除,共${this.selectedRowKeys.length}个,成功${successNum}个,失败${errorNum}个` + }) + } + this.loading = false + this.loadTip = '' + this.selectedRowKeys = [] + this.$refs.xTable.getVxetableRef().clearCheckboxRow() + this.$refs.xTable.getVxetableRef().clearCheckboxReserve() + this.$nextTick(() => { + if (this.currentPage === 1) { + this.loadTableData() + } else { + this.currentPage = 1 + } + }) + }, deleteCI(record) { const that = this this.$confirm({ diff --git a/cmdb-ui/src/modules/cmdb/views/tree_views/index.vue b/cmdb-ui/src/modules/cmdb/views/tree_views/index.vue index a4b705b..c65d942 100644 --- a/cmdb-ui/src/modules/cmdb/views/tree_views/index.vue +++ b/cmdb-ui/src/modules/cmdb/views/tree_views/index.vue @@ -14,16 +14,12 @@ } " class="cmdb-views-header-metadata" - > + > 属性说明 - 新建新建 {{ value }}{{ value }} 暂无数据 +
{ - return deleteCI(ciId).then((res) => { - return 'ok' - }) - }) - Promise.all(promises) - .then((res) => { - that.$message.success('删除成功!') - }) - .catch((e) => { - console.log(e) - }) - .finally(() => { - that.loading = false - that.reload() - }) + that.batchDeleteAsync() }, }) }, + async batchDeleteAsync() { + let successNum = 0 + let errorNum = 0 + this.loading = true + this.loadTip = `正在删除...` + for (let i = 0; i < this.selectedRowKeys.length; i++) { + await deleteCI(this.selectedRowKeys[i], false) + .then(() => { + successNum += 1 + }) + .catch(() => { + errorNum += 1 + }) + .finally(() => { + this.loadTip = `正在删除,共${this.selectedRowKeys.length}个,成功${successNum}个,失败${errorNum}个` + }) + } + this.loading = false + this.loadTip = '' + this.reload() + }, sumbitFromCreateInstance({ ci_id }) { this.reload() }, @@ -999,52 +1004,55 @@ export default { title: '警告', content: '确认要批量修改吗 ?', onOk() { - that.loading = true - const payload = {} - Object.keys(values).forEach((key) => { - if (values[key] || values[key] === 0) { - payload[key] = values[key] - } - // 字段值支持置空 - // 目前存在字段值不支持置空,由后端返回 - if (values[key] === undefined || values[key] === null) { - payload[key] = null - } - }) - const promises = that.selectedRowKeys.map((ciId) => { - return updateCI(ciId, payload).then((res) => { - return 'ok' - }) - }) - Promise.all(promises) - .then((res) => { - that.$message.success('批量修改成功') - }) - .catch((e) => { - console.log(e) - }) - .finally(() => { - that.loading = false - that.$refs.create.visible = false - const arr1 = that.treeViewsLevels.map((item) => item.name) - const arr2 = Object.keys(values) - const arr3 = arr1.filter((item) => { - return arr2.includes(item) - }) - if (arr3.length) { - that.reload() - return - } - setTimeout(() => { - that.handleLoadInstance() - }, 1000) - that.selectedRowKeys = [] - that.$refs.xTable.getVxetableRef().clearCheckboxRow() - that.$refs.xTable.getVxetableRef().clearCheckboxReserve() - }) + that.batchUpdateAsync(values) }, }) }, + async batchUpdateAsync(values) { + let successNum = 0 + let errorNum = 0 + this.loading = true + this.loadTip = `正在批量修改...` + const payload = {} + Object.keys(values).forEach((key) => { + if (values[key] || values[key] === 0) { + payload[key] = values[key] + } + // 字段值支持置空 + // 目前存在字段值不支持置空,由后端返回 + if (values[key] === undefined || values[key] === null) { + payload[key] = null + } + }) + this.$refs.create.visible = false + for (let i = 0; i < this.selectedRowKeys.length; i++) { + await updateCI(this.selectedRowKeys[i], payload, false) + .then(() => { + successNum += 1 + }) + .catch(() => { + errorNum += 1 + }) + .finally(() => { + this.loadTip = `正在批量修改,共${this.selectedRowKeys.length}个,成功${successNum}个,失败${errorNum}个` + }) + } + this.loading = false + this.loadTip = '' + const arr1 = this.treeViewsLevels.map((item) => item.name) + const arr2 = Object.keys(values) + const arr3 = arr1.filter((item) => { + return arr2.includes(item) + }) + if (arr3.length) { + this.reload() + return + } + this.selectedRowKeys = [] + this.$refs.xTable.getVxetableRef().clearCheckboxRow() + this.$refs.xTable.getVxetableRef().clearCheckboxReserve() + this.handleLoadInstance() + }, onShowSizeChange(current, pageSize) { this.pageSize = pageSize this.currentPage = 1