@jx3box/jx3box-editor 2.2.47 → 2.2.48
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/Tinymce.vue +51 -2
package/package.json
CHANGED
package/src/Tinymce.vue
CHANGED
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
|
|
27
27
|
<script>
|
|
28
28
|
import Vue from "vue";
|
|
29
|
+
import axios from "axios";
|
|
29
30
|
import Editor from "@tinymce/tinymce-vue";
|
|
30
31
|
import Upload from "./Upload";
|
|
31
32
|
import Resource from "./Resource";
|
|
@@ -143,9 +144,10 @@ export default {
|
|
|
143
144
|
image_advtab: true,
|
|
144
145
|
// paste_data_images: true,
|
|
145
146
|
file_picker_types: "file image",
|
|
146
|
-
images_upload_url: API,
|
|
147
147
|
automatic_uploads: true,
|
|
148
|
-
|
|
148
|
+
images_upload_handler: (blobInfo, success, failure, progress) => {
|
|
149
|
+
this.imagesUploadHandler(blobInfo, success, failure, progress);
|
|
150
|
+
},
|
|
149
151
|
|
|
150
152
|
// Hook
|
|
151
153
|
// setup: this.setup,
|
|
@@ -183,6 +185,53 @@ export default {
|
|
|
183
185
|
},
|
|
184
186
|
},
|
|
185
187
|
methods: {
|
|
188
|
+
imagesUploadHandler: function (blobInfo, success, failure, progress) {
|
|
189
|
+
let fdata = new FormData();
|
|
190
|
+
fdata.append("file", blobInfo.blob(), blobInfo.filename());
|
|
191
|
+
|
|
192
|
+
axios
|
|
193
|
+
.post(API, fdata, {
|
|
194
|
+
headers: {
|
|
195
|
+
"Content-Type": "multipart/form-data",
|
|
196
|
+
},
|
|
197
|
+
withCredentials: true,
|
|
198
|
+
auth: {
|
|
199
|
+
username: (localStorage && localStorage.getItem("token")) || "",
|
|
200
|
+
password: "cms common request",
|
|
201
|
+
},
|
|
202
|
+
onUploadProgress: function (e) {
|
|
203
|
+
if (progress && e.total > 0) {
|
|
204
|
+
progress((e.loaded / e.total) * 100);
|
|
205
|
+
}
|
|
206
|
+
},
|
|
207
|
+
})
|
|
208
|
+
.then((res) => {
|
|
209
|
+
const payload = res.data || {};
|
|
210
|
+
if (payload.code) {
|
|
211
|
+
failure(payload.msg || payload.message || "上传失败");
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const url =
|
|
216
|
+
payload.location ||
|
|
217
|
+
payload.url ||
|
|
218
|
+
(payload.data &&
|
|
219
|
+
(Array.isArray(payload.data)
|
|
220
|
+
? payload.data[0]
|
|
221
|
+
: payload.data.url || payload.data.location || payload.data));
|
|
222
|
+
|
|
223
|
+
if (!url) {
|
|
224
|
+
failure("上传成功但未返回图片地址");
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
success(url);
|
|
229
|
+
})
|
|
230
|
+
.catch((err) => {
|
|
231
|
+
const message = (err.response && err.response.data && (err.response.data.msg || err.response.data.message)) || "图片上传请求异常";
|
|
232
|
+
failure(message);
|
|
233
|
+
});
|
|
234
|
+
},
|
|
186
235
|
setup: function (editor) {
|
|
187
236
|
// console.log("ID为: " + editor.id + " 的编辑器即将初始化.");
|
|
188
237
|
},
|