普兆健康管家前端代码仓库
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.

104 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. methods: {
  76. deleteFile(e){
  77. console.log('deleteFile', e)
  78. const fileList = [...this.fileList]
  79. fileList.splice(e.index, 1)
  80. this.fileList = fileList
  81. },
  82. afterRead(e){
  83. this.$Oss.ossUpload(e.file.url).then(url => {
  84. this.fileList = this.fileList.concat(url)
  85. })
  86. },
  87. },
  88. }
  89. </script>
  90. <style scoped lang="scss">
  91. .btn {
  92. width: 190rpx;
  93. height: 190rpx;
  94. background: #F3F2F7;
  95. border-radius: 16rpx;
  96. &-icon {
  97. width: 61rpx;
  98. height: auto;
  99. }
  100. }
  101. </style>