project.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /* *********************************************************** */
  2. // 创建: Macheng 2025/09/10.
  3. // 修改: Macheng 2025/09/10
  4. // Description:
  5. // 该文件定义了项目类 Project。用于保存项目的配置数据。
  6. /* *********************************************************** */
  7. import BaseModel from './baseModel'
  8. import Location from './location'
  9. import Person from './person'
  10. class Project extends BaseModel {
  11. id = 0 // 项目ID
  12. name = '' // 项目名称
  13. version = 0 // 项目版本
  14. locations = [] // 区域列表
  15. persons = [] // 人员列表
  16. status = 0
  17. constructor(opts) {
  18. if (!opts) opts = {}
  19. super(opts)
  20. this.init(opts)
  21. }
  22. init(opts) {
  23. if (!opts) opts = {}
  24. super.init(opts)
  25. this.id = Number(opts.id) || this.id
  26. this.name = opts.name || this.wifiLocalMaskname
  27. this.version = Number(opts.version) || this.version
  28. this.locations = (opts.locations || []).map(item => new Location(item))
  29. for (const loc of this.locations) {
  30. loc.parent = this
  31. }
  32. this.persons = (opts.persons || []).map(item => new Person(item))
  33. this.status = Number(opts.status) || this.status
  34. this.isEnable = opts.enable || opts.isEnable || false
  35. }
  36. toJson() {
  37. const obj1 = super.toJson()
  38. const obj2 = {
  39. id: this.id,
  40. name: this.name,
  41. version: this.version,
  42. locations: this.locations.map(item => item.toJson()),
  43. persons: this.persons.map(item => item.toJson()),
  44. status: this.status
  45. }
  46. return Object.assign({}, obj1, obj2)
  47. }
  48. }
  49. export default Project