58 lines
1.4 KiB
JavaScript
58 lines
1.4 KiB
JavaScript
|
|
/**
|
||
|
|
* 存储localStorage
|
||
|
|
*/
|
||
|
|
export const setStore = (name, content) => {
|
||
|
|
if (!name) return
|
||
|
|
if (typeof content !== 'string') {
|
||
|
|
content = JSON.stringify(content)
|
||
|
|
}
|
||
|
|
window.localStorage.setItem(name, content)
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 获取localStorage
|
||
|
|
*/
|
||
|
|
export const getStore = name => {
|
||
|
|
if (!name) return
|
||
|
|
return window.localStorage.getItem(name)
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* yy-mm-dd
|
||
|
|
*/
|
||
|
|
export const dateFtt = date => {
|
||
|
|
if (date == null) {
|
||
|
|
return ''
|
||
|
|
}
|
||
|
|
let year = date.getFullYear()
|
||
|
|
let month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1
|
||
|
|
let day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate()
|
||
|
|
return `${year}-${month}-${day}`
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* yy-mm-dd hh:mm:ss
|
||
|
|
*/
|
||
|
|
export const dateTimeFtt = date => {
|
||
|
|
if (date == null) {
|
||
|
|
return ''
|
||
|
|
}
|
||
|
|
let year = date.getFullYear()
|
||
|
|
let month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1
|
||
|
|
let day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate()
|
||
|
|
let hh = date.getHours() < 10 ? '0' + date.getHours() : date.getHours()
|
||
|
|
let mm = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()
|
||
|
|
let ss = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
|
||
|
|
return `${year}-${month}-${day} ${hh}:${mm}:${ss}`
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 将字符串形式的日期转换成日期对象
|
||
|
|
*/
|
||
|
|
export const dateNew = date => {
|
||
|
|
if (date === undefined || date === 'undefined') {
|
||
|
|
return new Date()
|
||
|
|
}
|
||
|
|
return new Date(Date.parse(date))
|
||
|
|
}
|