filter.wxs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. var mathFormat = function (num) {
  2. var patt = getRegExp('\.','g');
  3. var formatnum
  4. if(!patt.test(num)){
  5. formatnum= num
  6. }else{
  7. formatnum= Number(num).toFixed(1)||'--';
  8. }
  9. return formatnum
  10. }
  11. var initItemNum = function(project,value,name) {
  12. // var specialProject=["Pj1101080259"];
  13. /* // PM2d5 不用乘 1000
  14. console.log(project,'project222');
  15. var specialProject=["VOTn11010802592ab7d57ca79b47ee95a0b9eb1cd6a902"];
  16. var falg=false;
  17. for(var i=0;i<specialProject.length;i++){
  18. if(specialProject[i]===project){
  19. falg=true;
  20. break;
  21. }
  22. }
  23. if(falg&&name==="PM2.5"&&value){
  24. value = parseInt(value*1000);
  25. }
  26. */
  27. if(name==="PM2.5"&&value){
  28. value = parseInt(value*1000);
  29. }
  30. if(name==="CO₂"&&value){
  31. value = parseInt(value);
  32. }
  33. if(name==="甲醛"&&value){
  34. value =Number(value).toFixed(2);
  35. }
  36. if(name==="湿度"&&value){
  37. value = parseInt(value);
  38. }
  39. if(name==="温度"&&value){
  40. value = Number(value).toFixed(1);
  41. }
  42. return (value||value==0)?value:'--'
  43. }
  44. /*
  45. * 导出
  46. */
  47. module.exports = {
  48. mathFormat: mathFormat,
  49. initItemNum:initItemNum
  50. }