uniapp+<script setup lang=“ts“>解决有数据与暂无数据切换显示,有数据加载时暂无数据闪现(先加载空数据)问题

声明showEmpty 为false,在接口返回处判断有数据时设置showEmpty 为false,接口返回数据为空则判断showEmpty 为true (这样就解决有数据的时候会闪现暂无数据的问题啦)

复制代码
<!--
 * @Date: 2024-02-26 03:38:52
 * @LastEditTime: 2025-06-05 09:02:58
 * @Description: 救援详情页面
-->
<template>
    <view class="consolidated-order">
        <view class="consolidated-order-filter">
            <view class="consolidated-order-filter-cont flex-center-between">
                <select-date ref="dateRef" @change-date="changeDate" />
                <select-time ref="timeRef" @change-time="changeTime" />
                <select-goods ref="goodsRef" @change-goods="changeGoods" />
            </view>
        </view>
        <scroll-view
            v-if="!showEmpty"
            scroll-with-animation
            :scroll-y="true"
            :show-scrollbar="false"
            class="consolidated-cont"
        >
            <view class="service-order-item-box">
                <view v-for="(item, index) in splicingOrdersList" :key="index" class="service-order-item">
                    <view class="service-order-item-time"
                        >{{ timeFormat(item.departureTime) }} - {{ timeFormat(item.arriveTime) }}</view
                    >
                    <view
                        v-for="(item1, index1) in item.flyRecordModelList"
                        :key="index1"
                        class="service-order-item-cont flex-center-start"
                    >
                        <view class="cont-left flex-center-between">
                            <view class="fly-no-box fly-no-yellow flex-center-start">
                                <view class="fly-no-text">架次</view
                                ><view class="fly-no-num">{{ item1.flyNo || '--' }}</view></view
                            >
                            <view class="fly-id">飞行记录ID:{{ item1.id }}</view>
                        </view>
                        <view class="cont-right flex-center-start">
                            <view class="balance-num">空位:{{ item1.balanceNum }}人</view>
                            <view class="service-order-item-btn" @click="splicingOrders(item1)">拼单</view>
                        </view>
                    </view>
                </view>
            </view>
        </scroll-view>
        <!-- 拼单空状态 -->
        <view v-if="showEmpty" class="empty-wrap">
            <empty-block :image-src="EMPTY_PNG" text="还没有拼单信息哦" />
        </view>
    </view>
</template>

<script setup lang="ts">
import config from '@/../config/config';
import { qryCanJoinFly, combineServerOrder } from '@/services/api-order';
import { timeFormat } from '@/utils/DateUtils';
import { onLoad } from '@dcloudio/uni-app';
import { computed, ref, onMounted } from 'vue';
const EMPTY_PNG = `${config.assetPath}/images/book/empty-order.png`;
import { useStore } from 'vuex';
const store = useStore();
const openId = computed(() => store.state.userStore?.userInfo.openId);
const changeDate = (e) => {};
const changeTime = (e) => {};
const changeGoods = (e) => {};
const splicingOrdersList = ref();
const orderNoVal = ref();
const showEmpty = ref(false); //是否显示空状态
// 拼单列表
const getCanJoinFly = async () => {
    // ATO24080900075466有数据
    await qryCanJoinFly({
        orderNo: orderNoVal.value,
    }).then((res) => {
        if (res?.code == 0 && res?.data) {
           if (res?.data.length <= 0) {
                showEmpty.value = true; //没有数据的时候展示空状态
            } else {
                showEmpty.value = false; //有数据则正常展示数据
            }
            splicingOrdersList.value = res?.data;
        }
    });
};
const splicingOrders = (item) => {
    uni.showModal({
        title: '',
        content: '是否选择拼机',
        confirmText: '确认',
        success: (data) => {
            if (data.confirm) {
                let params = {
                    orderNo: orderNoVal.value,
                    combineFlyId: item.id,
                    openId: openId.value,
                };
                combineServerOrder(params).then((res) => {
                    if (res?.code == 0) {
                        uni.showToast({
                            title: '拼机成功',
                            icon: 'success',
                        });
                    }
                });
            } else if (data.cancel) {
                console.log('用户取消了操作');
            }
        },
    });
};
onLoad((option) => {
    orderNoVal.value = option.orderNo || '';
});
onMounted(() => {
    getCanJoinFly();
});
</script>

<style lang="scss">
@import './index.scss';
</style>

有数据

空状态

相关推荐
MrFlySand_飞沙2 小时前
uniapp开发微信小程序实现接入企业微信客服
微信小程序·小程序·uni-app·企业微信
PedroQue991 天前
Vue Router 4.x风格导航守卫全面升级
前端·uni-app
Haibakeji1 天前
APP小程序定制开发项目频繁延期?前期规避方法与落地避坑指南
小程序·uni-app·软件需求
anyup1 天前
迁移uni-app x,我是如何让 AI 把我一步步搞崩溃的...
前端·uni-app·trae
2501_916007471 天前
申请 iOS 推送证书并配置 APNs 群发推送教程
android·ios·小程序·https·uni-app·iphone·webview
博客zhu虎康1 天前
uni-app云打包显示编译成功,但是一直没有进入打包队列,后面也一直没反应
uni-app
JavaDog程序狗2 天前
【指南】uni-app微信小程序多环境CI-CD完全指南
ci/cd·uni-app·jenkins
PedroQue992 天前
uni-router v2.1.0 升级:导航守卫全面支持返回值模式
前端·uni-app
2501_915909063 天前
iOS test 测试怎么做?功能、性能、兼容、稳定与安全五类测试指南
android·ios·小程序·https·uni-app·iphone·webview
游戏开发爱好者84 天前
App Store 上传 IPA 自动化,.p8 密钥认证与 CI/CD 接入实战
android·运维·ci/cd·小程序·uni-app·自动化·iphone