| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- export function timeFix() {
- const time = new Date()
- const hour = time.getHours()
- return hour < 9 ? '早上好' : (hour <= 11 ? '上午好' : (hour <= 13 ? '中午好' : (hour < 20 ? '下午好' : '晚上好')))
- }
- export function welcome() {
- const arr = ['休息一会儿吧', '准备吃什么呢?', '要不要打一把 DOTA', '我猜你可能累了']
- const index = Math.floor((Math.random() * arr.length))
- return arr[index]
- }
- /**
- * 触发 window.resize
- */
- export function triggerWindowResizeEvent() {
- const event = document.createEvent('HTMLEvents')
- event.initEvent('resize', true, true)
- event.eventType = 'message'
- window.dispatchEvent(event)
- }
- /**
- * 过滤对象中为空的属性
- * @param obj
- * @returns {*}
- */
- export function filterObj(obj) {
- if (!(typeof obj === 'object')) {
- return
- }
- for (const key in obj) {
- if (obj.hasOwnProperty(key) &&
- (obj[key] == null || obj[key] == undefined || obj[key] === '')) {
- delete obj[key]
- }
- }
- return obj
- }
- /**
- * 时间格式化
- * @param value
- * @param fmt
- * @returns {*}
- */
- export function formatDate(value, fmt) {
- const regPos = /^\d+(\.\d+)?$/
- if (regPos.test(value)) {
- // 如果是数字
- const getDate = new Date(value)
- const o = {
- 'M+': getDate.getMonth() + 1,
- 'd+': getDate.getDate(),
- 'h+': getDate.getHours(),
- 'm+': getDate.getMinutes(),
- 's+': getDate.getSeconds(),
- 'q+': Math.floor((getDate.getMonth() + 3) / 3),
- 'S': getDate.getMilliseconds()
- }
- if (/(y+)/.test(fmt)) {
- fmt = fmt.replace(RegExp.$1, (getDate.getFullYear() + '').substr(4 - RegExp.$1.length))
- }
- for (const k in o) {
- if (new RegExp('(' + k + ')').test(fmt)) {
- fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k]).length)))
- }
- }
- return fmt
- } else {
- // TODO
- value = value.trim()
- return value.substr(0, fmt.length)
- }
- }
|