diff --git a/frontend/src/business/components/common/components/table/MsTable.vue b/frontend/src/business/components/common/components/table/MsTable.vue index c57b0a0d7b..61a4add24d 100644 --- a/frontend/src/business/components/common/components/table/MsTable.vue +++ b/frontend/src/business/components/common/components/table/MsTable.vue @@ -328,7 +328,9 @@ export default { } }, doLayout() { - setTimeout(this.$refs.table.doLayout(), 200); + if (this.$refs.table) { + setTimeout(this.$refs.table.doLayout(), 200); + } }, filter(filters) { _filter(filters, this.condition); diff --git a/frontend/src/business/components/track/case/components/FormRichTextItem.vue b/frontend/src/business/components/track/case/components/FormRichTextItem.vue index c984cc593a..8371d4379c 100644 --- a/frontend/src/business/components/track/case/components/FormRichTextItem.vue +++ b/frontend/src/business/components/track/case/components/FormRichTextItem.vue @@ -78,13 +78,15 @@ export default { mounted() { // 点击编辑,失去焦点展示 let el = document.getElementById(this.id); - el.addEventListener('click', () => { - this.defaultOpen = null; - }); - let input = el.getElementsByClassName('auto-textarea-input'); - input[0].addEventListener('blur', () => { - this.defaultOpen = 'preview'; - }); + if (el) { + el.addEventListener('click', () => { + this.defaultOpen = null; + }); + let input = el.getElementsByClassName('auto-textarea-input'); + input[0].addEventListener('blur', () => { + this.defaultOpen = 'preview'; + }); + } }, methods: { imgAdd(pos, file){ diff --git a/frontend/src/common/js/tableUtils.js b/frontend/src/common/js/tableUtils.js index 4084237f2a..9e9a9cc9fe 100644 --- a/frontend/src/common/js/tableUtils.js +++ b/frontend/src/common/js/tableUtils.js @@ -1,4 +1,4 @@ -import {getCurrentProjectID, getCurrentUser, humpToLine} from "@/common/js/utils"; +import {getCurrentProjectID, getCurrentUser, getUUID, humpToLine} from "@/common/js/utils"; import {CUSTOM_TABLE_HEADER} from "@/common/js/default-table-header"; import {updateCustomFieldTemplate} from "@/network/custom-field-template"; import i18n from "@/i18n/i18n"; @@ -529,10 +529,20 @@ export function getCustomFieldBatchEditOption(customFields, typeArr, valueArr, m export function handleRowDrop(data, callback) { setTimeout(() => { const tbody = document.querySelector('.el-table__body-wrapper tbody'); + const dropBars = tbody.getElementsByClassName('table-row-drop-bar'); + + // 每次调用生成一个class + // 避免增删列表数据时,回调函数中的 data 与实际 data 不一致 + let dropClass = 'table-row-drop-bar-random' + '_' + getUUID(); + + dropBars.forEach(dropBar => { + dropBar.classList.add(dropClass); + }); + Sortable.create(tbody, { - handle: ".table-row-drop-bar", + handle: "." + dropClass, animation: 100, - onEnd({ newIndex, oldIndex }) { + onEnd({ newIndex, oldIndex}) { let param = {}; param.moveId = data[oldIndex].id; if (newIndex === 0) { @@ -543,10 +553,12 @@ export function handleRowDrop(data, callback) { param.moveMode = 'AFTER'; param.targetId = data[newIndex].id; } - const currRow = data.splice(oldIndex, 1)[0]; - data.splice(newIndex, 0, currRow); - if (callback) { - callback(param); + if (data && data.length > 1) { + const currRow = data.splice(oldIndex, 1)[0]; + data.splice(newIndex, 0, currRow); + if (callback) { + callback(param); + } } } });