chore: initial import
This commit is contained in:
49
utils/message-helper.js
Normal file
49
utils/message-helper.js
Normal file
@@ -0,0 +1,49 @@
|
||||
export function resolveNotificationList(response) {
|
||||
const payload = response && response.data ? response.data : response
|
||||
if (payload && Array.isArray(payload.data)) {
|
||||
return payload.data
|
||||
}
|
||||
if (payload && payload.data && Array.isArray(payload.data.data)) {
|
||||
return payload.data.data
|
||||
}
|
||||
if (Array.isArray(payload)) {
|
||||
return payload
|
||||
}
|
||||
return []
|
||||
}
|
||||
|
||||
export function resolveNotificationUnreadTotal(response) {
|
||||
const payload = response && response.data ? response.data : response
|
||||
return Number((payload && payload.total) || (payload && payload.data && payload.data.total) || 0)
|
||||
}
|
||||
|
||||
export function extractInspectionList(response) {
|
||||
const payload = response && response.data ? response.data : response
|
||||
if (Array.isArray(payload)) {
|
||||
return payload
|
||||
}
|
||||
if (payload && Array.isArray(payload.data)) {
|
||||
return payload.data
|
||||
}
|
||||
return []
|
||||
}
|
||||
|
||||
export function isPendingInspectionRecord(record) {
|
||||
return !!record && record.checkedUserAgree !== true && record.checkedUserAgree !== false
|
||||
}
|
||||
|
||||
export function countPendingInspectionRecords(list = []) {
|
||||
return (Array.isArray(list) ? list : []).filter(item => isPendingInspectionRecord(item)).length
|
||||
}
|
||||
|
||||
export function formatMessageDateTime(value) {
|
||||
if (!value) {
|
||||
return ''
|
||||
}
|
||||
const date = new Date(value)
|
||||
if (Number.isNaN(date.getTime())) {
|
||||
return String(value).replace('T', ' ').slice(0, 16)
|
||||
}
|
||||
const pad = item => String(item).padStart(2, '0')
|
||||
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}`
|
||||
}
|
||||
Reference in New Issue
Block a user