2024-11-17 11:45:08 +08:00
|
|
|
export const getAssetURL = (image: string) => {
|
|
|
|
// 参数一: 相对路径
|
|
|
|
// 参数二: 当前路径的URL
|
2024-12-01 13:09:44 +08:00
|
|
|
if (import.meta.client)
|
|
|
|
return new URL(`../assets/images/${image}`, import.meta.url).href
|
|
|
|
return `/_nuxt/assets/images/${image}`
|
2024-11-17 11:45:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const debounce = (fn: Function, delay: number) => {
|
|
|
|
let timeoutId: NodeJS.Timeout
|
|
|
|
return (...args: any[]) => {
|
|
|
|
clearTimeout(timeoutId)
|
|
|
|
timeoutId = setTimeout(() => {
|
|
|
|
fn(...args)
|
|
|
|
}, delay)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const setMobileTopColor = () => {
|
|
|
|
const lightMeta = document.createElement('meta');
|
|
|
|
lightMeta.setAttribute('name', 'theme-color');
|
|
|
|
lightMeta.setAttribute('media', '(prefers-color-scheme: light)');
|
|
|
|
lightMeta.setAttribute('content', '#60a5fa');
|
|
|
|
|
|
|
|
const darkMeta = document.createElement('meta');
|
|
|
|
darkMeta.setAttribute('name', 'theme-color');
|
|
|
|
darkMeta.setAttribute('media', '(prefers-color-scheme: dark)');
|
|
|
|
darkMeta.setAttribute('content', '#60a5fa');
|
|
|
|
|
|
|
|
document.head.appendChild(lightMeta);
|
|
|
|
document.head.appendChild(darkMeta);
|
|
|
|
}
|
|
|
|
|
|
|
|
export const removeMobileTopColor = () => {
|
|
|
|
document.querySelectorAll('meta[name="theme-color"]').forEach(meta => meta.remove());
|
|
|
|
}
|