|
@@ -12,11 +12,21 @@ import styles from "./index.module.scss";
|
|
|
interface Props {
|
|
|
actKey?: number;
|
|
|
onChange?: (key: number) => void;
|
|
|
+ useInnerVip?: boolean;
|
|
|
+ vip_level?: number;
|
|
|
+ vips?: Record<string, any>[];
|
|
|
}
|
|
|
|
|
|
-const VipProgress: React.FC<Props> = ({ actKey = 0, onChange }) => {
|
|
|
+const VipProgress: React.FC<Props> = ({
|
|
|
+ actKey = 0,
|
|
|
+ onChange,
|
|
|
+ useInnerVip = true,
|
|
|
+ vip_level,
|
|
|
+ vips,
|
|
|
+}) => {
|
|
|
const { data: userVip, run: runVip } = useRequest<any, any>(getNewVip, {
|
|
|
pollingErrorRetryCount: 1,
|
|
|
+ manual: !useInnerVip,
|
|
|
});
|
|
|
|
|
|
const vipInfo: NewVip = React.useMemo(() => {
|
|
@@ -28,10 +38,34 @@ const VipProgress: React.FC<Props> = ({ actKey = 0, onChange }) => {
|
|
|
const swiperRef = React.useRef<SwiperClass | null>(null);
|
|
|
|
|
|
React.useEffect(() => {
|
|
|
- if (!vipInfo?.vip_level) return;
|
|
|
+ if (!vipInfo?.vip_level || !useInnerVip) return;
|
|
|
+
|
|
|
setAct(vipInfo.vip_level);
|
|
|
swiperRef.current?.slideTo(vipInfo.vip_level);
|
|
|
- }, [vipInfo]);
|
|
|
+ }, [vipInfo, useInnerVip]);
|
|
|
+ React.useEffect(() => {
|
|
|
+ if (!useInnerVip) {
|
|
|
+ setTimeout(() => {
|
|
|
+ setAct(vip_level || 0);
|
|
|
+ swiperRef.current?.slideTo(vip_level || 0);
|
|
|
+ }, 100);
|
|
|
+ }
|
|
|
+ }, [useInnerVip, vip_level]);
|
|
|
+
|
|
|
+ const renderVip = React.useMemo(() => {
|
|
|
+ if (useInnerVip) {
|
|
|
+ return vipInfo?.level_info;
|
|
|
+ }
|
|
|
+ return vips;
|
|
|
+ }, [useInnerVip, vipInfo, vips]);
|
|
|
+
|
|
|
+ const curVipLevel = React.useMemo(() => {
|
|
|
+ if (useInnerVip) {
|
|
|
+ return vipInfo?.vip_level;
|
|
|
+ }
|
|
|
+ return vip_level;
|
|
|
+ }, [useInnerVip, vipInfo, vip_level]);
|
|
|
+
|
|
|
React.useEffect(() => {
|
|
|
setAct(actKey);
|
|
|
swiperRef.current?.slideTo(actKey);
|
|
@@ -58,15 +92,15 @@ const VipProgress: React.FC<Props> = ({ actKey = 0, onChange }) => {
|
|
|
swiperRef.current = swiper;
|
|
|
}}
|
|
|
>
|
|
|
- {!!vipInfo?.level_info?.length &&
|
|
|
- vipInfo.level_info.map((item) => {
|
|
|
+ {!!renderVip?.length &&
|
|
|
+ renderVip.map((item) => {
|
|
|
const curVipCfg = VipProgressMap.get(item.id) as VipItem;
|
|
|
|
|
|
return (
|
|
|
<SwiperSlide key={item.id} className="relative pb-[.15rem]">
|
|
|
<div
|
|
|
className={clsx(styles.VipItem, {
|
|
|
- [styles.disabled]: item.id > (vipInfo?.vip_level || 0),
|
|
|
+ [styles.disabled]: item.id > (curVipLevel || 0),
|
|
|
[styles.active]: item.id === act,
|
|
|
})}
|
|
|
onClick={() => doChange(item.id)}
|