123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- import dayjs from 'dayjs'
- import numeral from 'numeral'
- import Cookies from 'js-cookie'
- import { state as helpState } from './helpState'
- export const browser = () => {
- const u = navigator.userAgent
-
- return {
- trident: u.indexOf('Trident') > -1,
- presto: u.indexOf('Presto') > -1,
- webKit: u.indexOf('AppleWebKit') > -1,
- gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1,
- mobile: !!u.match(/AppleWebKit.*Mobile.*/),
- ios: !!u.match(/Mac OS X/),
-
- android: u.indexOf('COLEXIUAPPA') > -1 || u.indexOf('Adr') > -1,
- iPhone: u.indexOf('COLEXIUAPPI') > -1,
- isApp:
- u.indexOf('COLEXIUAPPI') > -1 ||
- u.indexOf('COLEXIUAPPA') > -1 ||
- u.indexOf('Adr') > -1,
- iPad: u.indexOf('iPad') > -1,
- webApp: u.indexOf('Safari') == -1,
- weixin: u.indexOf('MicroMessenger') > -1,
- huawei: !!u.match(/huawei/i) || !!u.match(/honor/i),
- xiaomi: !!u.match(/mi\s/i) || !!u.match(/redmi/i) || !!u.match(/mix/i)
- }
- }
- export const getRandomKey = () => {
- const key = '' + new Date().getTime() + Math.floor(Math.random() * 1000000)
- return key
- }
- export const removeAuth = () => {
- Cookies.remove('token')
- }
- export const setAuth = (token: any) => {
-
- Cookies.set('token', token, { expires: 7 })
- }
- export const getAuth = () => {
- let token = Cookies.get('token')
- token = token ? JSON.parse(token) : {}
- return token.token || null
- }
- export const getUserType = () => {
- let token = Cookies.get('token')
- token = token ? JSON.parse(token) : {}
- return token.userType || null
- }
- export const getWeekCh = (week: number, type = 0) => {
- const template = ['周日', '周一', '周二', '周三', '周四', '周五', '周六']
- const template2 = [
- '星期天',
- '星期一',
- '星期二',
- '星期三',
- '星期四',
- '星期五',
- '星期六'
- ]
- return type ? template2[week] : template[week]
- }
- export const formatterDate = (type: string, val: any) => {
- if (type === 'year') {
- return `${val}年`
- }
- if (type === 'month') {
- return `${val}月`
- }
- if (type === 'day') {
- return `${val}日`
- }
- if (type === 'hour') {
- return `${val}时`
- }
- if (type === 'minute') {
- return `${val}分`
- }
- return val
- }
- export const moneyFormat = (value: number) => {
- return numeral(value).format('0,0.00')
- }
- export const dateFormat = (
- value: string | Date,
- format = 'YYYY-MM-DD HH:mm:ss'
- ) => {
- return dayjs(value).format(format)
- }
|