Graphics.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. <template>
  2. <div class="graphics">
  3. <div class="input-search">
  4. <div class="btn">
  5. <t-icon name="search" />
  6. </div>
  7. <t-input placeholder="搜索" />
  8. </div>
  9. <div class="groups">
  10. <div class="sub-groups">
  11. <div
  12. v-for="group in groups"
  13. :class="group.active ? 'active' : ''"
  14. @click="groupChange(group.name)"
  15. >
  16. <t-icon :name="group.icon" />
  17. {{ group.name }}
  18. </div>
  19. </div>
  20. <div class="list">
  21. <div
  22. class="show-item"
  23. v-for="item in showList"
  24. :draggable="true"
  25. @dragstart="dragStart($event, item)"
  26. @drag="drag($event, item)"
  27. @dragend="dragEnd()"
  28. >
  29. <t-image
  30. v-if="item.image"
  31. :src="item.image"
  32. fit="cover"
  33. :style="{ width: '88px', height: '88px' }"
  34. />
  35. <i v-else class="t-icon" :class="item.icon"></i>
  36. <p>{{ item.name }}</p>
  37. </div>
  38. </div>
  39. </div>
  40. </div>
  41. </template>
  42. <script lang="ts" setup>
  43. import { onMounted, onUnmounted, reactive } from 'vue';
  44. const groups = reactive([
  45. {
  46. icon: 'desktop',
  47. name: '场景',
  48. key: '',
  49. active: false,
  50. },
  51. {
  52. icon: 'root-list',
  53. name: '模板',
  54. key: '',
  55. active: false,
  56. },
  57. {
  58. icon: 'chart',
  59. name: '图表',
  60. key: '',
  61. active: false,
  62. },
  63. {
  64. icon: 'control-platform',
  65. name: '控件',
  66. key: '',
  67. active: false,
  68. },
  69. {
  70. icon: 'file-icon',
  71. name: '图标',
  72. key: '',
  73. active: false,
  74. },
  75. {
  76. icon: 'chart-bubble',
  77. name: '图形',
  78. key: '',
  79. active: true,
  80. },
  81. {
  82. icon: 'app',
  83. name: '我的',
  84. key: '',
  85. active: false,
  86. },
  87. ]);
  88. const groupChange = (name: string) => {
  89. if (name === '图形') {
  90. }
  91. };
  92. const showList = [
  93. {
  94. name: 'square',
  95. icon: 't-icon t-rect',
  96. id: '',
  97. data: {
  98. text: '正方形',
  99. width: 100,
  100. height: 100,
  101. name: 'square',
  102. },
  103. },
  104. {
  105. name: 'rectangle',
  106. icon: 't-icon t-rectangle',
  107. id: 2,
  108. data: {
  109. text: '圆角矩形',
  110. width: 200,
  111. height: 50,
  112. borderRadius: 0.1,
  113. name: 'rectangle',
  114. },
  115. },
  116. {
  117. name: 'circle',
  118. icon: 't-icon t-circle',
  119. image: '',
  120. id: 3,
  121. data: {
  122. text: '圆',
  123. width: 100,
  124. height: 100,
  125. name: 'circle',
  126. },
  127. },
  128. {
  129. name: 'triangle',
  130. icon: 't-icon t-triangle',
  131. id: 4,
  132. data: {
  133. text: '三角形',
  134. width: 100,
  135. height: 100,
  136. name: 'triangle',
  137. },
  138. },
  139. ];
  140. const dragStart = (event: DragEvent, item: any) => {
  141. if (!item || !event.dataTransfer) {
  142. return;
  143. }
  144. event.dataTransfer.setData(
  145. 'Meta2d',
  146. JSON.stringify(item.componentData || item.data)
  147. );
  148. event.stopPropagation();
  149. };
  150. const drag = (event: DragEvent, item: any) => {};
  151. const dragEnd = () => {};
  152. const dragstart = (event: any) => {
  153. event.target.style.opacity = 0.5;
  154. };
  155. const dragend = (event: any) => {
  156. event.target.style.opacity = 1;
  157. };
  158. onMounted(() => {
  159. document.removeEventListener('dragstart', dragstart);
  160. document.removeEventListener('dragend', dragend);
  161. });
  162. onUnmounted(() => {
  163. document.addEventListener('dragstart', dragstart, false);
  164. document.addEventListener('dragend', dragend, false);
  165. });
  166. </script>
  167. <style lang="postcss" scoped>
  168. .graphics {
  169. display: flex;
  170. flex-direction: column;
  171. .input-search {
  172. flex-shrink: 0;
  173. height: 40px;
  174. }
  175. .groups {
  176. display: grid;
  177. grid-template-columns: 50px 1fr;
  178. border-top: 1px solid var(--color-background-input);
  179. flex-grow: 1;
  180. overflow-y: auto;
  181. font-size: 12px;
  182. .sub-groups {
  183. & > div {
  184. display: flex;
  185. flex-direction: column;
  186. align-items: center;
  187. padding: 16px 4px;
  188. line-height: 1;
  189. cursor: pointer;
  190. .t-icon {
  191. font-size: 20px;
  192. margin-bottom: 5px;
  193. }
  194. &:hover {
  195. color: var(--color-primary);
  196. }
  197. }
  198. .active {
  199. background-color: var(--color-background-active);
  200. color: var(--color-primary);
  201. border-left: 2px solid var(--color-primary);
  202. }
  203. }
  204. .list {
  205. background-color: var(--color-background-active);
  206. padding: 12px;
  207. display: grid;
  208. grid-template-columns: 112px 112px;
  209. grid-template-rows: 142px;
  210. .show-item {
  211. padding: 12px;
  212. p {
  213. margin-top: 10px;
  214. height: 20px;
  215. line-height: 20px;
  216. text-align: center;
  217. font-size: 14px;
  218. }
  219. i {
  220. background-color: #fff;
  221. border-radius: 4px;
  222. height: 88px;
  223. width: 88px;
  224. }
  225. .t-image {
  226. background-color: #fff;
  227. border-radius: 4px;
  228. }
  229. }
  230. }
  231. }
  232. }
  233. </style>