Home.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. <template>
  2. <div class="persagyPlan">
  3. <basePlan @onMousedown="onMousedown" @postDeviceIds="postDeviceIds" ref="planEl"></basePlan>
  4. <tooltip ref="tooltip_map" v-show="showtip" class="toolTip">
  5. <div class="title">
  6. {{ this.tooltipName }}
  7. </div>
  8. <div class="tip-body">
  9. <div class="info">
  10. <p v-for="(item, index) in device_params" :key="index">
  11. <span class="label">{{ item.infoName }}:</span>
  12. <span class="value">{{ showData(item) }}</span>
  13. <span class="unit">{{ item.unit }}</span>
  14. </p>
  15. </div>
  16. </div>
  17. <div class="tip-footer">查看设备详情</div>
  18. </tooltip>
  19. </div>
  20. </template>
  21. <script>
  22. import { readPubGroup, readDeviceParams, readDeviceStatus } from "@/api/plan"; // 引入获取底图得接口
  23. import basePlan from "@/components/basePlan.vue";
  24. import tooltip from "@/components/tooltip.vue";
  25. export default {
  26. components: { basePlan, tooltip },
  27. data() {
  28. return {
  29. showtip: false,
  30. tooltipName: "",
  31. device_params: [],
  32. deviceIds: [],
  33. graphId: "e4c6b131ced74032b02b5721cb496b77",
  34. id: "ad1195f2492f41e3a06f792d6701365c",
  35. };
  36. },
  37. mounted() {
  38. let _this = this;
  39. let canvasEl = document.getElementsByTagName("canvas")[0];
  40. window._resizeTimer = null;
  41. window.addEventListener("resize", () => {
  42. clearTimeout(window._resizeTimer);
  43. window._resizeTimer = setTimeout(() => {
  44. canvasEl.height = document.body.clientHeight;
  45. canvasEl.width = document.body.clientWidth;
  46. _this.$refs.planEl.fixWindow();
  47. }, 50);
  48. });
  49. },
  50. beforeMount() {
  51. let searchStr = window.location.search.substr(1);
  52. // 设备
  53. // searchStr =
  54. // 'projectId=Pj1101050029&&buildingId=Bd1101050029cb77fbd1846611eaac87cd1cd6a961c6&floorId=Fl11010500295de391e3e5564ce58003c7e5391dc5e4&id=c57264b1252245e6b2713f1cbb9c4148&graphId=cbe7180ead0f420782acf1c39382319a&floorMap=base/ebd53bb00d3511eb9a1db95f725712e8.jsonz'
  55. // 设备 + 空间
  56. searchStr =
  57. "projectId=Pj1101050029&&buildingId=Bd1101050029cb77fbd1846611eaac87cd1cd6a961c6&floorId=Fl1101050029f18b92c5ceaf408d893e257bf03692df&id=0234df7a9a7b40dca38358b7e0a71ce9&graphId=e43a9c03d9bb482ca96b3b545735be35&floorMap=base/a5f453020d4111eb9a1d57eee76e51f1.jsonz";
  58. // buildingId=Bd1101050029cb77fbd1846611eaac87cd1cd6a961c6&floorId=Fl1101050029f18b92c5ceaf408d893e257bf03692df&name=%E5%BE%88%E8%B4%B9%E5%8A%B2&id=0234df7a9a7b40dca38358b7e0a71ce9&graphId=e43a9c03d9bb482ca96b3b545735be35&version=1.1.1&floorMap=base%2Fa5f453020d4111eb9a1d57eee76e51f1.jsonz
  59. // 项目id,建筑id,楼层id,图id,图graphId,底图floorMap
  60. const params = this.queryURLParams(searchStr);
  61. Object.entries(params).map((arr) => {
  62. this[arr[0]] = arr[1];
  63. window[`_${arr[0]}`] = arr[1];
  64. });
  65. console.log(params);
  66. // console.log("here");
  67. // console.log("id:", this.id);
  68. // console.log("graphId:", this.graphId);
  69. // console.log("url:", this.url);
  70. // console.log("projectId:", this.projectId);
  71. },
  72. methods: {
  73. /**
  74. * 查询url参数
  75. */
  76. queryURLParams(url) {
  77. let obj = {};
  78. url.replace(/([^?=&#]+)=([^?=&#]+)/g, (_, key, value) => (obj[key] = value));
  79. url.replace(/#([^?=&#]+)/g, (_, hash) => (obj["HASH"] = hash));
  80. return obj;
  81. },
  82. postDeviceIds(ids) {
  83. this.deviceIds = ids;
  84. if (ids.length > 0) {
  85. readDeviceStatus({ objectIds: ids }).then((res) => {
  86. // console.log('res')
  87. // console.log(res)
  88. window.parse.nodes.forEach((nodeItem) => {
  89. let sItem = res.content.find((_item) => {
  90. return _item.objectId == nodeItem._data.attachObjectIds[0];
  91. });
  92. // if(sItem == null){
  93. // sItem = res.content[0]
  94. // }
  95. let key = null;
  96. /**
  97. * 0: 灰
  98. 1:蓝
  99. 2:红
  100. 3:黄
  101. 4:绿
  102. 5:棕
  103. *
  104. */
  105. if (sItem) {
  106. switch (sItem.status) {
  107. case 0:
  108. // 空
  109. key = 0;
  110. break;
  111. case 1:
  112. // 运行
  113. key = 1;
  114. break;
  115. case 2:
  116. // 关闭
  117. key = 0;
  118. break;
  119. default:
  120. break;
  121. }
  122. let picUrl = nodeItem._data.properties.state.find((item) => {
  123. return item.state == key;
  124. }).pic;
  125. if (nodeItem.__picUrl && nodeItem.__picUrl == picUrl) {
  126. } else {
  127. nodeItem.__picUrl = picUrl;
  128. nodeItem.url = window.img_baseurl + "/image-service/common/image_get?systemId=dataPlatform&key=" + picUrl;
  129. // nodeItem.url ='/dp-auxiliary/image-service/common/image_get?systemId=dataPlatform&key='+picUrl
  130. }
  131. }
  132. });
  133. });
  134. }
  135. },
  136. showData(item) {
  137. if (item.dataSource) {
  138. return item.dataSource.find((item) => {
  139. return item.code == "0";
  140. }).name;
  141. } else {
  142. return item.data;
  143. }
  144. },
  145. onMousedown(item, e) {
  146. let time = new Date().getTime();
  147. window._now = console.log("item:", item);
  148. setTimeout(() => {
  149. if (item) {
  150. clearTimeout(window._caller);
  151. let operationType = "click";
  152. console.log(111);
  153. this.showtip = true;
  154. this.tooltipName = "test";
  155. this.device_params = [
  156. {
  157. infoName: "hhh",
  158. unit: "g",
  159. },
  160. ];
  161. this.$refs.tooltip_map.$el.style.left = e[0].offsetX + "px";
  162. this.$refs.tooltip_map.$el.style.top = e[0].offsetY + "px";
  163. return;
  164. let deviceId = item.data.attachObjectIds[0];
  165. if (window._now) {
  166. let diff = time - window._now;
  167. console.log("diff:", diff);
  168. if (diff < 400) {
  169. operationType = "dbclick";
  170. // 双击
  171. } else {
  172. // 单击
  173. }
  174. }
  175. window._now = time;
  176. if (operationType == "click") {
  177. // 单击
  178. window._caller = setTimeout(() => {
  179. readDeviceParams({ objectId: deviceId }).then((res) => {
  180. this.tooltipName = item.data.name;
  181. this.device_params = res.content;
  182. this.$refs.tooltip_map.$el.style.left = e[0].offsetX + "px";
  183. this.$refs.tooltip_map.$el.style.top = e[0].offsetY + "px";
  184. this.showtip = true;
  185. });
  186. }, 300);
  187. } else {
  188. // 双击
  189. try {
  190. window.postMsgToU3d(JSON.stringify({ time: new Date(), data: { deviceId: deviceId } }));
  191. } catch (error) {
  192. console.error("to u3d error", error);
  193. }
  194. }
  195. } else {
  196. this.showtip = false;
  197. }
  198. }, 200);
  199. },
  200. // 移入
  201. onMousedownx(item, e) {
  202. // return false;
  203. let deviceId = item.data.attachObjectIds[0];
  204. let res = readDeviceParams(deviceId);
  205. this.tooltipName = item.data.name;
  206. this.device_params = res.content;
  207. this.showtip = true;
  208. console.log(e[0].offsetX + "px");
  209. this.$refs.tooltip_map.$el.style.left = e[0].offsetX + "px";
  210. this.$refs.tooltip_map.$el.style.top = e[0].offsetY + "px";
  211. },
  212. },
  213. };
  214. </script>
  215. <style lang="less">
  216. .persagyPlan {
  217. padding: 6 px 10px 6px 10px;
  218. width: 100%;
  219. height: 100%;
  220. overflow: hidden;
  221. }
  222. .title {
  223. padding: 10px 16px;
  224. line-height: 22px;
  225. color: #ebeef5;
  226. font-size: 16px;
  227. font-weight: 600;
  228. }
  229. .toolTip {
  230. min-width: 40px;
  231. box-shadow: 0px 2px 4px 0px rgba(31, 36, 41, 0.1);
  232. border: 1px solid #5d6177;
  233. // padding: 6px 10px 6px 10px;
  234. position: absolute;
  235. border-radius: 8px;
  236. box-shadow: 0px 1px 13px rgba(0, 0, 0, 0.189549), 0px 1px 11px rgba(0, 0, 0, 0.5);
  237. }
  238. .tip-body {
  239. border-top: 1px solid #5d6177;
  240. border-bottom: 1px solid #5d6177;
  241. }
  242. .info {
  243. padding: 16px;
  244. max-height: 280px;
  245. overflow: auto;
  246. line-height: 29px;
  247. span {
  248. color: #a7abc0;
  249. }
  250. .value {
  251. color: #fff;
  252. // margin-left: 12px;
  253. }
  254. .unit {
  255. margin-left: 0;
  256. }
  257. }
  258. .tip-footer {
  259. width: 100%;
  260. height: 50px;
  261. line-height: 50px;
  262. font-size: 16px;
  263. text-align: center;
  264. color: #a7abc0;
  265. transition: background-color 0.3s;
  266. cursor: pointer;
  267. &:hover {
  268. color: #fff;
  269. background-color: rgba(0, 145, 255, 0.295974);
  270. }
  271. }
  272. ::-webkit-scrollbar {
  273. width: 6px;
  274. height: 6px;
  275. }
  276. ::-webkit-scrollbar-track {
  277. border-radius: 0;
  278. }
  279. ::-webkit-scrollbar-thumb {
  280. background-color: #21262f;
  281. border-radius: 3px;
  282. &:hover {
  283. background-color: #21262f;
  284. }
  285. }
  286. </style>