import { ref } from 'vue';
|
import { clearMobileScroll } from './scroll';
|
export type TerminalType = 'pc' | 'mobile';
|
const KEY = 'mom-terminal';
|
function initial(): TerminalType {
|
const stored = sessionStorage.getItem(KEY);
|
return stored === 'pc' || stored === 'mobile' ? stored : (window.innerWidth < 768 ? 'mobile' : 'pc');
|
}
|
export const terminalType = ref<TerminalType>(initial());
|
export function selectTerminal(value: TerminalType) {
|
terminalType.value = value;
|
sessionStorage.setItem(KEY, value);
|
}
|
export function resetTerminal() {
|
clearMobileScroll();
|
sessionStorage.removeItem(KEY);
|
for (const key of Object.keys(sessionStorage)) {
|
if (key.startsWith('mom-mobile-')) sessionStorage.removeItem(key);
|
}
|
terminalType.value = window.innerWidth < 768 ? 'mobile' : 'pc';
|
}
|
export function terminalHome() { return terminalType.value === 'mobile' ? '/mobile/home' : undefined; }
|
export function safeDestination(path: unknown, fallback: string) {
|
if (typeof path !== 'string') return fallback;
|
let decoded: string;
|
try { decoded = decodeURIComponent(path); } catch { return fallback; }
|
if (!decoded.startsWith('/') || decoded.startsWith('//') || decoded.includes('\\') || decoded.startsWith('/auth')) return fallback;
|
return decoded.startsWith('/mobile/') === (terminalType.value === 'mobile') ? decoded : fallback;
|
}
|