Forráskód Böngészése

ctrl+c复制组件

dsy 5 napja
szülő
commit
d8eac19822

+ 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) => {