decode.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /**
  2. * FeHelper QR码解码
  3. */
  4. module.exports = (() => {
  5. "use strict";
  6. let _show = (text) => {
  7. let el = $('#__fehelper_qr_decode__');
  8. if (!el[0]) {
  9. el = $('<div id="__fehelper_qr_decode__" style="z-index:999999;position: fixed;left:0;top:0;right: 0;bottom: 0;display: none;">' +
  10. '<div style="position: fixed;left:0;top:0;right: 0;bottom: 0;background: #000;opacity: 0.5;"></div>' +
  11. '<div style="position: relative;top: 100px;left: ' + ($('body').width() / 2 - 200) + 'px;border:1px solid #000;background:#fff;width:420px;padding:15px;border-radius:5px 5px;box-shadow:2px 2px 5px #000;">' +
  12. '<div style="margin: 0 0 10px 0;font-size: 14px;font-weight: bold;">二维码解码结果:</div>' +
  13. '<textarea style="display:block;border-radius:5px 5px;width:398px;border:1px solid #aaa;min-height:80px;resize:none;box-shadow:2px 2px 5px #aaa;padding:10px;font-size:14px;color:#888;"></textarea>' +
  14. '<div style="margin-top:10px;font-size:0">' +
  15. '<span id="__fehelper_qr_msg_" style="float: right;color:#f00;display:none;">复制成功!</span>' +
  16. '<a id="__fehelper_qr_open_" style="margin-right:20px;color: #00f;text-decoration: underline;display: inline;font-size:12px" href="#">打开</a>' +
  17. '<a id="__fehelper_qr_copy_" style="margin-right:20px;color: #00f;text-decoration: underline;display: inline;font-size:12px" href="#">复制</a>' +
  18. '<a id="__fehelper_qr_close_" style="margin-top:10px;color: #00f;text-decoration: underline;display: inline;font-size:12px" href="#">关闭</a>' +
  19. '</div></div>' +
  20. '</div>').appendTo('body');
  21. el.find('a#__fehelper_qr_open_').click(function (e) {
  22. e.preventDefault();
  23. window.open(el.find('textarea').val());
  24. });
  25. el.find('a#__fehelper_qr_copy_').click(function (e) {
  26. e.preventDefault();
  27. el.find('textarea').select();
  28. document.execCommand('Copy');
  29. el.find('#__fehelper_qr_msg_').show().delay(2000).hide('slow');
  30. });
  31. el.find('a#__fehelper_qr_close_').click(function (e) {
  32. e.preventDefault();
  33. el.hide('slow');
  34. });
  35. }
  36. if (text === 'error decoding QR Code') {
  37. text = '抱歉,二维码识别失败!';
  38. }
  39. el.show('slow').find('textarea').val(text);
  40. };
  41. return {
  42. show: _show
  43. };
  44. })();