| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341 |
- <template>
- <view v-if="show"
- :style="{width: systemInfo.width * 2 + 'rpx', height: systemInfo.height * 2 + 'rpx', backgroundColor: bgcolor, position: 'absolute', left: 0, top: 0, zIndex: 9998}">
- <view v-for="(item,rect_idx) in skeletonRectLists" :key="rect_idx + 'rect'"
- :class="[loading == 'chiaroscuro' ? 'chiaroscuro' : '']"
- :style="{width: item.width * 2 + 'rpx', height: item.height * 2 + 'rpx', backgroundColor: 'rgb(194, 207, 214,.3)', position: 'absolute', left: item.left * 2 + 'rpx', top: item.top * 2 + 'rpx'}">
- </view>
- <view v-for="(item,circle_idx) in skeletonCircleLists" :key="circle_idx + 'circle'"
- :class="loading == 'chiaroscuro' ? 'chiaroscuro' : ''"
- :style="{width: item.width * 2 + 'rpx', height: item.height * 2 + 'rpx', backgroundColor: 'rgb(194, 207, 214,.3)', borderRadius: item.width * 2 + 'rpx', position: 'absolute', left: item.left * 2 + 'rpx', top: item.top * 2 + 'rpx'}">
- </view>
- <view class="spinbox" v-if="loading == 'spin'">
- <view class="spin"></view>
- </view>
- </view>
- </template>
- <script>
- export default {
- name: "skeleton",
- props: {
- bgcolor: {
- type: String,
- value: '#FFF'
- },
- selector: {
- type: String,
- value: 'skeleton'
- },
- loading: {
- type: String,
- value: 'chiaroscuro'
- },
- show: {
- type: Boolean,
- value: false
- },
- isNodes: {
- type: Number,
- value: false
- } //控制什么时候开始抓取元素节点,只要数值改变就重新抓取
- },
- data() {
- return {
- loadingAni: ['spin', 'chiaroscuro'],
- systemInfo: {},
- skeletonRectLists: [{
- bottom: 35,
- dataset: {},
- height: 25,
- id: "",
- left: 15,
- right: 65,
- top: 10,
- width: 50,
- }, {
- bottom: 72,
- dataset: {},
- height: 30,
- id: "",
- left: 15,
- right: 360,
- top: 42,
- width: 345,
- }, {
- bottom: 232,
- dataset: {},
- height: 145,
- id: "",
- left: 15,
- right: 360,
- top: 87,
- width: 345,
- }, {
- bottom: 436,
- dataset: {},
- height: 30,
- id: "",
- left: 15,
- right: 360,
- top: 406,
- width: 345,
- }, {
- bottom: 596,
- dataset: {},
- height: 150,
- id: "",
- left: 15,
- right: 183,
- top: 446,
- width: 168,
- }, {
- bottom: 519,
- dataset: {},
- height: 73,
- id: "",
- left: 188,
- right: 360,
- top: 446,
- width: 172,
- }, {
- bottom: 596,
- dataset: {},
- height: 73,
- id: "",
- left: 188,
- right: 360,
- top: 523,
- width: 172,
- }, {
- bottom: 793,
- dataset: {},
- height: 177,
- id: "",
- left: 15,
- right: 360,
- top: 616,
- width: 345,
- }, {
- bottom: 1680,
- dataset: {},
- height: 206,
- id: "",
- left: 15,
- right: 360,
- top: 1474,
- width: 345,
- }],
- skeletonCircleLists: [{
- "id": "",
- "dataset": {},
- "left": 27,
- "right": 72,
- "top": 245,
- "bottom": 270,
- "width": 45,
- "height": 45
- },
- {
- "id": "",
- "dataset": {},
- "left": 96,
- "right": 141,
- "top": 245,
- "bottom": 270,
- "width": 45,
- "height": 45
- },
- {
- "id": "",
- "dataset": {},
- "left": 165,
- "right": 210,
- "top": 245,
- "bottom": 270,
- "width": 45,
- "height": 45
- },
- {
- "id": "",
- "dataset": {},
- "left": 234,
- "right": 279,
- "top": 245,
- "bottom": 270,
- "width": 45,
- "height": 45
- },
- {
- "id": "",
- "dataset": {},
- "left": 303,
- "right": 348,
- "top": 245,
- "bottom": 270,
- "width": 45,
- "height": 45
- },
- {
- "id": "",
- "dataset": {},
- "left": 27,
- "right": 72,
- "top": 327,
- "bottom": 352,
- "width": 45,
- "height": 45
- },
- {
- "id": "",
- "dataset": {},
- "left": 96,
- "right": 141,
- "top": 327,
- "bottom": 352,
- "width": 45,
- "height": 45
- },
- {
- "id": "",
- "dataset": {},
- "left": 165,
- "right": 210,
- "top": 327,
- "bottom": 352,
- "width": 45,
- "height": 45
- },
- {
- "id": "",
- "dataset": {},
- "left": 234,
- "right": 279,
- "top": 327,
- "bottom": 352,
- "width": 45,
- "height": 45
- },
- {
- "id": "",
- "dataset": {},
- "left": 303,
- "right": 348,
- "top": 327,
- "bottom": 352,
- "width": 45,
- "height": 45
- }
- ]
- }
- },
- watch: {
- isNodes(val) {
- // this.readyAction();
- }
- },
- mounted() {
- this.attachedAction();
- },
- methods: {
- attachedAction: function() {
- //默认的首屏宽高,防止内容闪现
- const systemInfo = uni.getSystemInfoSync();
- this.systemInfo = {
- width: systemInfo.windowWidth,
- height: systemInfo.windowHeight
- };
- this.loading = this.loadingAni.includes(this.loading) ? this.loading : 'spin';
- }
- }
- }
- </script>
- <style>
- .spinbox {
- position: fixed;
- display: flex;
- justify-content: center;
- align-items: center;
- height: 100%;
- width: 100%;
- z-index: 9999
- }
- .spin {
- display: inline-block;
- width: 64rpx;
- height: 64rpx;
- }
- .spin:after {
- content: " ";
- display: block;
- width: 46rpx;
- height: 46rpx;
- margin: 1rpx;
- border-radius: 50%;
- border: 5rpx solid #409eff;
- border-color: #409eff transparent #409eff transparent;
- animation: spin 1.2s linear infinite;
- }
- @keyframes spin {
- 0% {
- transform: rotate(0deg);
- }
- 100% {
- transform: rotate(360deg);
- }
- }
- .chiaroscuro {
- width: 100%;
- height: 100%;
- background: rgb(194, 207, 214);
- animation-duration: 2s;
- animation-name: blink;
- animation-iteration-count: infinite;
- }
- @keyframes blink {
- 0% {
- opacity: .4;
- }
- 50% {
- opacity: 1;
- }
- 100% {
- opacity: .4;
- }
- }
- @keyframes flush {
- 0% {
- left: -100%;
- }
- 50% {
- left: 0;
- }
- 100% {
- left: 100%;
- }
- }
- .shine {
- animation: flush 2s linear infinite;
- position: absolute;
- top: 0;
- bottom: 0;
- width: 100%;
- background: linear-gradient(to left,
- rgba(255, 255, 255, 0) 0%,
- rgba(255, 255, 255, .85) 50%,
- rgba(255, 255, 255, 0) 100%)
- }
- </style>
|