|
|
|
@ -2,7 +2,7 @@
|
|
|
|
|
* Created by jiachenpan on 16/11/18.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
export function parseTime(time, cFormat) {
|
|
|
|
|
export function parseTime(time, cFormat) {
|
|
|
|
|
if (arguments.length === 0) {
|
|
|
|
|
return null
|
|
|
|
|
}
|
|
|
|
@ -32,9 +32,9 @@
|
|
|
|
|
return value || 0
|
|
|
|
|
})
|
|
|
|
|
return time_str
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function formatTime(time, option) {
|
|
|
|
|
export function formatTime(time, option) {
|
|
|
|
|
time = +time * 1000
|
|
|
|
|
const d = new Date(time)
|
|
|
|
|
const now = Date.now()
|
|
|
|
@ -55,10 +55,10 @@
|
|
|
|
|
} else {
|
|
|
|
|
return d.getMonth() + 1 + '月' + d.getDate() + '日' + d.getHours() + '时' + d.getMinutes() + '分'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 格式化时间
|
|
|
|
|
export function getQueryObject(url) {
|
|
|
|
|
export function getQueryObject(url) {
|
|
|
|
|
url = url == null ? window.location.href : url
|
|
|
|
|
const search = url.substring(url.lastIndexOf('?') + 1)
|
|
|
|
|
const obj = {}
|
|
|
|
@ -71,14 +71,14 @@
|
|
|
|
|
return rs
|
|
|
|
|
})
|
|
|
|
|
return obj
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*get getByteLen
|
|
|
|
|
* @param {Sting} val input value
|
|
|
|
|
* @returns {number} output value
|
|
|
|
|
*/
|
|
|
|
|
export function getByteLen(val) {
|
|
|
|
|
export function getByteLen(val) {
|
|
|
|
|
let len = 0
|
|
|
|
|
for (let i = 0; i < val.length; i++) {
|
|
|
|
|
if (val[i].match(/[^\x00-\xff]/ig) != null) {
|
|
|
|
@ -86,9 +86,9 @@
|
|
|
|
|
} else { len += 0.5 }
|
|
|
|
|
}
|
|
|
|
|
return Math.floor(len)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function cleanArray(actual) {
|
|
|
|
|
export function cleanArray(actual) {
|
|
|
|
|
const newArray = []
|
|
|
|
|
for (let i = 0; i < actual.length; i++) {
|
|
|
|
|
if (actual[i]) {
|
|
|
|
@ -96,32 +96,32 @@
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return newArray
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function param(json) {
|
|
|
|
|
export function param(json) {
|
|
|
|
|
if (!json) return ''
|
|
|
|
|
return cleanArray(Object.keys(json).map(key => {
|
|
|
|
|
if (json[key] === undefined) return ''
|
|
|
|
|
return encodeURIComponent(key) + '=' +
|
|
|
|
|
encodeURIComponent(json[key])
|
|
|
|
|
})).join('&')
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function param2Obj(url) {
|
|
|
|
|
export function param2Obj(url) {
|
|
|
|
|
const search = url.split('?')[1]
|
|
|
|
|
if (!search) {
|
|
|
|
|
return {}
|
|
|
|
|
}
|
|
|
|
|
return JSON.parse('{"' + decodeURIComponent(search).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g, '":"') + '"}')
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function html2Text(val) {
|
|
|
|
|
export function html2Text(val) {
|
|
|
|
|
const div = document.createElement('div')
|
|
|
|
|
div.innerHTML = val
|
|
|
|
|
return div.textContent || div.innerText
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function objectMerge(target, source) {
|
|
|
|
|
export function objectMerge(target, source) {
|
|
|
|
|
/* Merges two objects,
|
|
|
|
|
giving the last one precedence */
|
|
|
|
|
|
|
|
|
@ -142,9 +142,9 @@
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return target
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function scrollTo(element, to, duration) {
|
|
|
|
|
export function scrollTo(element, to, duration) {
|
|
|
|
|
if (duration <= 0) return
|
|
|
|
|
const difference = to - element.scrollTop
|
|
|
|
|
const perTick = difference / duration * 10
|
|
|
|
@ -154,9 +154,9 @@
|
|
|
|
|
if (element.scrollTop === to) return
|
|
|
|
|
scrollTo(element, to, duration - 10)
|
|
|
|
|
}, 10)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function toggleClass(element, className) {
|
|
|
|
|
export function toggleClass(element, className) {
|
|
|
|
|
if (!element || !className) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
@ -168,9 +168,9 @@
|
|
|
|
|
classString = classString.substr(0, nameIndex) + classString.substr(nameIndex + className.length)
|
|
|
|
|
}
|
|
|
|
|
element.className = classString
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const pickerOptions = [
|
|
|
|
|
export const pickerOptions = [
|
|
|
|
|
{
|
|
|
|
|
text: '今天',
|
|
|
|
|
onClick(picker) {
|
|
|
|
@ -205,15 +205,15 @@
|
|
|
|
|
}
|
|
|
|
|
}]
|
|
|
|
|
|
|
|
|
|
export function getTime(type) {
|
|
|
|
|
export function getTime(type) {
|
|
|
|
|
if (type === 'start') {
|
|
|
|
|
return new Date().getTime() - 3600 * 1000 * 24 * 90
|
|
|
|
|
} else {
|
|
|
|
|
return new Date(new Date().toDateString())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function debounce(func, wait, immediate) {
|
|
|
|
|
export function debounce(func, wait, immediate) {
|
|
|
|
|
let timeout, args, context, timestamp, result
|
|
|
|
|
|
|
|
|
|
const later = function() {
|
|
|
|
@ -246,9 +246,9 @@
|
|
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function deepClone(source) {
|
|
|
|
|
export function deepClone(source) {
|
|
|
|
|
if (!source && typeof source !== 'object') {
|
|
|
|
|
throw new Error('error arguments', 'shallowClone')
|
|
|
|
|
}
|
|
|
|
@ -264,4 +264,4 @@
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return targetObj
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|