Browse Source

报表列表右键复制

zhuth 7 years ago
parent
commit
5a13be9b7b
1 changed files with 48 additions and 1 deletions
  1. 48 1
      frontend/saas-web/app/view/core/report/ReportPanel.js

+ 48 - 1
frontend/saas-web/app/view/core/report/ReportPanel.js

@@ -151,6 +151,27 @@ Ext.define('saas.view.core.report.ReportPanel', {
                     displayInfo: true,
                     store: store
                 }],
+                actions: {
+                    copy: {
+                        iconCls: 'x-fa fa-copy',
+                        text: '复制单元格',
+                        handler: function() {
+                            me.onCopy(me.selectedData);
+                        }
+                    }
+                },
+                viewConfig: {
+                    deferEmptyText: false,
+                    emptyText: '无数据',
+                    listeners: {
+                        itemcontextmenu: function(view, rec, node, index, e) {
+                            e.stopEvent();
+                            me.getContextMenu().show().setLocalXY(e.getXY());
+                            me.selectedData = e.target.innerText;
+                            return false;
+                        }
+                    }
+                },
             }]
         });
 
@@ -480,5 +501,31 @@ Ext.define('saas.view.core.report.ReportPanel', {
 
     applyParams: function(p) {
         return p;
-    }
+    },
+
+    getContextMenu: function() {
+        var me = this,
+        grid = me.items.items[1];
+
+        return grid.contextMenu || (grid.contextMenu = grid.add({
+            xtype: 'menu',
+            items: [
+                // Actions can be converted into MenuItems
+                '@copy',
+            ]
+        }));
+    },
+
+    onCopy: function(text) {
+		var target = Ext.DomHelper.append(document.body, {
+			tag: 'textarea',
+			style: 'opacity: 0;position: absolute;top: -10000px;right: 0;',
+			html: text
+		});
+		target.focus();
+		target.select();
+	    document.execCommand('Copy');
+	    target.blur();
+	    document.body.removeChild(target);
+	},
 });