tools.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. /**
  2. * 常用正则表达式替换方法
  3. *
  4. * @replaceSale 月销量,超过一万的加上'w+'
  5. */
  6. // 月销量,超过一万的加上'w+'
  7. export const replaceSale = (sale) => {
  8. return sale > 10000 ? sale.replace(/\d{4}$/, 'w+') : sale
  9. }
  10. // 对象key 排序
  11. export const objKeySort = (arys) => {
  12. var newkey = Object.keys(arys).sort();
  13. var newObj = {};
  14. for (var i = 0; i < newkey.length; i++) {
  15. newObj[newkey[i]] = arys[newkey[i]];
  16. }
  17. return JSON.stringify(newObj)
  18. }
  19. // 返回并刷新指定接口
  20. export const naviBackEmit = (fun) => {
  21. uni.$emit(fun);
  22. uni.navigateBack({delta:1});
  23. }
  24. export const formatDate = (v, type) => {
  25. var date = new Date(v);
  26. const Y = date.getFullYear();
  27. const M = (date.getMonth()+1)< 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1;
  28. const D = date.getDate()< 10 ? '0'+date.getDate() : date.getDate();
  29. const h = date.getHours() < 10 ? '0'+date.getHours() : date.getHours();
  30. const m = date.getMinutes() < 10 ? '0'+date.getMinutes() : date.getMinutes();
  31. const s = date.getSeconds() < 10 ? '0'+date.getSeconds() : date.getSeconds();
  32. if (type == 'all') {
  33. return Y+'/'+M+'/'+D+' '+h+':'+m+':'+s;
  34. }
  35. return Y+'/'+M+'/'+D;
  36. }