!12 骨架屏组件封装

Merge pull request !12 from 莫名点/develop
This commit is contained in:
就眠儀式 2021-12-29 08:07:17 +00:00 committed by Gitee
commit f61a4c9e8b
9 changed files with 269 additions and 0 deletions

View File

@ -0,0 +1,109 @@
::: title 基础使用
:::
::: demo
<template>
<div>
<div style="margin-bottom: 10px">
<lay-switch v-model="loading" active-text="加载" inactive-text="关闭"></lay-switch>
</div>
<lay-skeleton :rows="4" :loading="loading" animated>
<p style="margin-bottom: 18px">1 layui-vue , 基 于 vue 3.0 的 桌 面 端 组 件 库 , layui 的 另 一 种 呈 现 方 式</p>
<p style="margin-bottom: 18px">2 layui-vue , 基 于 vue 3.0 的 桌 面 端 组 件 库 , layui 的 另 一 种 呈 现 方 式</p>
<p style="margin-bottom: 18px">3 layui-vue , 基 于 vue 3.0 的 桌 面 端 组 件 库 , layui 的 另 一 种 呈 现 方 式</p>
<p style="margin-bottom: 18px">4 layui-vue , 基 于 vue 3.0 的 桌 面 端 组 件 库 , layui 的 另 一 种 呈 现 方 式</p>
</lay-skeleton>
</div>
</template>
<script>
import { ref } from 'vue';
export default {
setup() {
const loading = ref(true);
return {
loading,
}
}
}
</script>
:::
::: title 图片
:::
::: demo
<template>
<div>
<div style="margin-bottom: 10px">
<lay-switch v-model="loading" active-text="加载" inactive-text="关闭"></lay-switch>
</div>
<lay-skeleton :loading="loading" animated>
<template #skeleton>
<lay-skeleton-item type="image"/>
<lay-skeleton-item type="p" style="width: 240px"/>
</template>
<div class="img-content">
<img src="https://portrait.gitee.com/uploads/avatars/user/2813/8441097_shaynas_1610801433.png" />
<p style="margin-top: 18px">layui-vue 发展史....</p>
</div>
</lay-skeleton>
</div>
</template>
<script>
import { ref } from 'vue';
export default {
setup() {
const loading = ref(true);
return {
loading,
}
}
}
</script>
<style>
.img-content {
width: 240px;
height: 240px;
}
</style>
:::
::: title 骨架屏属性
:::
::: table
| 属性 | 描述 | 可选值 |
| ----- | ---- | ------ |
| loading | 是否显示 | `true` `false` |
| rows | 显示行数 | -- |
| animated | 是否动画 | `true` `false` |
| type | 展示类型 | `p` `image` |
:::
::: title 骨架屏插槽
:::
::: table
| 插槽 | 描述 | 可选值 |
| ------ | -------- | ------ |
| default| 默认插槽 | -- |
| skeleton | 自定义插槽 | -- |
:::
::: comment
:::

View File

@ -76,6 +76,11 @@ const zhCN = [
component: Component, component: Component,
meta: { title: '组件' }, meta: { title: '组件' },
children: [ children: [
{
path: '/zh-CN/components/skeleton',
component: () => import('../../docs/zh-CN/components/skeleton.md'),
meta: { title: '骨架屏' },
},
{ {
path: '/zh-CN/components/layout', path: '/zh-CN/components/layout',
component: () => import('../../docs/zh-CN/components/layout.md'), component: () => import('../../docs/zh-CN/components/layout.md'),

View File

@ -98,6 +98,12 @@ export default {
id: 1, id: 1,
title: '布局', title: '布局',
children: [ children: [
{
id: 111,
title: '骨架屏',
subTitle: 'skeleton',
path: '/zh-CN/components/skeleton',
},
{ {
id: 4, id: 4,
title: '布局', title: '布局',

View File

@ -67,6 +67,8 @@ import LayCarouselItem from "./module/carouselItem/index";
import LayColorPicker from "./module/colorPicker/index"; import LayColorPicker from "./module/colorPicker/index";
import LayTooltip from "./module/tooltip/index"; import LayTooltip from "./module/tooltip/index";
import LayInputNumber from "./module/inputNumber/index"; import LayInputNumber from "./module/inputNumber/index";
import LaySkeleton from './module/skeleton/index';
import LaySkeletonItem from './module/skeletonItem/index';
const components: Record<string, IDefineComponent> = { const components: Record<string, IDefineComponent> = {
LayRadio, LayRadio,
@ -129,6 +131,8 @@ const components: Record<string, IDefineComponent> = {
LayModal, LayModal,
LayTooltip, LayTooltip,
LayInputNumber, LayInputNumber,
LaySkeleton,
LaySkeletonItem,
LayCountUp, LayCountUp,
}; };
@ -142,6 +146,8 @@ const install = (app: App, options?: InstallOptions): void => {
}; };
export { export {
LaySkeleton,
LaySkeletonItem,
LayRadio, LayRadio,
LayIcon, LayIcon,
LayButton, LayButton,

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>-