InspectionPreview.vue 3.12 KB
<template>
    <view>
        <web-view :src="h5Url" />
    </view>
</template>

<script lang="ts">
import { Component, Hook, Vue } from "vue-facing-decorator";
import { onLoad, onShow } from "@dcloudio/uni-app";
import { AuctionController } from "@/api/AuctionController";
import { AuthService } from "@/common/AuthService";


@Component({ components: {} })

export default class InspectionPreview extends Vue {
    h5Url: string = '';
    vehicleId: string = '';
    aucvehId: string = '';
    imageUrl: string = '';
    vehicleData: any = {};

    created(): void {
        onLoad((option) => {
            const that = this;
            that.vehicleId = option.vehicleId;
            that.aucvehId = option.aucvehId;
            that.getReportVehicleData(option.vehicleId);
            that.getVehicleDetail(option.aucvehId);
        });

        // 每次都加载
        onShow(() => {
            const that = this;
            setTimeout(() => {
                that.toLoginPage();
            }, 1600);
        });
    }

    toLoginPage() {
        const that = this;
        const authService: AuthService = that.$auth;
        if (!authService.isLogin()) {
            uni.showToast({
                title: '请先登录', icon: 'none', duration: 2000, complete: function () {
                    setTimeout(() => {
                        uni.navigateTo({ url: '/pages/LoginPage?vehicleId=' + that.vehicleId + '&aucvehId=' + that.aucvehId });
                    }, 1200);
                }
            });
        }
    }

    getVehicleDetail(aucvehId: string) {
        AuctionController.getAuctionVehicleDetailById(this.axios, aucvehId).then(res => {
            const data = res.data || {};
            this.imageUrl = data?.vehicle?.cover?.url || '';
            this.vehicleData = data?.vehicle || {};
        });
    }

    getReportVehicleData(vehicleId: string): void {
        AuctionController.reportVehicleData(this.axios, vehicleId).then(res => {
            this.h5Url = res.data.data?.h5Url || '';
        });
    }

    // 定义分享内容(必写)
    @Hook('onShareAppMessage')
    onShareAppMessage(res: any) {
        // res.from 可判断分享触发来源:'button'(按钮触发)、'menu'(右上角菜单)
        const name = this.vehicleData?.baseInfo?.carSeriesName + this.vehicleData?.baseInfo?.carTypeName;
        let title = '优加二手车:专业检测报告[' + name + ']';
        return {
            title: title,
            path: '/module/auction/InspectionPreview?vehicleId=' + this.vehicleId + '&aucvehId=' + this.aucvehId,
            imageUrl: this.imageUrl || '', // 分享图片(建议尺寸 5:4,默认使用页面截图)
        };
    }

    @Hook('onShareTimeline')
    onShareTimeline() {
        const name = this.vehicleData?.baseInfo?.carSeriesName + this.vehicleData?.baseInfo?.carTypeName;
        let title = '优加二手车:专业检测报告[' + name + ']';
        return {
            title: title,
            query: 'vehicleId=' + this.vehicleId + '&aucvehId=' + this.aucvehId, // 分享参数
            imageUrl: this.imageUrl || '',
        };
    }

}

</script>

<style lang="scss" scoped></style>