anchor.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /* *********************************************************** */
  2. // 创建: Macheng 2019/08/29.
  3. // 修改: Macheng 2025/09/10
  4. // Description:
  5. // 该文件定义了基站类Anchor。用于保存基站的配置数据。
  6. /* *********************************************************** */
  7. import BaseModel from './baseModel'
  8. class Anchor extends BaseModel {
  9. id = 0 // 基站ID
  10. imei = '' // 基站IMEI号
  11. iccid = '' // 基站ICCID号
  12. projId = 0 // 所属项目ID
  13. battery = 0 // 电池电量
  14. status = 0 // 基站状态 , bit0: 1-在线, 0-离线, bit1: 1-充电, 0-未充电
  15. x = 0 // 基站X坐标
  16. y = 0 // 基站Y坐标
  17. z = 0 // 基站Z坐标
  18. lastUpdateTime = 0 // 最后更新时间
  19. get addr() {
  20. return this.id
  21. }
  22. set addr(val) {
  23. this.id = val
  24. }
  25. get isOnline() {
  26. return (this.status & 0x1)
  27. }
  28. get isCharging() {
  29. return (this.status & 0x2)
  30. }
  31. get percentBattery() {
  32. let perBat = Math.floor((this.battery - 3700) / (4100 - 3700) * 100);
  33. if (perBat < 0) {
  34. perBat = 0;
  35. } else if (perBat > 100) {
  36. perBat = 100;
  37. }
  38. return perBat;
  39. }
  40. constructor(opts) {
  41. if (!opts) opts = {}
  42. super(opts)
  43. this.init(opts)
  44. }
  45. init(opts) {
  46. if (!opts) opts = {}
  47. super.init(opts)
  48. this.id = Number(opts.id) || Number(opts.addr) || this.id
  49. this.imei = opts.imei || this.imei
  50. this.iccid = opts.iccid || this.iccid
  51. this.projId = Number(opts.projId) || this.projId
  52. this.battery = Number(opts.battery) || this.battery
  53. this.status = Number(opts.status) || this.status
  54. this.x = Number(opts.x) || this.x
  55. this.y = Number(opts.y) || this.y
  56. this.z = Number(opts.z) || this.z
  57. this.lastUpdateTime = Number(opts.lastUpdateTime) || this.lastUpdateTime
  58. this.isEnable = opts.enable || opts.isEnable || false
  59. }
  60. toJson() {
  61. const obj1 = super.toJson()
  62. const obj2 = {
  63. id: this.id,
  64. addr: this.addr,
  65. imei: this.imei,
  66. iccid: this.iccid,
  67. projId: this.projId,
  68. battery: this.battery,
  69. status: this.status,
  70. x: this.x,
  71. y: this.y,
  72. z: this.z,
  73. lastUpdateTime: this.lastUpdateTime
  74. }
  75. return Object.assign({}, obj1, obj2)
  76. }
  77. }
  78. export default Anchor