|
@@ -1,213 +1,33 @@
|
|
import { useEffect, useState } from "react";
|
|
import { useEffect, useState } from "react";
|
|
-import { View, Swiper, SwiperItem } from "@tarojs/components";
|
|
|
|
|
|
+import { View,Image } from "@tarojs/components";
|
|
import Taro, { useDidShow, useReady } from "@tarojs/taro";
|
|
import Taro, { useDidShow, useReady } from "@tarojs/taro";
|
|
import style from "./index.module.less";
|
|
import style from "./index.module.less";
|
|
-import NavBar from "@/components/nav-bar/index";
|
|
|
|
-import PopupTips from "@/components/popup/popup-tips/index";
|
|
|
|
-import AICard from "./components/AICard/Index";
|
|
|
|
-import AICardAdd from "./components/AICardAdd/Index";
|
|
|
|
-import { useUserStore } from "@/store/userStore";
|
|
|
|
-import { useCharacterStore, useCurrentCharacter } from "@/store/characterStore";
|
|
|
|
-import { useAppStore } from "@/store/appStore";
|
|
|
|
-import { APP_NAME_TEXT } from '@/config'
|
|
|
|
-import { reportPageVisit } from '@/utils/report'
|
|
|
|
-import TabPageWrapper from "@/components/tab-page-wrapper/index";
|
|
|
|
|
|
+import NavBarNormal from "@/components/nav-bar-normal/index";
|
|
|
|
+import LogoImage from '@/images/logo.png'
|
|
|
|
+import PageCustom from "@/components/page-custom/index";
|
|
|
|
+// import { useUserStore } from "@/store/userStore";
|
|
|
|
+// import { useCharacterStore, useCurrentCharacter } from "@/store/characterStore";
|
|
|
|
+// import { useAppStore } from "@/store/appStore";
|
|
|
|
|
|
-
|
|
|
|
-// 判断角色是否是刚创建
|
|
|
|
-const checkCreateTime = (createdAt = '')=> {
|
|
|
|
- let characterCreateAt = new Date();
|
|
|
|
- if(createdAt){
|
|
|
|
- characterCreateAt = new Date(createdAt)
|
|
|
|
- }
|
|
|
|
- // 创建时间与当前时间差是否小于1秒,用于判断是否要显示默认头像
|
|
|
|
- const createTimeCloseEnough = ((new Date().getTime() - characterCreateAt.getTime())) < 1000 ? true : false
|
|
|
|
- return createTimeCloseEnough
|
|
|
|
-}
|
|
|
|
|
|
+import WelcomeTips from './components/welcome/index'
|
|
|
|
|
|
export default function Index() {
|
|
export default function Index() {
|
|
- const {
|
|
|
|
- characters,
|
|
|
|
- fetchCharacterList,
|
|
|
|
- setCurrentCharacter,
|
|
|
|
- saveCharacter,
|
|
|
|
- deleteCharacterById,
|
|
|
|
- } = useCharacterStore();
|
|
|
|
- const character = useCurrentCharacter()
|
|
|
|
- const { fetchAppConfig, setVip } = useAppStore();
|
|
|
|
- const appConfig = useAppStore((state) => state.appConfig);
|
|
|
|
- const vip = useAppStore((state) => state.vip);
|
|
|
|
- const [currentSwiperIndex, setCurrentSwiperIndex] = useState(0);
|
|
|
|
- const [showVip, setShowVip] = useState(false);
|
|
|
|
- const statusBarHeight = useAppStore((state) => state.statusBarHeight);
|
|
|
|
- const headerHeight = useAppStore((state) => state.headerHeight);
|
|
|
|
- const { fetchUser } = useUserStore();
|
|
|
|
- const user = useUserStore((state) => state.user);
|
|
|
|
|
|
|
|
|
|
|
|
- const onSwiperChange = (e: any) => {
|
|
|
|
- const i = e.detail.current;
|
|
|
|
- setCurrentSwiperIndex(i);
|
|
|
|
- const c = characters[i];
|
|
|
|
- console.log(c);
|
|
|
|
- setCurrentCharacter(!!c ? c : null);
|
|
|
|
- };
|
|
|
|
- let creating = false;
|
|
|
|
- const handleCreate = async () => {
|
|
|
|
- const maxPage = vip?.metadata?.maxCharacterNum;
|
|
|
|
- // 大于可创建角色数量
|
|
|
|
- if(maxPage !== -1 && characters.length >= maxPage){
|
|
|
|
- setShowVip(true)
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- creating = true;
|
|
|
|
|
|
|
|
- const c = await saveCharacter({
|
|
|
|
- name: "您的主页名称",
|
|
|
|
- });
|
|
|
|
- creating = false;
|
|
|
|
- if (c) {
|
|
|
|
- const createTimeCloseEnough = checkCreateTime(character?.createdAt)
|
|
|
|
- Taro.navigateTo({ url: `/pages/page/index?profileId=${c.data.profileId}&createTimeCloseEnough=${createTimeCloseEnough}` });
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- };
|
|
|
|
|
|
|
|
- const handleLongPress = (profileId: string) => {
|
|
|
|
- console.log("longpress");
|
|
|
|
- Taro.showModal({
|
|
|
|
- content: `😭 确认删除${APP_NAME_TEXT}?`,
|
|
|
|
- async success(result) {
|
|
|
|
- if (result.confirm) {
|
|
|
|
- deleteCharacterById(profileId);
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
- });
|
|
|
|
- };
|
|
|
|
|
|
+
|
|
|
|
|
|
- const fetchList = async () => {
|
|
|
|
- const r = await fetchCharacterList();
|
|
|
|
- // 如果没有当前选中角色,且角色列表有数据,则设置第一个角色为当前角色
|
|
|
|
- // 如果不设置当前角色,就无法调用 greeting 获取聊天的 session
|
|
|
|
- if(!character && r?.length){
|
|
|
|
- setCurrentCharacter(r[0])
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- useReady(async () => {
|
|
|
|
- // 静默登录
|
|
|
|
- // await authLogin();
|
|
|
|
- fetchUser();
|
|
|
|
- fetchAppConfig();
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- useDidShow(()=> {
|
|
|
|
- fetchList()
|
|
|
|
- })
|
|
|
|
-
|
|
|
|
- useEffect(() => {
|
|
|
|
- if(appConfig && user){
|
|
|
|
- const vip =
|
|
|
|
- appConfig?.vips?.find((item) => {
|
|
|
|
- if (user?.vip !== undefined && item.id === user.vip) {
|
|
|
|
- return item;
|
|
|
|
- }
|
|
|
|
- return null;
|
|
|
|
- }) ?? null;
|
|
|
|
- vip && setVip(vip)
|
|
|
|
- }
|
|
|
|
- }, [appConfig?.vips, user?.id]);
|
|
|
|
-
|
|
|
|
- reportPageVisit()
|
|
|
|
-
|
|
|
|
- const renderIndicator = (currentIndex: number)=> {
|
|
|
|
- // 大于 10 张后指示器变为数字
|
|
|
|
- if(characters.length > 10){
|
|
|
|
- return <View className="flex justify-center mt-12">
|
|
|
|
- <View className="text-center text-gray-45 text-10 rounded-full bg-gray-light w-12 h-12">{currentIndex+1}</View>
|
|
|
|
- </View>
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return <>
|
|
|
|
- <View className={style.indicatorContainer}>
|
|
|
|
- <View
|
|
|
|
- className={
|
|
|
|
- currentSwiperIndex === 0
|
|
|
|
- ? `${style.indicator} ${style.indicatorActive}`
|
|
|
|
- : style.indicator
|
|
|
|
- }
|
|
|
|
- ></View>
|
|
|
|
- {
|
|
|
|
- characters.map((_item, index) => {
|
|
|
|
- return (
|
|
|
|
- <View
|
|
|
|
- key={index}
|
|
|
|
- className={
|
|
|
|
- index + 1 === currentSwiperIndex
|
|
|
|
- ? `${style.indicator} ${style.indicatorActive}`
|
|
|
|
- : style.indicator
|
|
|
|
- }
|
|
|
|
- ></View>
|
|
|
|
- );
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
- </View>
|
|
|
|
- </>
|
|
|
|
|
|
+ const renderLogo = ()=> {
|
|
|
|
+ return <View><Image className="w-68 h-24" src={LogoImage}></Image></View>
|
|
}
|
|
}
|
|
|
|
|
|
return (
|
|
return (
|
|
- <TabPageWrapper>
|
|
|
|
- <NavBar>{APP_NAME_TEXT}</NavBar>
|
|
|
|
- <PopupTips show={showVip} onClose={() => setShowVip(false)}>
|
|
|
|
- <View className={style.vipTips}>
|
|
|
|
- <View className={style.vipTipsFigure}></View>
|
|
|
|
- <View className="text-28 leading-36 font-semibold text-black pt-24">温馨提示</View>
|
|
|
|
- <View className='text-14 leading-24 text-black pt-12'>
|
|
|
|
- 当前最多支持创建{vip?.metadata?.maxCharacterNum}个{APP_NAME_TEXT}面,您可以先编辑它们,或者长按删除
|
|
|
|
- </View>
|
|
|
|
- <View className='rounded-button-big mt-20' onClick={() => setShowVip(false)}>知道了</View>
|
|
|
|
- </View>
|
|
|
|
- </PopupTips>
|
|
|
|
- <View style={{ paddingTop: 0 }}>
|
|
|
|
-
|
|
|
|
|
|
+ <PageCustom>
|
|
|
|
+ <NavBarNormal leftColumn={renderLogo}></NavBarNormal>
|
|
|
|
+
|
|
|
|
+ <WelcomeTips></WelcomeTips>
|
|
|
|
|
|
- <Swiper
|
|
|
|
- className={style.mySwiper}
|
|
|
|
- indicatorColor="#999"
|
|
|
|
- indicatorActiveColor="#333"
|
|
|
|
- indicatorDots={false}
|
|
|
|
- duration={200}
|
|
|
|
- next-margin="-120rpx"
|
|
|
|
- current={currentSwiperIndex}
|
|
|
|
- onChange={(e) => onSwiperChange(e)}
|
|
|
|
- >
|
|
|
|
- {characters.map((item, _index) => {
|
|
|
|
- return (
|
|
|
|
- <SwiperItem key={item.profileId}>
|
|
|
|
- <View onLongPress={() => handleLongPress(item.profileId)}>
|
|
|
|
- <AICard
|
|
|
|
- playGreeting={false}
|
|
|
|
- character={item}
|
|
|
|
- index={_index + 1}
|
|
|
|
- currentIndex={currentSwiperIndex}
|
|
|
|
- ></AICard>
|
|
|
|
- </View>
|
|
|
|
- </SwiperItem>
|
|
|
|
- );
|
|
|
|
- })}
|
|
|
|
- <SwiperItem className={style.swiperItem}>
|
|
|
|
- <AICardAdd
|
|
|
|
- onClick={() => handleCreate()}
|
|
|
|
- length={characters.length}
|
|
|
|
- ></AICardAdd>
|
|
|
|
- </SwiperItem>
|
|
|
|
- </Swiper>
|
|
|
|
- {/* <!-- 自定义指示点容器 --> */}
|
|
|
|
- {renderIndicator(currentSwiperIndex)}
|
|
|
|
- </View>
|
|
|
|
- </TabPageWrapper>
|
|
|
|
|
|
+ </PageCustom>
|
|
);
|
|
);
|
|
}
|
|
}
|