|
@@ -8,11 +8,11 @@ import encHex from 'crypto-js/enc-hex'
|
|
|
* @param {Object} datetime
|
|
* @param {Object} datetime
|
|
|
*/
|
|
*/
|
|
|
export function formateTime(datetime) {
|
|
export function formateTime(datetime) {
|
|
|
- if (datetime == null) return ''
|
|
|
|
|
|
|
+ if (datetime === null) return ''
|
|
|
|
|
|
|
|
datetime = datetime.replace(/-/g, '/')
|
|
datetime = datetime.replace(/-/g, '/')
|
|
|
|
|
|
|
|
- let time = new Date()
|
|
|
|
|
|
|
+ const time = new Date()
|
|
|
let outTime = new Date(datetime)
|
|
let outTime = new Date(datetime)
|
|
|
if (/^[1-9]\d*$/.test(datetime)) {
|
|
if (/^[1-9]\d*$/.test(datetime)) {
|
|
|
outTime = new Date(parseInt(datetime) * 1000)
|
|
outTime = new Date(parseInt(datetime) * 1000)
|
|
@@ -20,36 +20,36 @@ export function formateTime(datetime) {
|
|
|
|
|
|
|
|
if (
|
|
if (
|
|
|
time.getTime() < outTime.getTime() ||
|
|
time.getTime() < outTime.getTime() ||
|
|
|
- time.getFullYear() != outTime.getFullYear()
|
|
|
|
|
|
|
+ time.getFullYear() === outTime.getFullYear()
|
|
|
) {
|
|
) {
|
|
|
return parseTime(outTime, '{y}-{m}-{d} {h}:{i}')
|
|
return parseTime(outTime, '{y}-{m}-{d} {h}:{i}')
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (time.getMonth() != outTime.getMonth()) {
|
|
|
|
|
|
|
+ if (time.getMonth() !== outTime.getMonth()) {
|
|
|
return parseTime(outTime, '{m}-{d} {h}:{i}')
|
|
return parseTime(outTime, '{m}-{d} {h}:{i}')
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (time.getDate() != outTime.getDate()) {
|
|
|
|
|
- let day = outTime.getDate() - time.getDate()
|
|
|
|
|
- if (day == -1) {
|
|
|
|
|
|
|
+ if (time.getDate() !== outTime.getDate()) {
|
|
|
|
|
+ const day = outTime.getDate() - time.getDate()
|
|
|
|
|
+ if (day === -1) {
|
|
|
return parseTime(outTime, '昨天 {h}:{i}')
|
|
return parseTime(outTime, '昨天 {h}:{i}')
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (day == -2) {
|
|
|
|
|
|
|
+ if (day === -2) {
|
|
|
return parseTime(outTime, '前天 {h}:{i}')
|
|
return parseTime(outTime, '前天 {h}:{i}')
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return parseTime(outTime, '{m}-{d} {h}:{i}')
|
|
return parseTime(outTime, '{m}-{d} {h}:{i}')
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- let diff = time.getTime() - outTime.getTime()
|
|
|
|
|
|
|
+ const diff = time.getTime() - outTime.getTime()
|
|
|
|
|
|
|
|
- if (time.getHours() != outTime.getHours() || diff > 30 * 60 * 1000) {
|
|
|
|
|
|
|
+ if (time.getHours() !== outTime.getHours() || diff > 30 * 60 * 1000) {
|
|
|
return parseTime(outTime, '{h}:{i}')
|
|
return parseTime(outTime, '{h}:{i}')
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
let minutes = outTime.getMinutes() - time.getMinutes()
|
|
let minutes = outTime.getMinutes() - time.getMinutes()
|
|
|
- if (minutes == 0) {
|
|
|
|
|
|
|
+ if (minutes === 0) {
|
|
|
return '刚刚'
|
|
return '刚刚'
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -63,15 +63,15 @@ export function formateTime(datetime) {
|
|
|
* @param {String} value 文件大小(字节)
|
|
* @param {String} value 文件大小(字节)
|
|
|
*/
|
|
*/
|
|
|
export function formateSize(value) {
|
|
export function formateSize(value) {
|
|
|
- if (null == value || value == '') {
|
|
|
|
|
|
|
+ if (value === null || value === '') {
|
|
|
return '0'
|
|
return '0'
|
|
|
}
|
|
}
|
|
|
- let unitArr = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
|
|
|
|
|
|
|
+ const unitArr = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
|
|
|
let index = 0
|
|
let index = 0
|
|
|
- let srcsize = parseFloat(value)
|
|
|
|
|
|
|
+ const srcsize = parseFloat(value)
|
|
|
index = Math.floor(Math.log(srcsize) / Math.log(1000))
|
|
index = Math.floor(Math.log(srcsize) / Math.log(1000))
|
|
|
let size = srcsize / Math.pow(1000, index)
|
|
let size = srcsize / Math.pow(1000, index)
|
|
|
- size = size.toFixed(2) //保留的小数位数
|
|
|
|
|
|
|
+ size = size.toFixed(2) // 保留的小数位数
|
|
|
return size + unitArr[index]
|
|
return size + unitArr[index]
|
|
|
}
|
|
}
|
|
|
/**
|
|
/**
|
|
@@ -91,19 +91,19 @@ export function getFileExt(fileName) {
|
|
|
* @param {String} name
|
|
* @param {String} name
|
|
|
*/
|
|
*/
|
|
|
export function downloadIamge(imgsrc, name) {
|
|
export function downloadIamge(imgsrc, name) {
|
|
|
- //下载图片地址和图片名
|
|
|
|
|
- let image = new Image()
|
|
|
|
|
|
|
+ // 下载图片地址和图片名
|
|
|
|
|
+ const image = new Image()
|
|
|
// 解决跨域 Canvas 污染问题
|
|
// 解决跨域 Canvas 污染问题
|
|
|
image.setAttribute('crossOrigin', 'anonymous')
|
|
image.setAttribute('crossOrigin', 'anonymous')
|
|
|
image.onload = function() {
|
|
image.onload = function() {
|
|
|
- let canvas = document.createElement('canvas')
|
|
|
|
|
|
|
+ const canvas = document.createElement('canvas')
|
|
|
canvas.width = image.width
|
|
canvas.width = image.width
|
|
|
canvas.height = image.height
|
|
canvas.height = image.height
|
|
|
- let context = canvas.getContext('2d')
|
|
|
|
|
|
|
+ const context = canvas.getContext('2d')
|
|
|
context.drawImage(image, 0, 0, image.width, image.height)
|
|
context.drawImage(image, 0, 0, image.width, image.height)
|
|
|
- let url = canvas.toDataURL('image/png') //得到图片的base64编码数据
|
|
|
|
|
- let a = document.createElement('a') // 生成一个a元素
|
|
|
|
|
- let event = new MouseEvent('click') // 创建一个单击事件
|
|
|
|
|
|
|
+ const url = canvas.toDataURL('image/png') // 得到图片的base64编码数据
|
|
|
|
|
+ const a = document.createElement('a') // 生成一个a元素
|
|
|
|
|
+ const event = new MouseEvent('click') // 创建一个单击事件
|
|
|
a.download = name || 'photo' // 设置图片名称
|
|
a.download = name || 'photo' // 设置图片名称
|
|
|
a.href = url // 将生成的URL设置为a.href属性
|
|
a.href = url // 将生成的URL设置为a.href属性
|
|
|
a.dispatchEvent(event) // 触发a的单击事件
|
|
a.dispatchEvent(event) // 触发a的单击事件
|
|
@@ -117,21 +117,21 @@ export function downloadIamge(imgsrc, name) {
|
|
|
* @param {String} imgsrc 例如图片名: D8x5f13a53dbc4b9_350x345.png
|
|
* @param {String} imgsrc 例如图片名: D8x5f13a53dbc4b9_350x345.png
|
|
|
*/
|
|
*/
|
|
|
export function getImageInfo(imgsrc) {
|
|
export function getImageInfo(imgsrc) {
|
|
|
- let data = {
|
|
|
|
|
|
|
+ const data = {
|
|
|
width: 0,
|
|
width: 0,
|
|
|
- height: 0,
|
|
|
|
|
|
|
+ height: 0
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- let arr = imgsrc.split('_')
|
|
|
|
|
- if (arr.length == 1) return data
|
|
|
|
|
|
|
+ const arr = imgsrc.split('_')
|
|
|
|
|
+ if (arr.length === 1) return data
|
|
|
|
|
|
|
|
let info = arr[arr.length - 1].match(/\d+x\d+/g)
|
|
let info = arr[arr.length - 1].match(/\d+x\d+/g)
|
|
|
- if (info == null) return data
|
|
|
|
|
|
|
+ if (info === null) return data
|
|
|
|
|
|
|
|
info = info[0].split('x')
|
|
info = info[0].split('x')
|
|
|
return {
|
|
return {
|
|
|
width: parseInt(info[0]),
|
|
width: parseInt(info[0]),
|
|
|
- height: parseInt(info[1]),
|
|
|
|
|
|
|
+ height: parseInt(info[1])
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -170,7 +170,7 @@ export function parseTime(time, cFormat) {
|
|
|
h: date.getHours(),
|
|
h: date.getHours(),
|
|
|
i: date.getMinutes(),
|
|
i: date.getMinutes(),
|
|
|
s: date.getSeconds(),
|
|
s: date.getSeconds(),
|
|
|
- a: date.getDay(),
|
|
|
|
|
|
|
+ a: date.getDay()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const time_str = format.replace(/{([ymdhisa])+}/g, (result, key) => {
|
|
const time_str = format.replace(/{([ymdhisa])+}/g, (result, key) => {
|
|
@@ -194,7 +194,7 @@ export function parseTime(time, cFormat) {
|
|
|
export function trim(str, type = null) {
|
|
export function trim(str, type = null) {
|
|
|
if (type) {
|
|
if (type) {
|
|
|
return str.replace(/(^\s*)|(\s*$)/g, '')
|
|
return str.replace(/(^\s*)|(\s*$)/g, '')
|
|
|
- } else if (type == 'l') {
|
|
|
|
|
|
|
+ } else if (type === 'l') {
|
|
|
return str.replace(/(^\s*)/g, '')
|
|
return str.replace(/(^\s*)/g, '')
|
|
|
} else {
|
|
} else {
|
|
|
return str.replace(/(\s*$)/g, '')
|
|
return str.replace(/(\s*$)/g, '')
|
|
@@ -263,7 +263,7 @@ export function toggleClass(element, className) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
let classString = element.className
|
|
let classString = element.className
|
|
|
- let nameIndex = classString.indexOf(className)
|
|
|
|
|
|
|
+ const nameIndex = classString.indexOf(className)
|
|
|
if (nameIndex === -1) {
|
|
if (nameIndex === -1) {
|
|
|
classString += '' + className
|
|
classString += '' + className
|
|
|
} else {
|
|
} else {
|
|
@@ -320,13 +320,13 @@ export function imgZoom(src, width = 200) {
|
|
|
if (info.width < width) {
|
|
if (info.width < width) {
|
|
|
return {
|
|
return {
|
|
|
width: `${info.width}px`,
|
|
width: `${info.width}px`,
|
|
|
- height: `${info.height}px`,
|
|
|
|
|
|
|
+ height: `${info.height}px`
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
return {
|
|
|
width: width + 'px',
|
|
width: width + 'px',
|
|
|
- height: parseInt(info.height / (info.width / width)) + 'px',
|
|
|
|
|
|
|
+ height: parseInt(info.height / (info.width / width)) + 'px'
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -349,7 +349,7 @@ export function getSelection() {
|
|
|
* @param {Function} callback 复制成功回调方法
|
|
* @param {Function} callback 复制成功回调方法
|
|
|
*/
|
|
*/
|
|
|
export const copyTextToClipboard = (value, callback) => {
|
|
export const copyTextToClipboard = (value, callback) => {
|
|
|
- let textArea = document.createElement('textarea')
|
|
|
|
|
|
|
+ const textArea = document.createElement('textarea')
|
|
|
textArea.style.background = 'transparent'
|
|
textArea.style.background = 'transparent'
|
|
|
textArea.value = value
|
|
textArea.value = value
|
|
|
|
|
|
|
@@ -382,13 +382,13 @@ export function hidePhone(phone) {
|
|
|
* @param {Object} datetime
|
|
* @param {Object} datetime
|
|
|
*/
|
|
*/
|
|
|
export function beautifyTime(datetime = '') {
|
|
export function beautifyTime(datetime = '') {
|
|
|
- if (datetime == null) {
|
|
|
|
|
|
|
+ if (datetime === null) {
|
|
|
return ''
|
|
return ''
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
datetime = datetime.replace(/-/g, '/')
|
|
datetime = datetime.replace(/-/g, '/')
|
|
|
|
|
|
|
|
- let time = new Date()
|
|
|
|
|
|
|
+ const time = new Date()
|
|
|
let outTime = new Date(datetime)
|
|
let outTime = new Date(datetime)
|
|
|
if (/^[1-9]\d*$/.test(datetime)) {
|
|
if (/^[1-9]\d*$/.test(datetime)) {
|
|
|
outTime = new Date(parseInt(datetime) * 1000)
|
|
outTime = new Date(parseInt(datetime) * 1000)
|
|
@@ -398,33 +398,33 @@ export function beautifyTime(datetime = '') {
|
|
|
return parseTime(outTime, '{y}/{m}/{d}')
|
|
return parseTime(outTime, '{y}/{m}/{d}')
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (time.getFullYear() != outTime.getFullYear()) {
|
|
|
|
|
|
|
+ if (time.getFullYear() !== outTime.getFullYear()) {
|
|
|
return parseTime(outTime, '{y}/{m}/{d}')
|
|
return parseTime(outTime, '{y}/{m}/{d}')
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (time.getMonth() != outTime.getMonth()) {
|
|
|
|
|
|
|
+ if (time.getMonth() !== outTime.getMonth()) {
|
|
|
return parseTime(outTime, '{m}/{d}')
|
|
return parseTime(outTime, '{m}/{d}')
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (time.getDate() != outTime.getDate()) {
|
|
|
|
|
- let day = outTime.getDate() - time.getDate()
|
|
|
|
|
- if (day == -1) {
|
|
|
|
|
|
|
+ if (time.getDate() !== outTime.getDate()) {
|
|
|
|
|
+ const day = outTime.getDate() - time.getDate()
|
|
|
|
|
+ if (day === -1) {
|
|
|
return parseTime(outTime, '昨天 {h}:{i}')
|
|
return parseTime(outTime, '昨天 {h}:{i}')
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (day == -2) {
|
|
|
|
|
|
|
+ if (day === -2) {
|
|
|
return parseTime(outTime, '前天 {h}:{i}')
|
|
return parseTime(outTime, '前天 {h}:{i}')
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return parseTime(outTime, '{m}-{d}')
|
|
return parseTime(outTime, '{m}-{d}')
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (time.getHours() != outTime.getHours()) {
|
|
|
|
|
|
|
+ if (time.getHours() !== outTime.getHours()) {
|
|
|
return parseTime(outTime, '{h}:{i}')
|
|
return parseTime(outTime, '{h}:{i}')
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
let minutes = outTime.getMinutes() - time.getMinutes()
|
|
let minutes = outTime.getMinutes() - time.getMinutes()
|
|
|
- if (minutes == 0) {
|
|
|
|
|
|
|
+ if (minutes === 0) {
|
|
|
return '刚刚'
|
|
return '刚刚'
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -458,7 +458,7 @@ export function getMutipSort(arr) {
|
|
|
|
|
|
|
|
do {
|
|
do {
|
|
|
tmp = arr[i++](a, b)
|
|
tmp = arr[i++](a, b)
|
|
|
- } while (tmp == 0 && i < arr.length)
|
|
|
|
|
|
|
+ } while (tmp === 0 && i < arr.length)
|
|
|
|
|
|
|
|
return tmp
|
|
return tmp
|
|
|
}
|
|
}
|
|
@@ -471,7 +471,7 @@ export function getMutipSort(arr) {
|
|
|
* @param {String} color 超链接颜色
|
|
* @param {String} color 超链接颜色
|
|
|
*/
|
|
*/
|
|
|
export function textReplaceLink(text, color = '#409eff') {
|
|
export function textReplaceLink(text, color = '#409eff') {
|
|
|
- let exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gi
|
|
|
|
|
|
|
+ const exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gi
|
|
|
return text.replace(
|
|
return text.replace(
|
|
|
exp,
|
|
exp,
|
|
|
`<a href='$1' target="_blank" style="color:${color};text-decoration: revert;">$1</a >`
|
|
`<a href='$1' target="_blank" style="color:${color};text-decoration: revert;">$1</a >`
|
|
@@ -490,12 +490,12 @@ export function debounce(func, wait, immediate) {
|
|
|
let timeout
|
|
let timeout
|
|
|
|
|
|
|
|
return function() {
|
|
return function() {
|
|
|
- let context = this
|
|
|
|
|
- let args = arguments
|
|
|
|
|
|
|
+ const context = this
|
|
|
|
|
+ const args = arguments
|
|
|
|
|
|
|
|
if (timeout) clearTimeout(timeout) // timeout 不为null
|
|
if (timeout) clearTimeout(timeout) // timeout 不为null
|
|
|
if (immediate) {
|
|
if (immediate) {
|
|
|
- let callNow = !timeout // 第一次会立即执行,以后只有事件执行后才会再次触发
|
|
|
|
|
|
|
+ const callNow = !timeout // 第一次会立即执行,以后只有事件执行后才会再次触发
|
|
|
timeout = setTimeout(function() {
|
|
timeout = setTimeout(function() {
|
|
|
timeout = null
|
|
timeout = null
|
|
|
}, wait)
|
|
}, wait)
|
|
@@ -521,7 +521,7 @@ export function sha256sum(file) {
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-export function hashFile (file) {
|
|
|
|
|
|
|
+export function hashFile(file) {
|
|
|
/**
|
|
/**
|
|
|
* 使用指定的算法计算hash值
|
|
* 使用指定的算法计算hash值
|
|
|
*/
|
|
*/
|
|
@@ -537,7 +537,7 @@ export function hashFile (file) {
|
|
|
/**
|
|
/**
|
|
|
* 更新文件块的hash值
|
|
* 更新文件块的hash值
|
|
|
*/
|
|
*/
|
|
|
- function hashBlob (blob) {
|
|
|
|
|
|
|
+ function hashBlob(blob) {
|
|
|
return new Promise((resolve, reject) => {
|
|
return new Promise((resolve, reject) => {
|
|
|
const reader = new FileReader()
|
|
const reader = new FileReader()
|
|
|
reader.onload = ({ target }) => {
|
|
reader.onload = ({ target }) => {
|
|
@@ -555,10 +555,15 @@ export function hashFile (file) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 同时计算文件的sha256和md5,并使用promise返回
|
|
// 同时计算文件的sha256和md5,并使用promise返回
|
|
|
|
|
+ /* return Promise.all([hashFileInternal(file, CryptoJs.algo.SHA256.create()),
|
|
|
|
|
+ hashFileInternal(file, CryptoJs.algo.MD5.create())])
|
|
|
|
|
+ .then(([sha256sum, md5sum]) => ({
|
|
|
|
|
+ sha256sum,
|
|
|
|
|
+ md5sum
|
|
|
|
|
+ }))*/
|
|
|
return Promise.all([hashFileInternal(file, CryptoJs.algo.SHA256.create()),
|
|
return Promise.all([hashFileInternal(file, CryptoJs.algo.SHA256.create()),
|
|
|
hashFileInternal(file, CryptoJs.algo.MD5.create())])
|
|
hashFileInternal(file, CryptoJs.algo.MD5.create())])
|
|
|
- .then(([sha256sum, md5sum]) => ({
|
|
|
|
|
- sha256sum,
|
|
|
|
|
- md5sum
|
|
|
|
|
- }))
|
|
|
|
|
|
|
+ .then(([sha256sum]) => ({
|
|
|
|
|
+ sha256sum
|
|
|
|
|
+ }))
|
|
|
}
|
|
}
|