Graphics.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. <script setup lang="ts">
  2. import { computed, onMounted, onUnmounted, ref } from "vue";
  3. import { deepClone } from "@meta2d/core";
  4. import { monitorRoomData } from "./pens/monitorRoom";
  5. import { monitorNoRoomData } from "./pens/monitorNoRoom";
  6. import { monitorPointData } from "./pens/monitorPoint";
  7. type AssetsType = "space" | "monitor";
  8. const activeAssets = ref<AssetsType>("space");
  9. const monitorPoints = ref([
  10. { name: "3F-R1", disabled: true },
  11. { name: "3F-R2", data: monitorPointData },
  12. ]);
  13. const roomList = [
  14. {
  15. id: 1,
  16. name: "有监测点房间",
  17. cssClass: "space-item-has-monitor",
  18. data: monitorRoomData,
  19. },
  20. {
  21. id: 2,
  22. name: "无监测点房间",
  23. cssClass: "space-item-no-monitor",
  24. data: monitorNoRoomData,
  25. },
  26. ];
  27. const isSpacePanel = computed(() => {
  28. return activeAssets.value === "space";
  29. });
  30. const isMonitorPanel = computed(() => {
  31. return activeAssets.value === "monitor";
  32. });
  33. onMounted(() => {
  34. document.addEventListener("dragstart", dragstart, false);
  35. document.addEventListener("dragend", dragend, false);
  36. });
  37. onUnmounted(() => {
  38. document.removeEventListener("dragstart", dragstart);
  39. document.removeEventListener("dragend", dragend);
  40. });
  41. const dragstart = (event: any) => {
  42. event.target.style.opacity = 0.5;
  43. };
  44. const dragend = (event: any) => {
  45. event.target.style.opacity = 1;
  46. };
  47. const handleDragStart = async (item: any) => {
  48. if (!item) {
  49. return;
  50. }
  51. let { data } = item;
  52. if (!Array.isArray(data)) {
  53. data = deepClone([data]);
  54. }
  55. meta2d.canvas.addCaches = data;
  56. };
  57. const assetsChange = () => {
  58. return;
  59. };
  60. </script>
  61. <template>
  62. <div class="graphics">
  63. <div class="group-asset">
  64. <t-radio-group
  65. v-model="activeAssets"
  66. @change="assetsChange"
  67. variant="primary-filled"
  68. >
  69. <t-radio-button value="space">{{ $t("空间组件") }}</t-radio-button>
  70. <t-radio-button value="monitor">{{ $t("监测点") }}</t-radio-button>
  71. </t-radio-group>
  72. </div>
  73. <div :class="['groups-panel', { 'groups-panel-monitor': isMonitorPanel }]">
  74. <div v-show="isSpacePanel">
  75. <div class="space-item" v-for="item in roomList" :key="item.id">
  76. <div class="space-item-title">{{ $t(item.name) }}</div>
  77. <div
  78. :class="item.cssClass"
  79. :draggable="true"
  80. @dragstart="handleDragStart(item)"
  81. @click.stop="handleDragStart(item)"
  82. @touchstart.passive="handleDragStart(item)"
  83. ></div>
  84. </div>
  85. </div>
  86. <div v-show="isMonitorPanel">
  87. <div
  88. :class="['monitor-item', { 'monitor-item-disabled': item.disabled }]"
  89. v-for="(item, index) in monitorPoints"
  90. :key="index"
  91. :draggable="!item.disabled"
  92. @dragstart="handleDragStart(item)"
  93. @click.stop="handleDragStart(item)"
  94. @touchstart.passive="handleDragStart(item)"
  95. >
  96. <div class="monitor-item-circle"></div>
  97. <div class="monitor-item-title">{{ item.name }}</div>
  98. </div>
  99. </div>
  100. </div>
  101. </div>
  102. </template>
  103. <style lang="postcss" scoped>
  104. .graphics {
  105. display: flex;
  106. flex-direction: column;
  107. background-color: #f5f7fa;
  108. .group-asset {
  109. height: 48px;
  110. align-items: center;
  111. display: flex;
  112. padding: 8px 16px;
  113. background-color: #fff;
  114. border-bottom: 1px solid #e4e7ed;
  115. .t-radio-group.t-radio-group--filled {
  116. padding: 0px;
  117. height: 32px;
  118. background-color: #fff;
  119. .t-radio-button::before {
  120. content: none;
  121. }
  122. }
  123. :deep(.t-radio-button__label) {
  124. margin: auto;
  125. }
  126. .t-radio-button {
  127. width: 88px;
  128. height: 32px;
  129. border-radius: 4px;
  130. padding: 0px;
  131. color: #000;
  132. &:hover {
  133. color: var(--color-primary);
  134. }
  135. &.t-is-checked {
  136. background-color: var(--color-primary) !important;
  137. color: #fff !important;
  138. }
  139. }
  140. }
  141. .groups-panel {
  142. flex: 1;
  143. overflow-y: auto;
  144. padding: 24px 16px;
  145. .space-item {
  146. .space-item-title {
  147. font-weight: 500;
  148. font-size: 12px;
  149. color: rgba(0, 0, 0, 0.65);
  150. line-height: 22px;
  151. margin-bottom: 8px;
  152. }
  153. .space-item-has-monitor {
  154. height: 140px;
  155. background: #fff;
  156. border-radius: 12px;
  157. cursor: pointer;
  158. }
  159. .space-item-no-monitor {
  160. height: 140px;
  161. background: repeating-linear-gradient(
  162. -60deg,
  163. #f1f1f1,
  164. #f1f1f1 7px,
  165. #d4d8d7 7px,
  166. #d4d8d7 14px
  167. );
  168. border-radius: 12px;
  169. cursor: pointer;
  170. }
  171. & + .space-item {
  172. margin-top: 24px;
  173. }
  174. }
  175. .monitor-item {
  176. height: 56px;
  177. background-color: #fff;
  178. border-radius: 8px;
  179. padding: 16px;
  180. display: flex;
  181. align-items: center;
  182. cursor: pointer;
  183. .monitor-item-circle {
  184. position: relative;
  185. width: 24px;
  186. height: 24px;
  187. background-color: rgba(103, 194, 58, 0.3);
  188. border-radius: 50%;
  189. margin-right: 12px;
  190. &::before {
  191. position: absolute;
  192. top: 6px;
  193. left: 6px;
  194. display: block;
  195. content: "";
  196. width: 12px;
  197. height: 12px;
  198. background-color: rgba(103, 194, 58, 0.6);
  199. border-radius: 50%;
  200. }
  201. &::after {
  202. position: absolute;
  203. top: 9px;
  204. left: 9px;
  205. display: block;
  206. content: "";
  207. width: 6px;
  208. height: 6px;
  209. background-color: rgba(103, 194, 58, 1);
  210. border-radius: 50%;
  211. }
  212. }
  213. .monitor-item-title {
  214. font-weight: 500;
  215. font-size: 12px;
  216. color: rgba(0, 0, 0, 0.65);
  217. line-height: 22px;
  218. user-select: none;
  219. }
  220. & + .monitor-item {
  221. margin-top: 8px;
  222. }
  223. }
  224. .monitor-item-disabled {
  225. background-color: initial;
  226. cursor: not-allowed;
  227. .monitor-item-title {
  228. color: rgba(0, 0, 0, 0.25);
  229. }
  230. }
  231. }
  232. .groups-panel-monitor {
  233. padding: 8px;
  234. }
  235. }
  236. </style>