utils.ts 992 Bytes
Newer Older
duanledexianxianxian's avatar
duanledexianxianxian committed
1 2
import store from '@/utils/store';

3
/* eslint no-useless-escape:0 import/prefer-default-export:0 */
4
const reg = /(((^https?:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(?::\d+)?|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)$/;
5

6
const isUrl = (path: string): boolean => reg.test(path);
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
7

duanledexianxianxian's avatar
duanledexianxianxian committed
8 9 10
/**
 * ๆ˜ฏๅฆไธบantd design pro
 */
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
11
const isAntDesignPro = (): boolean => {
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
12 13 14
  if (ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION === 'site') {
    return true;
  }
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
15
  return window.location.hostname === 'preview.pro.ant.design';
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
16
};
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
17 18

// ็ป™ๅฎ˜ๆ–นๆผ”็คบ็ซ™็‚น็”จ๏ผŒ็”จไบŽๅ…ณ้—ญ็œŸๅฎžๅผ€ๅ‘็Žฏๅขƒไธ้œ€่ฆไฝฟ็”จ็š„็‰นๆ€ง
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
19
const isAntDesignProOrDev = (): boolean => {
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
20
  const { NODE_ENV } = process.env;
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
21 22 23
  if (NODE_ENV === 'development') {
    return true;
  }
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
24
  return isAntDesignPro();
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
25 26
};

duanledexianxianxian's avatar
duanledexianxianxian committed
27 28 29 30 31 32
const clearLoginStatus = () => {
  store.set('token', '');
  store.set('userId', '');
};

export { isAntDesignProOrDev, isAntDesignPro, isUrl, clearLoginStatus };