utils.js 911 B

12345678910111213141516171819202122232425
  1. export const isDevelopment = import.meta.env.MODE === "development";
  2. export const getEnvImagePath = (path) => {
  3. return isDevelopment
  4. ? "http://192.168.0.18:8080" + path
  5. : `${window.origin}/project/yz-enamel-exhibition/base${path}`;
  6. };
  7. export function isMobile() {
  8. const userAgent = navigator.userAgent.toLowerCase();
  9. return /iphone|ipod|android|windows phone|blackberry|mobile/i.test(userAgent);
  10. }
  11. export function checkDeviceAndRedirect() {
  12. const isMobileDevice = isMobile();
  13. const currentPath = window.location.pathname;
  14. const isInMobilePath = currentPath.includes("/mobile/");
  15. const isInPCPath = currentPath.includes("/pc/");
  16. if (isMobileDevice && !isInMobilePath) {
  17. window.location.href = currentPath.replace("/pc/", "/mobile/");
  18. } else if (!isMobileDevice && !isInPCPath) {
  19. window.location.href = currentPath.replace("/mobile/", "/pc/");
  20. }
  21. }