import { useRouter } from "vue-router";
export function useGotoPage() {
	const router = useRouter();
	return (path, data, isNewTabs = true) => {
		console.log("path", path);
		if (isNewTabs) {
			// 打开新页面
			const url = new URL(window.location.origin + path);
			if (data) {
				Object.entries(data).forEach(([key, value]) => {
					url.searchParams.append(key, value);
				});
			}
			window.open(url.toString(), "_blank");
		} else {
			// 当前页面打开
			router.push({ path, query: data });
		}
	};
}
// 滚动到指定元素
export function scrollToElement(elementId) {
	document.getElementById(elementId).scrollIntoView({
		behavior: "smooth", // 平滑滚动
		block: "start" // 滚动到元素顶部
	});
}
