a.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. modal = new Vue({
  2. el: '#modal',
  3. data: {
  4. msg: '么有',
  5. title: '提示'
  6. },
  7. methods: {
  8. show: function(msg, title) {
  9. if (title) {
  10. this.title = title;
  11. }
  12. this.msg = msg;
  13. $('#mmodal').modal();
  14. }
  15. }
  16. })
  17. Vue.component('vue-easymde', VueEasyMDE.VueEasyMDE)
  18. var blobMap = {}
  19. app = new Vue({
  20. el: '#app',
  21. data: {
  22. text: null,
  23. enurl: null,
  24. copyicon: 'fa-clone',
  25. easyMDEOpts: {
  26. maxHeight: '47vh',
  27. onToggleFullScreen: function() { $('.navbar').toggle(); },
  28. sideBySideFullscreen: false,
  29. spellChecker: false,
  30. renderingConfig: { codeSyntaxHighlighting: true },
  31. uploadImage: true,
  32. imageUploadFunction: function(file, onSuccess, onError) {
  33. var url = URL.createObjectURL(file);
  34. var reader = new FileReader();
  35. reader.onerror = onError;
  36. reader.onload = function() {
  37. blobMap[url] = reader.result;
  38. var prefix = '[' + file.name + ']';
  39. if (file.type.startsWith('image')) {
  40. prefix = '!' + prefix;
  41. }
  42. var test = new RegExp('\\[(.+)(' + file.name + ')?\\]\\(blob:.*?\\1\\)');
  43. app.text = app.text.replace(test, prefix + '(' + url + ')');
  44. };
  45. onSuccess(url);
  46. reader.readAsDataURL(file);
  47. },
  48. },
  49. },
  50. methods: {
  51. copyTempURL: function() {
  52. navigator.clipboard.writeText(app.enurl).then(function() {
  53. app.copyicon = 'fa-check';
  54. setTimeout(function() {
  55. app.copyicon = 'fa-clone';
  56. }, 3000);
  57. })
  58. },
  59. getTempURL: function() {
  60. $('#enurl').loading({
  61. message: '加载中...',
  62. onStop: function(loading) {
  63. loading.overlay.fadeOut(650);
  64. }
  65. });
  66. axios.post('/api/get-temp', {
  67. text: app.text.replace(/\]\((blob:[^)]*)\)/g, function(_, blobURL) {
  68. return '](' + blobMap[blobURL] + ')';
  69. })
  70. }).then(function(response) {
  71. $('#enurl').loading('stop');
  72. var data = response.data;
  73. if (data.status == 1) {
  74. var newURL = location.protocol + '//' + location.host + location.pathname;
  75. app.enurl = newURL + data.guid;
  76. } else {
  77. throw 'failure to get the tmp url!';
  78. modal.show('操作失败!<br>', '错误')
  79. }
  80. console.log(response);
  81. }).catch(function(error) {
  82. console.warn(error.response);
  83. $('#enurl').loading('stop');
  84. modal.show('操作失败!<br>' + error.response.data.message, '错误')
  85. })
  86. }
  87. }
  88. })