Coder Social home page Coder Social logo

Comments (7)

F-loat avatar F-loat commented on June 4, 2024

可以考虑,目前可以通过自定义工具栏来自行实现,欢迎PR。

from vue-simplemde.

F-loat avatar F-loat commented on June 4, 2024

不过感觉这个功能由simplemde来实现比较好,#294,simplemde的作者好像也有2.0的计划,就是不知道要什么时候了。。

from vue-simplemde.

jiemoon avatar jiemoon commented on June 4, 2024

这个功能可以有,

from vue-simplemde.

jiemoon avatar jiemoon commented on June 4, 2024

我自己实现了功能,但不知怎么整合进去 🍔

export default {
    components: {
            markdownEditor
    },
    computed: {
            simplemde () {
                return this.$refs.markdownEditor.simplemde
            }
    },
    mount() {
            let _this = this;
            this.simplemde.codemirror.on('drop', function (editor, e) {
                var fileList = e.dataTransfer.files;
                if (fileList.length > 1){
                    _this.$message.error('一次只能上传一张图片');
                    return false;
                }
                if(fileList[0].type.indexOf('image') === -1){
                    _this.$message.error("只能上传图片!");
                    return false;
                }

                // placeholder
                let placeholder = "![Uploading " + fileList[0]['name'] + "...]()"
                editor.replaceRange(placeholder, {
                    line: editor.getCursor().line,
                    ch: editor.getCursor().ch
                });

                var img = new FormData();
                img.append('img', fileList[0]);
                axios.post('/images/upload', img).then((res) => {
                    if (res.data["status"] == "success") {
                        editor.setValue(editor.getValue().replace(tips, "![](" + res.data['uri'] + ")"));
                    } else {
                        _this.$message.error(res.data["message"]);
                    }
                })
            });
    }
}

后端实现(Laravel)

public function store(Request $request)
    {
        $file = $request->file('img');
        if($file->isValid()) {
            $image = new Image();
            $image->name = $file->getClientOriginalName();
            $image->extension = $file->getClientOriginalExtension();
            if (!in_array($image->extension, array('jpg', 'jpeg', 'gif', 'png')))  {
                return response()->json([
                    'status' => 'fail',
                    'message' => 'Invalid image extension we just allow JPG, GIF, PNG, JPEG'
                ]);
            };

            $image->mime_type = $file->getMimeType();
            $image->path = $file->store('/upload/images');
            return response()->json([
                'status' => 'success',
                'uri' => url('/') . '/' . $image->path
            ]);
        } else {
           return response()->json([
              'status' => 'fail',
              'message' => '文件非法'
          ]);
    }

from vue-simplemde.

F-loat avatar F-loat commented on June 4, 2024

@liniu 不好意思,之前没看到,整合具体是要达到什么效果,现在已经实现了什么呢

from vue-simplemde.

liniu avatar liniu commented on June 4, 2024

用了第三方的库,可以实现黏贴上传

new InlineAttachment.CodeMirror4(simplemde.codemirror,{        		 
	 	 uploadUrl: 'http://127.0.0.1:8080/doc/attach/upload',
         progressText: '' ,
         onFileUploadResponse(xhr) {
             //var placeholder=this.settings.progressText;
             var result = JSON.parse(xhr.responseText);    
             var content='![]('+result.data+')';        
             this.editor.insertValue(content);            
         }
    });

但是细节还要处理,如:progressText是提示 正在上传中,上传完将这段提示替换成正式的url.

from vue-simplemde.

F-loat avatar F-loat commented on June 4, 2024

还是觉得不适合加在这个库里,有需要的话参考上面的示例先自行实现吧,实在想要加入这个功能的话,可以给simplemde提pr

from vue-simplemde.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.