index.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /**
  2. * FeHelper Code Compress
  3. */
  4. let editor = {};
  5. new Vue({
  6. el: '#pageContainer',
  7. data: {
  8. sourceContent: '',
  9. resultContent: ''
  10. },
  11. mounted: function () {
  12. editor = CodeMirror.fromTextArea(this.$refs.codeSource, {
  13. mode: "text/javascript",
  14. lineNumbers: true,
  15. matchBrackets: true,
  16. styleActiveLine: true,
  17. lineWrapping: true
  18. });
  19. //输入框聚焦
  20. editor.focus();
  21. },
  22. methods: {
  23. compress: function () {
  24. this.sourceContent = editor.getValue().trim();
  25. if (!this.sourceContent) {
  26. alert('请先粘贴您需要压缩的代码');
  27. } else {
  28. // 用uglifyjs3进行在线压缩
  29. let UglifyJs3 = Tarp.require('./uglifyjs3');
  30. let result = UglifyJs3.compress(this.sourceContent);
  31. this.resultContent = result.out || result.error;
  32. this.$refs.jfContent.style.color = result.error ? 'red' : 'black';
  33. }
  34. },
  35. getResult: function () {
  36. this.$refs.jfContent.select();
  37. }
  38. }
  39. });