fix: welcome card flip bug

这个提交包含在:
binary-husky
2024-08-02 11:20:41 +00:00
父节点 573dc4d184
当前提交 f35f6633e0

查看文件

@@ -67,6 +67,17 @@ class WelcomeMessage {
this.card_array = []; this.card_array = [];
this.static_welcome_message_previous = []; this.static_welcome_message_previous = [];
this.reflesh_time_interval = 15*1000; this.reflesh_time_interval = 15*1000;
const reflesh_render_status = () => {
for (let index = 0; index < this.card_array.length; index++) {
const card = this.card_array[index];
card.classList.remove('hide');
card.classList.remove('show');
}
};
const pageFocusHandler = new PageFocusHandler();
pageFocusHandler.addFocusCallback(reflesh_render_status);
} }
begin_render() { begin_render() {
@@ -106,8 +117,12 @@ class WelcomeMessage {
} }
const card = this.card_array[index]; const card = this.card_array[index];
card.classList.remove('hide'); // 已经包含了 hide 属性?
card.classList.remove('show'); if (card.classList.contains('hide') || card.classList.contains('show')) {
card.classList.remove('hide');
card.classList.remove('show');
continue;
}
// 等待动画结束 // 等待动画结束
card.addEventListener('transitionend', () => { card.addEventListener('transitionend', () => {
@@ -158,7 +173,7 @@ class WelcomeMessage {
} }
async update() { async update() {
console.log('update') // console.log('update')
var page_width = document.documentElement.clientWidth; var page_width = document.documentElement.clientWidth;
const width_to_hide_welcome = 1200; const width_to_hide_welcome = 1200;
if (!await this.isChatbotEmpty() || page_width < width_to_hide_welcome) { if (!await this.isChatbotEmpty() || page_width < width_to_hide_welcome) {
@@ -269,3 +284,34 @@ class WelcomeMessage {
} }
class PageFocusHandler {
constructor() {
this.hasReturned = false;
this.focusCallbacks = [];
// Bind the focus and blur event handlers
window.addEventListener('visibilitychange', this.handleFocus.bind(this));
}
// Method to handle the focus event
handleFocus() {
if (this.hasReturned) {
this.focusCallbacks.forEach(callback => callback());
}
this.hasReturned = true;
}
// Method to add a custom callback function
addFocusCallback(callback) {
if (typeof callback === 'function') {
this.focusCallbacks.push(callback);
} else {
throw new Error('Callback must be a function');
}
}
}