distribution.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <template>
  2. <div class="distribution-index">
  3. <div class="">
  4. <el-button @click="getCamera" size="medium">恢复视角</el-button>
  5. </div>
  6. <div :id="'previewBim'+_uid" class="previewBim"></div>
  7. </div>
  8. </template>
  9. <script>
  10. import {
  11. getBimViewToken,
  12. } from '@/httpApi/bim'
  13. import bimView from '@/uitls/controls'
  14. import list from '@/config/demo'
  15. export default {
  16. data() {
  17. return {
  18. room: {
  19. id: 10
  20. },
  21. form: {
  22. color: 'rgba(19, 206, 102, 0.6)'
  23. },
  24. bimViewer: {},
  25. positionData: [],
  26. roomList: [],
  27. cameraState: {
  28. "name": "persp",
  29. "position": {
  30. "x": 50517.95896971393,
  31. "y": 18087.393345876066,
  32. "z": 103831.28504386776
  33. },
  34. "target": {
  35. "x": 50179.33289519571,
  36. "y": 18085.315836337795,
  37. "z": 48242.8852979743
  38. },
  39. "up": {
  40. "x": 0.9999587456475146,
  41. "y": 0.006737846700867504,
  42. "z": -0.006091668481171846
  43. },
  44. "near": 47374.75658240926,
  45. "far": 52908.82272199217,
  46. "zoom": 0.8936346625264161,
  47. "version": 1,
  48. "fov": 45,
  49. "aspect": 2.0664819944598336,
  50. "coordinateSystem": "world"
  51. }
  52. }
  53. },
  54. created() {
  55. this.roomList = list;
  56. this.init();
  57. },
  58. beforeDestroy() {
  59. if (this.bimViewer) this.bimViewer.destroy();
  60. },
  61. methods: {
  62. init() {
  63. getBimViewToken(10000890570651).then(this.successFunc);
  64. },
  65. returnRGBA(color) {
  66. let [r, g, b, a] = color.match(/\d+(\.\d+)?/g).map(Number);
  67. return {
  68. r,
  69. g,
  70. b,
  71. a
  72. }
  73. },
  74. getCamera() {
  75. if (!this.bimViewer) return;
  76. this.bimViewer.setStatus(this.cameraState);
  77. // console.log(this.bimViewer.getCameraState());
  78. },
  79. successFunc(res) {
  80. if (res.state) {
  81. this.bimViewer = new bimView({
  82. dom: document.getElementById('previewBim' + this._uid),
  83. viewToken: res.data,
  84. renderSuccess: () => {
  85. this.bimViewer.setStatus(this.cameraState);
  86. this.bimViewer.setToolbars(true)
  87. for (var i = 0; i < this.roomList.length; i++) {
  88. this.bimViewer.insertRooms({
  89. id: this.roomList[i].id,
  90. boundary: {
  91. "outer": this.roomList[i].boundary
  92. },
  93. height: this.roomList[i].height,
  94. roomColor: this.returnRGBA(this.roomList[i].color)
  95. })
  96. this.bimViewer.addDrawable({
  97. position: this.roomList[i].position,
  98. offsetX: -75,
  99. offsetY: -40,
  100. html: ` <div class="tips-4">
  101. ${this.roomList[i].name}
  102. <i class="iconfont huifont-sanjiaojiantou-xia"></i>
  103. </div>`,
  104. }, data => {})
  105. }
  106. },
  107. roomSaved: data => {
  108. console.log(data);
  109. },
  110. click: data => {
  111. let point = data.worldPosition;
  112. // console.log(point);
  113. // if (!point) return this.$message.warning('请点击模型范围内的点');
  114. // this.positionData.push(point);
  115. // this.bimViewer.add3DMaker('image', point);
  116. // if (this.positionData.length == 3) {
  117. // this.bimViewer.insertRooms({
  118. // id: this.room.id,
  119. // boundary: {
  120. // "outer": this.positionData
  121. // },
  122. // height: 500,
  123. // roomColor: this.returnRGBA(this.form.color)
  124. // })
  125. // this.bimViewer.clear3DMaker();
  126. // this.positionData = [];
  127. // this.bimViewer.editRoom({
  128. // roomId: this.room.id
  129. // })
  130. // this.room.id++;
  131. // }
  132. }
  133. })
  134. }
  135. }
  136. }
  137. }
  138. </script>
  139. <style lang="scss">
  140. .distribution-index {
  141. width: 100%;
  142. height: 100%;
  143. display: flex;
  144. flex-direction: column;
  145. .previewBim {
  146. flex: 1;
  147. height: 0;
  148. }
  149. }
  150. </style>