diff --git a/resources/assets/js/functions/common.js b/resources/assets/js/functions/common.js index 0dfa3f2ec..beb99a7d9 100755 --- a/resources/assets/js/functions/common.js +++ b/resources/assets/js/functions/common.js @@ -1082,13 +1082,14 @@ const timezone = require("dayjs/plugin/timezone"); /** * 滚动到元素并抖动 * @param element + * @param viewIfNeeded */ - scrollIntoAndShake(element) { + scrollIntoAndShake(element, viewIfNeeded = true) { if (!element) return; const elements = Array.isArray(element) ? element : [element]; elements.forEach(el => { if (el) { - $A.scrollIntoViewIfNeeded(el); + viewIfNeeded && $A.scrollIntoViewIfNeeded(el); $A.addClassWithTimeout(el, "common-shake", 800); } }); @@ -1300,6 +1301,28 @@ const timezone = require("dayjs/plugin/timezone"); item === arr2[arr2.length - arr1.length + index] ).length)); }, + + /** + * 查找元素并在失败时重试 + * @param {Function} findElementFn - 查找元素的函数 + * @param {number} maxAttempts - 最大尝试次数 + * @param {number} delayMs - 每次尝试之间的延迟(毫秒) + * @returns {Promise<*>} + */ + async findElementWithRetry(findElementFn, maxAttempts = 3, delayMs = 500) { + for (let attempt = 1; attempt <= maxAttempts; attempt++) { + const element = findElementFn(); + + if (element) { + return element; + } + + if (attempt < maxAttempts) { + await new Promise(resolve => setTimeout(resolve, delayMs)); + } + } + throw new Error(`Element not found after ${maxAttempts} attempts`); + } }); /** diff --git a/resources/assets/js/pages/manage/components/DialogWrapper.vue b/resources/assets/js/pages/manage/components/DialogWrapper.vue index 75ccba9a3..b62cc8fd5 100644 --- a/resources/assets/js/pages/manage/components/DialogWrapper.vue +++ b/resources/assets/js/pages/manage/components/DialogWrapper.vue @@ -1487,8 +1487,7 @@ export default { msgActiveId(val) { if (val > 0) { this.msgActiveId = 0 - const element = this.$refs.scroller.$el.querySelector(`[data-id="${val}"]`)?.querySelector(".dialog-head") - $A.scrollIntoAndShake(element) + this.shakeToMsgId(val) } }, @@ -2650,6 +2649,8 @@ export default { msg_id: this.msgId, msg_type: this.msgType, clear_before: true + }).then(_ => { + this.onToBottom() }).catch(_ => {}) }, @@ -4382,6 +4383,15 @@ export default { $A.messageError(msg); }); }, + + async shakeToMsgId(id) { + try { + const element = await $A.findElementWithRetry(() => this.$refs.scroller.$el.querySelector(`[data-id="${id}"]`)?.querySelector(".dialog-head")); + $A.scrollIntoAndShake(element, false) + } catch (e) { + // console.log(e) + } + } } }