diff --git a/src/views/attachment/components/AttachmentDrawer.vue b/src/views/attachment/components/AttachmentDrawer.vue new file mode 100644 index 00000000..df47f89d --- /dev/null +++ b/src/views/attachment/components/AttachmentDrawer.vue @@ -0,0 +1,199 @@ + + + + + diff --git a/src/views/post/PostEdit.vue b/src/views/post/PostEdit.vue index df140f98..a624a63d 100644 --- a/src/views/post/PostEdit.vue +++ b/src/views/post/PostEdit.vue @@ -1,7 +1,13 @@ @@ -240,6 +167,7 @@ import tagApi from '@/api/tag' import categoryApi from '@/api/category' import postApi from '@/api/post' import attachmentApi from '@/api/attachment' +import AttachmentDrawer from '../attachment/components/AttachmentDrawer' const toolbars = { bold: true, // 粗体 @@ -266,7 +194,8 @@ export default { components: { mavonEditor, CategoryTree, - FooterToolBar + FooterToolBar, + AttachmentDrawer }, mixins: [mixin, mixinDevice], data() { @@ -294,7 +223,8 @@ export default { page: 1, size: 8, sort: '' - } + }, + attachmentUploadHandler: attachmentApi.upload } }, computed: { @@ -338,7 +268,7 @@ export default { loadAttachments() { const pagination = Object.assign({}, this.pagination) pagination.page-- - attachmentApi.list(pagination).then(response => { + attachmentApi.query(pagination).then(response => { this.attachments = response.data.data.content this.pagination.total = response.data.data.total }) @@ -439,38 +369,8 @@ export default { this.$message.error(`${info.file.name} 文件上传失败`) } }, - handleUpload(option) { - this.$log.debug('Uploading option', option) - const CancelToken = attachmentApi.CancelToken - const source = CancelToken.source() - - const data = new FormData() - data.append('file', option.file) - attachmentApi - .upload( - data, - progressEvent => { - if (progressEvent.total > 0) { - progressEvent.percent = (progressEvent.loaded / progressEvent.total) * 100 - } - this.$log.debug('Uploading percent: ', progressEvent.percent) - option.onProgress(progressEvent) - }, - source.token - ) - .then(response => { - option.onSuccess(response, option.file) - this.loadAttachments() - }) - .catch(error => { - option.onError(error, error.response) - }) - - return { - abort: () => { - source.cancel('Upload operation canceled by the user.') - } - } + handleAttachmentUploadSuccess() { + this.$message.success('上传成功') }, showUploadModal() { this.uploadVisible = true