From bfb979591374ca529711edc9e71f6e11853e1ea2 Mon Sep 17 00:00:00 2001 From: kuaifan Date: Thu, 10 Apr 2025 16:48:35 +0800 Subject: [PATCH] no message --- resources/assets/js/functions/common.js | 54 +++++++++++++++++++ .../pages/manage/components/DialogWrapper.vue | 7 +++ 2 files changed, 61 insertions(+) diff --git a/resources/assets/js/functions/common.js b/resources/assets/js/functions/common.js index 2ad97a315..bcbc50fab 100755 --- a/resources/assets/js/functions/common.js +++ b/resources/assets/js/functions/common.js @@ -1343,6 +1343,60 @@ const timezone = require("dayjs/plugin/timezone"); } throw new Error('等待条件超时'); + }, + + /** + * 执行指定次数的定时任务,返回一个可以取消的对象 + * @param {Function} fn 要执行的函数 + * @param {number} interval 间隔时间(毫秒) + * @param {number} times 执行次数 + * @returns {object} 包含 clear 方法的对象 + */ + repeatWithCount(fn, interval, times) { + if (typeof fn !== 'function') { + return () => {}; // 返回空函数而不是null,保持返回类型一致 + } + + if (interval < 0 || times < 0) { + return () => {}; // 返回空函数 + } + + let count = 0; + let timer = null; + + const clear = () => { + if (timer) { + clearTimeout(timer); + timer = null; + } + }; + + const execute = () => { + if (count >= times) { + clear(); + return; + } + + try { + if (fn(count) === true) { + clear(); + return; + } + } catch (error) { + clear(); + console.error('Error in callback function:', error); + return; + } + + count++; + timer = setTimeout(execute, interval); + }; + + // 立即开始第一次执行 + timer = setTimeout(execute, 0); + + // 直接返回clear函数 + return clear; } }); diff --git a/resources/assets/js/pages/manage/components/DialogWrapper.vue b/resources/assets/js/pages/manage/components/DialogWrapper.vue index 9c90a836f..907ce76f3 100644 --- a/resources/assets/js/pages/manage/components/DialogWrapper.vue +++ b/resources/assets/js/pages/manage/components/DialogWrapper.vue @@ -2356,6 +2356,13 @@ export default { this.focusTimer && clearTimeout(this.focusTimer) this.focusLazy = true this.$emit("on-focus") + // + if ($A.isIos()) { + this.tempRepeat && this.tempRepeat() + this.tempRepeat = $A.repeatWithCount(() => { + this.$refs.footer.scrollIntoView({block: 'end'}) + }, 50, 10) + } }, onEventBlur() {