소스 검색

ctrl+c复制组件

dsy 5 일 전
부모
커밋
d8eac19822
1개의 변경된 파일11개의 추가작업 그리고 0개의 파일을 삭제
  1. 11 0
      src/views/book/courseware/create/components/CreateCanvas.vue

+ 11 - 0
src/views/book/courseware/create/components/CreateCanvas.vue

@@ -360,12 +360,23 @@ export default {
   mounted() {
     document.addEventListener('mousemove', this.dragMove);
     document.addEventListener('mouseup', this.dragEnd);
+    window.addEventListener('keydown', this.handleCopy);
   },
   beforeDestroy() {
     document.removeEventListener('mousemove', this.dragMove);
     document.removeEventListener('mouseup', this.dragEnd);
+    window.removeEventListener('keydown', this.handleCopy);
   },
   methods: {
+    /**
+     * 监听复制事件,触发复制组件方法
+     * @param {KeyboardEvent} event 键盘事件
+     */
+    handleCopy(event) {
+      if (event.ctrlKey && event.key === 'c' && this.curComponentId.length > 0) {
+        this.findChildComponentByKey(`grid-${this.curComponentId}`)?.copyComponent();
+      }
+    },
     handleHeightChange(id, newHeight) {
       this.data.row_list.forEach((row) => {
         row.col_list.forEach((col) => {