普兆健康管家前端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
2.0 KiB

  1. <template>
  2. <view>
  3. <uv-upload
  4. :fileList="displayFileList"
  5. :accept="accept"
  6. :maxCount="maxCount"
  7. :width="width"
  8. :height="height"
  9. @afterRead="afterRead"
  10. @delete="deleteFile"
  11. >
  12. <button class="flex btn">
  13. <image class="btn-icon" src="@/pages_order/static/comment/icon-plus.png" mode="widthFix" />
  14. </button>
  15. </uv-upload>
  16. </view>
  17. </template>
  18. <script>
  19. export default {
  20. props: {
  21. value: {
  22. type: Array,
  23. default() {
  24. return []
  25. }
  26. },
  27. accept: {
  28. type: String,
  29. default: 'image' // all | media | image | file | video
  30. },
  31. width: {
  32. type: Number | String,
  33. default: 190,
  34. },
  35. height: {
  36. type: Number | String,
  37. default: 190,
  38. },
  39. maxCount: {
  40. type: Number | String,
  41. default: 100,
  42. }
  43. },
  44. data() {
  45. return {
  46. }
  47. },
  48. computed: {
  49. fileList: {
  50. set(val) {
  51. this.$emit('input', val)
  52. },
  53. get() {
  54. return this.value
  55. }
  56. },
  57. displayFileList() {
  58. return this.fileList.map(url => ({ url }))
  59. },
  60. },
  61. watch: {
  62. fileList: {
  63. handler(val) {
  64. console.log('watch fileList', val)
  65. },
  66. deep: true,
  67. },
  68. displayFileList: {
  69. handler(val) {
  70. console.log('watch displayFileList', val)
  71. },
  72. deep: true,
  73. },
  74. },
  75. mounted() {
  76. console.log('form upload mounted')
  77. },
  78. methods: {
  79. deleteFile(e){
  80. console.log('deleteFile', e)
  81. const fileList = [...this.fileList]
  82. fileList.splice(e.index, 1)
  83. this.fileList = fileList
  84. },
  85. afterRead(e){
  86. this.$Oss.ossUpload(e.file.url).then(url => {
  87. this.fileList = this.fileList.concat(url)
  88. })
  89. },
  90. },
  91. }
  92. </script>
  93. <style scoped lang="scss">
  94. .btn {
  95. width: 190rpx;
  96. height: 190rpx;
  97. background: #F3F2F7;
  98. border-radius: 16rpx;
  99. &-icon {
  100. width: 61rpx;
  101. height: auto;
  102. }
  103. }
  104. </style>