filepond-image.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <template>
  2. <div>
  3. <file-pond
  4. ref="pond"
  5. name="file[]"
  6. label-idle="选择图片或拖动图片到此处"
  7. label-file-processing="图片正在上传,请稍后"
  8. label-file-processing-aborted="图片上传被取消"
  9. label-tap-to-retry="尝试重试"
  10. label-file-processing-complete="图片上传成功!"
  11. :allow-multiple="false"
  12. accepted-file-types="image/png, image/jpeg, image/jpg, image/gif"
  13. :server="server"
  14. :files="myFiles"
  15. :instant-upload="false"
  16. :image-edit-editor="editor"
  17. :image-edit-instant-edit="true"
  18. @init="handleFilePondInit"
  19. @processfile="success"
  20. />
  21. <!-- :instant-upload="false" 关闭立即上传到服务器 -->
  22. </div>
  23. </template>
  24. <script>
  25. // Import Vue FilePond
  26. import vueFilePond from 'vue-filepond'
  27. // Import FilePond styles
  28. import 'filepond/dist/filepond.min.css'
  29. // Import FilePond plugins
  30. // Please note that you need to install these plugins separately
  31. // Import image preview plugin styles
  32. import 'filepond-plugin-image-preview/dist/filepond-plugin-image-preview.min.css'
  33. import 'filepond-plugin-image-edit/dist/filepond-plugin-image-edit.css'
  34. // Import image preview and file type validation plugins
  35. import FilePondPluginFileValidateType from 'filepond-plugin-file-validate-type'
  36. import FilePondPluginImageEdit from 'filepond-plugin-image-edit'
  37. import FilePondPluginImagePreview from 'filepond-plugin-image-preview'
  38. import FilePondPluginImageExifOrientation from 'filepond-plugin-image-exif-orientation'
  39. import FilePondPluginFileValidateSize from 'filepond-plugin-file-validate-size'
  40. // Create component
  41. const FilePond = vueFilePond(
  42. FilePondPluginFileValidateType,
  43. FilePondPluginImagePreview,
  44. FilePondPluginImageExifOrientation,
  45. FilePondPluginFileValidateSize,
  46. FilePondPluginImageEdit
  47. )
  48. let videMessage = {}
  49. export default {
  50. name: 'FilePondUpdate',
  51. components: {
  52. FilePond
  53. },
  54. videMessage,
  55. data() {
  56. return {
  57. videMessage: {},
  58. myFiles: [],
  59. server: {
  60. url: '/api/file/upload/video',
  61. process: {
  62. headers: {
  63. 'X-XSRF-TOKEN': this.$cookies.get('XSRF-TOKEN')
  64. },
  65. onload(response) {
  66. // 返回上传数据
  67. videMessage = JSON.parse(response)
  68. }
  69. }
  70. },
  71. editor: {
  72. // Called by FilePond to edit the image
  73. // - should open your image editor
  74. // - receives file object and image edit instructions
  75. open: (file, instructions) => {
  76. // open editor here
  77. },
  78. // Callback set by FilePond
  79. // - should be called by the editor when user confirms editing
  80. // - should receive output object, resulting edit information
  81. onconfirm: (output) => {},
  82. // Callback set by FilePond
  83. // - should be called by the editor when user cancels editing
  84. oncancel: () => {},
  85. // Callback set by FilePond
  86. // - should be called by the editor when user closes the editor
  87. onclose: () => {}
  88. }
  89. }
  90. },
  91. created() {
  92. },
  93. methods: {
  94. handleFilePondInit() {
  95. // console.log('FilePond has initialized')
  96. // FilePond instance methods are available on `this.$refs.pond`
  97. },
  98. success() {
  99. this.$emit('photo', videMessage)
  100. }
  101. }
  102. }
  103. </script>