util.js 861 B

1234567891011121314151617181920212223242526272829
  1. import env from '@/config/env.js';
  2. export function formatTime(time, format = 'yyyy年MM月dd日') {
  3. const date = new Date(time)
  4. const formatObj = {
  5. 'y+': date.getFullYear(),
  6. 'M+': date.getMonth() + 1,
  7. 'd+': date.getDate(),
  8. 'H+': date.getHours(),
  9. 'm+': date.getMinutes(),
  10. 's+': date.getSeconds()
  11. }
  12. for (let key in formatObj) {
  13. if (new RegExp(`(${key})`).test(format)) {
  14. const str = formatObj[key].toString()
  15. format = format.replace(RegExp.$1,
  16. RegExp.$1.length === 1 ? str :
  17. ('00' + str).slice(str.length)
  18. )
  19. }
  20. }
  21. return format
  22. }
  23. export function getImageUrl(path) {
  24. return env.baseUrl + '/service?ssServ=dlByHttp&wdConfirmationCaptchaService=0&type=img&path=' + path;
  25. }