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

200 lines
2.7 KiB

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