cld_model.js 1019 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. 'use strict';
  2. /**
  3. * cld接口模型
  4. *
  5. * @author EllisRan.
  6. * @date 2020/12/4
  7. * @version
  8. */
  9. const Request = require("request");
  10. class CLDModel {
  11. CLDUrl = 'http://cld.smartcost.com.cn';
  12. /**
  13. * 获取cld所有员工信息
  14. *
  15. * @return {Promise}
  16. */
  17. async getAllStaff() {
  18. let postData = {
  19. url: this.CLDUrl + '/api/building/staff/list',
  20. encoding: 'utf8'
  21. };
  22. return new Promise(function (resolve, reject) {
  23. try {
  24. // 请求接口
  25. Request.post(postData, function (err, postResponse, body) {
  26. if (err) {
  27. throw '请求错误';
  28. }
  29. if (postResponse.statusCode !== 200) {
  30. throw 'CLD通讯失败!';
  31. }
  32. resolve(body);
  33. });
  34. } catch (error) {
  35. reject([]);
  36. }
  37. });
  38. }
  39. }
  40. module.exports = CLDModel;