uploadImg.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <template>
  2. <view class="">
  3. <view style="position: relative;" class="uploadImg" @click="chooseImage">
  4. <view v-if="!model" :style="{'width':width+'rpx','height':height+'rpx'}">
  5. <image style="width: 60rpx;height: 60rpx;margin-bottom: 20rpx;" :src="addImg"></image>
  6. <text>{{title}}</text>
  7. </view>
  8. <image v-else :src="model" :style="{'width':width+'rpx','height':height+'rpx'}"></image>
  9. <image v-if="!model && enableImg" style="height: 160rpx;width: 90%;position: absolute" :src="bgImg">
  10. </image>
  11. </view>
  12. </view>
  13. </template>
  14. <script>
  15. export default {
  16. props: {
  17. title:String,
  18. //图标
  19. addImg: {
  20. type: String,
  21. default: 'https://guosen-bucket-ldt.obs.cn-south-1.myhuaweicloud.com:443/723e0e52706a46159203f2d243873485-t5yIWXtGE8l04314394a1700881f3d4c73f10db523dd.png'
  22. },
  23. //是否开启背景图片
  24. enableImg: Boolean,
  25. //背景图片
  26. bgImg: {
  27. type: String,
  28. default: 'https://guosen-bucket-ldt.obs.cn-south-1.myhuaweicloud.com:443/704abb0fbe654e95ae1f57a458dc5f92-FPFbZdIYvEv4be3706cc937d3313d3674ac283ae53fe.png'
  29. },
  30. dataName: String,
  31. model:String,
  32. width:{
  33. type:Number,
  34. default:480
  35. },
  36. height:{
  37. type:Number,
  38. default:300
  39. },
  40. },
  41. data() {
  42. return {
  43. };
  44. },
  45. onLoad() {
  46. },
  47. methods: {
  48. chooseImage() {
  49. this.$emit('click', this.dataName)
  50. }
  51. }
  52. };
  53. </script>
  54. <style lang="scss" scoped>
  55. .uploadImg {
  56. display: flex;
  57. align-items: center;
  58. justify-content: center;
  59. margin: 20rpx;
  60. view {
  61. z-index: 10;
  62. border: 4rpx dashed #e1e1e1;
  63. width: 480rpx;
  64. height: 300rpx;
  65. border-radius: 10rpx;
  66. display: flex;
  67. justify-content: center;
  68. align-items: center;
  69. flex-direction: column;
  70. }
  71. .icon {
  72. width: 70rpx;
  73. height: 70rpx;
  74. }
  75. text {
  76. color: #999;
  77. }
  78. }
  79. </style>