uploadFile.vue 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <template>
  2. <div class="upload-file">
  3. <Input type="text" v-model="payHtml" :placeholder="placeholdered" readonly></Input>
  4. <Input type="text" v-model="validateVar" style="display:none"></Input>
  5. <Upload
  6. :multiple="multipled"
  7. action="/filemanage/upload"
  8. :before-upload="beforeImgFile"
  9. :on-success="handleSuccess"
  10. :on-exceeded-size="handleExceeded"
  11. :on-error="handleError"
  12. :show-upload-list="false"
  13. :accept="accepted"
  14. :format="formated"
  15. :on-format-error="formatError"
  16. name="transferAccounts"
  17. :data="uploadData"
  18. :max-size="15120"
  19. class="pay-load"
  20. >
  21. <Button class="find-btn">浏览</Button>
  22. </Upload>
  23. <Spin fix style="height:36px" v-if="uploadShow">
  24. <Icon type="ios-loading" size=18 class="demo-spin-icon-load"></Icon>
  25. </Spin>
  26. </div>
  27. </template>
  28. <script>
  29. export default {
  30. name: "uploadFile",
  31. props: {
  32. placeholdered: String,
  33. accepted: String,
  34. formated: Array,
  35. multipled: Boolean,
  36. validateVar: String
  37. },
  38. data() {
  39. return {
  40. uploadShow: false,
  41. payHtml: '',
  42. uploadData: {
  43. type: 'transferAccounts'
  44. }
  45. }
  46. },
  47. methods: {
  48. beforeImgFile() {// 上传合同
  49. this.uploadShow = true
  50. },
  51. handleSuccess(res, file) {// 文件上传成功
  52. this.uploadShow = false
  53. this.$Notice.success({title: '上传成功'})
  54. this.payHtml = file.name
  55. this.$emit('fileData', file.response.url)
  56. },
  57. handleError() {// 文件上传失败
  58. this.$Notice.error({title: '上传失败'})
  59. },
  60. handleExceeded() {// 文件超出指定大小限制
  61. this.$Notice.warning({title: '上传文件内存应小于14M'})
  62. },
  63. formatError() {// 文件格式验证失败
  64. this.$Notice.warning({
  65. title: '上传文件格式错误',
  66. desc: '格式支持',
  67. render: h => {
  68. return h('span', [
  69. '格式仅支持:',
  70. h('p', this.accepted)
  71. ])
  72. }
  73. })
  74. }
  75. },
  76. }
  77. </script>