详情小程序
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.

196 lines
2.7 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. <template>
  2. <image
  3. :class="{'loading': loading}"
  4. :data-loading-text="loadingText"
  5. :src="img_src"
  6. :mode="mode"
  7. :lazy-load="true"
  8. @click="click"
  9. @load="load"
  10. @error="error">
  11. </image>
  12. </template>
  13. <script>
  14. export default {
  15. props: {
  16. src: {
  17. type: String,
  18. default: ''
  19. },
  20. mode: {
  21. type: String,
  22. default: 'scaleToFill'
  23. },
  24. errSrc: {
  25. type: String,
  26. default: '../../static/images/empty.png'
  27. },
  28. loadingText: {
  29. type: String,
  30. default: '正在加载中'
  31. }
  32. },
  33. data(){
  34. return {
  35. img_src: '',
  36. loading: true
  37. }
  38. },
  39. watch: {
  40. src(val){
  41. console.log("val", val)
  42. this.img_src = val;
  43. }
  44. },
  45. methods: {
  46. load(event){
  47. this.loading = false;
  48. },
  49. error(event){
  50. this.loading = false;
  51. this.img_src = this.$props.errSrc;
  52. },
  53. click(event){
  54. this.$emit('click', event);
  55. }
  56. }
  57. }
  58. </script>
  59. <style lang="scss" scoped="scoped">
  60. image{
  61. width: 100%;
  62. height: 100%;
  63. }
  64. .loading{
  65. position: relative;
  66. // background-color: #e5e5e5;
  67. background: linear-gradient(-45deg, #e5e5e5, #d9d9d9, #f1f3f5, #f0f0f0);
  68. animation: gradientBG 15s ease infinite;
  69. background-size: 400% 400%;
  70. transition: all 1s;
  71. &::after{
  72. content: attr(data-loading-text);
  73. position: absolute;
  74. top: 0;
  75. right: 0;
  76. bottom: 0;
  77. left: 0;
  78. color: #969696;
  79. font-size: 20rpx;
  80. display: flex;
  81. justify-content: center;
  82. align-items: center;
  83. flex-wrap: wrap;
  84. animation: flicker-in-1 2s linear both infinite;
  85. transition: all 2s;
  86. }
  87. }
  88. @keyframes gradientBG {
  89. 0% {
  90. background-position: 0% 50%;
  91. }
  92. 50% {
  93. background-position: 100% 50%;
  94. }
  95. 100% {
  96. background-position: 0% 50%;
  97. }
  98. }
  99. @keyframes flicker-in-1 {
  100. 0% {
  101. opacity: 0.5;
  102. }
  103. 10% {
  104. opacity: 0.5;
  105. }
  106. 10.1% {
  107. opacity: 1;
  108. }
  109. 10.2% {
  110. opacity: 0.5;
  111. }
  112. 20% {
  113. opacity: 0.5;
  114. }
  115. 20.1% {
  116. opacity: 1;
  117. }
  118. 20.6% {
  119. opacity: 0.5;
  120. }
  121. 30% {
  122. opacity: 0.5;
  123. }
  124. 30.1% {
  125. opacity: 1;
  126. }
  127. 30.5% {
  128. opacity: 1;
  129. }
  130. 30.6% {
  131. opacity: 0.5;
  132. }
  133. 45% {
  134. opacity: 0.5;
  135. }
  136. 45.1% {
  137. opacity: 1;
  138. }
  139. 50% {
  140. opacity: 1;
  141. }
  142. 55% {
  143. opacity: 1;
  144. }
  145. 55.1% {
  146. opacity: 0.5;
  147. }
  148. 57% {
  149. opacity: 0.5;
  150. }
  151. 57.1% {
  152. opacity: 1;
  153. }
  154. 60% {
  155. opacity: 1;
  156. }
  157. 60.1% {
  158. opacity: 0.5;
  159. }
  160. 65% {
  161. opacity: 0.5;
  162. }
  163. 65.1% {
  164. opacity: 1;
  165. }
  166. 75% {
  167. opacity: 1;
  168. }
  169. 75.1% {
  170. opacity: 0.5;
  171. }
  172. 77% {
  173. opacity: 0.5;
  174. }
  175. 77.1% {
  176. opacity: 1;
  177. }
  178. 85% {
  179. opacity: 1;
  180. }
  181. 85.1% {
  182. opacity: 0.5;
  183. }
  184. 86% {
  185. opacity: 0.5;
  186. }
  187. 86.1% {
  188. opacity: 1;
  189. }
  190. 100% {
  191. opacity: 1;
  192. }
  193. }
  194. </style>