tool.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import store from "@/store/index.js";
  2. import config from "@/common/config";
  3. export default {
  4. isGoLogin(isBack = true) {
  5. if (!uni.getStorageSync("seller_account")) {
  6. uni.navigateTo({
  7. url: "/pages/login/login?isBack=" + 1,
  8. });
  9. return true;
  10. } else {
  11. return false;
  12. }
  13. },
  14. isLogin() {
  15. if (uni.getStorageSync("seller_account")) {
  16. return true;
  17. } else {
  18. return false;
  19. }
  20. },
  21. //提示
  22. showToast(title, icon = "none", time = 2000) {
  23. return setTimeout(() => {
  24. uni.showToast({
  25. title: title,
  26. icon: icon,
  27. duration: time,
  28. });
  29. }, 500);
  30. },
  31. //图片路径填补
  32. splitImgHost(url, scale = false, width = 250) {
  33. if (!url) {
  34. return "";
  35. } else if (
  36. url.indexOf("http") != -1 ||
  37. url.indexOf("https") != -1 ||
  38. url.indexOf("wxfile") != -1
  39. ) {
  40. } else {
  41. url = config.BASE_IMG_URL + url;
  42. }
  43. if (scale) {
  44. url = url + "?x-oss-process=image/resize,w_" + width;
  45. }
  46. return url;
  47. },
  48. setUuid(id) {
  49. uni.setStorageSync("uuid", id);
  50. },
  51. getUuid() {
  52. return uni.getStorageSync("uuid");
  53. },
  54. exit() {
  55. uni.removeStorageSync("seller_account");
  56. uni.removeStorageSync("token");
  57. store.state.userInfo = null;
  58. uni.reLaunch({
  59. url: "/pages/index/index",
  60. });
  61. },
  62. };
  63. // 监测域名
  64. export function checkDomain(str) {
  65. let domain =
  66. /^([\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))$/;
  67. return domain.test(str);
  68. }