风险测评小程序前端代码仓库
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.

99 lines
1.9 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. <!-- todo: 缺切图 -->
  14. <uv-icon name="camera-fill" color="#014FA2" size="56rpx"></uv-icon>
  15. </button>
  16. </uv-upload>
  17. </view>
  18. </template>
  19. <script>
  20. export default {
  21. props: {
  22. value: {
  23. type: Array,
  24. default() {
  25. return []
  26. }
  27. },
  28. accept: {
  29. type: String,
  30. default: 'image' // all | media | image | file | video
  31. },
  32. width: {
  33. type: Number | String,
  34. default: 133,
  35. },
  36. height: {
  37. type: Number | String,
  38. default: 133,
  39. },
  40. maxCount: {
  41. type: Number | String,
  42. default: 100,
  43. }
  44. },
  45. data() {
  46. return {
  47. }
  48. },
  49. computed: {
  50. fileList: {
  51. set(val) {
  52. this.$emit('input', val)
  53. },
  54. get() {
  55. return this.value
  56. }
  57. },
  58. displayFileList() {
  59. return this.fileList.map(url => ({ url }))
  60. },
  61. },
  62. watch: {
  63. fileList: {
  64. handler(val) {
  65. console.log('watch fileList', val)
  66. },
  67. deep: true,
  68. },
  69. displayFileList: {
  70. handler(val) {
  71. console.log('watch displayFileList', val)
  72. },
  73. deep: true,
  74. },
  75. },
  76. methods: {
  77. deleteFile(e){
  78. console.log('deleteFile', e)
  79. const fileList = [...this.fileList]
  80. fileList.splice(e.index, 1)
  81. this.fileList = fileList
  82. },
  83. afterRead(e){
  84. this.$Oss.ossUpload(e.file.url).then(url => {
  85. this.fileList = this.fileList.concat(url)
  86. })
  87. },
  88. },
  89. }
  90. </script>
  91. <style scoped lang="scss">
  92. .btn {
  93. width: 133rpx;
  94. height: 133rpx;
  95. border: 2rpx dashed #014FA2;
  96. }
  97. </style>