This commit is contained in:
xd 2025-06-05 22:53:22 +08:00
commit f9af84fb65
7 changed files with 49 additions and 30 deletions

View File

@ -12,6 +12,8 @@ import './index.less';
const PREFIX = 'partner-invite-list';
const log = logWithPrefix(PREFIX);
const FIRST_PAGE = 0;
function PartnerList(props: {
refreshDisabled?: boolean;
visible?: boolean;
@ -20,10 +22,12 @@ function PartnerList(props: {
onListEmpty?: () => void;
}) {
const { className, listHeight, refreshDisabled, visible = true, onListEmpty } = props;
const [hasMore, setHasMore] = useState(true);
const [refreshing, setRefreshing] = useState(false);
const [loadingMore, setLoadingMore] = useState(false);
const [loadMoreError, setLoadMoreError] = useState(false);
const [dataList, setDataList] = useState<InviteUserInfo[]>([]);
const currentPage = useRef<number>(FIRST_PAGE);
const onListEmptyRef = useRef(onListEmpty);
const handleRefresh = useCallback(async () => {
@ -31,19 +35,44 @@ function PartnerList(props: {
try {
setRefreshing(true);
setLoadMoreError(false);
const list = await requestData();
setDataList(list);
!list.length && onListEmptyRef.current?.();
const { content, totalPages } = await requestData({ page: 1 });
setDataList(content);
currentPage.current = 1;
setHasMore(currentPage.current < totalPages);
!content.length && onListEmptyRef.current?.();
log('pull refresh success');
} catch (e) {
setDataList([]);
setHasMore(false);
setLoadMoreError(true);
currentPage.current = FIRST_PAGE;
log('pull refresh failed');
} finally {
setRefreshing(false);
}
}, []);
const handleLoadMore = useCallback(async () => {
log('start load more', hasMore);
if (!hasMore) {
return;
}
setLoadMoreError(false);
setLoadingMore(true);
try {
const { totalPages, content } = await requestData({ page: currentPage.current + 1 });
setDataList([...dataList, ...content]);
currentPage.current = currentPage.current + 1;
setHasMore(currentPage.current < totalPages);
log('load more success');
} catch (e) {
setLoadMoreError(true);
log('load more failed');
} finally {
setLoadingMore(false);
}
}, [dataList, hasMore]);
useEffect(() => {
onListEmptyRef.current = onListEmpty;
}, [onListEmpty]);
@ -62,11 +91,14 @@ function PartnerList(props: {
setDataList([]);
setLoadingMore(true);
setLoadMoreError(false);
const list = await requestData();
setDataList(list);
!list.length && onListEmptyRef.current?.();
const { totalPages, content } = await requestData({ page: 1 });
setDataList(content);
currentPage.current = 1;
setHasMore(currentPage.current < totalPages);
!content.length && onListEmptyRef.current?.();
} catch (e) {
setDataList([]);
setHasMore(false);
setLoadMoreError(true);
} finally {
log('visible changed, refresh list data end');
@ -90,8 +122,8 @@ function PartnerList(props: {
disabled={refreshDisabled}
>
<List
hasMore={false}
onLoad={() => {}}
hasMore={hasMore}
onLoad={handleLoadMore}
loading={loadingMore || refreshing}
disabled={loadMoreError}
fixedHeight={typeof listHeight !== 'undefined'}

View File

@ -27,8 +27,7 @@ import { logWithPrefix } from '@/utils/common';
import { getLastSelectMyJobId, requestJobManageList, setLastSelectMyJobId } from '@/utils/job';
import { getWxLocation } from '@/utils/location';
import { requestUnreadMessageCount } from '@/utils/message';
import { getInviteCodeFromQueryAndUpdate } from '@/utils/partner';
import { getPageQuery, navigateTo } from '@/utils/route';
import { navigateTo } from '@/utils/route';
import { getCommonShareMessage } from '@/utils/share';
import Toast from '@/utils/toast';
import './index.less';
@ -165,9 +164,6 @@ export default function AnchorPage() {
}, [location]);
useLoad(async () => {
const query = getPageQuery();
getInviteCodeFromQueryAndUpdate(query);
try {
const { jobResults = [] } = await requestJobManageList({ status: JobManageStatus.Open });
if (!jobResults.length) {

View File

@ -1,4 +1,4 @@
import { useLoad, useShareAppMessage } from '@tarojs/taro';
import { useShareAppMessage } from '@tarojs/taro';
import { useCallback } from 'react';
@ -8,8 +8,6 @@ import { GROUPS } from '@/constants/group';
import useInviteCode from '@/hooks/use-invite-code';
import { openCustomerServiceChat } from '@/utils/common';
import { getCurrentCityCode } from '@/utils/location';
import { getInviteCodeFromQueryAndUpdate } from '@/utils/partner';
import { getPageQuery } from '@/utils/route';
import { getCommonShareMessage } from '@/utils/share';
import './index.less';
@ -18,11 +16,6 @@ const PREFIX = 'group-v2-page';
export default function GroupV2() {
const inviteCode = useInviteCode();
useLoad(() => {
const query = getPageQuery();
getInviteCodeFromQueryAndUpdate(query);
});
useShareAppMessage(() => getCommonShareMessage(true, inviteCode));
const handleSelectCity = useCallback(cityCode => {

View File

@ -28,7 +28,6 @@ import { getJobTitle, getJobSalary, postPublishJob, requestJobDetail } from '@/u
import { calcDistance, isValidLocation } from '@/utils/location';
import { requestProfileDetail } from '@/utils/material';
import { isChatWithSelf, postCreateChat } from '@/utils/message';
import { getInviteCodeFromQueryAndUpdate } from '@/utils/partner';
import { getJumpUrl, getPageQuery, navigateTo } from '@/utils/route';
import { getCommonShareMessage } from '@/utils/share';
import { formatDate } from '@/utils/time';
@ -219,8 +218,7 @@ export default function JobDetail() {
}, []);
useLoad(async () => {
const query = getPageQuery<Pick<JobDetails, 'id'> & { c: string }>();
getInviteCodeFromQueryAndUpdate(query);
const query = getPageQuery<Pick<JobDetails, 'id'>>();
const jobId = query?.id;
if (!jobId) {
return;

View File

@ -17,7 +17,6 @@ import { Coordinate } from '@/types/location';
import { logWithPrefix } from '@/utils/common';
import { getWxLocation, isNotNeedAuthorizeLocation, requestLocation } from '@/utils/location';
import { requestUnreadMessageCount } from '@/utils/message';
import { getInviteCodeFromQueryAndUpdate } from '@/utils/partner';
import { getJumpUrl, getPageQuery, navigateTo } from '@/utils/route';
import { getCommonShareMessage } from '@/utils/share';
import Toast from '@/utils/toast';
@ -109,7 +108,6 @@ export default function Job() {
if (type === SortType.CREATE_TIME) {
setSortType(type);
}
getInviteCodeFromQueryAndUpdate(query);
if (await isNotNeedAuthorizeLocation()) {
log('not need authorize location');
requestLocation();

View File

@ -21,7 +21,6 @@ import { collectEvent } from '@/utils/event';
import { requestHasPublishedJob, requestJobDetail } from '@/utils/job';
import { getMaterialShareMessage, requestReadProfile, requestShareProfile } from '@/utils/material';
import { isChatWithSelf, postCreateChat } from '@/utils/message';
import { getInviteCodeFromQueryAndUpdate } from '@/utils/partner';
import { getPageQuery, navigateBack, navigateTo, redirectTo } from '@/utils/route';
import Toast from '@/utils/toast';
import './index.less';
@ -142,7 +141,6 @@ export default function MaterialViewPage() {
useLoad(async () => {
const context = getPageQuery<IViewContext | IShareContext>();
getInviteCodeFromQueryAndUpdate(context as BL.Anything);
try {
const profileDetail = await requestProfile(context);
setProfile(profileDetail);

View File

@ -5,6 +5,7 @@ import http from '@/http';
import { API } from '@/http/api';
import store from '@/store';
import { setInviteCode } from '@/store/actions/partner';
import { IPaginationRequest } from '@/types/common';
import {
GetProfitRequest,
InviteUserInfo,
@ -51,8 +52,11 @@ export const getPartnerQrcode = async () => {
export const getPartnerProfitStat = async () => {
return await http.post<PartnerProfitsState>(API.GET_PROFIT_STAT);
};
export const getPartnerInviteList = async () => {
return await http.post<InviteUserInfo[]>(API.GET_INVITE_LIST);
export const getPartnerInviteList = async (data: IPaginationRequest) => {
return await http.post<{ content: InviteUserInfo[]; totalPages: number }>(API.GET_INVITE_LIST, {
data,
contentType: 'application/x-www-form-urlencoded',
});
};
export const dispatchUpdateInviteCode = (code: string) => store.dispatch(setInviteCode(code));
export const getInviteCode = async () => {