feat: 广告

This commit is contained in:
chashaobao
2025-07-07 01:15:50 +08:00
parent de7f0e14fe
commit e8cf28b6e9
18 changed files with 507 additions and 53 deletions

View File

@ -1,12 +1,13 @@
import { Map, MapProps, Text, Image, Button } from '@tarojs/components';
import Taro, { useLoad, useShareAppMessage } from '@tarojs/taro';
import React, { useCallback, useEffect, useState } from 'react';
import React, { useCallback, useEffect, useRef, useState } from 'react';
import { CertificationStatusIcon } from '@/components/certification-status';
import CommonDialog from '@/components/common-dialog';
import DevDiv from '@/components/dev-div';
import JobRecommendList from '@/components/job-recommend-list';
import { JoinGroupHint } from '@/components/join-group-hint';
import LoginButton from '@/components/login-button';
import MaterialGuide from '@/components/material-guide';
import PageLoading from '@/components/page-loading';
@ -37,7 +38,6 @@ import Toast from '@/utils/toast';
import { isNeedCreateMaterial } from '@/utils/user';
import './index.less';
import { JoinGroupHint } from '@/components/join-group-hint';
const PREFIX = 'job-detail';
const log = logWithPrefix(PREFIX);
@ -183,6 +183,7 @@ export default function JobDetail() {
const roleType = useRoleType();
const userInfo = useUserInfo();
const [data, setData] = useState<JobDetails | null>(null);
const videoRef = useRef<Taro.RewardedVideoAd | null>(null);
const isOwner = roleType === RoleType.Company && userInfo.userId === data?.userId;
const inviteCode = useInviteCode();
@ -219,6 +220,56 @@ export default function JobDetail() {
};
}, []);
useEffect(() => {
const handleLoad = () => {
log('视频奖励加载成功');
};
const handleError = err => {
Taro.eventCenter.trigger(EventName.PRE_ACTION_VIDEO_ERROR);
log('视频奖励加载失败', err);
};
const handleClose = res => {
if (res.isEnded) {
Taro.eventCenter.trigger(EventName.PRE_ACTION_VIDEO_SUCCESS);
} else {
Toast.info('请完整观看广告以获得奖励');
}
};
const handleShowVideo = async () => {
if (videoRef.current) {
try {
await videoRef.current.show();
} catch (error) {
Taro.eventCenter.trigger(EventName.PRE_ACTION_VIDEO_ERROR);
Toast.info('广告奖励加载失败,请重试');
log('激励视频显示失败');
}
} else {
Taro.eventCenter.trigger(EventName.PRE_ACTION_VIDEO_ERROR);
Toast.info('广告奖励加载失败,请重试');
log('激励视频加载&显示失败');
}
};
videoRef.current = Taro.createRewardedVideoAd({
adUnitId: 'adunit-ca879f574edfeb33',
});
videoRef.current.onLoad(handleLoad);
videoRef.current.onClose(handleClose);
videoRef.current.onError(handleError);
videoRef.current.load();
Taro.eventCenter.on(EventName.SHOW_VIDEO_REWARD, handleShowVideo);
return () => {
if (videoRef.current) {
videoRef.current.offLoad(handleLoad);
videoRef.current.offError(handleError);
videoRef.current.offClose(handleClose);
}
Taro.eventCenter.off(EventName.SHOW_VIDEO_REWARD);
};
}, []);
useLoad(async () => {
switchRoleType(RoleType.Anchor);

View File

@ -15,7 +15,7 @@ import useLocation from '@/hooks/use-location';
import { MaterialProfile } from '@/types/material';
import { logWithPrefix } from '@/utils/common';
import { collectEvent } from '@/utils/event';
import { isFullTimePriceRequired, isPartTimePriceRequired } from '@/utils/job';
import { isFullTimePriceRequired, isPartTimePriceRequired, setSkipPrejobAction } from '@/utils/job';
import { updateProfile, subscribeMaterialMessage } from '@/utils/material';
import { navigateBack } from '@/utils/route';
import Toast from '@/utils/toast';
@ -110,6 +110,7 @@ export default function MaterialCreateProfile() {
// 发起订阅不能在异步任务中,保证是第一个
await Promise.all([subscribeMaterialMessage(), updateProfile(data)]);
}
setSkipPrejobAction();
Taro.eventCenter.trigger(EventName.CREATE_PROFILE);
nextType ? setGroupType(nextType) : navigateBack(2);
} catch (e) {

View File

@ -0,0 +1,3 @@
export default definePageConfig({
navigationBarTitleText: '分享',
});

View File

@ -0,0 +1,57 @@
@import '@/styles/common.less';
@import '@/styles/variables.less';
page {
background: #fff;
}
.partner-share {
padding-top: 175px;
&__money {
width: 140px;
height: 140px;
margin-bottom: 35px;
}
&__header {
.flex-column();
justify-content: center;
font-weight: 500;
font-size: 48px;
line-height: 48px;
color: #333333;
}
&__body {
padding-top: 86px;
.flex-column();
}
&__item {
.flex-row();
margin-top: 72px;
font-weight: 500;
font-size: 32px;
line-height: 48px;
width: 640px;
color: #000000;
.highlight {
color: @blHighlightColor;
font-weight: 400;
padding-left: 8px;
display: inline-block;
}
}
&__no {
width: 74px;
height: 46px;
margin-right: 21px;
vertical-align: middle;
}
&__btn {
.button(@width: 360px; @height: 72px;);
margin-top: 150px;
}
}

View File

@ -0,0 +1,61 @@
import { Button, Image } from '@tarojs/components';
import Taro, { useDidShow, useShareAppMessage } from '@tarojs/taro';
import { EventName } from '@/constants/app';
import useInviteCode from '@/hooks/use-invite-code';
import { hasShareToGetContact, setShareToGetContact } from '@/utils/job';
import { navigateBack } from '@/utils/route';
import { getCommonShareMessage } from '@/utils/share';
import './index.less';
const PREFIX = 'partner-share';
export default function Partner() {
const inviteCode = useInviteCode();
useDidShow(() => {
if (!hasShareToGetContact()) {
Taro.eventCenter.trigger(EventName.PRE_ACTION_SHARE_SUCCESS);
navigateBack(-1);
}
});
useShareAppMessage(() => {
setShareToGetContact();
console.log('Partner inviteCode', inviteCode);
return getCommonShareMessage({ useCapture: false, inviteCode });
});
return (
<div className={PREFIX}>
<div className={`${PREFIX}__header`}>
<Image
src="https://publiccdn.neighbourhood.com.cn/img/money.png"
mode="aspectFit"
className={`${PREFIX}__money`}
/>
<div>3</div>
</div>
<div className={`${PREFIX}__body`}>
<div className={`${PREFIX}__item`}>
<Image src="https://publiccdn.neighbourhood.com.cn/img/01.svg" mode="aspectFit" className={`${PREFIX}__no`} />
<div>
<div className="highlight">20%</div>
</div>
</div>
<div className={`${PREFIX}__item`}>
<Image src="https://publiccdn.neighbourhood.com.cn/img/02.svg" mode="aspectFit" className={`${PREFIX}__no`} />
<div></div>
</div>
<div className={`${PREFIX}__item`}>
<Image src="https://publiccdn.neighbourhood.com.cn/img/03.svg" mode="aspectFit" className={`${PREFIX}__no`} />
<div>
<div className="highlight">5%</div>
</div>
</div>
<Button className={`${PREFIX}__btn`} openType="share">
</Button>
</div>
</div>
);
}