useTools.js 879 B

123456789101112131415161718192021222324252627282930313233343536
  1. import { format } from '@/utils';
  2. function useTool() {
  3. // 处理消息时间显示
  4. function handleTime(index, list) {
  5. //第一条消息展示 && 两条消息的间隔时间超过10分钟则显示
  6. const { indate } = list[index]
  7. if (index >= 1) {
  8. const { indate: old_indate } = list[index - 1]
  9. if((Number(indate) - Number(old_indate)) >= 10 * 60){
  10. return handleBetterTimeShow(Number(indate * 1000))
  11. }
  12. }
  13. else {
  14. return handleBetterTimeShow(Number(indate * 1000))
  15. }
  16. }
  17. // 处理时间显示格式
  18. function handleBetterTimeShow(value) {
  19. // 今天的消息显示hh:mm 其余的显示yyyy-MM-dd hh:mm
  20. if(format(new Date(value), 'yyyy-MM-dd') === format(new Date(), 'yyyy-MM-dd')){
  21. return format(new Date(value), 'HH:mm')
  22. }
  23. return format(new Date(value), 'yyyy-MM-dd HH:mm')
  24. }
  25. return {
  26. handleTime
  27. }
  28. }
  29. export default useTool