index.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import { formatTimestamp } from '@/common/util/utils'
  2. export const getYear = value => { //时间戳转年份过滤器
  3. return formatTimestamp(+value)[0]
  4. }
  5. export const getMonth = value => { //时间戳转月份过滤器
  6. const month = formatTimestamp(+value)[1] + ''
  7. return month.length === 1 ? '0' + month : month //月份只有一位数字时补零
  8. }
  9. export const getDay = value => { //时间戳转周过滤器
  10. return formatTimestamp(+value)[2]
  11. }
  12. export const getDate = value => { //时间戳转 日 过滤器
  13. const date = formatTimestamp(+value)[3] + ''
  14. return date.length === 1 ? '0' + date : date //日期份只有一位数字时补零
  15. }
  16. export const getHousr = value => { //时间戳转 时 过滤器
  17. const hour = formatTimestamp(+value)[4] + ''
  18. return hour.length === 1 ? '0' + hour : hour // 小时只有一位时补零
  19. }
  20. export const getMinute = value => { //时间戳转 分 过滤器
  21. const minute = formatTimestamp(+value)[5] + ''
  22. return minute.length === 1 ? '0' + minute : minute // 分钟只有一位时补零
  23. }
  24. export const getSecond = value => { //时间戳转 秒 过滤器
  25. return formatTimestamp(+value)[6]
  26. }
  27. export const formatTime = value => { //格式化时间
  28. return `${getYear(value)}-${getMonth(value)}-${getDate(value)} ${getHousr(value)}:${getMinute(value)}`
  29. }
  30. export const formatDate = value => { //格式化日期
  31. return `${getYear(value)}-${getMonth(value)}-${getDate(value)}`
  32. }
  33. export const formatHourMin = value => { //格式化时分
  34. return `${getHousr(value)}:${getMinute(value)}`
  35. }
  36. export const numDot = num => {
  37. return (num + '').replace(/(?=(?:\d{3})+(?!\d))/g, ',').replace(/^,/, '') || ''
  38. }
  39. export const getOrderStatus = val => {
  40. if (val) {
  41. if (+val === 0) {
  42. return '待付款'
  43. } else if (+val === 1) {
  44. return '待发货'
  45. } else if (+val === 2) {
  46. return '配送中'
  47. } else if (+val === 3) {
  48. return '已完成'
  49. } else if (+val === 4) {
  50. return '已取消'
  51. }
  52. } else {
  53. return ''
  54. }
  55. }
  56. export const getAddressString = val => {
  57. return val.provice ? `${val.provice}-${val.city}-${val.area}-${val.address}` : ''
  58. }
  59. export const DistanceNow = t => { // 计算动态距离现在的发布时间
  60. t = (t + '').length === 10 ? `${t}000` : t
  61. const d = Date.now() - Number(t)
  62. if (d >= 0 && d < 10800000) {
  63. return '刚刚发表'
  64. } else if (d >= 10800000 && d < 86400000) {
  65. return `${Math.floor(d / 3600000)}小时前`
  66. } else if (d >= 86400000) {
  67. return Math.floor(d / 86400000) > 9 ? formatDate(t) : `${Math.floor(d / 86400000)}天前`
  68. }
  69. }