正在显示
2 个修改的文件
包含
56 行增加
和
0 行删除
| @@ -3,10 +3,12 @@ import hasPermi from './permission/hasPermi' | @@ -3,10 +3,12 @@ import hasPermi from './permission/hasPermi' | ||
| 3 | import dialogDrag from './dialog/drag' | 3 | import dialogDrag from './dialog/drag' |
| 4 | import dialogDragWidth from './dialog/dragWidth' | 4 | import dialogDragWidth from './dialog/dragWidth' |
| 5 | import dialogDragHeight from './dialog/dragHeight' | 5 | import dialogDragHeight from './dialog/dragHeight' |
| 6 | +import clipboard from './module/clipboard' | ||
| 6 | 7 | ||
| 7 | const install = function(Vue) { | 8 | const install = function(Vue) { |
| 8 | Vue.directive('hasRole', hasRole) | 9 | Vue.directive('hasRole', hasRole) |
| 9 | Vue.directive('hasPermi', hasPermi) | 10 | Vue.directive('hasPermi', hasPermi) |
| 11 | + Vue.directive('clipboard', clipboard) | ||
| 10 | Vue.directive('dialogDrag', dialogDrag) | 12 | Vue.directive('dialogDrag', dialogDrag) |
| 11 | Vue.directive('dialogDragWidth', dialogDragWidth) | 13 | Vue.directive('dialogDragWidth', dialogDragWidth) |
| 12 | Vue.directive('dialogDragHeight', dialogDragHeight) | 14 | Vue.directive('dialogDragHeight', dialogDragHeight) |
ruoyi-ui/src/directive/module/clipboard.js
0 → 100644
| 1 | +/** | ||
| 2 | +* v-clipboard 文字复制剪贴 | ||
| 3 | +* Copyright (c) 2021 ruoyi | ||
| 4 | +*/ | ||
| 5 | + | ||
| 6 | +import Clipboard from 'clipboard' | ||
| 7 | +export default { | ||
| 8 | + bind(el, binding, vnode) { | ||
| 9 | + switch (binding.arg) { | ||
| 10 | + case 'success': | ||
| 11 | + el._vClipBoard_success = binding.value; | ||
| 12 | + break; | ||
| 13 | + case 'error': | ||
| 14 | + el._vClipBoard_error = binding.value; | ||
| 15 | + break; | ||
| 16 | + default: { | ||
| 17 | + const clipboard = new Clipboard(el, { | ||
| 18 | + text: () => binding.value, | ||
| 19 | + action: () => binding.arg === 'cut' ? 'cut' : 'copy' | ||
| 20 | + }); | ||
| 21 | + clipboard.on('success', e => { | ||
| 22 | + const callback = el._vClipBoard_success; | ||
| 23 | + callback && callback(e); | ||
| 24 | + }); | ||
| 25 | + clipboard.on('error', e => { | ||
| 26 | + const callback = el._vClipBoard_error; | ||
| 27 | + callback && callback(e); | ||
| 28 | + }); | ||
| 29 | + el._vClipBoard = clipboard; | ||
| 30 | + } | ||
| 31 | + } | ||
| 32 | + }, | ||
| 33 | + update(el, binding) { | ||
| 34 | + if (binding.arg === 'success') { | ||
| 35 | + el._vClipBoard_success = binding.value; | ||
| 36 | + } else if (binding.arg === 'error') { | ||
| 37 | + el._vClipBoard_error = binding.value; | ||
| 38 | + } else { | ||
| 39 | + el._vClipBoard.text = function () { return binding.value; }; | ||
| 40 | + el._vClipBoard.action = () => binding.arg === 'cut' ? 'cut' : 'copy'; | ||
| 41 | + } | ||
| 42 | + }, | ||
| 43 | + unbind(el, binding) { | ||
| 44 | + if (!el._vClipboard) return | ||
| 45 | + if (binding.arg === 'success') { | ||
| 46 | + delete el._vClipBoard_success; | ||
| 47 | + } else if (binding.arg === 'error') { | ||
| 48 | + delete el._vClipBoard_error; | ||
| 49 | + } else { | ||
| 50 | + el._vClipBoard.destroy(); | ||
| 51 | + delete el._vClipBoard; | ||
| 52 | + } | ||
| 53 | + } | ||
| 54 | +} |
-
请 注册 或 登录 后发表评论