123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- export function deepClone (source) {
- if (!source && typeof source !== 'object') {
- throw new Error('error arguments', 'deepClone')
- }
- const targetObj = source.constructor === Array ? [] : {}
- Object.keys(source).forEach(keys => {
- if (source[keys] && typeof source[keys] === 'object') {
- targetObj[keys] = deepClone(source[keys])
- } else {
- targetObj[keys] = source[keys]
- }
- })
- return targetObj
- }
- export const isEmpty = function (val) {
-
- if (val === null) return true
- if (typeof val === 'boolean') return false
- if (typeof val === 'number') return !val
- if (val instanceof Error) return val.message === ''
- switch (Object.prototype.toString.call(val)) {
-
- case '[object String]':
- case '[object Array]':
- return !val.length
-
- case '[object File]':
- case '[object Map]':
- case '[object Set]': {
- return !val.size
- }
-
- case '[object Object]': {
- return !Object.keys(val).length
- }
- }
- return false
- }
- export function validatePhone (phone) {
- const reg = /^[1]([3-9])[0-9]{9}$/
- return reg.test(phone)
- }
- export function getQueryString (url, name) {
- const reg = new RegExp('(^|&|/?)' + name + '=([^&|/?]*)(&|/?|$)', 'i')
- const r = url.substr(1).match(reg)
- if (r !== null) {
- return r[2]
- }
- return null
- }
- export function sortObject (property) {
- return function (obj1, obj2) {
- const value1 = obj1[property]
- const value2 = obj2[property]
- return value1 - value2
- }
- }
- export function sortDescObject (property) {
- return function (obj1, obj2) {
- const value1 = obj1[property]
- const value2 = obj2[property]
- return value2 - value1
- }
- }
- export function tmIsIneffective (status) {
- return status === '商标无效'
- }
- export function encodeParam (link, params) {
- let url = ''
- if (params && Object.keys(params).length > 0) {
- for (const k in params) {
- const value = params[k] !== undefined ? params[k] : ''
- url += '&' + k + '=' + encodeURIComponent(value)
- }
- url = url ? url.substring(1) : ''
- if (params) {
- link += (link.indexOf('?') < 0 && params ? '?' : '&') + url
- }
- }
- return link
- }
- export function parseTime(time, cFormat) {
- if (arguments.length === 0) {
- return null
- }
- const format = cFormat || '{y}-{m}-{d} {h}:{i}:{s}'
- let date
- if (typeof time === 'object') {
- date = time
- } else {
- if (('' + time).length === 10) time = parseInt(time) * 1000
- date = new Date(time)
- }
- const formatObj = {
- y: date.getFullYear(),
- m: date.getMonth() + 1,
- d: date.getDate(),
- h: date.getHours(),
- i: date.getMinutes(),
- s: date.getSeconds(),
- a: date.getDay()
- }
- const timeStr = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => {
- let value = formatObj[key]
- if (key === 'a') return ['一', '二', '三', '四', '五', '六', '日'][value - 1]
- if (result.length > 0 && value < 10) {
- value = '0' + value
- }
- return value || 0
- })
- return timeStr
- }
- export function getDate(date, AddDayCount = 0) {
- if (!date) {
- date = new Date()
- }
- if (typeof date !== 'object') {
- date = date.replace(/-/g, '/')
- }
- const dd = new Date(date)
- dd.setDate(dd.getDate() + AddDayCount)
- const y = dd.getFullYear()
- const m = dd.getMonth() + 1 < 10 ? '0' + (dd.getMonth() + 1) : dd.getMonth() + 1
- const d = dd.getDate() < 10 ? '0' + dd.getDate() : dd.getDate()
- return {
- fullDate: y + '-' + m + '-' + d,
- fullMonth: y + '-' + m,
- year: y,
- month: m,
- date: d,
- day: dd.getDay()
- }
- }
- export function checkTypes(source, type) {
- const types = {
- video: ['m3u8', 'ts', 'mp4', '3gp', 'asf', 'wmv', 'avi', 'mkv', 'rmvb', 'flv', 'mp3', 'ogg', 'amr'],
- imgs: ['png', 'jpg', 'jpeg']
- }
- if (!types[type]) return false
- const arr = source.split('.')
- return types[type].includes(arr[arr.length - 1])
- }
|