location.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /* *********************************************************** */
  2. // 创建: Macheng 2025/09/10.
  3. // 修改: Macheng 2025/09/10
  4. // Description:
  5. // 该文件定义了 区域类 Location 。用于保存项目的区域数据。
  6. /* *********************************************************** */
  7. import BaseModel from './baseModel'
  8. class Location extends BaseModel {
  9. id = 0 // 区域ID
  10. name = '' // 区域名称
  11. center = { x: 0, y: 0 } // 区域中心点
  12. coordinates = [] // 区域坐标点列表
  13. parent = null
  14. constructor(opts) {
  15. if (!opts) opts = {}
  16. super(opts)
  17. this.init(opts)
  18. }
  19. init(opts) {
  20. if (!opts) opts = {}
  21. super.init(opts)
  22. this.id = Number(opts.id) || this.id
  23. this.name = opts.name || this.wifiLocalMaskname
  24. this.center = opts.center || this.center
  25. if (Number(opts.cx) || Number(opts.cy)) {
  26. this.center.x = Number(opts.cx);
  27. this.center.y = Number(opts.cy);
  28. }
  29. this.coordinates = opts.coordinates || this.coordinates
  30. this.isEnable = opts.enable || opts.isEnable || false
  31. }
  32. toJson() {
  33. const obj1 = super.toJson()
  34. const obj2 = {
  35. id: this.id,
  36. name: this.name,
  37. center: this.center,
  38. cx: this.center.x,
  39. cy: this.center.y,
  40. coordinates: this.coordinates
  41. }
  42. return Object.assign({}, obj1, obj2)
  43. }
  44. }
  45. export default Location