| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- import { parse } from 'querystring'
- import dayjs from 'dayjs'
- /* eslint no-useless-escape:0 import/prefer-default-export:0 */
- const reg =
- /(((^https?:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(?::\d+)?|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)$/
- export const isUrl = path => reg.test(path)
- export const isAntDesignPro = () => {
- if (ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION === 'site') {
- return true
- }
- return window.location.hostname === 'preview.pro.ant.design'
- } // 给官方演示站点用,用于关闭真实开发环境不需要使用的特性
- export const isAntDesignProOrDev = () => {
- const { NODE_ENV } = process.env
- if (NODE_ENV === 'development') {
- return true
- }
- return isAntDesignPro()
- }
- export const getPageQuery = () => parse(window.location.href.split('?')[1])
- /**
- * 日期格式化
- * @param format - 格式
- */
- export const dayjsFormat = (date, format = 'YYYY-MM-DD HH:mm:ss') => {
- if (date === '0001-01-01 00:00:00' || !date) return ''
- return dayjs(date).format(format)
- }
- /** 处理表格排序字段 */
- export const refactorSortField = sort => {
- if (!sort) return {}
- // 处理后的排序,格式{ field: 'xxxxx', order: 'desc/asc' }
- const s = { field: null, order: null }
- const keys = Object.keys(sort)
- const orKey = keys[0]
- if (orKey) {
- s.field = orKey
- s.order = sort[orKey].replace('end', '')
- return s
- }
- return {}
- }
- /** 处理表格中的筛选(特殊情况) */
- export const refactorFilterField = filter => {
- if (!filter) return {}
- const keys = Object.keys(filter)
- const nFiter = { ...filter }
- const district = keys.find(item => item.startsWith('district'))
- if (district?.length) {
- const [province = null, city = null, area = null] = filter[district] || []
- nFiter.province = province
- nFiter.city = city
- nFiter.area = area
- delete nFiter[district]
- }
- return nFiter
- }
- // 可控长度的随机数拼接时间戳成产唯一id
- export const createUid = length =>
- Number(Math.random().toString().substr(3, length) + Date.now()).toString(36)
|