import { TOKEN_KEY } from "@/enums/cacheEnums";
import cache from "./cache";
import Cookies from "js-cookie";

// 判断是否为企微环境
const isWechatWork = () => {
  const ua = navigator.userAgent.toLowerCase();
  return ua.includes("micromessenger") && ua.includes("wxwork");
};

export function getToken() {
  if (isWechatWork()) {
    const token = Cookies.get("token");
    const obj = { expire: "", value: token };
    localStorage.setItem("app_token", JSON.stringify(obj));
    return token || "";
  } else {
    return cache.get(TOKEN_KEY) || "";
  }
}
