fix(mobile): focus SOP answers after search
This commit is contained in:
@@ -237,7 +237,7 @@ import {
|
||||
submitAnswerFeedback
|
||||
} from '@/services/knowledge';
|
||||
import { getSelectedPosition, getSelectedPositionProfile, isLoggedIn, rememberLoginRedirect } from '@/services/auth';
|
||||
import { resetPageScroll } from '@/services/navigation';
|
||||
import { scrollPageToSelector } from '@/services/navigation';
|
||||
import { ensureEmployeePosition } from '@/services/position';
|
||||
|
||||
const positionProfile = ref(getSelectedPositionProfile());
|
||||
@@ -315,7 +315,7 @@ const search = async () => {
|
||||
resetResultState();
|
||||
try {
|
||||
result.value = await searchKnowledge(value);
|
||||
resetPageScroll();
|
||||
scrollPageToSelector('.answer-panel');
|
||||
if (!result.value.answer && !result.value.snippets?.length) {
|
||||
message.value = '未检索到可引用内容';
|
||||
}
|
||||
|
||||
@@ -14,6 +14,37 @@ export const resetPageScroll = () => {
|
||||
setTimeout(scrollTop, 240);
|
||||
};
|
||||
|
||||
export const scrollPageToSelector = (selector: string, offset = 16) => {
|
||||
const scrollToTarget = () => {
|
||||
if (typeof window !== 'undefined' && typeof document !== 'undefined') {
|
||||
const element = document.querySelector<HTMLElement>(selector);
|
||||
if (element) {
|
||||
const scrollTop = Math.max(0, window.scrollY + element.getBoundingClientRect().top - offset);
|
||||
uni.pageScrollTo({ scrollTop, duration: 0 });
|
||||
window.scrollTo({ top: scrollTop, left: 0, behavior: 'auto' });
|
||||
document.documentElement.scrollTop = scrollTop;
|
||||
document.body.scrollTop = scrollTop;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
uni.createSelectorQuery()
|
||||
.select(selector)
|
||||
.boundingClientRect((rect) => {
|
||||
const target = Array.isArray(rect) ? rect[0] : rect;
|
||||
if (target && typeof target.top === 'number') {
|
||||
uni.pageScrollTo({ scrollTop: Math.max(0, target.top - offset), duration: 0 });
|
||||
}
|
||||
})
|
||||
.exec();
|
||||
};
|
||||
|
||||
scrollToTarget();
|
||||
setTimeout(scrollToTarget, 0);
|
||||
setTimeout(scrollToTarget, 80);
|
||||
setTimeout(scrollToTarget, 240);
|
||||
};
|
||||
|
||||
const switchToToday = () => {
|
||||
uni.switchTab({ url: '/pages/user/today/index' });
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user