index.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <template>
  2. <!-- <el-image
  3. :src="`${realSrc}`"
  4. fit="cover"
  5. :style="`width:${realWidth};height:${realHeight};`"
  6. :preview-src-list="realSrcList"
  7. >
  8. <div slot="error" class="image-slot">
  9. <i class="el-icon-picture-outline"></i>
  10. </div>
  11. </el-image> -->
  12. <div class="uploaders">
  13. <div class="images">
  14. <div v-for="(v, i) in fileList" :key="i">
  15. <!-- -->
  16. <slot v-if="$slots.default"
  17. :v="v"
  18. :i="i"></slot>
  19. <!-- -->
  20. <div class="image relative"
  21. v-else>
  22. <el-image :src="v.url"
  23. class="avatar"
  24. :preview-src-list="previewSrcList"
  25. :z-index="6000" />
  26. <!-- <i v-show="!disabled"
  27. class="el-icon-error"
  28. @click="onRemove(i)"></i> -->
  29. </div>
  30. </div>
  31. </div>
  32. </div>
  33. </template>
  34. <script>
  35. export default {
  36. name: "ImageListPreview",
  37. data() {
  38. return {
  39. fileList: [],
  40. previewSrcList:[]
  41. }
  42. },
  43. watch: {
  44. value: {
  45. immediate: true,
  46. handler(newVal) {
  47. if(newVal){
  48. const list = Array.isArray(newVal) ? newVal : this.value.split(",");
  49. this.fileList = list.map((url) => ({ name: url, url }));
  50. this.previewSrcList=list.map((url) => url);
  51. console.log("this.fileList",this.fileList,this.previewSrcList);
  52. }
  53. else{
  54. this.fileList =[];
  55. this.previewSrcList=[];
  56. }
  57. },
  58. },
  59. },
  60. props: {
  61. value: {
  62. type: [Array,String],
  63. default: [],
  64. },
  65. src: {
  66. type: String,
  67. default: ""
  68. },
  69. width: {
  70. type: [Number, String],
  71. default: ""
  72. },
  73. height: {
  74. type: [Number, String],
  75. default: ""
  76. }
  77. },
  78. computed: {
  79. realSrc() {
  80. if (!this.src) {
  81. return;
  82. }
  83. let real_src = this.src.split(",")[0];
  84. return real_src;
  85. },
  86. realSrcList() {
  87. if (!this.src) {
  88. return;
  89. }
  90. let real_src_list = this.src.split(",");
  91. let srcList = [];
  92. real_src_list.forEach(item => {
  93. return srcList.push(item);
  94. });
  95. return srcList;
  96. },
  97. realWidth() {
  98. return typeof this.width == "string" ? this.width : `${this.width}px`;
  99. },
  100. realHeight() {
  101. return typeof this.height == "string" ? this.height : `${this.height}px`;
  102. }
  103. },
  104. };
  105. </script>
  106. <style lang="scss" scoped>
  107. .el-image {
  108. border-radius: 5px;
  109. background-color: #ebeef5;
  110. box-shadow: 0 0 5px 1px #ccc;
  111. ::v-deep .el-image__inner {
  112. transition: all 0.3s;
  113. cursor: pointer;
  114. &:hover {
  115. transform: scale(1.2);
  116. }
  117. }
  118. ::v-deep .image-slot {
  119. display: flex;
  120. justify-content: center;
  121. align-items: center;
  122. width: 100%;
  123. height: 100%;
  124. color: #909399;
  125. font-size: 30px;
  126. }
  127. }
  128. $width: 100px;
  129. $height: 100px;
  130. .uploaders {
  131. .red {
  132. font-size: 12px;
  133. }
  134. //
  135. .image {
  136. float: left;
  137. margin-right: 4px;
  138. margin-bottom: 4px;
  139. width: $width;
  140. height: $height;
  141. border: 1px solid #d9d9d9;
  142. position: relative;
  143. .avatar {
  144. width: 100%;
  145. height: 100%;
  146. }
  147. &:hover {
  148. i.el-icon-error {
  149. display: block;
  150. }
  151. }
  152. i.el-icon-error {
  153. display: none;
  154. position: absolute;
  155. top: 4px;
  156. right: 4px;
  157. font-size: 20px;
  158. }
  159. }
  160. //
  161. .uploader {
  162. width: $width;
  163. height: $height;
  164. float: left;
  165. position: relative;
  166. margin-right: 4px;
  167. margin-bottom: 4px;
  168. .el-upload {
  169. width: 100%;
  170. height: 100%;
  171. border: 1px dashed #d9d9d9;
  172. border-radius: 6px;
  173. cursor: pointer;
  174. position: relative;
  175. overflow: hidden;
  176. }
  177. .el-upload:hover {
  178. border-color: #20a0ff;
  179. }
  180. .avatar {
  181. width: 100%;
  182. height: 100%;
  183. display: block;
  184. }
  185. .avatar-uploader-icon {
  186. font-size: 28px;
  187. color: #8c939d;
  188. position: absolute;
  189. left: 50%;
  190. top: 50%;
  191. transform: translate(-50%, -50%);
  192. }
  193. .el-upload__input {
  194. opacity: 0;
  195. position: absolute;
  196. }
  197. }
  198. }
  199. </style>