index.vue 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <template>
  2. <view :class="{ 'disabled-box': $attrs.disabled }">
  3. <imageUpload
  4. v-bind="__attrs"
  5. v-on="__listeners"
  6. v-if="accept === 'image'"
  7. >
  8. <template :slot="name" v-for="(_, name) in $scopedSlots">
  9. <slot :name="name"></slot>
  10. </template>
  11. </imageUpload>
  12. <!-- 视频上传 -->
  13. <videoUpload
  14. v-bind="__attrs"
  15. v-on="__listeners"
  16. v-if="accept === 'video'"
  17. >
  18. <template :slot="name" v-for="(_, name) in $scopedSlots">
  19. <slot :name="name"></slot>
  20. </template>
  21. </videoUpload>
  22. </view>
  23. </template>
  24. <script>
  25. import imageUpload from './imageUpload.vue'; // 图片上传
  26. import videoUpload from './videoUpload.vue'; // 视频上传
  27. export default {
  28. name: 'c-upload',
  29. model: {
  30. prop: 'value',
  31. event: 'change',
  32. },
  33. computed: {
  34. __attrs() {
  35. return {
  36. ...this.$attrs,
  37. ...this.$props,
  38. };
  39. },
  40. __listeners() {
  41. return {
  42. ...this.$listeners,
  43. };
  44. },
  45. accept() {
  46. // 接受的文件类型;
  47. return this.$attrs.accept || 'image'; // image | video
  48. },
  49. },
  50. inheritAttrs: false,
  51. components: {
  52. imageUpload,
  53. videoUpload,
  54. },
  55. };
  56. </script>
  57. <style scoped lang="scss">
  58. .disabled-box {
  59. /deep/ .u-upload__button--disabled {
  60. display: none;
  61. }
  62. }
  63. </style>