com-image-upload.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <style>
  2. .com-image-upload {
  3. display: inline-block;
  4. }
  5. .com-image-upload .pic-box {
  6. width: 70px;
  7. height: 70px;
  8. border: 1px solid #ccc;
  9. cursor: pointer;
  10. background-color: #fff;
  11. background-size: contain;
  12. background-position: center;
  13. background-repeat: no-repeat;
  14. position: relative;
  15. }
  16. .com-image-upload .pic-box i {
  17. font-size: 22px;
  18. color: #909399;
  19. }
  20. .com-image-upload .pic-box .size-tip {
  21. line-height: 1.35;
  22. text-align: center;
  23. position: absolute;
  24. bottom: 0;
  25. left: 0;
  26. width: 100%;
  27. white-space: nowrap;
  28. overflow: hidden;
  29. text-overflow: ellipsis;
  30. font-size: 12px;
  31. color: #fff;
  32. background: rgba(0, 0, 0, 0.2);
  33. letter-spacing: -1px;
  34. }
  35. .com-image-upload .image-delete {
  36. position: absolute;
  37. top: -10px;
  38. right: -10px;
  39. padding: 5px;
  40. visibility: hidden;
  41. z-index: 1;
  42. }
  43. .com-image-upload:hover .image-delete {
  44. visibility: visible;
  45. }
  46. .com-image-upload .image-delete i {
  47. font-size: 12px;
  48. color: #fff;
  49. }
  50. </style>
  51. <template id="com-image-upload">
  52. <div class="com-image-upload">
  53. <com-attachment v-model="url">
  54. <div class="pic-box" v-if="url" :style="'background-image: url('+url+');'">
  55. <div class="size-tip" v-if="cSizeTip">{{cSizeTip}}</div>
  56. <el-button @click.stop="imageDelete" class="image-delete" icon="el-icon-close" size="mini" circle type="danger"></el-button>
  57. </div>
  58. <div class="pic-box" v-else flex="main:center cross:center">
  59. <i class="el-icon-picture-outline"></i>
  60. <div class="size-tip" v-if="cSizeTip">{{cSizeTip}}</div>
  61. </div>
  62. </com-attachment>
  63. </div>
  64. </template>
  65. <script>
  66. Vue.component('com-image-upload', {
  67. template: '#com-image-upload',
  68. props: ['value', 'width', 'height'],
  69. data() {
  70. return {
  71. url: '',
  72. };
  73. },
  74. created() {
  75. this.url = this.value;
  76. },
  77. watch: {
  78. value: {
  79. handler(newVal, oldVal) {
  80. this.url = newVal;
  81. },
  82. },
  83. url: {
  84. handler(newVal, oldVal) {
  85. this.$emit('input', newVal, oldVal)
  86. },
  87. },
  88. },
  89. computed: {
  90. cSizeTip() {
  91. if (!this.width && !this.height) {
  92. return false;
  93. }
  94. return (this.width ? this.width : '') + ' × ' + (this.height ? this.height : '');
  95. },
  96. },
  97. methods: {
  98. imageDelete() {
  99. this.url = '';
  100. },
  101. },
  102. });
  103. </script>