@penggy/vue-context-menu 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +110 -0
- package/dist/vue-context-menu.js +395 -0
- package/package.json +81 -0
- package/src/VueContextMenu.vue +102 -0
- package/src/vue-context-menu.js +20 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017 xunlei
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# vue-context-menu
|
|
2
|
+
|
|
3
|
+
> Vue 2.0 右键菜单组件,菜单内容可以随意自定义
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
## 安装
|
|
8
|
+
```
|
|
9
|
+
npm install @penggy/vue-context-menu
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## 在线Demo
|
|
13
|
+
|
|
14
|
+
## 使用
|
|
15
|
+
|
|
16
|
+
### 1. 注册组件
|
|
17
|
+
|
|
18
|
+
#### 方式1 利用插件方式全局注册
|
|
19
|
+
|
|
20
|
+
```javascript
|
|
21
|
+
import VueContextMenu from '@penggy/vue-context-menu'
|
|
22
|
+
import Vue from 'vue'
|
|
23
|
+
|
|
24
|
+
Vue.use(VueContextMenu)
|
|
25
|
+
```
|
|
26
|
+
#### 方式2 局部注册
|
|
27
|
+
|
|
28
|
+
```javascript
|
|
29
|
+
import { component as VueContextMenu } from '@penggy/vue-context-menu'
|
|
30
|
+
|
|
31
|
+
export default {
|
|
32
|
+
// ...
|
|
33
|
+
components: {
|
|
34
|
+
'vue-context-menu': VueContextMenu
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
#### 方式3 独立版本引入,自动全局注册
|
|
40
|
+
> 前提是 vue 也是独立版本通过script标签引入
|
|
41
|
+
|
|
42
|
+
```html
|
|
43
|
+
<script src="./node_modules/dist/vue-context-menu.js"></script>
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### 2. 模版语法
|
|
47
|
+
```html
|
|
48
|
+
<context-menu class="right-menu"
|
|
49
|
+
:target="contextMenuTarget"
|
|
50
|
+
:show="contextMenuVisible"
|
|
51
|
+
@update:show="(show) => contextMenuVisible = show">
|
|
52
|
+
<a href="javascript:;" @click="copyMsg">复制</a>
|
|
53
|
+
<a href="javascript:;" @click="quoteMsg">引用</a>
|
|
54
|
+
<a href="javascript:;" @click="deleteMsg">删除</a>
|
|
55
|
+
</context-menu>
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Props
|
|
59
|
+
|
|
60
|
+
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
|
|
61
|
+
|-------------------------|-------|------|--------|--------|
|
|
62
|
+
| target | 触发右键事件的元素 | Element | - | - |
|
|
63
|
+
| show | 是否显示右键菜单 | Boolean | - | false |
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
## Events
|
|
67
|
+
|
|
68
|
+
| 事件名 | 说明 | 事件参数
|
|
69
|
+
|-------------------------|-------|------|
|
|
70
|
+
| update:show | 右键菜单显示/隐藏时触发 | 是否显示 |
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
## 注意
|
|
74
|
+
|
|
75
|
+
如果target是某个兄弟元素,可以使用 `$refs`来访问,但是注意请在父组件mounted 之后获取。
|
|
76
|
+
|
|
77
|
+
参考 https://cn.vuejs.org/v2/guide/components.html#子组件索引
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
## ChangeLog
|
|
81
|
+
- [1.0.1] 2017-07-10
|
|
82
|
+
- 修复 target 为空时可能出错的bug
|
|
83
|
+
|
|
84
|
+
- [1.0.0] 2017-06-23
|
|
85
|
+
- 实现右键菜单基本功能
|
|
86
|
+
|
|
87
|
+
## Development Setup
|
|
88
|
+
|
|
89
|
+
``` bash
|
|
90
|
+
# install deps
|
|
91
|
+
npm install
|
|
92
|
+
|
|
93
|
+
# serve demo at localhost:8080
|
|
94
|
+
npm run dev
|
|
95
|
+
|
|
96
|
+
# build library and demo
|
|
97
|
+
npm run build
|
|
98
|
+
|
|
99
|
+
# build library
|
|
100
|
+
npm run build:library
|
|
101
|
+
|
|
102
|
+
# build demo
|
|
103
|
+
npm run build:demo
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## License
|
|
107
|
+
|
|
108
|
+
[MIT](http://opensource.org/licenses/MIT)
|
|
109
|
+
|
|
110
|
+
Copyright (c) 2017 赵兵
|
|
@@ -0,0 +1,395 @@
|
|
|
1
|
+
(function webpackUniversalModuleDefinition(root, factory) {
|
|
2
|
+
if(typeof exports === 'object' && typeof module === 'object')
|
|
3
|
+
module.exports = factory();
|
|
4
|
+
else if(typeof define === 'function' && define.amd)
|
|
5
|
+
define([], factory);
|
|
6
|
+
else if(typeof exports === 'object')
|
|
7
|
+
exports["VueContextMenu"] = factory();
|
|
8
|
+
else
|
|
9
|
+
root["VueContextMenu"] = factory();
|
|
10
|
+
})(this, function() {
|
|
11
|
+
return /******/ (function(modules) { // webpackBootstrap
|
|
12
|
+
/******/ // The module cache
|
|
13
|
+
/******/ var installedModules = {};
|
|
14
|
+
/******/
|
|
15
|
+
/******/ // The require function
|
|
16
|
+
/******/ function __webpack_require__(moduleId) {
|
|
17
|
+
/******/
|
|
18
|
+
/******/ // Check if module is in cache
|
|
19
|
+
/******/ if(installedModules[moduleId]) {
|
|
20
|
+
/******/ return installedModules[moduleId].exports;
|
|
21
|
+
/******/ }
|
|
22
|
+
/******/ // Create a new module (and put it into the cache)
|
|
23
|
+
/******/ var module = installedModules[moduleId] = {
|
|
24
|
+
/******/ i: moduleId,
|
|
25
|
+
/******/ l: false,
|
|
26
|
+
/******/ exports: {}
|
|
27
|
+
/******/ };
|
|
28
|
+
/******/
|
|
29
|
+
/******/ // Execute the module function
|
|
30
|
+
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
|
31
|
+
/******/
|
|
32
|
+
/******/ // Flag the module as loaded
|
|
33
|
+
/******/ module.l = true;
|
|
34
|
+
/******/
|
|
35
|
+
/******/ // Return the exports of the module
|
|
36
|
+
/******/ return module.exports;
|
|
37
|
+
/******/ }
|
|
38
|
+
/******/
|
|
39
|
+
/******/
|
|
40
|
+
/******/ // expose the modules object (__webpack_modules__)
|
|
41
|
+
/******/ __webpack_require__.m = modules;
|
|
42
|
+
/******/
|
|
43
|
+
/******/ // expose the module cache
|
|
44
|
+
/******/ __webpack_require__.c = installedModules;
|
|
45
|
+
/******/
|
|
46
|
+
/******/ // identity function for calling harmony imports with the correct context
|
|
47
|
+
/******/ __webpack_require__.i = function(value) { return value; };
|
|
48
|
+
/******/
|
|
49
|
+
/******/ // define getter function for harmony exports
|
|
50
|
+
/******/ __webpack_require__.d = function(exports, name, getter) {
|
|
51
|
+
/******/ if(!__webpack_require__.o(exports, name)) {
|
|
52
|
+
/******/ Object.defineProperty(exports, name, {
|
|
53
|
+
/******/ configurable: false,
|
|
54
|
+
/******/ enumerable: true,
|
|
55
|
+
/******/ get: getter
|
|
56
|
+
/******/ });
|
|
57
|
+
/******/ }
|
|
58
|
+
/******/ };
|
|
59
|
+
/******/
|
|
60
|
+
/******/ // getDefaultExport function for compatibility with non-harmony modules
|
|
61
|
+
/******/ __webpack_require__.n = function(module) {
|
|
62
|
+
/******/ var getter = module && module.__esModule ?
|
|
63
|
+
/******/ function getDefault() { return module['default']; } :
|
|
64
|
+
/******/ function getModuleExports() { return module; };
|
|
65
|
+
/******/ __webpack_require__.d(getter, 'a', getter);
|
|
66
|
+
/******/ return getter;
|
|
67
|
+
/******/ };
|
|
68
|
+
/******/
|
|
69
|
+
/******/ // Object.prototype.hasOwnProperty.call
|
|
70
|
+
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
|
|
71
|
+
/******/
|
|
72
|
+
/******/ // __webpack_public_path__
|
|
73
|
+
/******/ __webpack_require__.p = "";
|
|
74
|
+
/******/
|
|
75
|
+
/******/ // Load entry module and return exports
|
|
76
|
+
/******/ return __webpack_require__(__webpack_require__.s = 4);
|
|
77
|
+
/******/ })
|
|
78
|
+
/************************************************************************/
|
|
79
|
+
/******/ ([
|
|
80
|
+
/* 0 */
|
|
81
|
+
/***/ (function(module, exports, __webpack_require__) {
|
|
82
|
+
|
|
83
|
+
var disposed = false
|
|
84
|
+
var Component = __webpack_require__(2)(
|
|
85
|
+
/* script */
|
|
86
|
+
__webpack_require__(1),
|
|
87
|
+
/* template */
|
|
88
|
+
__webpack_require__(3),
|
|
89
|
+
/* styles */
|
|
90
|
+
null,
|
|
91
|
+
/* scopeId */
|
|
92
|
+
null,
|
|
93
|
+
/* moduleIdentifier (server only) */
|
|
94
|
+
null
|
|
95
|
+
)
|
|
96
|
+
Component.options.__file = "C:\\Users\\Administrator\\Documents\\vue-context-menu\\src\\VueContextMenu.vue"
|
|
97
|
+
if (Component.esModule && Object.keys(Component.esModule).some(function (key) {return key !== "default" && key.substr(0, 2) !== "__"})) {console.error("named exports are not supported in *.vue files.")}
|
|
98
|
+
if (Component.options.functional) {console.error("[vue-loader] VueContextMenu.vue: functional components are not supported with templates, they should use render functions.")}
|
|
99
|
+
|
|
100
|
+
/* hot reload */
|
|
101
|
+
if (false) {(function () {
|
|
102
|
+
var hotAPI = require("vue-hot-reload-api")
|
|
103
|
+
hotAPI.install(require("vue"), false)
|
|
104
|
+
if (!hotAPI.compatible) return
|
|
105
|
+
module.hot.accept()
|
|
106
|
+
if (!module.hot.data) {
|
|
107
|
+
hotAPI.createRecord("data-v-6f0575c0", Component.options)
|
|
108
|
+
} else {
|
|
109
|
+
hotAPI.reload("data-v-6f0575c0", Component.options)
|
|
110
|
+
}
|
|
111
|
+
module.hot.dispose(function (data) {
|
|
112
|
+
disposed = true
|
|
113
|
+
})
|
|
114
|
+
})()}
|
|
115
|
+
|
|
116
|
+
module.exports = Component.exports
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
/***/ }),
|
|
120
|
+
/* 1 */
|
|
121
|
+
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
122
|
+
|
|
123
|
+
"use strict";
|
|
124
|
+
Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
|
|
125
|
+
//
|
|
126
|
+
//
|
|
127
|
+
//
|
|
128
|
+
//
|
|
129
|
+
//
|
|
130
|
+
//
|
|
131
|
+
//
|
|
132
|
+
//
|
|
133
|
+
//
|
|
134
|
+
|
|
135
|
+
/* harmony default export */ __webpack_exports__["default"] = ({
|
|
136
|
+
name: 'context-menu',
|
|
137
|
+
data: function data() {
|
|
138
|
+
return {
|
|
139
|
+
triggerShowFn: function triggerShowFn() {},
|
|
140
|
+
triggerHideFn: function triggerHideFn() {},
|
|
141
|
+
x: null,
|
|
142
|
+
y: null,
|
|
143
|
+
style: {},
|
|
144
|
+
binded: false
|
|
145
|
+
};
|
|
146
|
+
},
|
|
147
|
+
|
|
148
|
+
props: {
|
|
149
|
+
target: null,
|
|
150
|
+
show: Boolean
|
|
151
|
+
},
|
|
152
|
+
mounted: function mounted() {
|
|
153
|
+
this.bindEvents();
|
|
154
|
+
},
|
|
155
|
+
|
|
156
|
+
watch: {
|
|
157
|
+
show: function show(_show) {
|
|
158
|
+
if (_show) {
|
|
159
|
+
this.bindHideEvents();
|
|
160
|
+
} else {
|
|
161
|
+
this.unbindHideEvents();
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
target: function target(_target) {
|
|
165
|
+
this.bindEvents();
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
methods: {
|
|
169
|
+
// 初始化事件
|
|
170
|
+
bindEvents: function bindEvents() {
|
|
171
|
+
var _this = this;
|
|
172
|
+
|
|
173
|
+
this.$nextTick(function () {
|
|
174
|
+
if (!_this.target || _this.binded) return;
|
|
175
|
+
_this.triggerShowFn = _this.contextMenuHandler.bind(_this);
|
|
176
|
+
_this.target.addEventListener('contextmenu', _this.triggerShowFn);
|
|
177
|
+
_this.binded = true;
|
|
178
|
+
});
|
|
179
|
+
},
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
// 取消绑定事件
|
|
183
|
+
unbindEvents: function unbindEvents() {
|
|
184
|
+
if (!this.target) return;
|
|
185
|
+
this.target.removeEventListener('contextmenu', this.triggerShowFn);
|
|
186
|
+
},
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
// 绑定隐藏菜单事件
|
|
190
|
+
bindHideEvents: function bindHideEvents() {
|
|
191
|
+
this.triggerHideFn = this.clickDocumentHandler.bind(this);
|
|
192
|
+
document.addEventListener('mousedown', this.triggerHideFn);
|
|
193
|
+
document.addEventListener('mousewheel', this.triggerHideFn);
|
|
194
|
+
},
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
// 取消绑定隐藏菜单事件
|
|
198
|
+
unbindHideEvents: function unbindHideEvents() {
|
|
199
|
+
document.removeEventListener('mousedown', this.triggerHideFn);
|
|
200
|
+
document.removeEventListener('mousewheel', this.triggerHideFn);
|
|
201
|
+
},
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
// 鼠标按压事件处理器
|
|
205
|
+
clickDocumentHandler: function clickDocumentHandler(e) {
|
|
206
|
+
this.$emit('update:show', false);
|
|
207
|
+
},
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
// 右键事件事件处理
|
|
211
|
+
contextMenuHandler: function contextMenuHandler(e) {
|
|
212
|
+
this.x = e.clientX;
|
|
213
|
+
this.y = e.clientY;
|
|
214
|
+
this.$emit('update:show', true);
|
|
215
|
+
e.preventDefault();
|
|
216
|
+
this.$nextTick(this.layout);
|
|
217
|
+
},
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
// 布局
|
|
221
|
+
layout: function layout() {
|
|
222
|
+
if (this.y + this.$el.offsetHeight > document.documentElement.clientHeight) {
|
|
223
|
+
this.style = {
|
|
224
|
+
left: this.x + 'px',
|
|
225
|
+
bottom: 0
|
|
226
|
+
};
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
this.style = {
|
|
230
|
+
left: this.x + 'px',
|
|
231
|
+
top: this.y + 'px'
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
/***/ }),
|
|
238
|
+
/* 2 */
|
|
239
|
+
/***/ (function(module, exports) {
|
|
240
|
+
|
|
241
|
+
/* globals __VUE_SSR_CONTEXT__ */
|
|
242
|
+
|
|
243
|
+
// this module is a runtime utility for cleaner component module output and will
|
|
244
|
+
// be included in the final webpack user bundle
|
|
245
|
+
|
|
246
|
+
module.exports = function normalizeComponent (
|
|
247
|
+
rawScriptExports,
|
|
248
|
+
compiledTemplate,
|
|
249
|
+
injectStyles,
|
|
250
|
+
scopeId,
|
|
251
|
+
moduleIdentifier /* server only */
|
|
252
|
+
) {
|
|
253
|
+
var esModule
|
|
254
|
+
var scriptExports = rawScriptExports = rawScriptExports || {}
|
|
255
|
+
|
|
256
|
+
// ES6 modules interop
|
|
257
|
+
var type = typeof rawScriptExports.default
|
|
258
|
+
if (type === 'object' || type === 'function') {
|
|
259
|
+
esModule = rawScriptExports
|
|
260
|
+
scriptExports = rawScriptExports.default
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// Vue.extend constructor export interop
|
|
264
|
+
var options = typeof scriptExports === 'function'
|
|
265
|
+
? scriptExports.options
|
|
266
|
+
: scriptExports
|
|
267
|
+
|
|
268
|
+
// render functions
|
|
269
|
+
if (compiledTemplate) {
|
|
270
|
+
options.render = compiledTemplate.render
|
|
271
|
+
options.staticRenderFns = compiledTemplate.staticRenderFns
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// scopedId
|
|
275
|
+
if (scopeId) {
|
|
276
|
+
options._scopeId = scopeId
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
var hook
|
|
280
|
+
if (moduleIdentifier) { // server build
|
|
281
|
+
hook = function (context) {
|
|
282
|
+
// 2.3 injection
|
|
283
|
+
context =
|
|
284
|
+
context || // cached call
|
|
285
|
+
(this.$vnode && this.$vnode.ssrContext) || // stateful
|
|
286
|
+
(this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext) // functional
|
|
287
|
+
// 2.2 with runInNewContext: true
|
|
288
|
+
if (!context && typeof __VUE_SSR_CONTEXT__ !== 'undefined') {
|
|
289
|
+
context = __VUE_SSR_CONTEXT__
|
|
290
|
+
}
|
|
291
|
+
// inject component styles
|
|
292
|
+
if (injectStyles) {
|
|
293
|
+
injectStyles.call(this, context)
|
|
294
|
+
}
|
|
295
|
+
// register component module identifier for async chunk inferrence
|
|
296
|
+
if (context && context._registeredComponents) {
|
|
297
|
+
context._registeredComponents.add(moduleIdentifier)
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
// used by ssr in case component is cached and beforeCreate
|
|
301
|
+
// never gets called
|
|
302
|
+
options._ssrRegister = hook
|
|
303
|
+
} else if (injectStyles) {
|
|
304
|
+
hook = injectStyles
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
if (hook) {
|
|
308
|
+
var functional = options.functional
|
|
309
|
+
var existing = functional
|
|
310
|
+
? options.render
|
|
311
|
+
: options.beforeCreate
|
|
312
|
+
if (!functional) {
|
|
313
|
+
// inject component registration as beforeCreate hook
|
|
314
|
+
options.beforeCreate = existing
|
|
315
|
+
? [].concat(existing, hook)
|
|
316
|
+
: [hook]
|
|
317
|
+
} else {
|
|
318
|
+
// register for functioal component in vue file
|
|
319
|
+
options.render = function renderWithStyleInjection (h, context) {
|
|
320
|
+
hook.call(context)
|
|
321
|
+
return existing(h, context)
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
return {
|
|
327
|
+
esModule: esModule,
|
|
328
|
+
exports: scriptExports,
|
|
329
|
+
options: options
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
/***/ }),
|
|
335
|
+
/* 3 */
|
|
336
|
+
/***/ (function(module, exports, __webpack_require__) {
|
|
337
|
+
|
|
338
|
+
module.exports={render:function (){var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;
|
|
339
|
+
return _c('div', {
|
|
340
|
+
directives: [{
|
|
341
|
+
name: "show",
|
|
342
|
+
rawName: "v-show",
|
|
343
|
+
value: (_vm.show),
|
|
344
|
+
expression: "show"
|
|
345
|
+
}],
|
|
346
|
+
staticStyle: {
|
|
347
|
+
"display": "block"
|
|
348
|
+
},
|
|
349
|
+
style: (_vm.style),
|
|
350
|
+
on: {
|
|
351
|
+
"mousedown": function($event) {
|
|
352
|
+
$event.stopPropagation();
|
|
353
|
+
},
|
|
354
|
+
"contextmenu": function($event) {
|
|
355
|
+
$event.preventDefault();
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
}, [_vm._t("default")], 2)
|
|
359
|
+
},staticRenderFns: []}
|
|
360
|
+
module.exports.render._withStripped = true
|
|
361
|
+
if (false) {
|
|
362
|
+
module.hot.accept()
|
|
363
|
+
if (module.hot.data) {
|
|
364
|
+
require("vue-hot-reload-api").rerender("data-v-6f0575c0", module.exports)
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
/***/ }),
|
|
369
|
+
/* 4 */
|
|
370
|
+
/***/ (function(module, exports, __webpack_require__) {
|
|
371
|
+
|
|
372
|
+
const VueContextMenu = __webpack_require__(0)
|
|
373
|
+
const vueContextMenu = {}
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* Plugin API
|
|
377
|
+
*/
|
|
378
|
+
vueContextMenu.install = function (Vue, options) {
|
|
379
|
+
Vue.component(VueContextMenu.name, VueContextMenu)
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
vueContextMenu.component = VueContextMenu
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* Auto install
|
|
386
|
+
*/
|
|
387
|
+
if (typeof window !== 'undefined' && window.Vue) {
|
|
388
|
+
window.Vue.use(vueContextMenu)
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
module.exports = vueContextMenu
|
|
392
|
+
|
|
393
|
+
/***/ })
|
|
394
|
+
/******/ ]);
|
|
395
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@penggy/vue-context-menu",
|
|
3
|
+
"description": "Vue 2.0 右键菜单组件,菜单内容可以随意自定义",
|
|
4
|
+
"version": "1.0.3",
|
|
5
|
+
"private": false,
|
|
6
|
+
"main": "dist/vue-context-menu.js",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist/*.js",
|
|
9
|
+
"src"
|
|
10
|
+
],
|
|
11
|
+
"unpkg": "dist/vue-context-menu.js",
|
|
12
|
+
"keywords": [
|
|
13
|
+
"vue.js",
|
|
14
|
+
"vue-plugin",
|
|
15
|
+
"vue-component"
|
|
16
|
+
],
|
|
17
|
+
"author": "penggy",
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"scripts": {
|
|
20
|
+
"dev": "node build/dev-server.js",
|
|
21
|
+
"build": "npm run build:library && npm run build:demo",
|
|
22
|
+
"build:demo": "node build/build.js",
|
|
23
|
+
"build:library": "webpack --config build/webpack.lib.conf.js",
|
|
24
|
+
"publish": "npm publish --access=public"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"babel-cli": "^6.14.0",
|
|
29
|
+
"babel-plugin-external-helpers": "^6.22.0",
|
|
30
|
+
"babel-polyfill": "^6.13.0",
|
|
31
|
+
"babel-preset-es2015": "^6.22.0",
|
|
32
|
+
"babel-preset-es2015-rollup": "^1.2.0",
|
|
33
|
+
"rollup": "^0.35.10",
|
|
34
|
+
"rollup-plugin-babel": "^2.6.1",
|
|
35
|
+
"rollup-plugin-uglify": "^1.0.1",
|
|
36
|
+
"vue": "^2.3.3",
|
|
37
|
+
"vue-router": "^2.3.1",
|
|
38
|
+
"autoprefixer": "^6.7.2",
|
|
39
|
+
"babel-core": "^6.22.1",
|
|
40
|
+
"babel-loader": "^6.2.10",
|
|
41
|
+
"babel-plugin-transform-runtime": "^6.22.0",
|
|
42
|
+
"babel-preset-env": "^1.3.2",
|
|
43
|
+
"babel-preset-stage-2": "^6.22.0",
|
|
44
|
+
"babel-register": "^6.22.0",
|
|
45
|
+
"chalk": "^1.1.3",
|
|
46
|
+
"connect-history-api-fallback": "^1.3.0",
|
|
47
|
+
"copy-webpack-plugin": "4.0.1",
|
|
48
|
+
"css-loader": "^0.28.0",
|
|
49
|
+
"eventsource-polyfill": "^0.9.6",
|
|
50
|
+
"express": "^4.14.1",
|
|
51
|
+
"extract-text-webpack-plugin": "^2.0.0",
|
|
52
|
+
"file-loader": "^0.11.1",
|
|
53
|
+
"friendly-errors-webpack-plugin": "^1.1.3",
|
|
54
|
+
"html-webpack-plugin": "^2.28.0",
|
|
55
|
+
"http-proxy-middleware": "^0.17.3",
|
|
56
|
+
"webpack-bundle-analyzer": "^2.2.1",
|
|
57
|
+
"semver": "^5.3.0",
|
|
58
|
+
"shelljs": "^0.7.6",
|
|
59
|
+
"opn": "^4.0.2",
|
|
60
|
+
"optimize-css-assets-webpack-plugin": "^1.3.0",
|
|
61
|
+
"ora": "^1.2.0",
|
|
62
|
+
"rimraf": "^2.6.0",
|
|
63
|
+
"url-loader": "^0.5.8",
|
|
64
|
+
"vue-loader": "^12.1.0",
|
|
65
|
+
"vue-style-loader": "^3.0.1",
|
|
66
|
+
"vue-template-compiler": "^2.3.3",
|
|
67
|
+
"webpack": "^2.6.1",
|
|
68
|
+
"webpack-dev-middleware": "^1.10.0",
|
|
69
|
+
"webpack-hot-middleware": "^2.18.0",
|
|
70
|
+
"webpack-merge": "^4.1.0"
|
|
71
|
+
},
|
|
72
|
+
"engines": {
|
|
73
|
+
"node": ">= 4.0.0",
|
|
74
|
+
"npm": ">= 3.0.0"
|
|
75
|
+
},
|
|
76
|
+
"browserslist": [
|
|
77
|
+
"> 1%",
|
|
78
|
+
"last 2 versions",
|
|
79
|
+
"not ie <= 8"
|
|
80
|
+
]
|
|
81
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div :style="style" style="display: block;" v-show="show"
|
|
3
|
+
@mousedown.stop
|
|
4
|
+
@contextmenu.prevent
|
|
5
|
+
>
|
|
6
|
+
<slot></slot>
|
|
7
|
+
</div>
|
|
8
|
+
</template>
|
|
9
|
+
|
|
10
|
+
<script>
|
|
11
|
+
export default {
|
|
12
|
+
name: 'context-menu',
|
|
13
|
+
data () {
|
|
14
|
+
return {
|
|
15
|
+
triggerShowFn: () => {},
|
|
16
|
+
triggerHideFn: () => {},
|
|
17
|
+
x: null,
|
|
18
|
+
y: null,
|
|
19
|
+
style: {},
|
|
20
|
+
binded: false
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
props: {
|
|
24
|
+
target: null,
|
|
25
|
+
show: Boolean
|
|
26
|
+
},
|
|
27
|
+
mounted () {
|
|
28
|
+
this.bindEvents()
|
|
29
|
+
},
|
|
30
|
+
watch: {
|
|
31
|
+
show (show) {
|
|
32
|
+
if (show) {
|
|
33
|
+
this.bindHideEvents()
|
|
34
|
+
} else {
|
|
35
|
+
this.unbindHideEvents()
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
target (target) {
|
|
39
|
+
this.bindEvents()
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
methods: {
|
|
43
|
+
// 初始化事件
|
|
44
|
+
bindEvents () {
|
|
45
|
+
this.$nextTick(() => {
|
|
46
|
+
if (!this.target || this.binded) return
|
|
47
|
+
this.triggerShowFn = this.contextMenuHandler.bind(this)
|
|
48
|
+
this.target.addEventListener('contextmenu', this.triggerShowFn)
|
|
49
|
+
this.binded = true
|
|
50
|
+
})
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
// 取消绑定事件
|
|
54
|
+
unbindEvents () {
|
|
55
|
+
if (!this.target) return
|
|
56
|
+
this.target.removeEventListener('contextmenu', this.triggerShowFn)
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
// 绑定隐藏菜单事件
|
|
60
|
+
bindHideEvents () {
|
|
61
|
+
this.triggerHideFn = this.clickDocumentHandler.bind(this)
|
|
62
|
+
document.addEventListener('mousedown', this.triggerHideFn)
|
|
63
|
+
document.addEventListener('mousewheel', this.triggerHideFn)
|
|
64
|
+
},
|
|
65
|
+
|
|
66
|
+
// 取消绑定隐藏菜单事件
|
|
67
|
+
unbindHideEvents () {
|
|
68
|
+
document.removeEventListener('mousedown', this.triggerHideFn)
|
|
69
|
+
document.removeEventListener('mousewheel', this.triggerHideFn)
|
|
70
|
+
},
|
|
71
|
+
|
|
72
|
+
// 鼠标按压事件处理器
|
|
73
|
+
clickDocumentHandler (e) {
|
|
74
|
+
this.$emit('update:show', false)
|
|
75
|
+
},
|
|
76
|
+
|
|
77
|
+
// 右键事件事件处理
|
|
78
|
+
contextMenuHandler (e) {
|
|
79
|
+
this.x = e.clientX
|
|
80
|
+
this.y = e.clientY
|
|
81
|
+
this.$emit('update:show', true)
|
|
82
|
+
e.preventDefault()
|
|
83
|
+
this.$nextTick(this.layout);
|
|
84
|
+
},
|
|
85
|
+
|
|
86
|
+
// 布局
|
|
87
|
+
layout () {
|
|
88
|
+
if (this.y + this.$el.offsetHeight > document.documentElement.clientHeight) {
|
|
89
|
+
this.style = {
|
|
90
|
+
left: this.x + 'px',
|
|
91
|
+
bottom: 0,
|
|
92
|
+
}
|
|
93
|
+
return
|
|
94
|
+
}
|
|
95
|
+
this.style = {
|
|
96
|
+
left: this.x + 'px',
|
|
97
|
+
top: this.y + 'px'
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
</script>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const VueContextMenu = require('./VueContextMenu.vue')
|
|
2
|
+
const vueContextMenu = {}
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Plugin API
|
|
6
|
+
*/
|
|
7
|
+
vueContextMenu.install = function (Vue, options) {
|
|
8
|
+
Vue.component(VueContextMenu.name, VueContextMenu)
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
vueContextMenu.component = VueContextMenu
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Auto install
|
|
15
|
+
*/
|
|
16
|
+
if (typeof window !== 'undefined' && window.Vue) {
|
|
17
|
+
window.Vue.use(vueContextMenu)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
module.exports = vueContextMenu
|