jybms.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. var params = require('./params.js');
  2. var http = require('./http.js');
  3. var jybms_url = params.jybms_url;
  4. function login(login_name, callBack, login_password = 123456) {
  5. var url =
  6. jybms_url + '/GetDateServices.asmx/loginSystem?LoginName=' + login_name + '&LoginPassword=' + login_password + '&LoginType=USER&language=en&ISMD5=0&timeZone=+08&apply=APP';
  7. uni.request({
  8. header: {
  9. 'content-type': 'application/x-www-form-urlencoded; charset=UTF-8'
  10. },
  11. url: url,
  12. method: 'GET',
  13. success: function (res) {
  14. if (res.data.success != 'false' && res.data.errorCode == 200) {
  15. callBack(res.data);
  16. }
  17. }
  18. });
  19. }
  20. function bmsRefresh(macid, callBack) {
  21. login(macid, (loginInfo) => {
  22. var url = jybms_url + '/GetDataService.aspx?method=SupplyBatteryInfo&work=6&cmd=BMS_REFRESH&macid=' + macid;
  23. uni.request({
  24. header: {
  25. 'content-type': 'application/x-www-form-urlencoded; charset=UTF-8'
  26. },
  27. url: url,
  28. method: 'GET',
  29. success: (res) => {
  30. callBack(loginInfo);
  31. }
  32. });
  33. });
  34. }
  35. function bmsState(macid, callBack) {
  36. bmsRefresh(macid, (loginInfo) => {
  37. var url = jybms_url + '/GetDateServices.asmx/GetDate?method=BMSrealTimeState&mds=' + loginInfo.mds + '&macid=' + macid;
  38. uni.request({
  39. header: {
  40. 'content-type': 'application/x-www-form-urlencoded; charset=UTF-8'
  41. },
  42. url: url,
  43. method: 'GET',
  44. success: function (res) {
  45. if (res.data.success != 'false' && res.data.errorCode == 200) {
  46. callBack(res.data.data);
  47. }
  48. }
  49. });
  50. setTimeout(() => {
  51. uni.request({
  52. header: {
  53. 'content-type': 'application/x-www-form-urlencoded; charset=UTF-8'
  54. },
  55. url: url,
  56. method: 'GET',
  57. success: function (res) {
  58. if (res.data.success != 'false' && res.data.errorCode == 200) {
  59. callBack(res.data.data);
  60. }
  61. }
  62. });
  63. }, 5000);
  64. });
  65. }
  66. module.exports = {
  67. bmsState: bmsState
  68. };