skeleton.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. <template>
  2. <view
  3. v-if="show"
  4. :style="{
  5. width: '100vw',
  6. height: '100vh',
  7. backgroundColor: bgcolor,
  8. position: 'absolute',
  9. left: 0,
  10. top: 0,
  11. zIndex: 9998,
  12. }"
  13. >
  14. <view
  15. v-for="(item, rect_idx) in skeletonRectLists"
  16. :key="rect_idx + 'rect'"
  17. :class="[loading == 'chiaroscuro' ? 'chiaroscuro' : '']"
  18. :style="{
  19. width: item.width * 2 + 'rpx',
  20. height: item.height * 2 + 'rpx',
  21. backgroundColor: 'rgb(194, 207, 214,.3)',
  22. position: 'absolute',
  23. left: item.left * 2 + 'rpx',
  24. top: item.top * 2 + 'rpx',
  25. }"
  26. >
  27. </view>
  28. <view
  29. v-for="(item, circle_idx) in skeletonCircleLists"
  30. :key="circle_idx + 'circle'"
  31. :class="loading == 'chiaroscuro' ? 'chiaroscuro' : ''"
  32. :style="{
  33. width: item.width * 2 + 'rpx',
  34. height: item.height * 2 + 'rpx',
  35. backgroundColor: 'rgb(194, 207, 214,.3)',
  36. borderRadius: item.width * 2 + 'rpx',
  37. position: 'absolute',
  38. left: item.left * 2 + 'rpx',
  39. top: item.top * 2 + 'rpx',
  40. zIndex: 9998,
  41. }"
  42. >
  43. </view>
  44. <view class="spinbox" v-if="loading == 'spin'">
  45. <view class="spin"></view>
  46. </view>
  47. </view>
  48. </template>
  49. <script>
  50. export default {
  51. name: "skeleton",
  52. props: {
  53. bgcolor: {
  54. type: String,
  55. value: "#FFF",
  56. },
  57. selector: {
  58. type: String,
  59. value: "skeleton",
  60. },
  61. loading: {
  62. type: String,
  63. value: "chiaroscuro",
  64. },
  65. show: {
  66. type: Boolean,
  67. value: false,
  68. },
  69. isNodes: {
  70. type: Number,
  71. value: false,
  72. }, //控制什么时候开始抓取元素节点,只要数值改变就重新抓取
  73. },
  74. data() {
  75. return {
  76. loadingAni: ["spin", "chiaroscuro"],
  77. systemInfo: {},
  78. skeletonRectLists: [
  79. {
  80. bottom: 35,
  81. dataset: {},
  82. height: 25,
  83. id: "",
  84. left: 15,
  85. right: 65,
  86. top: 10,
  87. width: 50,
  88. },
  89. {
  90. bottom: 72,
  91. dataset: {},
  92. height: 30,
  93. id: "",
  94. left: 15,
  95. right: 360,
  96. top: 42,
  97. width: 345,
  98. },
  99. {
  100. bottom: 232,
  101. dataset: {},
  102. height: 145,
  103. id: "",
  104. left: 15,
  105. right: 360,
  106. top: 87,
  107. width: 345,
  108. },
  109. {
  110. bottom: 436,
  111. dataset: {},
  112. height: 30,
  113. id: "",
  114. left: 15,
  115. right: 360,
  116. top: 406,
  117. width: 345,
  118. },
  119. {
  120. bottom: 596,
  121. dataset: {},
  122. height: 150,
  123. id: "",
  124. left: 15,
  125. right: 183,
  126. top: 446,
  127. width: 168,
  128. },
  129. {
  130. bottom: 519,
  131. dataset: {},
  132. height: 73,
  133. id: "",
  134. left: 188,
  135. right: 360,
  136. top: 446,
  137. width: 172,
  138. },
  139. {
  140. bottom: 596,
  141. dataset: {},
  142. height: 73,
  143. id: "",
  144. left: 188,
  145. right: 360,
  146. top: 523,
  147. width: 172,
  148. },
  149. {
  150. bottom: 793,
  151. dataset: {},
  152. height: 177,
  153. id: "",
  154. left: 15,
  155. right: 360,
  156. top: 616,
  157. width: 345,
  158. },
  159. {
  160. bottom: 1680,
  161. dataset: {},
  162. height: 206,
  163. id: "",
  164. left: 15,
  165. right: 360,
  166. top: 1474,
  167. width: 345,
  168. },
  169. ],
  170. skeletonCircleLists: [
  171. {
  172. id: "",
  173. dataset: {},
  174. left: 27,
  175. right: 72,
  176. top: 245,
  177. bottom: 270,
  178. width: 45,
  179. height: 45,
  180. },
  181. {
  182. id: "",
  183. dataset: {},
  184. left: 96,
  185. right: 141,
  186. top: 245,
  187. bottom: 270,
  188. width: 45,
  189. height: 45,
  190. },
  191. {
  192. id: "",
  193. dataset: {},
  194. left: 165,
  195. right: 210,
  196. top: 245,
  197. bottom: 270,
  198. width: 45,
  199. height: 45,
  200. },
  201. {
  202. id: "",
  203. dataset: {},
  204. left: 234,
  205. right: 279,
  206. top: 245,
  207. bottom: 270,
  208. width: 45,
  209. height: 45,
  210. },
  211. {
  212. id: "",
  213. dataset: {},
  214. left: 303,
  215. right: 348,
  216. top: 245,
  217. bottom: 270,
  218. width: 45,
  219. height: 45,
  220. },
  221. {
  222. id: "",
  223. dataset: {},
  224. left: 27,
  225. right: 72,
  226. top: 327,
  227. bottom: 352,
  228. width: 45,
  229. height: 45,
  230. },
  231. {
  232. id: "",
  233. dataset: {},
  234. left: 96,
  235. right: 141,
  236. top: 327,
  237. bottom: 352,
  238. width: 45,
  239. height: 45,
  240. },
  241. {
  242. id: "",
  243. dataset: {},
  244. left: 165,
  245. right: 210,
  246. top: 327,
  247. bottom: 352,
  248. width: 45,
  249. height: 45,
  250. },
  251. {
  252. id: "",
  253. dataset: {},
  254. left: 234,
  255. right: 279,
  256. top: 327,
  257. bottom: 352,
  258. width: 45,
  259. height: 45,
  260. },
  261. {
  262. id: "",
  263. dataset: {},
  264. left: 303,
  265. right: 348,
  266. top: 327,
  267. bottom: 352,
  268. width: 45,
  269. height: 45,
  270. },
  271. ],
  272. };
  273. },
  274. watch: {
  275. isNodes(val) {
  276. // this.readyAction();
  277. },
  278. },
  279. mounted() {
  280. this.attachedAction();
  281. },
  282. methods: {
  283. attachedAction: function () {
  284. //默认的首屏宽高,防止内容闪现
  285. const systemInfo = uni.getSystemInfoSync();
  286. this.systemInfo = {
  287. width: systemInfo.windowWidth,
  288. height: systemInfo.windowHeight,
  289. };
  290. this.loading = this.loadingAni.includes(this.loading)
  291. ? this.loading
  292. : "spin";
  293. },
  294. },
  295. };
  296. </script>
  297. <style>
  298. .box {
  299. z-index: 1000;
  300. }
  301. .spinbox {
  302. position: fixed;
  303. display: flex;
  304. justify-content: center;
  305. align-items: center;
  306. height: 100%;
  307. width: 100%;
  308. z-index: 10000;
  309. }
  310. .spin {
  311. display: inline-block;
  312. width: 64rpx;
  313. height: 64rpx;
  314. }
  315. .spin:after {
  316. content: " ";
  317. display: block;
  318. width: 46rpx;
  319. height: 46rpx;
  320. margin: 1rpx;
  321. border-radius: 50%;
  322. border: 5rpx solid #409eff;
  323. border-color: #409eff transparent #409eff transparent;
  324. animation: spin 1.2s linear infinite;
  325. }
  326. @keyframes spin {
  327. 0% {
  328. transform: rotate(0deg);
  329. }
  330. 100% {
  331. transform: rotate(360deg);
  332. }
  333. }
  334. .chiaroscuro {
  335. width: 100%;
  336. height: 100%;
  337. background: rgb(194, 207, 214);
  338. animation-duration: 2s;
  339. animation-name: blink;
  340. animation-iteration-count: infinite;
  341. }
  342. @keyframes blink {
  343. 0% {
  344. opacity: 0.4;
  345. }
  346. 50% {
  347. opacity: 1;
  348. }
  349. 100% {
  350. opacity: 0.4;
  351. }
  352. }
  353. @keyframes flush {
  354. 0% {
  355. left: -100%;
  356. }
  357. 50% {
  358. left: 0;
  359. }
  360. 100% {
  361. left: 100%;
  362. }
  363. }
  364. .shine {
  365. animation: flush 2s linear infinite;
  366. position: absolute;
  367. top: 0;
  368. bottom: 0;
  369. width: 100%;
  370. background: linear-gradient(
  371. to left,
  372. rgba(255, 255, 255, 0) 0%,
  373. rgba(255, 255, 255, 0.85) 50%,
  374. rgba(255, 255, 255, 0) 100%
  375. );
  376. }
  377. </style>