uniapp项目实践总结(八)自定义加载组件

在这里插入图片描述
在这里插入图片描述

<view
  class="q-loading"
  :style="{'backgroundColor': props.bgColor}"
  v-if="props.show"
>
  <view class="q-loading-inner">
    <slot name="load">
      <!-- 图标部分 -->
      <view
        :class="{'q-loading-icon': true, 'pause': !props.show && !props.showIcon}"
        v-if="props.showIcon"
      >
        <slot name="icon">
          <!-- 圆环 -->
          <view
            class="q-loading-item q-loading-circle"
            :style="{'width': props.borSize +'rpx', 'height': props.borSize +'rpx', 'borderWidth': props.borWin + 'rpx', 'borderColor': props.borColor, 'borderLeftColor': props.bordActiveColor}"
            v-if="props.iconName == 'circle'"
          >
          </view>
          <!-- 呼吸 -->
          <view
            class="q-loading-item q-loading-circle-breath"
            v-if="props.iconName == 'circle-breath'"
          >
          </view>
          <!-- 旋转 -->
          <view
            class="q-loading-item q-loading-circle-round"
            v-if="props.iconName == 'circle-round'"
          >
            <view
              class="loading-round"
              :style="{'backgroundColor': props.bordActiveColor}"
            ></view>
            <view
              class="loading-round"
              :style="{'backgroundColor': props.bordActiveColor}"
            ></view>
            <view
              class="loading-round"
              :style="{'backgroundColor': props.bordActiveColor}"
            ></view>
            <view
              class="loading-round"
              :style="{'backgroundColor': props.bordActiveColor}"
            ></view>
            <view
              class="loading-round"
              :style="{'backgroundColor': props.bordActiveColor}"
            ></view>
            <view
              class="loading-round"
              :style="{'backgroundColor': props.bordActiveColor}"
            ></view>
            <view
              class="loading-round"
              :style="{'backgroundColor': props.bordActiveColor}"
            ></view>
          </view>
        </slot>
      </view>
      <!-- 提示文本 -->
      <view
        class="q-loading-text"
        v-if="props.showText"
        :style="{'color': props.textColor, 'fontSize': props.textSize + 'rpx'}"
      >
        <slot name="text"> {{ props.text }} </slot>
      </view>
    </slot>
  </view>
</view>

在这里插入图片描述

.q-loading {
  position: fixed;
  top: 0;
  left: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  box-sizing: border-box;
  padding: 10rpx;
  width: 100%;
  height: 100vh;
  .q-loading-inner {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    .q-loading-icon {
      display: flex;
      justify-content: center;
      align-items: center;
      margin-bottom: 10rpx;
      width: 100rpx;
      height: 100rpx;
      .q-loading-circle {
        border-radius: 50%;
        border-style: solid;
        animation: loadingCircle 1s linear infinite;
      }
      .q-loading-circle-breath {
        box-shadow: 0 0 0 0 rgb(204, 73, 152);
        height: 36px;
        width: 36px;
        border-radius: 50%;
        animation: loadingCircleBreath 1s linear infinite;
      }
      .q-loading-circle-round {
        position: relative;
        width: 75rpx;
        height: 75rpx;
        .loading-round {
          position: absolute;
          width: 26rpx;
          height: 26rpx;
          border-radius: 50%;
          animation: loadingCircleRound 3s ease infinite;
          transform-origin: 120% 80rpx;
          &.loading-round:nth-child(1) {
            z-index: 7;
          }
          &.loading-round:nth-child(2) {
            height: 12px;
            width: 12px;
            animation-delay: 0.2s;
            z-index: 6;
          }
          &.loading-round:nth-child(3) {
            height: 11px;
            width: 11px;
            animation-delay: 0.4s;
            z-index: 5;
          }
          &.loading-round:nth-child(4) {
            height: 10px;
            width: 10px;
            animation-delay: 0.6s;
            z-index: 4;
          }
          &.loading-round:nth-child(5) {
            height: 9px;
            width: 9px;
            animation-delay: 0.8s;
            z-index: 3;
          }
          &.loading-round:nth-child(6) {
            height: 8px;
            width: 8px;
            animation-delay: 1s;
            z-index: 2;
          }
          &.loading-round:nth-child(7) {
            height: 7px;
            width: 7px;
            animation-delay: 1.2s;
            z-index: 1;
          }
        }
      }
      &.pause {
        .q-loading-item {
          animation-play-state: paused;
        }
      }
    }
  }
}

在这里插入图片描述
在这里插入图片描述

const props = defineProps({
  // 显示加载
  show: {
    type: Boolean,
    default: true,
  },
  // 背景色
  bgColor: {
    type: String,
    default: "#fff",
  },
  // 显示图标
  showIcon: {
    type: Boolean,
    default: true,
  },
  // 名称
  iconName: {
    type: String,
    default: "circle",
  },
  // 大小
  borSize: {
    type: Number,
    default: 60,
  },
  // 边框粗细
  borWin: {
    type: Number,
    default: 8,
  },
  // 颜色
  borColor: {
    type: String,
    default: "#e3e3e3",
  },
  // 活动颜色
  bordActiveColor: {
    type: String,
    default: "#24afd6",
  },
  // 显示文本
  showText: {
    type: Boolean,
    default: true,
  },
  // 文本内容
  text: {
    type: String,
    default: "加载中...",
  },
  // 文本颜色
  textColor: {
    type: String,
    default: "#555",
  },
  // 文本大小
  textSize: {
    type: Number,
    default: 20,
  },
});

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

JackieChan_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值