clipboard.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // +----------------------------------------------------------------------
  2. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  3. // +----------------------------------------------------------------------
  4. // | Copyright (c) 2016~2025 https://www.crmeb.com All rights reserved.
  5. // +----------------------------------------------------------------------
  6. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  7. // +----------------------------------------------------------------------
  8. // | Author: CRMEB Team <admin@crmeb.com>
  9. // +----------------------------------------------------------------------
  10. import Vue from 'vue';
  11. import Clipboard from 'clipboard';
  12. function clipboardSuccess() {
  13. Vue.prototype.$message({
  14. message: 'Copy successfully',
  15. type: 'success',
  16. duration: 1500,
  17. });
  18. }
  19. function clipboardError() {
  20. Vue.prototype.$message({
  21. message: 'Copy failed',
  22. type: 'error',
  23. });
  24. }
  25. export default function handleClipboard(text, event) {
  26. const clipboard = new Clipboard(event.target, {
  27. text: () => text,
  28. });
  29. clipboard.on('success', () => {
  30. clipboardSuccess();
  31. clipboard.destroy();
  32. });
  33. clipboard.on('error', () => {
  34. clipboardError();
  35. clipboard.destroy();
  36. });
  37. clipboard.onClick(event);
  38. }