index.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. var sceneReadyBehavior = require('../../behavior-scene/scene-ready');
  2. var handleDecodedXML = require('../../behavior-scene/util').handleDecodedXML;
  3. var xmlCode = `;`;
  4. Page({
  5. behaviors:[sceneReadyBehavior],
  6. data: {
  7. xmlCode: '',
  8. capacity: 0,
  9. emitRate: 0,
  10. lifeTime: 0,
  11. },
  12. calc: function(variable, add = true, number=1){
  13. var temp = variable;
  14. var result = temp;
  15. var count = 1;
  16. while(Math.floor(temp/10)){
  17. count++;
  18. temp = Math.floor(temp/10);
  19. }
  20. if(add){
  21. result += number * Math.pow(10, count-1);
  22. }else{
  23. if(result<=number * Math.pow(10,count-1)){
  24. count--;
  25. if(count < 1 ){
  26. count = 1;
  27. }
  28. }
  29. result -= number * Math.pow(10, count-1);
  30. if(result < 0 ){
  31. result = 0;
  32. }
  33. }
  34. return Number(result.toFixed(1));
  35. },
  36. handleAdd: function() {
  37. this.setData({capacity:this.calc(this.data.capacity, true)});
  38. },
  39. handleSub: function() {
  40. this.setData({capacity:this.calc(this.data.capacity, false)});
  41. },
  42. handleRateAdd: function() {
  43. this.setData({emitRate:this.calc(this.data.emitRate, true)});
  44. },
  45. handleRateSub: function() {
  46. this.setData({emitRate:this.calc(this.data.emitRate, false)});
  47. },
  48. handleTimeAdd: function() {
  49. this.setData({lifeTime:this.calc(this.data.lifeTime, true, 0.1)});
  50. },
  51. handleTimeSub: function() {
  52. this.setData({lifeTime:this.calc(this.data.lifeTime, false, 0.1)});
  53. }
  54. });