| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- modal = new Vue({
- el: '#modal',
- data: {
- msg: '么有',
- title: '提示'
- },
- methods: {
- show: function(msg, title) {
- if (title) {
- this.title = title;
- }
- this.msg = msg;
- $('#mmodal').modal();
- }
- }
- })
- Vue.component('vue-easymde', VueEasyMDE.VueEasyMDE)
- var blobMap = {}
- app = new Vue({
- el: '#app',
- data: {
- text: null,
- enurl: null,
- copyicon: 'fa-clone',
- easyMDEOpts: {
- maxHeight: '47vh',
- onToggleFullScreen: function() { $('.navbar').toggle(); },
- sideBySideFullscreen: false,
- spellChecker: false,
- renderingConfig: { codeSyntaxHighlighting: true },
- uploadImage: true,
- imageUploadFunction: function(file, onSuccess, onError) {
- var url = URL.createObjectURL(file);
- var reader = new FileReader();
- reader.onerror = onError;
- reader.onload = function() {
- blobMap[url] = reader.result;
- var prefix = '[' + file.name + ']';
- if (file.type.startsWith('image')) {
- prefix = '!' + prefix;
- }
- var test = new RegExp('\\[(.+)(' + file.name + ')?\\]\\(blob:.*?\\1\\)');
- app.text = app.text.replace(test, prefix + '(' + url + ')');
- };
- onSuccess(url);
- reader.readAsDataURL(file);
- },
- },
- },
- methods: {
- copyTempURL: function() {
- navigator.clipboard.writeText(app.enurl).then(function() {
- app.copyicon = 'fa-check';
- setTimeout(function() {
- app.copyicon = 'fa-clone';
- }, 3000);
- })
- },
- getTempURL: function() {
- $('#enurl').loading({
- message: '加载中...',
- onStop: function(loading) {
- loading.overlay.fadeOut(650);
- }
- });
- axios.post('/api/get-temp', {
- text: app.text.replace(/\]\((blob:[^)]*)\)/g, function(_, blobURL) {
- return '](' + blobMap[blobURL] + ')';
- })
- }).then(function(response) {
- $('#enurl').loading('stop');
- var data = response.data;
- if (data.status == 1) {
- var newURL = location.protocol + '//' + location.host + location.pathname;
- app.enurl = newURL + data.guid;
- } else {
- throw 'failure to get the tmp url!';
- modal.show('操作失败!<br>', '错误')
- }
- console.log(response);
- }).catch(function(error) {
- console.warn(error.response);
- $('#enurl').loading('stop');
- modal.show('操作失败!<br>' + error.response.data.message, '错误')
- })
- }
- }
- })
|