1234567891011121314151617181920212223242526272829303132333435363738394041 |
- export const isDevelopment = import.meta.env.MODE === "development";
- export const getBaseUrl = (url) => {
- let cleanUrl = url.split("#")[0];
- cleanUrl = cleanUrl.replace(/([^:])\/{2,}/g, "$1/");
- const regex = /^(https?:\/\/[^\/]+(?:\/[^\/]+)*)(\/(pc|mobile))\/?.*$/;
- const match = cleanUrl.match(regex);
- if (match) {
- return match[1];
- }
- return null;
- };
- export const baseUrl = getBaseUrl(location.href);
- export const getEnvImagePath = (path) => {
- return isDevelopment
- ? "http://192.168.0.18:8080" + path
- : `${baseUrl}/base${path}`;
- };
- export function isMobile() {
- const userAgent = navigator.userAgent.toLowerCase();
- return /iphone|ipod|android|windows phone|blackberry|mobile/i.test(userAgent);
- }
- export function checkDeviceAndRedirect() {
- const isMobileDevice = isMobile();
- const currentPath = window.location.pathname;
- const isInMobilePath = currentPath.includes("/mobile/");
- const isInPCPath = currentPath.includes("/pc/");
- if (isMobileDevice && !isInMobilePath) {
- window.location.href =
- location.origin + currentPath.replace("/pc/", "/mobile/");
- } else if (!isMobileDevice && !isInPCPath) {
- window.location.href =
- location.origin + currentPath.replace("/mobile/", "/pc/");
- }
- }
|