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