import Taro, { useLoad, useReady, useUnload } from '@tarojs/taro' import { PropsWithChildren, useState } from 'react' import { View, Video, Image } from '@tarojs/components' import useGetCustomClient from '@/hooks/useGetCustomClient' import { wrapProps, generateUUID } from '@/plugin/share' import './index.less' import http from '@/http/index' import { adSelfPredict } from '@/http/api/index' import { adActionLog } from '@/logCenter/index' import { reportBusinessType } from '@/plugin/share/const' // 在一些场景下 loadedMetaFiredInOnce 被触发了很多次 let loadedMetaFiredInOnce = 0 function PqCustom(props: PropsWithChildren) { let { adpId, autoplay, loop, muted, showMusk, zIndex, openEmbeddedMiniProgram, onPlay, onPause, onEnded, onTimeUpdate, onStop, onError, onLoad, onView, onClick, onClose } = wrapProps(props) const [show, setShow] = useState(true) const [adData, setAdData] = useState({}) useReady(() => { getAdConfig() adActionReport(reportBusinessType.buttonView, 'adView') }) function getAdConfig() { http.post(`${adSelfPredict}?adpId=uh2321awe1`, { baseInfo: {}, positionId: 1, phoneModel : '', careModelStatus : 1, videoId: 0 }, { header: { 'content-type': 'application/json;' } }).then((res: RequestType) => { const { code, data } = res // TODO: onError、logUpload if(code !== 0) { onError() // logUpload() return } const { ownPlatformAlliance } = data || {} const { adType, platformCreativeInfo } = ownPlatformAlliance || {} setAdData({ adType, ...platformCreativeInfo }) console.log(data) }).catch(err => { console.log(err) }) } function videoPlay() { onPlay() } function videoPause() { onPause() } function videoPlayEnded() { onEnded() } function videoTimeUpdate() { onTimeUpdate() } function videoStop() { onStop() } function videoClick() { closeCustom() } function closeCustom() { onClose() setShow(false) } function clickMask() { onClick() closeCustom() } function adActionReport(eventId, businessType) { const { adCode, adPosition, advertiserId, ownAdDetailId, ownAdPositionId, ownAdSystemType, planId, } = adData adActionLog([{ adCode, adPosition, advertiserId, businessType, eventId, ownAdDetailId, ownAdPositionId, ownAdSystemType, pageSource: 'plugin', planId, pqtId: generateUUID(), videoId: '000' }]) } return ( <> {show && 广告 {/* */} {/* */} } ) } function Custom({ autoplay, loop, muted, adData, onPlay, onPause, onEnded, onTimeUpdate, onStop, // 播放事件 onClick, onLoad, onView, onError }) { const [style, setStyle] = useState({ width: '0px', height: 'px' }) useReady(() => { loadedMetaFiredInOnce = 0 }) useGetCustomClient((customClient) => { let clientWidth = customClient.width let clientHeight = customClient.height setStyle({ width: `${clientWidth}px`, height: `${clientHeight}px` }) }) function onLoadedMetaData() { if (loadedMetaFiredInOnce++ < 1) { // 上报load onLoad() } } return ( ) } export default PqCustom