Browse Source

查询列表右键复制

zhuth 7 years ago
parent
commit
1ae2f2f9d6
1 changed files with 47 additions and 1 deletions
  1. 47 1
      frontend/saas-web/app/view/core/query/QueryGridPanel.js

+ 47 - 1
frontend/saas-web/app/view/core/query/QueryGridPanel.js

@@ -59,6 +59,27 @@ Ext.define('saas.view.core.query.QueryGridPanel', {
         }
 
         Ext.apply(me, {
+            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;
+                    }
+                }
+            },
             columns: me.initColumns(),
             store: Ext.create('Ext.data.Store', {
                 fields: me.getFields(),
@@ -420,5 +441,30 @@ Ext.define('saas.view.core.query.QueryGridPanel', {
                 }
             });
 		return data;
-    } 
+    },
+
+    getContextMenu: function() {
+        var me = this;
+
+        return me.contextMenu || (me.contextMenu = me.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);
+	},
 });