|
@@ -2,91 +2,150 @@ import { View, Swiper, SwiperItem, Image } from "@tarojs/components";
|
|
|
import React, { useEffect, useState } from "react";
|
|
|
import style from "./index.module.less";
|
|
|
import IconStarColor from "@/components/icon/icon-star-color";
|
|
|
+import { getUploadedAvatarStatus, TAvatarItem } from '@/service/storage'
|
|
|
+import useSWR from 'swr';
|
|
|
interface IProps {
|
|
|
- prev: ()=>void
|
|
|
- next: ()=>void
|
|
|
+ prev: () => void;
|
|
|
+ next: () => void;
|
|
|
+ setPickedAvatar: (pickedAvatar: TAvatarItem)=> void
|
|
|
+ taskId: string|number
|
|
|
}
|
|
|
-export default React.memo(function Index({prev, next}:IProps) {
|
|
|
+export default React.memo(function Index({ prev, next, taskId, setPickedAvatar }: IProps) {
|
|
|
const [currentSwiperIndex, setCurrentSwiperIndex] = useState(0);
|
|
|
- const characters = [1, 2];
|
|
|
+ const [avatars, setAvatars] = useState<TAvatarItem[]>([]);
|
|
|
+ const [shouldPoll, setShouldPoll] = useState(false);
|
|
|
+
|
|
|
+
|
|
|
+ const goNext = () => {
|
|
|
+ const pickedAvatar = avatars[currentSwiperIndex]
|
|
|
+ setPickedAvatar(pickedAvatar)
|
|
|
+ console.log(pickedAvatar)
|
|
|
+ next()
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ const { data } = useSWR(
|
|
|
+ shouldPoll ? 'getUploadedAvatarStatus' : null,
|
|
|
+ ()=> getUploadedAvatarStatus(taskId),
|
|
|
+ {
|
|
|
+ revalidateOnFocus: false,
|
|
|
+ refreshInterval: shouldPoll ? 3000 : 0,
|
|
|
+ refreshWhenHidden: false,
|
|
|
+ refreshWhenOffline: false,
|
|
|
+ revalidateOnMount: false
|
|
|
+ }
|
|
|
+ );
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ setShouldPoll(true);
|
|
|
+ return () => {
|
|
|
+ setShouldPoll(false);
|
|
|
+ };
|
|
|
+ }, []);
|
|
|
+
|
|
|
+ useEffect(()=> {
|
|
|
+ if(data?.data.status === 'success'){
|
|
|
+ setAvatars(data.data?.data.reverse())
|
|
|
+ setShouldPoll(false);
|
|
|
+ }
|
|
|
+ return ()=> {
|
|
|
+
|
|
|
+ }
|
|
|
+ }, [data])
|
|
|
+
|
|
|
+
|
|
|
const onSwiperChange = (e: any) => {
|
|
|
const i = e.detail.current;
|
|
|
setCurrentSwiperIndex(i);
|
|
|
};
|
|
|
- useEffect(()=> {
|
|
|
- console.log('helloworldrendeer')
|
|
|
- }, [])
|
|
|
- const renderIndicator = (currentIndex: number) => {
|
|
|
- return (
|
|
|
- <>
|
|
|
- <View className={style.indicatorContainer}>
|
|
|
- {characters.map((_item, index) => {
|
|
|
- return (
|
|
|
- <View
|
|
|
- key={index}
|
|
|
- className={
|
|
|
- index === currentIndex
|
|
|
- ? `${style.indicator} ${style.indicatorActive}`
|
|
|
- : style.indicator
|
|
|
- }
|
|
|
- ></View>
|
|
|
- );
|
|
|
- })}
|
|
|
- </View>
|
|
|
- </>
|
|
|
- );
|
|
|
- };
|
|
|
|
|
|
- return (
|
|
|
- <View>
|
|
|
- <View className={style.pickContainer}>
|
|
|
- {/* <View className={`${style.pickAvatarCard} ${style.pickGenCard}`}>
|
|
|
- <View className="flex items-center gap-4">
|
|
|
- <IconStarColor></IconStarColor> <View className="gradient-text">AI生成中</View>
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ const renderSwipers = () => {
|
|
|
+ const renderIndicator = (currentIndex: number) => {
|
|
|
+ return (
|
|
|
+ <>
|
|
|
+ <View className={style.indicatorContainer}>
|
|
|
+ {avatars.map((_item, index) => {
|
|
|
+ return (
|
|
|
+ <View
|
|
|
+ key={index}
|
|
|
+ className={
|
|
|
+ index === currentIndex
|
|
|
+ ? `${style.indicator} ${style.indicatorActive}`
|
|
|
+ : style.indicator
|
|
|
+ }
|
|
|
+ ></View>
|
|
|
+ );
|
|
|
+ })}
|
|
|
</View>
|
|
|
- </View> */}
|
|
|
+ </>
|
|
|
+ );
|
|
|
+ };
|
|
|
|
|
|
- <View className={`${style.pickAvatarCard}`}>
|
|
|
- <Swiper
|
|
|
- className={style.mySwiper}
|
|
|
- indicatorColor="#999"
|
|
|
- indicatorActiveColor="#333"
|
|
|
- indicatorDots={false}
|
|
|
- duration={200}
|
|
|
- next-margin="-120rpx"
|
|
|
- current={currentSwiperIndex}
|
|
|
- onChange={(e) => onSwiperChange(e)}
|
|
|
- >
|
|
|
- <SwiperItem>
|
|
|
- <View className={style.swiperItem}>
|
|
|
- <Image
|
|
|
- mode="widthFix"
|
|
|
- src="https://cdn.wehome.cn/cmn/png/53/META-H8UKWHWU-2JNUAG2BARJF55VHU9QS3-YBQGHDAM-IW.png"
|
|
|
- ></Image>
|
|
|
- </View>
|
|
|
- </SwiperItem>
|
|
|
-
|
|
|
- <SwiperItem>
|
|
|
+ return (
|
|
|
+ <View className={`${style.pickAvatarCard}`}>
|
|
|
+ <Swiper
|
|
|
+ className={style.mySwiper}
|
|
|
+ indicatorColor="#999"
|
|
|
+ indicatorActiveColor="#333"
|
|
|
+ indicatorDots={false}
|
|
|
+ duration={200}
|
|
|
+ next-margin="-120rpx"
|
|
|
+ current={currentSwiperIndex}
|
|
|
+ onChange={(e) => onSwiperChange(e)}
|
|
|
+ >
|
|
|
+ {avatars.map(avatar => {
|
|
|
+ return <SwiperItem>
|
|
|
<View className={style.swiperItem}>
|
|
|
<Image
|
|
|
mode="widthFix"
|
|
|
- src="https://cdn.wehome.cn/cmn/png/53/META-H8UKWHWU-2JNUAG2BARJF55VHU9QS3-YBQGHDAM-IW.png"
|
|
|
+ src={avatar.avatarUrl}
|
|
|
></Image>
|
|
|
- <View className={style.pickAvatarOriginal}>
|
|
|
+ {avatar.isOriginal && <View className={style.pickAvatarOriginal}>
|
|
|
<View>原图</View>
|
|
|
- </View>
|
|
|
+ </View> }
|
|
|
</View>
|
|
|
</SwiperItem>
|
|
|
- </Swiper>
|
|
|
- {/* <!-- 自定义指示点容器 --> */}
|
|
|
- {renderIndicator(currentSwiperIndex)}
|
|
|
- </View>
|
|
|
+ })}
|
|
|
+ </Swiper>
|
|
|
+ {/* <!-- 自定义指示点容器 --> */}
|
|
|
+ {renderIndicator(currentSwiperIndex)}
|
|
|
+ </View>
|
|
|
+ );
|
|
|
+ };
|
|
|
+
|
|
|
+ const renderContent = ()=> {
|
|
|
+ if(avatars.length){
|
|
|
+ return renderSwipers()
|
|
|
+ }
|
|
|
+
|
|
|
+ return <View className={`${style.pickAvatarCard} ${style.pickGenCard}`}>
|
|
|
+ <View className="flex items-center gap-4">
|
|
|
+ <IconStarColor></IconStarColor>{" "}
|
|
|
+ <View className="gradient-text">AI生成中</View>
|
|
|
+ </View>
|
|
|
+ </View>
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return (
|
|
|
+ <View>
|
|
|
+ <View className={style.pickContainer}>
|
|
|
+ {renderContent()}
|
|
|
</View>
|
|
|
|
|
|
<View className="bottom-bar">
|
|
|
<View className="grid grid-cols-2 gap-8 px-20 py-12">
|
|
|
- <View className={`button-rounded`} onClick={prev}>上一步</View>
|
|
|
- <View className={`button-rounded primary opacity-20`} onClick={next}>使用这张</View>
|
|
|
+ <View className={`button-rounded`} onClick={prev}>
|
|
|
+ 上一步
|
|
|
+ </View>
|
|
|
+ <View className={`button-rounded primary ${avatars.length ? '' : 'opacity-20'}`} onClick={()=> goNext()}>
|
|
|
+ 使用这张
|
|
|
+ </View>
|
|
|
</View>
|
|
|
</View>
|
|
|
</View>
|