index.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 === 0) {
  41. return '待付款'
  42. } else if (+val === 1) {
  43. return '待发货'
  44. } else if (+val === 2) {
  45. return '配送中'
  46. } else if (+val === 3) {
  47. return '已完成'
  48. } else if (+val === 4) {
  49. return '已取消'
  50. } else {
  51. return ''
  52. }
  53. }
  54. export const getAddressString = val => {
  55. return val ? `${val.provice}-${val.city}-${val.area}-${val.address}` : ''
  56. }
  57. export const DistanceNow = t => { // 计算动态距离现在的发布时间
  58. t = (t + '').length === 10 ? `${t}000` : t
  59. const d = Date.now() - Number(t)
  60. if (d >= 0 && d < 10800000) {
  61. return '刚刚发表'
  62. } else if (d >= 10800000 && d < 86400000) {
  63. return `${Math.floor(d / 3600000)}小时前`
  64. } else if (d >= 86400000) {
  65. return Math.floor(d / 86400000) > 9 ? formatDate(t) : `${Math.floor(d / 86400000)}天前`
  66. }
  67. }