1.骨架屏组件封装

This commit is contained in:
dingyongya
2021-12-29 15:47:31 +08:00
parent c6d823c751
commit 0ea613dbb0
9 changed files with 269 additions and 0 deletions

View File

@@ -0,0 +1,72 @@
.lay-skeleton{
.lay-skeleton-item {
height: 16px;
border-radius: 5px;
margin-bottom: 16px;
background: #eeeeee;
}
.lay-skeleton-type--p{
height: 16px;
border-radius: 5px;
margin-bottom: 16px;
background: #eeeeee;
}
.lay-skeleton-type--image{
width: 240px;
height: 240px;
background: #eeeeee;
display: flex;
justify-content: center;
align-items: center;
i{
font-size: 40px;
}
}
}
.lay-skeleton-animated {
.lay-skeleton-type--image{
width: 240px;
height: 240px !important;
display: flex;
justify-content: center;
align-items: center;
i{
font-size: 40px;
}
}
.lay-skeleton-item {
height: 16px;
border-radius: 5px;
margin-bottom: 16px;
background: #eeeeee;
background: linear-gradient(
90deg,#f2f2f2 25%,#ececec 37%,#f2f2f2 63%);
background-size: 400% 100%;
animation: lay-skeleton-loading 1.2s ease infinite;
}
}
.lay-skeleton-first {
width: 30%;
}
.lay-skeleton-last {
width: 62.8%;
}
@keyframes lay-skeleton-loading {
0% {
background-position: 100% 50%;
}
100% {
background-position: 0 50%;
}
}

View File

@@ -0,0 +1,9 @@
import type { App } from 'vue'
import Component from './index.vue'
import type { IDefineComponent } from '../type/index'
Component.install = (app: App) => {
app.component(Component.name || 'LaySkeleton', Component)
}
export default Component as IDefineComponent

View File

@@ -0,0 +1,34 @@
<template>
<div :class="['lay-skeleton', animated ? 'lay-skeleton-animated': '',]" v-bind="$attrs">
<template v-if="loading">
<slot name="skeleton">
<lay-skeleton-item
v-for="item in rows"
:class="[
item===1? 'lay-skeleton-first': '',
item === rows? 'lay-skeleton-last': '']"
type="p"
></lay-skeleton-item>
</slot>
</template>
<slot v-else></slot>
</div>
</template>
<script setup name="LaySkeleton" lang="ts">
import LaySkeletonItem from '../skeletonItem/index.vue'
import './index.less'
import { defineProps, withDefaults} from "vue";
export interface LaySkeletonProps {
rows?: number;
loading?: boolean;
animated?: boolean;
}
const props = withDefaults(defineProps<LaySkeletonProps>(), {
rows: 4,
loading: false,
animated: false,
});
</script>-

View File

@@ -0,0 +1,9 @@
import type { App } from 'vue'
import Component from './index.vue'
import type { IDefineComponent } from '../type/index'
Component.install = (app: App) => {
app.component(Component.name || 'LaySkeletonItem', Component)
}
export default Component as IDefineComponent

View File

@@ -0,0 +1,19 @@
<template>
<div :class="['lay-skeleton-item',`lay-skeleton-type--${type}`]" v-bind="$attrs">
<div v-if="type==='image'" >
<lay-icon type="layui-icon-picture"></lay-icon>
</div>
</div>
</template>
<script setup name="LaySkeletonItem" lang="ts">
import { defineProps, withDefaults} from "vue";
export interface LaySkeletonProps {
type?: string;
}
const props = withDefaults(defineProps<LaySkeletonProps>(), {
type: 'p',
});
</script>-