Commit b776f3ed by liimin

feat(components): 新增骨架屏组件并替换内联实现

新增 BannerSkeleton 和 ListSkeleton 两个可复用骨架屏组件,用于在数据加载时展示占位效果。将 Scene、MerchantList、AccountList 和 equity/index 页面中的内联骨架屏代码替换为组件引用,以提高代码复用性和可维护性。
1 parent 561a5068
<template>
<view class="swiper-loading">
<view class="skeleton-banner">
<un-skeleton :loading="loading" :animate="animate" :rows="0" :title="false" avatar avatar-shape="square" avatar-size="300"></un-skeleton>
</view>
<view class="skeleton-text">
<un-skeleton :loading="loading" :animate="animate" :rows="3" :title="true"></un-skeleton>
</view>
</view>
</template>
<script setup lang="uts">
defineProps({
loading: {
type: Boolean,
default: true
},
animate: {
type: Boolean,
default: true
}
});
</script>
<style scoped lang="scss">
.swiper-loading {
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
box-sizing: border-box;
}
.skeleton-banner {
width: 100%;
flex: 1;
min-height: 250px;
box-sizing: border-box;
margin-bottom: 20px;
}
.skeleton-banner :deep(.u-skeleton__wrapper) {
width: 100%;
height: 100%;
display: flex;
}
.skeleton-banner :deep(.u-skeleton__avatar) {
width: 100% !important;
height: 100% !important;
border-radius: 8px !important;
}
.skeleton-text {
padding: 0 16px 20px;
}
</style>
<template>
<view class="skeleton-wrap">
<un-skeleton :animate="animate"
:loading="loading"
:rows="rows"
:title="title"
:avatar="avatar"
:avatar-shape="avatarShape"
:avatar-size="avatarSize">
</un-skeleton>
<view :style="{ height: spacing + 'px' }"></view>
<un-skeleton :animate="animate"
:loading="loading"
:rows="rows"
:title="title"
:avatar="avatar"
:avatar-shape="avatarShape"
:avatar-size="avatarSize">
</un-skeleton>
<view :style="{ height: spacing + 'px' }"></view>
<un-skeleton :animate="animate"
:loading="loading"
:rows="rows"
:title="title"
:avatar="avatar"
:avatar-shape="avatarShape"
:avatar-size="avatarSize">
</un-skeleton>
</view>
</template>
<script setup lang="uts">
defineProps({
loading: {
type: Boolean,
default: true
},
animate: {
type: Boolean,
default: true
},
rows: {
type: Number,
default: 2
},
title: {
type: Boolean,
default: true
},
avatar: {
type: Boolean,
default: true
},
avatarShape: {
type: String,
default: 'circle' // 'circle' or 'square'
},
avatarSize: {
type: Number,
default: 48
},
spacing: {
type: Number,
default: 24
}
});
</script>
<style scoped lang="scss">
.skeleton-wrap {
padding: 24px;
width: 100%;
box-sizing: border-box;
}
</style>
<template> <template>
<!-- 保持单根节点,确保父组件 v-show 生效 --> <!-- 保持单根节点,确保父组件 v-show 生效 -->
<view class="fade-in-up"> <view class="fade-in-up">
<view v-if="!flag" class="skeleton-wrap"> <ListSkeleton v-if="!flag" />
<un-skeleton :animate="true"
:loading="true"
rows="2"
:title="true"
avatar
avatar-shape="circle"
avatar-size="48">
</un-skeleton>
<view style="height: 24px;"></view>
<un-skeleton :animate="true"
:loading="true"
rows="2"
:title="true"
avatar
avatar-shape="circle"
avatar-size="48">
</un-skeleton>
<view style="height: 24px;"></view>
<un-skeleton :animate="true"
:loading="true"
rows="2"
:title="true"
avatar
avatar-shape="circle"
avatar-size="48">
</un-skeleton>
</view>
<view v-else class="box"> <view v-else class="box">
<template v-if="loginUserInfoList.length > 0"> <template v-if="loginUserInfoList.length > 0">
<view v-for="(item, index) in loginUserInfoList" <view v-for="(item, index) in loginUserInfoList"
...@@ -58,6 +31,7 @@ ...@@ -58,6 +31,7 @@
import { defineExpose, onMounted, ref } from "vue"; import { defineExpose, onMounted, ref } from "vue";
import { apiGetListSelectAccount, apiGetSceneMerchantRefStoreList, apiSelectAccountLogin } from "@/api/user-api.uts"; import { apiGetListSelectAccount, apiGetSceneMerchantRefStoreList, apiSelectAccountLogin } from "@/api/user-api.uts";
import ListSkeleton from "@/components/Skeleton/ListSkeleton.uvue";
import { storage } from "@/utils/storage.uts"; import { storage } from "@/utils/storage.uts";
type AccountItem = { type AccountItem = {
...@@ -386,12 +360,6 @@ onMounted(() => { ...@@ -386,12 +360,6 @@ onMounted(() => {
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">
.skeleton-wrap {
padding: 24px;
width: 100%;
box-sizing: border-box;
}
.box { .box {
display: flex; display: flex;
align-items: center; align-items: center;
......
<template> <template>
<view class="fade-in-up"> <view class="fade-in-up">
<view v-if="!flag" class="skeleton-wrap"> <ListSkeleton v-if="!flag" />
<un-skeleton :animate="true"
:loading="true"
rows="2"
:title="true"
avatar
avatar-shape="circle"
avatar-size="48">
</un-skeleton>
<view style="height: 24px;"></view>
<un-skeleton :animate="true"
:loading="true"
rows="2"
:title="true"
avatar
avatar-shape="circle"
avatar-size="48">
</un-skeleton>
<view style="height: 24px;"></view>
<un-skeleton :animate="true"
:loading="true"
rows="2"
:title="true"
avatar
avatar-shape="circle"
avatar-size="48">
</un-skeleton>
</view>
<view v-if="flag" class="box"> <view v-if="flag" class="box">
<template v-if="loginUserInfoList.length > 0"> <template v-if="loginUserInfoList.length > 0">
<view v-for="(item, index) in loginUserInfoList" <view v-for="(item, index) in loginUserInfoList"
...@@ -53,6 +26,7 @@ ...@@ -53,6 +26,7 @@
import { defineExpose, ref } from "vue"; import { defineExpose, ref } from "vue";
import { apiGetSceneMerchantRefStoreList, apiGetYqMerchantSceneConfigAPI, apiSelectMerchantScene } from "@/api/user-api.uts"; import { apiGetSceneMerchantRefStoreList, apiGetYqMerchantSceneConfigAPI, apiSelectMerchantScene } from "@/api/user-api.uts";
import ListSkeleton from "@/components/Skeleton/ListSkeleton.uvue";
import { storage } from "@/utils/storage.uts"; import { storage } from "@/utils/storage.uts";
type MerchantItem = { type MerchantItem = {
...@@ -305,12 +279,6 @@ defineExpose({ ...@@ -305,12 +279,6 @@ defineExpose({
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">
.skeleton-wrap {
padding: 24px;
width: 100%;
box-sizing: border-box;
}
.box { .box {
display: flex; display: flex;
flex-direction: row; flex-direction: row;
......
<template> <template>
<view class="fade-in-up"> <view class="fade-in-up">
<view v-if="loading" class="skeleton-wrap"> <ListSkeleton v-if="loading" />
<un-skeleton :animate="true"
:loading="true"
rows="2"
:title="true"
avatar
avatar-shape="circle"
avatar-size="48">
</un-skeleton>
<view style="height: 24px;"></view>
<un-skeleton :animate="true"
:loading="true"
rows="2"
:title="true"
avatar
avatar-shape="circle"
avatar-size="48">
</un-skeleton>
<view style="height: 24px;"></view>
<un-skeleton :animate="true"
:loading="true"
rows="2"
:title="true"
avatar
avatar-shape="circle"
avatar-size="48">
</un-skeleton>
</view>
<view v-else class="box"> <view v-else class="box">
<view v-for="(item, index) in sceneList" <view v-for="(item, index) in sceneList"
:key="index" :key="index"
...@@ -50,6 +23,7 @@ ...@@ -50,6 +23,7 @@
import { defineExpose, ref } from "vue"; import { defineExpose, ref } from "vue";
import { apiGetMerchantBrand, apiSelectMerchantScene } from "@/api/user-api.uts"; import { apiGetMerchantBrand, apiSelectMerchantScene } from "@/api/user-api.uts";
import ListSkeleton from "@/components/Skeleton/ListSkeleton.uvue";
import { storage } from "@/utils/storage.uts"; import { storage } from "@/utils/storage.uts";
type SceneItem = { type SceneItem = {
...@@ -235,12 +209,6 @@ defineExpose({ ...@@ -235,12 +209,6 @@ defineExpose({
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">
.skeleton-wrap {
padding: 24px;
width: 100%;
box-sizing: border-box;
}
.box { .box {
display: flex; display: flex;
align-items: center; align-items: center;
......
...@@ -7,13 +7,7 @@ ...@@ -7,13 +7,7 @@
@start="handleStart"> @start="handleStart">
<template #swiperCustom> <template #swiperCustom>
<view v-if="!loadComplete" class="swiper-loading"> <view v-if="!loadComplete" class="swiper-loading">
<!-- 大气优雅的骨架屏 --> <BannerSkeleton />
<view class="skeleton-banner">
<un-skeleton :loading="true" :animate="true" :rows="0" :title="false" avatar avatar-shape="square" avatar-size="300"></un-skeleton>
</view>
<view class="skeleton-text">
<un-skeleton :loading="true" :animate="true" :rows="3" :title="true"></un-skeleton>
</view>
</view> </view>
<view v-else-if="moduleList.length > 0" class="swiper-custom-wrap fade-in"> <view v-else-if="moduleList.length > 0" class="swiper-custom-wrap fade-in">
<view class="swiper-custom-content"> <view class="swiper-custom-content">
...@@ -66,6 +60,7 @@ import { UnSwiperItem } from '@/uni_modules/uview-unix'; ...@@ -66,6 +60,7 @@ import { UnSwiperItem } from '@/uni_modules/uview-unix';
import { getCarBrandsListApi, getEmployeeListApi, getMerchantCarBrandList } from "@/api/common-api.uts"; import { getCarBrandsListApi, getEmployeeListApi, getMerchantCarBrandList } from "@/api/common-api.uts";
import { getMockData, getSoureData } from "@/api/system-api.uts"; import { getMockData, getSoureData } from "@/api/system-api.uts";
import BannerSkeleton from "@/components/Skeleton/BannerSkeleton.uvue";
import HomeFrame from "@/components/HomeFrame/index.uvue"; import HomeFrame from "@/components/HomeFrame/index.uvue";
import { dispatch, state } from "@/store/index.uts"; import { dispatch, state } from "@/store/index.uts";
// import { onLoad, onShow } from '@dcloudio/uni-app' // import { onLoad, onShow } from '@dcloudio/uni-app'
...@@ -652,8 +647,7 @@ onShow(() => { ...@@ -652,8 +647,7 @@ onShow(() => {
background: rgba(255, 255, 255, 0.8); background: rgba(255, 255, 255, 0.8);
} }
.swiper-empty, .swiper-empty {
.swiper-loading {
width: 100%; width: 100%;
height: 100%; height: 100%;
display: flex; display: flex;
...@@ -661,31 +655,6 @@ onShow(() => { ...@@ -661,31 +655,6 @@ onShow(() => {
box-sizing: border-box; box-sizing: border-box;
} }
.skeleton-banner {
width: 100%;
flex: 1; /* 让图片占位符自动填满大部分空间 */
min-height: 250px; /* 保证有一个比较大的基础高度 */
box-sizing: border-box;
margin-bottom: 20px;
}
/* 调整骨架屏头像占位符,使其填满 banner 区域,显得大气 */
.skeleton-banner :deep(.u-skeleton__wrapper) {
width: 100%;
height: 100%;
display: flex;
}
.skeleton-banner :deep(.u-skeleton__avatar) {
width: 100% !important;
height: 100% !important;
border-radius: 8px !important;
}
.skeleton-text {
padding: 0 16px 20px;
}
.empty-text { .empty-text {
font-size: var(--l-font-sm); font-size: var(--l-font-sm);
color: #999; color: #999;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!