import store from "@/store/index.js";
import config from "@/common/config";
export default {
  isGoLogin(isBack = true) {
    if (!uni.getStorageSync("user_account")) {
      uni.navigateTo({
        url: "/pages/login/login?isBack=" + 1,
      });
      return true;
    } else {
      return false;
    }
  },
  isLogin() {
    if (uni.getStorageSync("user_account")) {
      return true;
    } else {
      return false;
    }
  },
  //提示
  showToast(title, icon = "none", time = 2000) {
    return setTimeout(() => {
      uni.showToast({
        title: title,
        icon: icon,
        duration: time,
      });
    }, 500);
  },
  //图片路径填补
  splitImgHost(url, scale = false, width = 250) {
    if (!url) {
      return "";
    } else if (
      url.indexOf("http") != -1 ||
      url.indexOf("https") != -1 ||
      url.indexOf("wxfile") != -1
    ) {
    } else {
      url = config.BASE_IMG_URL + url;
    }
    if (scale) {
      url = url + "?x-oss-process=image/resize,w_" + width;
    }
    return url;
  },
  setUuid(id) {
    uni.setStorageSync("uuid", id);
  },

  getUuid() {
    return uni.getStorageSync("uuid");
  },
  exit() {
    uni.removeStorageSync("user_account");
    uni.removeStorageSync("token");
    store.state.userInfo = null;
    uni.reLaunch({
      url: "/pages/index/index",
    });
  },
};

// 监测域名
export function checkDomain(str) {
  let domain =
    /^([\w-]+\.)+((com)|(net)|(org)|(gov\.cn)|(info)|(cc)|(com\.cn)|(net\.cn)|(org\.cn)|(name)|(biz)|(tv)|(cn)|(mobi)|(name)|(sh)|(ac)|   (io)|(tw)|(com\.tw)|(hk)|(com\.hk)|(ws)|(travel)|(us)|(tm)|(la)|(me\.uk)|(org\.uk)|(ltd\.uk)|(plc\.uk)|(in)|(eu)|(it)|(jp))$/;
  return domain.test(str);
}
