123456789101112131415161718192021222324252627282930313233 |
- var uploadMixin = {
- methods: {
- initEditorOptions(editor, baseUrl) {
- const that = this;
- this.editor.config.zIndex = 333;
- this.editor.config.height = 400;
- this.editor.config.uploadImgMaxSize = 2 * 1024 * 1024;
- this.editor.config.uploadImgMaxLength = 5; // 一次最多上传 5 个图片
- this.editor.config.customUploadImg = function (resultFiles, insertImgFn) {
- resultFiles.forEach(function (file) {
- // resultFiles 是 input 中选中的文件列表
- // insertImgFn 是获取图片 url 后,插入到编辑器的方法
- that.uploadImage(file).then(res => {
- insertImgFn(res);
- })
- });
- }
- },
- // 上传图片
- uploadImage(file) {
- const formData = new FormData();
- formData.append('file', file);
- return new Promise(function (resolve, reject) {
- PublicApi.uploadimg(formData, function (res) {
- if (res.code === 0) {
- resolve(res.data);
- }
- reject()
- });
- })
- }
- }
- };
|