ContextMenu.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. <template>
  2. <t-menu class="context-menu" @change="onMenu">
  3. <template v-if="props.type === 'anchor'">
  4. <t-menu-item value="addAnchorHand">
  5. <div class="flex">添加手柄 <span class="flex-grow"></span> H</div>
  6. </t-menu-item>
  7. <t-menu-item value="removeAnchorHand">
  8. <div class="flex">删除手柄 <span class="flex-grow"></span> D</div>
  9. </t-menu-item>
  10. <t-menu-item value="toggleAnchorHand">
  11. <div class="flex">切换手柄 <span class="flex-grow"></span> Shift</div>
  12. </t-menu-item>
  13. </template>
  14. <template v-if="props.type === 'pen'">
  15. <t-menu-item v-if="!selections.mode&&hasC()" value="updateC"> 一键更新我的组件 </t-menu-item>
  16. <t-menu-item v-if="isAppend()" value="appendChild"> 追加状态 </t-menu-item>
  17. <t-menu-item v-if="is3D()" value="goto3d"> 进入3D可视化编辑 </t-menu-item>
  18. <t-menu-item v-if="is2D()" value="goto2d"> 进入2D可视化编辑 </t-menu-item>
  19. <t-menu-item v-if="isV()" value="gotov"> 进入大屏可视化编辑 </t-menu-item>
  20. <t-menu-item v-if="isIframe()" value="replaceScene"> 替换方案 </t-menu-item>
  21. <!-- <t-menu-item v-if="isTableNoFocus()" value="focus">
  22. <div class="flex">进入编辑模式<span class="flex-grow"></span>Enter</div>
  23. </t-menu-item> -->
  24. <!-- <t-menu-item v-if="isTableFocus()" value="unFocus">
  25. <div class="flex">退出编辑模式 <span class="flex-grow"></span>Esc</div>
  26. </t-menu-item> -->
  27. <t-menu-item :disabled="!selections.mode" value="top"> 置顶 </t-menu-item>
  28. <t-menu-item :disabled="!selections.mode" value="bottom">
  29. 置底
  30. </t-menu-item>
  31. <t-menu-item :disabled="!selections.mode" value="up">
  32. 上一个图层
  33. </t-menu-item>
  34. <t-menu-item :disabled="!selections.mode" value="down">
  35. 下一个图层
  36. </t-menu-item>
  37. <t-divider />
  38. <template v-if="selections.mode === SelectionMode.Pens">
  39. <t-menu-item value="group"> 组合 </t-menu-item>
  40. <t-menu-item value="states"> 组合为状态 </t-menu-item>
  41. </template>
  42. <t-menu-item v-if="hasChildren" value="unGroup">
  43. <t-popconfirm content="确认取消组合?(将丢失组合图元的数据)" @cancel="onMenu('xxxx')" @confirm="onMenu('unGroup')">
  44. <div @click.stop>
  45. 取消组合
  46. </div>
  47. </t-popconfirm>
  48. </t-menu-item>
  49. <t-menu-item :disabled="!selections.mode" value="lock">
  50. {{ locked ? '解锁' : '锁定' }}
  51. </t-menu-item>
  52. <t-divider />
  53. <t-menu-item :disabled="!selections.mode" value="del"> 删除 </t-menu-item>
  54. <template v-if="isNameLine">
  55. <t-menu-item value="changeType">
  56. {{ isLine ? '变成节点' : '变成连线' }}
  57. </t-menu-item>
  58. </template>
  59. <t-divider />
  60. <t-menu-item :disabled="cantUndo" value="undo">
  61. <div class="flex">撤销<span class="flex-grow"></span>Ctrl + Z</div>
  62. </t-menu-item>
  63. <t-menu-item :disabled="cantRedo" value="redo">
  64. <div class="flex">重做<span class="flex-grow"></span>Shift + Z</div>
  65. </t-menu-item>
  66. <t-divider />
  67. <t-menu-item :disabled="!selections.mode" value="cut">
  68. <div class="flex">剪切<span class="flex-grow"></span>Ctrl + X</div>
  69. </t-menu-item>
  70. <t-menu-item :disabled="!selections.mode" value="copy">
  71. <div class="flex">复制<span class="flex-grow"></span>Ctrl + C</div>
  72. </t-menu-item>
  73. <t-menu-item value="paste">
  74. <div class="flex">粘贴<span class="flex-grow"></span>Ctrl + V</div>
  75. </t-menu-item>
  76. </template>
  77. </t-menu>
  78. </template>
  79. <script setup lang="ts">
  80. import { onMounted, ref } from 'vue';
  81. import { LockState, Pen, PenType } from '@meta2d/core';
  82. import { useSelection, SelectionMode } from '@/services/selections';
  83. import { updateC } from '@/services/updateC';
  84. import { rootDomain } from '@/services/defaults';
  85. const props = defineProps({
  86. type: String,
  87. });
  88. const emit = defineEmits(['changeVisible','replaceScene']);
  89. const { selections } = useSelection();
  90. const hasChildren = ref(false);
  91. const locked = ref(false);
  92. const isNameLine = ref(false);
  93. const isLine = ref(false);
  94. const cantUndo = ref(false);
  95. const cantRedo = ref(false);
  96. onMounted(() => {
  97. if (selections.mode === SelectionMode.Pen) {
  98. hasChildren.value = meta2d?.store.active[0]?.children?.length > 0;
  99. isNameLine.value = meta2d?.store.active[0]?.name === 'line';
  100. isLine.value = meta2d?.store.active[0]?.type === PenType.Line;
  101. }
  102. if (selections.mode) {
  103. locked.value = meta2d?.store.active?.some((pen: Pen) => pen.locked);
  104. }
  105. cantUndo.value =
  106. !!meta2d?.store.data.locked ||
  107. meta2d?.store.histories.length == 0 ||
  108. meta2d?.store.historyIndex == null ||
  109. meta2d?.store.historyIndex < 0;
  110. cantRedo.value =
  111. !!meta2d?.store.data.locked ||
  112. meta2d?.store.histories.length == 0 ||
  113. meta2d?.store.historyIndex == null ||
  114. meta2d?.store.historyIndex > meta2d?.store.histories.length - 2;
  115. });
  116. const onMenu = (val: string) => {
  117. let id,url;
  118. switch (val) {
  119. case 'addAnchorHand':
  120. meta2d.addAnchorHand();
  121. break;
  122. case 'removeAnchorHand':
  123. meta2d.removeAnchorHand();
  124. break;
  125. case 'toggleAnchorHand':
  126. meta2d.toggleAnchorHand();
  127. break;
  128. case 'top':
  129. case 'bottom':
  130. case 'up':
  131. case 'down':
  132. case 'undo':
  133. case 'redo':
  134. case 'cut':
  135. case 'copy':
  136. case 'paste':
  137. (meta2d as any)[val]();
  138. break;
  139. case 'group':
  140. meta2d.combine(meta2d.store.active);
  141. break;
  142. case 'states':
  143. meta2d.combine(meta2d.store.active, 0);
  144. break;
  145. case 'unGroup':
  146. meta2d.uncombine();
  147. break;
  148. case 'lock':
  149. {
  150. const pens = meta2d.store.active;
  151. if (Array.isArray(pens)) {
  152. for (const pen of pens) {
  153. pen.locked = locked.value ? LockState.None : LockState.DisableMove;
  154. }
  155. }
  156. meta2d.render();
  157. }
  158. break;
  159. case 'del':
  160. meta2d.delete();
  161. break;
  162. case 'changeType':
  163. meta2d.setValue(
  164. {
  165. id: meta2d.store.active[0].id,
  166. type: isLine.value ? 0 : 1,
  167. },
  168. {
  169. history: true,
  170. }
  171. );
  172. break;
  173. case 'updateC':
  174. updateC();
  175. break;
  176. case 'appendChild':
  177. meta2d.appendChild();
  178. let pen = meta2d?.store.active.find((pen: any) => pen.name === "combine"&& pen.showChild !== undefined)
  179. meta2d.active([pen],true);
  180. meta2d.render();
  181. break;
  182. case 'focus':
  183. meta2d.store.active[0].calculative.focus = true;
  184. break;
  185. case 'unFocus':
  186. meta2d.store.active[0].calculative.focus = false;
  187. break;
  188. case 'goto3d':
  189. id = meta2d?.store.active[0].iframe.split("id=")[1];
  190. //安装包
  191. url = location.origin+ `/3d/?id=`;
  192. if (window.url3D) {
  193. url = window.url3D;
  194. }
  195. window.open(url + id, '_blank');
  196. break;
  197. case 'goto2d':
  198. id = meta2d?.store.active[0].iframe.split("id=")[1];
  199. url = location.origin+ `/2d/?id=`;
  200. window.open(url + id, '_blank');
  201. break;
  202. case 'gotov':
  203. id = meta2d?.store.active[0].iframe.split("id=")[1];
  204. url = location.origin+ `/v/?id=`;
  205. window.open(url + id, '_blank');
  206. break;
  207. case 'replaceScene':
  208. emit('replaceScene', false);
  209. break;
  210. }
  211. emit('changeVisible', false);
  212. };
  213. const hasC =() => {
  214. return meta2d?.store.data.pens?.some((pen: Pen) => pen.name === "combine");
  215. }
  216. const isAppend =() => {
  217. return meta2d?.store.active.length > 1 && meta2d?.store.active.some((pen: any) => pen.name === "combine"&& pen.showChild !== undefined);
  218. }
  219. const isTableNoFocus =() => {
  220. return meta2d?.store.active.length === 1 && meta2d?.store.active[0].name === "tablePlus" && !meta2d?.store.active[0].calculative.focus;
  221. }
  222. const isTableFocus =() => {
  223. return meta2d?.store.active.length === 1 && meta2d?.store.active[0].name === "tablePlus" && meta2d?.store.active[0].calculative.focus;
  224. }
  225. const is3D = ()=>{
  226. return meta2d?.store.active.length === 1 && meta2d?.store.active[0].name === "iframe" && (meta2d?.store.active[0].iframe.indexOf("3d.") > -1||meta2d?.store.active[0].iframe.indexOf("/3d") > -1);
  227. }
  228. const is2D = ()=>{
  229. return meta2d?.store.active.length === 1 && meta2d?.store.active[0].name === "iframe" && (meta2d?.store.active[0].iframe.indexOf("2d.") > -1||meta2d?.store.active[0].iframe.indexOf("/2d") > -1);
  230. }
  231. const isV = ()=>{
  232. return meta2d?.store.active.length === 1 && meta2d?.store.active[0].name === "iframe" && (meta2d?.store.active[0].iframe.indexOf("v.") > -1||meta2d?.store.active[0].iframe.indexOf("/v") > -1) &&(meta2d?.store.active[0].iframe.indexOf(`v${rootDomain}`) !== -1 || meta2d?.store.active[0].iframe.indexOf(`view${rootDomain}/v`) !== -1);
  233. }
  234. const isIframe = ()=>{
  235. return meta2d?.store.active.length === 1 && meta2d?.store.active[0].name === "iframe"
  236. }
  237. </script>
  238. <style lang="postcss" scoped>
  239. .context-menu {
  240. height: auto !important;
  241. }
  242. </style>