utils.js 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. import { parse } from 'querystring'
  2. import dayjs from 'dayjs'
  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. export const isUrl = path => reg.test(path)
  6. export const isAntDesignPro = () => {
  7. if (ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION === 'site') {
  8. return true
  9. }
  10. return window.location.hostname === 'preview.pro.ant.design'
  11. } // 给官方演示站点用,用于关闭真实开发环境不需要使用的特性
  12. export const isAntDesignProOrDev = () => {
  13. const { NODE_ENV } = process.env
  14. if (NODE_ENV === 'development') {
  15. return true
  16. }
  17. return isAntDesignPro()
  18. }
  19. export const getPageQuery = () => parse(window.location.href.split('?')[1])
  20. /**
  21. * 日期格式化
  22. * @param format - 格式
  23. */
  24. export const dayjsFormat = (date, format = 'YYYY-MM-DD HH:mm:ss') => {
  25. if (date === "0001-01-01 00:00:00" || !date) return ''
  26. return dayjs(date).format(format)
  27. }