index.tsx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import { Image, View } from "@tarojs/components";
  2. import style from "./index.module.less";
  3. import IconPlusBig from "@/components/icon/icon-plus-big";
  4. import Taro from "@tarojs/taro";
  5. import { uploadAndNavToGenNewAvatar } from "@/utils/avatar";
  6. import WemetaRadio from "@/components/WemetaRadio";
  7. import { useAgentStore, useAgentStoreActions } from "@/store/agentStore";
  8. import { editAgentChatBg } from "@/service/agent";
  9. import { isSuccess } from "@/utils";
  10. import { fetchMyAvatars } from "@/service/storage";
  11. import { AvatarMedia } from "@/components/AvatarMedia";
  12. export default () => {
  13. const agentEdit = useAgentStore((state) => state.agentEdit);
  14. const { fetchAgent } = useAgentStoreActions();
  15. const handleChange = async (isChecked: boolean) => {
  16. if (!agentEdit?.agentId || !agentEdit.avatarUrl) {
  17. return;
  18. }
  19. const response = await editAgentChatBg(agentEdit.agentId, isChecked);
  20. if (isSuccess(response.status)) {
  21. Taro.showToast({
  22. title: isChecked ? "启用成功" : "取消启用",
  23. icon: "success",
  24. });
  25. fetchAgent(agentEdit.agentId); // 刷新智能体信息
  26. }
  27. };
  28. const handleClick = async () => {
  29. const response = await fetchMyAvatars({ pageIndex: 1, pageSize: 2 });
  30. if (isSuccess(response.status)) {
  31. if (response.data.data.length > 0) {
  32. Taro.navigateTo({ url: "/pages/agent-avatars/index" });
  33. return;
  34. }
  35. }
  36. if (agentEdit?.avatarUrl) {
  37. return;
  38. }
  39. uploadAndNavToGenNewAvatar();
  40. };
  41. const handleChangeAvatar = async (e: any) => {
  42. e.stopPropagation();
  43. Taro.navigateTo({ url: "/pages/agent-avatars/index" });
  44. };
  45. const renderContent = () => {
  46. if (!agentEdit?.avatarUrl) {
  47. return (
  48. <View className={style.tips}>
  49. <View className={style.icon}>
  50. <IconPlusBig></IconPlusBig>
  51. </View>
  52. <View className={style.tipsText}>形象照</View>
  53. </View>
  54. );
  55. }
  56. return (
  57. <View className="relative overflow-hidden w-full h-full">
  58. <AvatarMedia source={agentEdit.avatarUrl} className={style.card} />
  59. {agentEdit?.enabledChatBg && <View className={style.confirmChatAvatarBgCover}>
  60. <View className={style.block1}></View>
  61. <View className={style.block2}></View>
  62. <View className={style.block3}></View>
  63. </View>}
  64. <View className={style.changeButton} onClick={handleChangeAvatar}>
  65. 更换形象
  66. </View>
  67. </View>
  68. );
  69. };
  70. const renderFooter = ()=> {
  71. if(agentEdit?.avatarUrl){
  72. return <View
  73. className="w-full flex-center pt-16 gap-6"
  74. onClick={() => handleChange(!!!agentEdit?.enabledChatBg)}
  75. >
  76. <WemetaRadio checkbox checked={agentEdit?.enabledChatBg}></WemetaRadio>
  77. <View className="font-medium text-14 text-black">启用聊天背景</View>
  78. </View>
  79. }
  80. return <View className="pt-16 font-medium text-14 text-gray-3 text-center">用于头像或聊天背景</View>
  81. }
  82. return (
  83. <View className={style.container}>
  84. <View className={style.cardContainer} onClick={handleClick}>
  85. {renderContent()}
  86. </View>
  87. {renderFooter()}
  88. </View>
  89. );
  90. };