소스 검색

feat: 自动填充开场白与人设

王晓东 4 달 전
부모
커밋
73b4997d0d
54개의 변경된 파일908개의 추가작업 그리고 498개의 파일을 삭제
  1. 16 2
      project.private.config.json
  2. 10 11
      src/app.config.ts
  3. 8 6
      src/components/AgentPage/components/AgentActionBar/index.tsx
  4. 4 4
      src/components/AgentPage/components/AgentSwap/index.tsx
  5. 82 0
      src/components/AvatarConfirm/index.module.less
  6. 71 0
      src/components/AvatarConfirm/index.tsx
  7. 12 4
      src/components/TextPolish/index.tsx
  8. 11 5
      src/components/WemetaRadio/index.module.less
  9. 7 6
      src/components/WemetaRadio/index.tsx
  10. 21 5
      src/components/WemetaTextareaAI/index.tsx
  11. 0 20
      src/components/buttons/ButtonMain.tsx
  12. 28 0
      src/components/buttons/WemetaButton.tsx
  13. 7 0
      src/components/icon/IconPlayWhite20/index.tsx
  14. 11 0
      src/images/svgs/icon-play-white-20.svg
  15. 1 1
      src/pages/agent-avatar-confirm/index.config.ts
  16. 0 0
      src/pages/agent-avatar-confirm/index.module.less
  17. 39 0
      src/pages/agent-avatar-confirm/index.tsx
  18. 57 0
      src/pages/agent-avatar-confirm/useAvatars.ts
  19. 39 14
      src/pages/agent-avatars/index.module.less
  20. 61 36
      src/pages/agent-avatars/index.tsx
  21. 8 8
      src/pages/agent-gen/components/step/StepConfirm.tsx
  22. 4 4
      src/pages/agent-gen/components/step/StepPick.tsx
  23. 20 10
      src/pages/agent/components/AgentSetting/components/AgentCard/index.module.less
  24. 12 12
      src/pages/agent/components/AgentSetting/components/AgentCard/index.tsx
  25. 12 6
      src/pages/agent/components/AgentSetting/components/AgentContactCard/index.tsx
  26. 6 6
      src/pages/agent/components/AgentSetting/components/AgentKnowledgeLib/index.tsx
  27. 50 22
      src/pages/agent/components/AgentSetting/components/AgentSettingList/index.tsx
  28. 20 9
      src/pages/agent/components/AgentSetting/index.tsx
  29. 66 4
      src/pages/agent/hooks/useConfirms.tsx
  30. 51 35
      src/pages/agent/index.tsx
  31. 2 2
      src/pages/contact-us/index.tsx
  32. 2 2
      src/pages/editor-pages/editor-channels/index.tsx
  33. 4 4
      src/pages/editor-pages/editor-ent-name/index.tsx
  34. 15 15
      src/pages/editor-pages/editor-greeting-questions/index.tsx
  35. 0 5
      src/pages/editor-pages/editor-greeting/index.config.ts
  36. 0 2
      src/pages/editor-pages/editor-greeting/index.module.less
  37. 0 45
      src/pages/editor-pages/editor-greeting/index.tsx
  38. 3 3
      src/pages/editor-pages/editor-link-social/index.tsx
  39. 5 5
      src/pages/editor-pages/editor-link/index.tsx
  40. 2 2
      src/pages/editor-pages/editor-mini-program/index.tsx
  41. 4 4
      src/pages/editor-pages/editor-name/index.tsx
  42. 0 49
      src/pages/editor-pages/editor-personality/index.tsx
  43. 4 4
      src/pages/editor-pages/editor-position/index.tsx
  44. 5 5
      src/pages/editor-pages/editor-tel/index.tsx
  45. 11 11
      src/pages/editor-pages/editor-textarea/index.tsx
  46. 9 9
      src/pages/editor-pages/editor-title/index.tsx
  47. 3 3
      src/pages/knowledge-item/components/ShareToEntPopup/index.tsx
  48. 1 1
      src/pages/voice/components/MyVoiceList/index.tsx
  49. 4 4
      src/pages/voice/components/ScrollVoiceList/index.tsx
  50. 1 0
      src/pages/voice/components/VoiceList/index.tsx
  51. 15 12
      src/pages/voice/index.tsx
  52. 1 18
      src/service/agent.ts
  53. 80 59
      src/store/agentStore.ts
  54. 3 4
      src/store/componentStore.ts

+ 16 - 2
project.private.config.json

@@ -9,11 +9,25 @@
     "miniprogram": {
       "list": [
         {
-          "name": "pages/agent/index",
-          "pathName": "pages/agent/index",
+          "name": "pages/agent-avatars/index",
+          "pathName": "pages/agent-avatars/index",
           "query": "",
           "scene": null,
           "launchMode": "default"
+        },
+        {
+          "name": "pages/agent/index",
+          "pathName": "pages/agent/index",
+          "query": "agentId=p_2e73c9d7efaYfDo2-agent_2689",
+          "launchMode": "default",
+          "scene": null
+        },
+        {
+          "name": "pages/agent/index",
+          "pathName": "pages/agent/index",
+          "query": "",
+          "launchMode": "default",
+          "scene": null
         }
       ]
     }

+ 10 - 11
src/app.config.ts

@@ -16,8 +16,7 @@ export default defineAppConfig({
     'pages/editor-correction-item/index',
     'pages/agent/index',
     'pages/agent-avatars/index',
-    'pages/editor-pages/editor-personality/index',
-    'pages/editor-pages/editor-greeting/index',
+    'pages/agent-avatar-confirm/index',
     'pages/editor-pages/editor-greeting-questions/index',
     'pages/voice/index',
     'pages/chat/index',
@@ -27,11 +26,11 @@ export default defineAppConfig({
     'pages/privacy/index',
     'pages/account/index',
     'pages/agreement/index',
-    
+
     'pages/test/index',
     'pages/component-library/index',
     'pages/editor-pages/editor-name/index',
-    
+
     'pages/editor-pages/editor-phone/index',
     'pages/editor-pages/editor-tel/index',
     'pages/editor-pages/editor-email/index',
@@ -41,20 +40,20 @@ export default defineAppConfig({
     'pages/editor-pages/editor-position/index',
 
 
-    
+
     'pages/editor-pages/editor-channels/index',
-    
-    
+
+
     'pages/editor-pages/editor-media/index',
-    
-  
+
+
     'pages/editor-pages/editor-link/index',
     'pages/editor-pages/editor-mini-program/index',
     'pages/editor-pages/editor-link-social/index',
     'pages/editor-pages/editor-link-contact/index',
     'pages/editor-pages/editor-textarea/index',
     'pages/editor-pages/editor-title/index',
-    
+
     'pages/webview/index',
 
   ],
@@ -63,7 +62,7 @@ export default defineAppConfig({
     selectedColor: '#000000',
     backgroundColor: '#FFFFFF',
     list: [
-      
+
       {
         pagePath: 'pages/index/index',
         selectedIconPath: 'images/tabbar/agent-actived.png',

+ 8 - 6
src/components/AgentPage/components/AgentActionBar/index.tsx

@@ -19,7 +19,7 @@ import PopupSheets from "@/components/popup/popup-sheets";
 
 import { useModalStore } from "@/store/modalStore";
 import { TAgentDetail } from "@/types/agent";
-import { useAgentStore, useAgentStoreActions } from "@/store/agentStore";
+import { useAgentStoreActions } from "@/store/agentStore";
 import LoginPopup from "@/components/LoginPopup";
 
 interface IProps {
@@ -27,13 +27,12 @@ interface IProps {
   isVisitor: boolean, // 是否是访问他人智能体
 }
 export default ({agent, isVisitor}: IProps) => {
-
   const [showAgentSwap, setShowAgentSwap] = useState(false);
   const [showAgentQRcode, setShowAgentQRcode] = useState(false);
   const [showPopup, setShowPopup] = useState(false);
   const [showShare, setShowShare] = useState(false);
   const [showLogin, setShowLogin] = useState(false);
-  const { deleteAgent } = useAgentStoreActions();
+  const { deleteAgent, updateEditAgent } = useAgentStoreActions();
 
 
   const {showModal} = useModalStore((state) => state.actions);
@@ -64,6 +63,11 @@ export default ({agent, isVisitor}: IProps) => {
     });
   }
 
+  const handleEdit = ()=> {
+    updateEditAgent(agent)
+    Taro.navigateTo({ url: `/pages/agent/index?agentId=${agent?.agentId}` });
+  }
+
   const confirmDelete = async () => {
     if(agent?.agentId){
       await deleteAgent(agent.agentId)
@@ -142,9 +146,7 @@ export default ({agent, isVisitor}: IProps) => {
               {/* 编辑智能体 */}
               {!isVisitor && <View
                 className={style.boxButton}
-                onClick={() => {
-                  Taro.navigateTo({ url: `/pages/agent/index?agentId=${agent?.agentId}` });
-                }}
+                onClick={handleEdit}
               >
                 <IconEditBlack />
               </View>}

+ 4 - 4
src/components/AgentPage/components/AgentSwap/index.tsx

@@ -17,7 +17,7 @@ interface IProps {
 }
 export default ({ show, setShow }: IProps) => {
   const agents = useAgentStore((state) => state.agents);
-  const { setDefaultAgent, fetchAgents, clearMyAgent } = useAgentStoreActions();
+  const { setDefaultAgent, fetchAgents, clearEditAgent, fetchDefaultNewAgentInfo } = useAgentStoreActions();
   let loading = false;
   const personalAgents = agents.filter((item) => !item.isEnt);
   const entAgents = agents.filter((item) => item.isEnt);
@@ -43,18 +43,18 @@ export default ({ show, setShow }: IProps) => {
   };
 
   const handleCreate = async ()=> {
-    Taro.showLoading()
     Taro.showTabBar().catch(()=> {});
     if (loading) {
       return;
     }
     loading = true;
     try{
-      Taro.navigateTo({ url: `/pages/agent/index` });
+      clearEditAgent()
+      await fetchDefaultNewAgentInfo();
+      Taro.navigateTo({ url: `/pages/agent/index`});
       loading = false;
       setShow(false)
     }catch(e:any){
-      Taro.hideLoading()
       loading = false;
     }
   }

+ 82 - 0
src/components/AvatarConfirm/index.module.less

@@ -0,0 +1,82 @@
+.confirmContainer{
+  width: 343px;
+  display: flex;
+  flex-direction: column;
+  align-items: center;
+}
+.confirmRoundedAvatarWrap{
+  width: 100px;
+  height: 100px;
+  margin-bottom: 24px;
+  border-radius: 100%;
+}
+.confirmRoundedAvatar{
+  width: 100px;
+  height: 100px;
+  overflow: hidden;
+
+  border-radius: 100%;
+}
+.confirmChatAvatarBg{
+  position: relative;
+  width: 240px;
+  min-height: 373px;
+  margin-bottom: 16px;
+  border-radius: 24px;
+  overflow: hidden;
+}
+.confirmChatAvatarImage{
+  width: 240px;
+  min-height: 373px;
+  overflow: hidden;
+}
+.confirmChatAvatarBgCover{
+  position: absolute;
+  display: flex;
+  flex-direction: column;
+  justify-content: flex-end;
+  position: absolute;
+  left: 0;
+  bottom: 0;
+  right: 0;
+  z-index: 1;
+  width: 240px;
+  min-height: 373px;
+  box-sizing: border-box;
+  padding: 0 24px 54px;
+  border-radius: 24px;
+  gap: 8px;
+  background: linear-gradient(180deg, rgba(255, 255, 255, 0) 50.12%, #D6D6D6 100%);
+}
+.block{
+  background-color: white;
+  border-radius: 8px;
+  height: 30px;
+}
+.block1{
+  .block();
+  width: 135px;
+}
+.block2{
+  .block();
+  align-self: flex-end;
+  width: 123px;
+  background-color: rgba(#317CFA, .5);
+}
+.block3{
+  .block();
+  width: 192px;
+}
+
+.aiTips{
+  position: absolute;
+  z-index: 1;
+  right: 12px;
+  bottom: 12px;
+  font-family: PingFangSC-Medium;
+  font-weight: 500;
+  font-size: 12px;
+  color: rgba(#fff, .5);
+  line-height: 12px;
+  text-shadow: 1px 1px 0 rgba(#000, .3);
+}

+ 71 - 0
src/components/AvatarConfirm/index.tsx

@@ -0,0 +1,71 @@
+import { useEffect, useRef, useState } from "react";
+import { Image, View, ScrollView, Video } from "@tarojs/components";
+
+import { uploadAndNavToGenNewAvatar } from "@/utils/avatar";
+
+import WemetaRadio from '@/components/WemetaRadio'
+import { AvatarMedia } from "@/components/AvatarMedia";
+import WemetaButton from '@/components/buttons/WemetaButton'
+import Taro from "@tarojs/taro";
+import style from "./index.module.less";
+import { isSuccess } from "@/utils";
+import { TAvatarItem } from "@/service/storage";
+interface IProps {
+  avatarItem: TAvatarItem
+}
+
+export default function Index({avatarItem}: IProps) {
+
+
+  const [enabledChatBg, setEnabledChatBg] = useState(true)
+
+  const handleConfirm = async () => {
+    console.log('confirm')
+  }
+  const handleChange = ()=> {
+
+  }
+
+  return (
+    <View>
+      <View>
+        <View className={style.confirmContainer}>
+          <View className={style.confirmRoundedAvatarWrap}>
+            <Image
+              mode='aspectFill'
+              className={style.confirmRoundedAvatar}
+              src={avatarItem?.avatarLogo}
+            ></Image>
+          </View>
+          <View className={style.confirmChatAvatarBg}>
+            <View className={style.confirmChatAvatarImage}>
+              <AvatarMedia roundedFull={false} source={avatarItem?.avatarUrl} className={style.confirmChatAvatarImage} />
+              {!avatarItem.isOriginal && <View className={style.aiTips}>图片由AI生成</View>}
+              {/* <Image
+                mode="widthFix"
+                className="w-full"
+                src={pickedAvatar.avatarUrl}
+              ></Image> */}
+            </View>
+            <View className={style.confirmChatAvatarBgCover}>
+              <View className={style.block1}></View>
+              <View className={style.block2}></View>
+              <View className={style.block3}></View>
+            </View>
+          </View>
+          <View className="flex-center gap-8 text-14 font-medium leading-22 text-black" onClick={() => setEnabledChatBg((prev) => !prev)}>
+            <WemetaRadio checked={enabledChatBg} checkbox></WemetaRadio>
+            启用聊天背景
+          </View>
+        </View>
+
+        <View className="bottom-bar">
+          <View className="grid grid-cols-2 gap-8 px-20 py-12">
+            <View className={`button-rounded`} onClick={handleChange}>更换形象</View>
+            <WemetaButton className="flex-1" onClick={handleConfirm}>确定</WemetaButton>
+          </View>
+        </View>
+      </View>
+    </View>
+  );
+}

+ 12 - 4
src/components/TextPolish/index.tsx

@@ -2,7 +2,7 @@ import { View } from "@tarojs/components";
 import IconStarColor from "@/components/icon/IconStarColor";
 import { textPolishing } from '@/service/agent'
 import { isSuccess } from "@/utils";
-import { useState } from "react";
+import { useState, forwardRef, useImperativeHandle } from "react";
 import Taro from '@tarojs/taro';
 interface Props {
   text: string;
@@ -15,13 +15,14 @@ const Index = ({
   type,
   onPolished,
   onStateChange,
-}: Props) => {
+}: Props, ref: any) => {
   const [isLoading, setIsLoading] = useState(false)
   const disabled =  text.length < 2
+
   const handleClick = async () => {
     // console.log('请求服务端润色')
     if(isLoading || disabled){
-      return
+      return Promise.resolve();
     }
     setIsLoading(true)
     onStateChange(true)
@@ -37,17 +38,24 @@ const Index = ({
       if(isSuccess(response.status)){
         onPolished(response.data?.content)
       }
+      return Promise.resolve();
     }catch(e){
       Taro.hideLoading()
       setIsLoading(false)
       onStateChange(false)
+      return Promise.resolve();
     }
   }
 
+  // Expose the handleClick method to parent components
+  useImperativeHandle(ref, () => ({
+    handleClick
+  }));
+
   return (
     <View className={`flex items-center gap-4 ${disabled ? 'opacity-20' : ''}`} onClick={handleClick}>
       {!isLoading ? <View className="text-primary flex flex-center"><IconStarColor color="blue"></IconStarColor><View>润色</View></View> : <View className="flex flex-center"><IconStarColor color="colorful"></IconStarColor><View className="gradient-text">润色中...</View></View>}
     </View>
   );
 };
-export default Index;
+export default forwardRef(Index);

+ 11 - 5
src/components/WemetaRadio/index.module.less

@@ -5,10 +5,14 @@
   width: 16px;
   height: 16px;
   overflow: hidden;
-  border: 1px solid rgba(#000, .45);
+  border: 1px solid #A4A4A4;
   border-radius: 100%;
   transition: all .3s;
 }
+.lightRadio{
+  border: 1px solid white;
+  box-shadow: -1px 1px 4px 1px rgba(0,0,0, .04);
+}
 .inner{
   opacity: 1;
   width: 6px;
@@ -35,11 +39,13 @@
   width: 16px;
   height: 16px;
 }
-.checkboxIcon{
+.checkboxIconChecked{
   width: 10px;
   height: 7px;
 }
+.checkboxIcon{
+  display: none;
+}
 .innerDisabledCheckBox{
- .innerCheckbox(); 
-//  background-color: #EDEDED;
-}
+ .innerCheckbox();
+}

+ 7 - 6
src/components/WemetaRadio/index.tsx

@@ -3,25 +3,26 @@ import style from './index.module.less'
 import IconChecked from '@/images/checked.png'
 
 interface Props {
-  checked?: boolean 
+  checked?: boolean
   disabled?: boolean
   checkbox?: boolean
+  theme?: 'dark' | 'light'
 }
-const index = ({ checked = false, disabled, checkbox=false }: Props) => {
+const index = ({ checked = false, disabled, checkbox=false, theme ='dark' }: Props) => {
   if(checkbox){
     return (
-      <View className={`${style.radio} ${checked ? style.checked :''} ${disabled ? style.innerDisabled : ''}`}>
+      <View className={`${style.radio} ${theme === 'light' ? style.lightRadio:''} ${checked ? style.checked :''} ${disabled ? style.innerDisabled : ''}`}>
         <View className={`${disabled ? style.innerDisabledCheckBox : style.innerCheckbox}`}>
-          <Image src={IconChecked} className={style.checkboxIcon}></Image>
+          <Image src={IconChecked} className={checked ? style.checkboxIconChecked : style.checkboxIcon}></Image>
         </View>
     </View>
     )
   }
   return (
-    <View className={`${style.radio} ${checked ? style.checked :''} ${disabled ? style.innerDisabled : ''}`}>
+    <View className={`${style.radio} ${theme === 'light'?style.lightRadio : ''} ${checked ? style.checked :''} ${disabled ? style.innerDisabled : ''}`}>
       <View className={`${disabled ? style.innerDisabled : style.inner}`}>
       </View>
     </View>
   )
 }
-export default index
+export default index

+ 21 - 5
src/components/WemetaTextareaAI/index.tsx

@@ -1,10 +1,11 @@
 import { View, Textarea, InputProps } from "@tarojs/components";
 import TextPolish from '@/components/TextPolish'
 import style from "./index.module.less";
-import { useState, useRef, useCallback, useMemo } from "react";
+import { useState, useRef, useCallback, useMemo, forwardRef, useImperativeHandle } from "react";
 import { countCharacters, getStrByMaxLength } from "@/utils/index";
 interface Props {
   aiType: "personality" | "greeting"
+  defaultAiTips: string;
   placeholder?: string;
   value: string;
   cursorSpacing?: number;
@@ -23,9 +24,10 @@ interface Props {
   onConfirm?: (value: string) => void;
 }
 const DEFAULT_TEXTAREA_MAXLENGTH = 10000;
-const index = ({
+const Index = ({
   value,
   aiType,
+  defaultAiTips,
   bgColor,
   extraClass,
   extraStyle,
@@ -41,11 +43,23 @@ const index = ({
   maxlength,
   extra,
   onConfirm,
-}: Props) => {
+}: Props, ref: any) => {
   const [focus, setFocus] = useState(false);
   const [isPolishing, setIsPolishing] = useState(false);
   const inputRef = useRef<HTMLInputElement>(null); // 创建一个 ref
 
+  // Create ref for TextPolish component
+  const textPolishRef = useRef<{ handleClick: () => void }>(null);
+
+  // Expose TextPolish ref to parent components
+  useImperativeHandle(ref, () => ({
+    handleClick: async () => {
+      if (textPolishRef.current) {
+        return await textPolishRef.current.handleClick();
+      }
+    }
+  }));
+
   // Memoize character count to avoid recalculation
   const currentLength = useMemo(() => countCharacters(value), [value]);
 
@@ -93,6 +107,8 @@ const index = ({
     return bgColor ? { backgroundColor: bgColor } : {};
   }, [bgColor]);
 
+  const polishText = value?.length > 0 ? value : defaultAiTips;
+
   return (
     <View
       className={`${
@@ -105,7 +121,7 @@ const index = ({
           {prefix && prefix()}
         </View>
       <View className="flex items-center gap-4 text-14 font-pingfangSCMedium">
-        <TextPolish text={value} type={aiType} onPolished={onPolished} onStateChange={setIsPolishing} />
+        <TextPolish ref={textPolishRef} text={polishText} type={aiType} onPolished={onPolished} onStateChange={setIsPolishing} />
       </View>
       </View>
 
@@ -144,4 +160,4 @@ const index = ({
     </View>
   );
 };
-export default index;
+export default forwardRef(Index);

+ 0 - 20
src/components/buttons/ButtonMain.tsx

@@ -1,20 +0,0 @@
-import { View } from "@tarojs/components";
-
-interface IProps {
-  onClick?: ()=> void
-  disabled?: boolean
-  className?: string
-  type?: 'main'|'normal'
-  children: JSX.Element|JSX.Element[]|string
-}
-export default function ButtonMain({ onClick, type = 'main', disabled = false, className='', children }:IProps) {
-  const typeClass = type === 'main'? 'button-primary' : ''
-  const handleClick = ()=> {
-    if(!disabled){
-      onClick && onClick()
-    }
-  }
-  return (
-    <View className={`button-rounded ${typeClass} ${disabled ? 'opacity-50': ''} ${className}`} onClick={handleClick}>{children}</View>
-  );
-}

+ 28 - 0
src/components/buttons/WemetaButton.tsx

@@ -0,0 +1,28 @@
+import { View } from "@tarojs/components";
+
+interface IProps {
+  onClick?: ()=> void
+  disabled?: boolean
+  className?: string
+  type?: 'primary'|'normal'|'danger'
+  children: JSX.Element|JSX.Element[]|string
+}
+export default function WemetaButton({ onClick, type = 'primary', disabled = false, className='', children }:IProps) {
+  let typeClass = ''
+  if(type ==='danger'){
+    typeClass = 'bg-white text-red'
+  }else if(type ==='primary'){
+    typeClass = 'bg-primary text-white'
+  }else{
+    typeClass = 'bg-white'
+  }
+
+  const handleClick = ()=> {
+    if(!disabled){
+      onClick && onClick()
+    }
+  }
+  return (
+    <View className={`p-14 leading-20 flex font-normal rounded-8 items-center justify-center  ${typeClass} ${disabled ? 'opacity-50': ''} ${className}`} onClick={handleClick}>{children}</View>
+  );
+}

+ 7 - 0
src/components/icon/IconPlayWhite20/index.tsx

@@ -0,0 +1,7 @@
+import { Image } from '@tarojs/components'
+import Icon from '@/images/svgs/icon-play-white-20.svg'
+export default () => {
+  return (
+    <Image src={Icon} mode="widthFix" style={{width: '20px', height: '20px'}}></Image>
+  )
+}

+ 11 - 0
src/images/svgs/icon-play-white-20.svg

@@ -0,0 +1,11 @@
+<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 20 20" class="design-iconfont">
+  <defs>
+    <path id="dxqyqi4o4__00kdp6a09a" d="M0 0H20V20H0z"/>
+  </defs>
+  <g fill="none" fill-rule="evenodd" opacity=".99">
+    <mask id="dxqyqi4o4__g1gmpetugb" fill="#fff">
+      <use xlink:href="#dxqyqi4o4__00kdp6a09a"/>
+    </mask>
+    <path d="M10.8660254,3.5 L16.0621778,12.5 C16.3383202,12.9782926 16.174445,13.589883 15.6961524,13.8660254 C15.5441332,13.9537937 15.3716891,14 15.1961524,14 L4.80384758,14 C4.25156283,14 3.80384758,13.5522847 3.80384758,13 C3.80384758,12.8244633 3.85005384,12.6520192 3.93782217,12.5 L9.1339746,3.5 C9.41011697,3.02170738 10.0217074,2.85783222 10.5,3.1339746 C10.6520192,3.22174293 10.7782571,3.34798079 10.8660254,3.5 Z" fill="#FFF" fill-rule="nonzero" mask="url(#dxqyqi4o4__g1gmpetugb)" transform="rotate(90 10 10)"/>
+  </g>
+</svg>

+ 1 - 1
src/pages/editor-pages/editor-personality/index.config.ts → src/pages/agent-avatar-confirm/index.config.ts

@@ -1,5 +1,5 @@
 export default definePageConfig({
-  navigationBarTitleText: '人设',
+  navigationBarTitleText: '开场提问引导',
   "usingComponents": {},
   navigationStyle: 'custom'
 })

+ 0 - 0
src/pages/editor-pages/editor-personality/index.module.less → src/pages/agent-avatar-confirm/index.module.less


+ 39 - 0
src/pages/agent-avatar-confirm/index.tsx

@@ -0,0 +1,39 @@
+import { useEffect, useRef, useState } from "react";
+import { Image, View, ScrollView, Video } from "@tarojs/components";
+import { formatSeconds } from "@/utils/index";
+import PageCustom from "@/components/page-custom/index";
+import NavBarNormal from "@/components/NavBarNormal/index";
+import AvatarConfirm from '@/components/AvatarConfirm/index'
+import WemetaButton from '@/components/buttons/WemetaButton'
+import Taro from "@tarojs/taro";
+import style from "./index.module.less";
+
+import { isSuccess } from "@/utils";
+import { TAvatarItem } from "@/service/storage";
+import { useAgentStore } from "@/store/agentStore";
+interface IProps {
+  avatarItem: TAvatarItem
+}
+
+export default function Index({avatarItem}: IProps) {
+
+  const currentEditAvatar = useAgentStore( state => state.currentEditAvatar)
+  const [enabledChatBg, setEnabledChatBg] = useState(true)
+
+  const handleConfirm = async () => {
+    console.log('confirm')
+  }
+  const handleChange = ()=> {
+
+  }
+
+
+  return (
+    <PageCustom>
+      <NavBarNormal>形象确认</NavBarNormal>
+      <>
+        {!!currentEditAvatar && <AvatarConfirm avatarItem={currentEditAvatar} />}
+      </>
+    </PageCustom>
+  );
+}

+ 57 - 0
src/pages/agent-avatar-confirm/useAvatars.ts

@@ -0,0 +1,57 @@
+import { fetchMyAvatars, TAvatarItem } from "@/service/storage";
+import { isSuccess } from "@/utils";
+import { useState, useCallback } from "react";
+
+export const useAvatars = (initPageSize: number = 20) => {
+  const [avatars, setAvatars] = useState<TAvatarItem[]>([]);
+  const [pageIndex, setPageIndex] = useState(1);
+  const [pageSize] = useState(initPageSize);
+  const [totalCount, setTotalCount] = useState(0);
+  const [isLoading, setIsLoading] = useState(false);
+  const [hasMore, setHasMore] = useState(true);
+
+  const loadAvatars = useCallback(async (reset: boolean = false) => {
+    if (isLoading) return;
+    setIsLoading(true);
+    const currentPage = reset ? 1 : pageIndex;
+    try {
+      const response = await fetchMyAvatars({ pageSize, pageIndex: currentPage });
+      if (isSuccess(response.status)) {
+        const { data, totalCount: total } = response.data;
+        setTotalCount(total);
+        if (reset) {
+          setAvatars(data);
+        } else {
+          setAvatars(prev => [...prev, ...data]);
+        }
+        setHasMore((currentPage * pageSize) < total);
+        setPageIndex(currentPage + 1);
+      }
+    } finally {
+      setIsLoading(false);
+    }
+  }, [isLoading, pageIndex, pageSize]);
+
+  const resetAvatars = useCallback(() => {
+    setAvatars([]);
+    setPageIndex(1);
+    setTotalCount(0);
+    setHasMore(true);
+  }, []);
+
+  // 首次加载
+  const initLoad = useCallback(async () => {
+    resetAvatars();
+    await loadAvatars(true);
+  }, [resetAvatars, loadAvatars]);
+
+  return {
+    avatars,
+    isLoading,
+    hasMore,
+    totalCount,
+    loadAvatars,
+    resetAvatars,
+    initLoad,
+  };
+};

+ 39 - 14
src/pages/agent-avatars/index.module.less

@@ -17,11 +17,36 @@
   overflow: hidden;
   background-color: white;
 }
+.mark{
+  position: absolute;
+  left: 0;
+  top: 0;
+  z-index: 1;
+  width: 44px;
+  height: 44px;
+  background-size: cover;
+}
+// 当前背景
+.gridItemCurrentUsedMark {
+  .mark();
+  background-image: url(https://cdn.wehome.cn/cmn/png/43/META-H8UKXHWU-X0WXBKY1C0G0QA1DIH762-VWDBZUFM-P81.png);
+
+}
+// 已启用
+.gridItemActivedMark {
+  .mark();
+  background-image: url(https://cdn.wehome.cn/cmn/png/184/META-H8UKWHWU-Q0WXNNJLF5IO3DRNO8GK3-VWDBZUFM-691.png);
+}
 .gridItemActived {
   .gridItem();
   background-color: var(--color-primary);
   border: 2px solid var(--color-primary);
 }
+.gridItemCreateBtn{
+  .gridItem();
+  background-image: url(https://cdn.wehome.cn/cmn/png/117/META-H8UKXHWU-X0WXBKY1C0G0QA1DIH762-HABOZOFM-A41.png);
+  background-size: cover;
+}
 
 .icon{
   display: flex;
@@ -41,7 +66,7 @@
 .deleted{
   display: none;
 }
-.deleteButton{
+.selected{
   position: absolute;
   top: 0;
   right: 0;
@@ -51,8 +76,6 @@
   justify-content: center;
   width: 28px;
   height: 28px;
-  background-color: rgba(#FFF, .6);
-  border-bottom-left-radius: 12px;
 }
 
 .videoContainer {
@@ -65,25 +88,27 @@
 }
 
 .playBtn{
-  width: 11px;
-  height: 11px;
-  background: url(https://cdn.wehome.cn/cmn/png/0/META-H8UK0IWU-9NNPJOLLD1MU95DE0NMA3-J2FYMV2M-T41.png) no-repeat;
-  background-size: 100%;
+  width: 20px;
+  height: 20px;
 }
 .durationStatus{
   display: flex;
   align-items: center;
-  padding: 0 8px;
+  justify-content: center;
   gap: 2px;
   position: absolute;
-  right: 8px;
-  bottom: 8px;
-  z-index: 1;
+  right: 0;
+  left: 0;
+  bottom: 0;
+  width: 100%;
+  z-index: 2;
   border-radius: 30px;
   font-size: 10px;
-  line-height: 18px;
+  line-height: 36px;
+  height:36px;
   color: white;
-  background-color: rgba(black, .45);
+  background-color: var(--color-gray-4);
+  backdrop-filter: blur(2px);
 }
 
 .aiTips{
@@ -97,4 +122,4 @@
   color: rgba(#fff, .5);
   line-height: 8px;
   text-shadow: 1px 1px 0 rgba(#000, .3);
-}
+}

+ 61 - 36
src/pages/agent-avatars/index.tsx

@@ -6,6 +6,7 @@ import NavBarNormal from "@/components/NavBarNormal/index";
 
 import { uploadAndNavToGenNewAvatar } from "@/utils/avatar";
 import IconPlusBig from "@/components/icon/icon-plus-big";
+import IconPlayWhite24 from '@/components/icon/IconPlayWhite20'
 
 import { deleteAvatar, fetchMyAvatars } from "@/service/storage";
 
@@ -15,14 +16,16 @@ import { useAgentStore, useAgentStoreActions } from "@/store/agentStore";
 
 import Taro, { useDidShow } from "@tarojs/taro";
 import { isSuccess } from "@/utils";
-import IconDeleteGray16 from "@/components/icon/IconDeleteGray16";
+import WemetaRadio from "@/components/WemetaRadio/index";
 import { useModalStore } from "@/store/modalStore";
 import { useLoadMoreInfinite, createKey } from "@/utils/loadMoreInfinite";
+import BottomBar from "@/components/BottomBar";
+import WemetaButton from "@/components/buttons/WemetaButton";
 
 export default function Index() {
   const agent = useAgentStore((state) => state.agent);
 
-  const { fetchAgent, saveAgent } = useAgentStoreActions();
+  const {setCurrentEditAvatar} =  useAgentStoreActions()
   const [scrollTop, setScrollTop] = useState(0);
   const scrollPositionRef = useRef(0);
 
@@ -41,22 +44,20 @@ export default function Index() {
   const [current, setCurrent] = useState<TAvatarItem | null>(null);
 
   // 选择形象
-  const handleClick = async (item: TAvatarItem) => {
+  const handleSelect = async (e:any, item: TAvatarItem) => {
+    e.stopPropagation()
     console.log(item);
-    if (!agent?.agentId) {
-      return;
+    if(current?.avatarId === item.avatarId){
+      setCurrent(null)
+    }else{
+      setCurrent(item);
     }
 
-    Taro.showLoading();
-    console.log(agent, 111111)
-    // const result = await saveAgent(agent.agentId, item.avatarId, true);
-    // await fetchAgent(agent.agentId);
-    // Taro.hideLoading();
-    // setCurrent(item);
-    // if (isSuccess(result.status)) {
-    //   Taro.navigateBack();
-    // }
   };
+  const handleSetBackground = () => {
+    current && setCurrentEditAvatar(current)
+    Taro.navigateTo({ url: '/pages/agent-avatar-confirm/index' });
+  }
   const onScrollToLower = () => {
     loadMore();
     console.log("lower");
@@ -65,12 +66,15 @@ export default function Index() {
     uploadAndNavToGenNewAvatar();
   };
 
-  const handleDelete = async (e: any, avatar: TAvatarItem) => {
+  const handleDelete = async (e: any) => {
     e.stopPropagation();
+    if(!current || !current.canDel){
+        return
+      }
     showModal({
       content: <>确认删除该形象?</>,
       async onConfirm() {
-        const response = await deleteAvatar(avatar.avatarId);
+        const response = await deleteAvatar(current.avatarId);
         if (isSuccess(response.status)) {
           mutate();
         }
@@ -78,14 +82,28 @@ export default function Index() {
     });
   };
 
+  const handlePreview = (index: number)=> {
+
+    Taro.previewMedia({
+      current: index,
+      //@ts-ignore
+      sources: list.map((item) => {
+        return {
+          url: item.avatarUrl,
+          type: item.isVideo ? 'video' : 'image',
+        }
+      }),
+    })
+  }
+
   useDidShow(() => {
     mutate()
   })
 
-  const renderMedia = (avatar: TAvatarItem) => {
+  const renderMedia = (avatar: TAvatarItem, index: number) => {
     if (avatar.isVideo) {
       return <>
-        <View className={style.videoContainer}>
+        <View className={style.videoContainer} onClick={() => handlePreview(index)}>
           <Video
             controls={false}
             showCenterPlayBtn={false}
@@ -95,14 +113,15 @@ export default function Index() {
             src={avatar.avatarUrl}
             className="w-full h-full"
           />
+          <View className={style.blurBg}></View>
           <View className={style.durationStatus}>
-            <View className={style.playBtn}></View>
-            <View>{formatSeconds(Math.round(avatar.videoSeconds))}</View>
+            <IconPlayWhite24 />
+            <View className="text-10">{formatSeconds(Math.round(avatar.videoSeconds))}</View>
           </View>
         </View>
       </>
     }
-    return <Image src={`${avatar.avatarUrl}?x-oss-process=image/quality,Q_60/format,jpg`} mode="widthFix" className="w-full" />;
+    return <Image src={`${avatar.avatarUrl}?x-oss-process=image/quality,Q_60/format,jpg`} mode="widthFix" className="w-full" onClick={() => handlePreview(index)} />;
   };
 
   const renderList = () => {
@@ -114,25 +133,24 @@ export default function Index() {
       );
     }
 
-    return list.map((avatar) => {
-      const isCurrent = agent?.avatarUrl === avatar.avatarUrl;
+    return list.map((avatar, index) => {
+      const currentUsed = agent?.avatarUrl === avatar.avatarUrl;
+      const isCurrentSelected = current?.avatarId === avatar.avatarId;
       return (
         <View
-          className={`${isCurrent ? style.gridItemActived : style.gridItem}`}
-          onClick={() => handleClick(avatar)}
+          className={`${currentUsed ? style.gridItemActived : style.gridItem}`}
         >
-          {avatar.canDel && (
-            <View
-              className={style.deleteButton}
-              onClick={(e) => handleDelete(e, avatar)}
-            >
-              <IconDeleteGray16 />
-            </View>
-          )}
 
+          <View
+              className={style.selected}
+              onClick={(e) => handleSelect(e, avatar)}
+            >
+            <WemetaRadio theme="light" checkbox checked={isCurrentSelected} />
+          </View>
+          {currentUsed && <View className={style.gridItemActivedMark}></View>}
+          {/* <View className={style.gridItemCurrentUsedMark}></View> */}
           {!avatar.isOriginal && <View className={style.aiTips}>图片由AI生成</View> }
-
-          {renderMedia(avatar)}
+          {renderMedia(avatar, index)}
         </View>
       );
     });
@@ -156,7 +174,7 @@ export default function Index() {
         >
           <View className="w-full p-16 pb-120">
             <View className={style.grid}>
-              <View className={style.gridItem} onClick={handleCreate}>
+              <View className={style.gridItemCreateBtn} onClick={handleCreate}>
                 <View className={style.icon}>
                   <IconPlusBig></IconPlusBig>
                 </View>
@@ -168,6 +186,13 @@ export default function Index() {
             </View>
           </View>
         </ScrollView>
+        <BottomBar className="pt-12 px-16">
+
+            <WemetaButton type='danger' className="w-88 text-red" disabled={!current?.canDel} onClick={handleDelete}>删除</WemetaButton>
+            <WemetaButton type='normal' className="w-102" disabled={!current}>下载</WemetaButton>
+            <WemetaButton type="primary" className="flex-1" disabled={!current} onClick={handleSetBackground}>设置为聊天背景</WemetaButton>
+
+        </BottomBar>
       </View>
     </PageCustom>
   );

+ 8 - 8
src/pages/agent-gen/components/step/StepConfirm.tsx

@@ -3,10 +3,10 @@ import React, { useState } from "react";
 import style from "./index.module.less";
 import WemetaRadio from '@/components/WemetaRadio'
 import { AvatarMedia } from "@/components/AvatarMedia";
-import ButtonMain from '@/components/buttons/ButtonMain'
+import WemetaButton from '@/components/buttons/WemetaButton'
 import Taro from "@tarojs/taro";
 import { TAvatarItem } from "@/service/storage";
-import { editAgentAvatar } from "@/service/agent";
+// import { editAgentAvatar } from "@/service/agent";
 import { useAgentStore, useAgentStoreActions } from "@/store/agentStore";
 interface IProps {
   prev: ()=>void
@@ -21,11 +21,11 @@ export default React.memo(function Index({prev, pickedAvatar}:IProps) {
     if(!agent?.agentId){
       return
     }
-    await editAgentAvatar(
-      agent.agentId,
-      pickedAvatar.avatarId,
-      enabledChatBg,
-    );
+    // await editAgentAvatar(
+    //   agent.agentId,
+    //   pickedAvatar.avatarId,
+    //   enabledChatBg,
+    // );
     await fetchAgent(agent.agentId)
 
     Taro.redirectTo({url: '/pages/agent/index'})
@@ -65,7 +65,7 @@ export default React.memo(function Index({prev, pickedAvatar}:IProps) {
       <View className="bottom-bar">
         <View className="grid grid-cols-2 gap-8 px-20 py-12">
           <View className={`button-rounded`} onClick={prev}>更换形象</View>
-          <ButtonMain className="flex-1" onClick={handleConfirm}>确定</ButtonMain>
+          <WemetaButton className="flex-1" onClick={handleConfirm}>确定</WemetaButton>
         </View>
       </View>
     </View>

+ 4 - 4
src/pages/agent-gen/components/step/StepPick.tsx

@@ -7,7 +7,7 @@ import { getUploadedAvatarStatus, genAvatarVideo, type TAvatarItem } from '@/ser
 import useSWR from 'swr';
 import Taro from "@tarojs/taro";
 import { isSuccess } from "@/utils";
-import ButtonMain from '@/components/buttons/ButtonMain'
+import WemetaButton from '@/components/buttons/WemetaButton'
 interface IProps {
   prev: () => void;
   next: () => void;
@@ -216,9 +216,9 @@ export default React.memo(function Index({ prev, next, taskId, avatars, videos,
 
       <View className="bottom-bar">
         <View className="flex items-center gap-8 px-20 py-12">
-          <ButtonMain type="normal" disabled={videoGenerating && !videos.length}  className="w-[76px]" onClick={handlePrev}>上一步</ButtonMain>
-          {!videoGenerating &&  <ButtonMain className="flex-1" type="normal" onClick={genVideo} disabled={!avatars.length} >生成微视频</ButtonMain> }
-          <ButtonMain className="flex-1" onClick={goNext} disabled={(!avatars.length && !videoGenerating) || (videoGenerating && !videos.length )} >使用这张</ButtonMain>
+          <WemetaButton type="normal" disabled={videoGenerating && !videos.length}  className="w-[76px]" onClick={handlePrev}>上一步</WemetaButton>
+          {!videoGenerating &&  <WemetaButton className="flex-1" type="normal" onClick={genVideo} disabled={!avatars.length} >生成微视频</WemetaButton> }
+          <WemetaButton className="flex-1" onClick={goNext} disabled={(!avatars.length && !videoGenerating) || (videoGenerating && !videos.length )} >使用这张</WemetaButton>
         </View>
       </View>
     </View>

+ 20 - 10
src/pages/agent/components/AgentSetting/components/AgentCard/index.module.less

@@ -1,18 +1,27 @@
 .container{
   padding: 20px 100px 20px;
 }
-.card{
+
+.cardContainer{
   display: flex;
   align-items: center;
   justify-content: center;
   width: 140px;
   height: 256px;
   overflow: hidden;
-  border-radius: 16px;
+  border-radius: 12px;
+  background-color: white;
+}
+.card{
+  width: 140px;
+  height: 256px;
+  overflow: hidden;
+  border-radius: 12px;
   background-color: white;
   background-image: url(https://cdn.wehome.cn/cmn/png/117/META-H8UKXHWU-X0WXBKY1C0G0QA1DIH762-HABOZOFM-A41.png);
   background-size: cover;
 }
+
 .tips{
   display: flex;
   flex-direction: column;
@@ -53,8 +62,9 @@
   height: 40px;
   font-weight: 500;
   font-size: 12px;
-  color: rgba(#000, .85);
-  background-color: rgba(#FFF, .7);
+  line-height: 22px;
+  color: white;
+  background-color: rgba(#111, .45);
   backdrop-filter: blur(7px) brightness(0.94) contrast(146%) grayscale(3%) opacity(81%);
 }
 
@@ -68,10 +78,10 @@
   bottom: 0;
   right: 0;
   z-index: 1;
-  width: 200px;
-  min-height: 373px;
+  width: 140px;
+  min-height: 200px;
   box-sizing: border-box;
-  padding: 0 24px 54px;
+  padding: 0 8px 54px;
   gap: 8px;
   background: linear-gradient(180deg, rgba(255, 255, 255, 0) 50.12%, #D6D6D6 100%);
 }
@@ -82,15 +92,15 @@
 }
 .block1{
   .block();
-  width: 114px;
+  width: 80px;
 }
 .block2{
   .block();
   align-self: flex-end;
-  width: 102px;
+  width: 80px;
   background-color: rgba(#317CFA, .5);
 }
 .block3{
   .block();
-  width: 160px;
+  width: 125px;
 }

+ 12 - 12
src/pages/agent/components/AgentSetting/components/AgentCard/index.tsx

@@ -11,20 +11,20 @@ import { fetchMyAvatars } from "@/service/storage";
 import { AvatarMedia } from "@/components/AvatarMedia";
 
 export default () => {
-  const agent = useAgentStore((state) => state.agent);
+  const agentEdit = useAgentStore((state) => state.agentEdit);
   const { fetchAgent } = useAgentStoreActions();
 
   const handleChange = async (isChecked: boolean) => {
-    if (!agent?.agentId || !agent.avatarUrl) {
+    if (!agentEdit?.agentId || !agentEdit.avatarUrl) {
       return;
     }
-    const response = await editAgentChatBg(agent.agentId, isChecked);
+    const response = await editAgentChatBg(agentEdit.agentId, isChecked);
     if (isSuccess(response.status)) {
       Taro.showToast({
         title: isChecked ? "启用成功" : "取消启用",
         icon: "success",
       });
-      fetchAgent(agent.agentId); // 刷新智能体信息
+      fetchAgent(agentEdit.agentId); // 刷新智能体信息
     }
   };
   const handleClick = async () => {
@@ -35,7 +35,7 @@ export default () => {
         return;
       }
     }
-    if (agent?.avatarUrl) {
+    if (agentEdit?.avatarUrl) {
       return;
     }
     uploadAndNavToGenNewAvatar();
@@ -48,7 +48,7 @@ export default () => {
 
   const renderContent = () => {
 
-    if (!agent?.avatarUrl) {
+    if (!agentEdit?.avatarUrl) {
       return (
         <View className={style.tips}>
           <View className={style.icon}>
@@ -61,8 +61,8 @@ export default () => {
 
     return (
       <View className="relative overflow-hidden w-full h-full">
-        <AvatarMedia source={agent.avatarUrl} className={style.card} />
-        {agent?.enabledChatBg &&  <View className={style.confirmChatAvatarBgCover}>
+        <AvatarMedia source={agentEdit.avatarUrl} className={style.card} />
+        {agentEdit?.enabledChatBg &&  <View className={style.confirmChatAvatarBgCover}>
           <View className={style.block1}></View>
           <View className={style.block2}></View>
           <View className={style.block3}></View>
@@ -75,12 +75,12 @@ export default () => {
   };
 
   const renderFooter = ()=> {
-    if(agent?.avatarUrl){
+    if(agentEdit?.avatarUrl){
       return <View
         className="w-full flex-center pt-16 gap-6"
-        onClick={() => handleChange(!!!agent?.enabledChatBg)}
+        onClick={() => handleChange(!!!agentEdit?.enabledChatBg)}
       >
-        <WemetaRadio checkbox checked={agent?.enabledChatBg}></WemetaRadio>
+        <WemetaRadio checkbox checked={agentEdit?.enabledChatBg}></WemetaRadio>
         <View className="font-medium text-14 text-black">启用聊天背景</View>
       </View>
     }
@@ -89,7 +89,7 @@ export default () => {
 
   return (
     <View className={style.container}>
-      <View className={style.card} onClick={handleClick}>
+      <View className={style.cardContainer} onClick={handleClick}>
         {renderContent()}
       </View>
 

+ 12 - 6
src/pages/agent/components/AgentSetting/components/AgentContactCard/index.tsx

@@ -4,13 +4,17 @@ import IconPlusBlue from "@/components/icon/icon-plus-blue"
 import { useAgentStore, useAgentStoreActions } from "@/store/agentStore";
 // import ContactIcon from '@/components/ContactIcon'
 export default () => {
-  const agentTemp = useAgentStore((state)=> state.agentTemp);
-  const { updateAgentTemp } = useAgentStoreActions();
+  const agentEdit = useAgentStore((state)=> state.agentEdit);
+  const { updateEditAgent } = useAgentStoreActions();
 
   // 处理表单字段更新
   const handleFieldChange = (field: string, value: string) => {
+    // 如果是手机号字段,只允许数字且限制11位
+    if (field === 'mobile') {
+      value = value.replace(/\D/g, '').slice(0, 11);
+    }
     console.log(field, value)
-    updateAgentTemp({ [field]: value });
+    updateEditAgent({ [field]: value });
   };
 
   const handleEdit = ()=> {
@@ -27,7 +31,7 @@ export default () => {
           <View className={style.value}>
             <Input
               className="py-16"
-              value={agentTemp?.name || ''}
+              value={agentEdit?.name || ''}
               onBlur={(e: any) => handleFieldChange('name', e.detail.value)}
               onInput={(e: any) => handleFieldChange('name', e.detail.value)}
               placeholderStyle="color: rgba(17,17,17,.25)"
@@ -41,7 +45,7 @@ export default () => {
           <View className={style.value}>
             <Input
               className="py-16"
-              value={agentTemp?.entName || ''}
+              value={agentEdit?.entName || ''}
               onBlur={(e: any) => handleFieldChange('entName', e.detail.value)}
               onInput={(e: any) => handleFieldChange('entName', e.detail.value)}
               placeholderStyle="color: rgba(17,17,17,.25)"
@@ -54,11 +58,13 @@ export default () => {
           <View className={style.value}>
             <Input
               className="py-16"
-              value={agentTemp?.mobile || ''}
+              type="number"
+              value={agentEdit?.mobile || ''}
               onBlur={(e: any) => handleFieldChange('mobile', e.detail.value)}
               onInput={(e: any) => handleFieldChange('mobile', e.detail.value)}
               placeholderStyle="color: rgba(17,17,17,.25)"
               placeholder="输入手机号"
+              maxlength={11}
             />
           </View>
         </View>

+ 6 - 6
src/pages/agent/components/AgentSetting/components/AgentKnowledgeLib/index.tsx

@@ -10,24 +10,24 @@ import Taro from "@tarojs/taro";
 import { useAgentStore, useAgentStoreActions } from "@/store/agentStore";
 
 export default function Index() {
-  const agent = useAgentStore((state) => state.agent);
+  const agentEdit = useAgentStore((state) => state.agentEdit);
   const agentCharacter = useAgentStore((state) => state.agentCharacter);
   const { editAgentCharacter, fetchAgent } = useAgentStoreActions();
   const handleSwitchChange = async (checked: boolean) => {
-    if (!agent?.agentId || !agentCharacter) {
+    if (!agentEdit?.agentId || !agentCharacter) {
       return;
     }
 
-    await editAgentCharacter(agent.agentId, {
+    await editAgentCharacter(agentEdit.agentId, {
       ...agentCharacter,
       enabledPersonalKb: checked,
     });
-    fetchAgent(agent.agentId);
+    fetchAgent(agentEdit.agentId);
   };
 
 
 
-  if (!agent || !agent.isEnt) {
+  if (!agentEdit || !agentEdit.isEnt) {
     return <></>;
   }
 
@@ -53,7 +53,7 @@ export default function Index() {
 
             <View className="flex-center">
               <WemetaSwitch
-                checked={agent.enabledPersonalKb ?? true}
+                checked={agentEdit.enabledPersonalKb ?? true}
                 onChange={(checked) => handleSwitchChange(checked)}
               ></WemetaSwitch>
             </View>

+ 50 - 22
src/pages/agent/components/AgentSetting/components/AgentSettingList/index.tsx

@@ -1,5 +1,4 @@
-
-import { View } from "@tarojs/components";
+import { View, Text } from "@tarojs/components";
 
 import IconVoiceColor from "@/components/icon/icon-voice-color";
 import CardList from "@/components/list/card-list";
@@ -11,39 +10,52 @@ import WemetaTextareaAI from '@/components/WemetaTextareaAI'
 import IconArrow from "@/components/icon/icon-arrow";
 import Taro from "@tarojs/taro";
 import { useVoiceStore } from "@/store/voiceStore";
-import { useAgentStore } from "@/store/agentStore";
+import { useAgentStore, useAgentStoreActions } from "@/store/agentStore";
+import { forwardRef, useImperativeHandle, useRef } from "react";
+
+export default forwardRef(function Index(props, ref) {
 
-export default function Index() {
+  const agentEdit = useAgentStore((state) => state.agentEdit)
+  const { updateEditAgent } = useAgentStoreActions()
 
-  const agent = useAgentStore((state) => state.agent)
-  const agentTemp = useAgentStore((state)=> state.agentTemp)
+  // Create refs for the TextPolish components
+  const personalityPolishRef = useRef<{ handleClick: () => void }>(null);
+  const greetingPolishRef = useRef<{ handleClick: () => void }>(null);
 
-  // 判断是编辑模式还是新建模式
-  const isEditMode = !!agent?.agentId
+  // Expose methods to parent components
+  useImperativeHandle(ref, () => ({
+    polishAllTexts: async () => {
+      // Call both polish functions if they exist
+      if (personalityPolishRef.current) {
+        if(!agentEdit?.personality){
+          await personalityPolishRef.current.handleClick();
+        }
+
+      }
+      if (greetingPolishRef.current) {
+        if(!agentEdit?.greeting){
+          await greetingPolishRef.current.handleClick();
+        }
+      }
+    }
+  }));
 
   // 根据模式获取显示值
   const getDisplayValue = (field: string) => {
-    if (isEditMode) {
-      // 编辑模式:优先显示agentTemp中的值,如果没有则显示agent中的值
-      return agentTemp[field] !== undefined ? agentTemp[field] : agent?.[field] ?? ''
-    } else {
-      // 新建模式:只显示agentTemp中的值
-      return agentTemp?.[field] ?? ''
-    }
+    return agentEdit?.[field] ?? ''
   }
+
   const { setEntId } = useVoiceStore()
   const handleEditVoice = () => {
     // 提前设置当前智能体 entId
-    setEntId(agent?.entId ?? 0);
+    setEntId(agentEdit?.entId ?? 0);
     Taro.navigateTo({ url: '/pages/voice/index' })
   }
 
-  const updateAgentTemp = useAgentStore((state)=> state.actions.updateAgentTemp)
-
   // 处理表单字段更新
   const handleFieldChange = (field: string, value: string) => {
     console.log(field, value)
-    updateAgentTemp({ [field]: value });
+    updateEditAgent({ [field]: value });
   };
 
   const IconArrowRight = () => {
@@ -54,14 +66,24 @@ export default function Index() {
     );
   };
 
+  // 如果有智能体名字,且名字字符串大于 2
+  const hasName = (agentEdit?.name && agentEdit.name.length >= 2)
+  const defalutPolishPersonality = hasName ? `你是 ${agentEdit?.entName} 的 ${agentEdit?.position} ${agentEdit?.name}`: ''
+  const defalutPolishGreeting = hasName ? `我是 ${agentEdit?.name},很高兴认识你!有什么想聊的或者想解决的问题吗`: ''
+
+  const questionGuides = agentEdit?.questionGuides ?? [];
+  const voiceName = agentEdit?.voiceName ?? '';
+
   return (
     <View className="flex flex-col gap-12">
       <WemetaTextareaAI
         aiType="personality"
+        defaultAiTips={defalutPolishPersonality}
         prefix={() => <View>人设</View>}
         placeholder="示例:你是一名汽车销售人员,拥有专业的汽车相关知识,善于耐心的解答客户提出的每一个问题,并会主动邀请客户上门试驾。"
         value={getDisplayValue('personality')}
         autoHeight
+        ref={personalityPolishRef}
         onInput={(value) => {
           handleFieldChange('personality', value)
         }}
@@ -69,10 +91,12 @@ export default function Index() {
 
       <WemetaTextareaAI
         aiType="greeting"
+        defaultAiTips={defalutPolishGreeting}
         prefix={() => <View>开场白</View>}
         placeholder="开场白是你的智能体和用户说的第一句话,简单做个自我介绍吧"
         value={getDisplayValue('greeting')}
         autoHeight
+        ref={greetingPolishRef}
         onInput={(value) => {
           handleFieldChange('greeting', value)
         }}
@@ -88,7 +112,9 @@ export default function Index() {
         >
           <View className="text-14 py-18 font-medium leading-22 flex items-center">
             <View className="flex-1">开场提问引导</View>
-            <View className="text-gray-4">去编辑</View>
+            <View className="text-gray-4">
+              { questionGuides.length === 0 ? '去编辑' : `${questionGuides.length} / 3 ` }
+            </View>
           </View>
         </CardListItem>
       </CardList>
@@ -102,10 +128,12 @@ export default function Index() {
         >
           <View className="text-14 py-18 font-medium leading-22 flex items-center">
             <View className="flex-1">声音</View>
-            <View className="text-gray-4">设置专属声音</View>
+            <View className="text-gray-4">
+              {voiceName ? `${voiceName}` : "设置专属声音"}
+            </View>
           </View>
         </CardListItem>
       </CardList>
     </View>
   );
-}
+})

+ 20 - 9
src/pages/agent/components/AgentSetting/index.tsx

@@ -5,21 +5,32 @@ import AgentCard from './components/AgentCard'
 import AgentContactCard from './components/AgentContactCard'
 import BottomBar from "@/components/BottomBar";
 
-import React, { useEffect, useState } from "react";
+import React, { useEffect, useState, forwardRef, useImperativeHandle, useRef } from "react";
 
-import ButtonMain from "@/components/buttons/ButtonMain";
+import WemetaButton from "@/components/buttons/WemetaButton";
 import { useAgentStore } from "@/store/agentStore";
 
 
-export default React.memo(function Index({save}: {save: ()=> void}) {
+export default forwardRef(function Index({save}: {save: ()=> void}, ref) {
   console.log('agent setting')
-  const agent = useAgentStore((state) => state.agent)
-  const agentTemp = useAgentStore((state)=> state.agentTemp)
+  const agentEdit = useAgentStore((state) => state.agentEdit)
+
+  // Create ref for AgentSettingList
+  const agentSettingListRef = useRef<{ polishAllTexts: () => Promise<void> }>(null);
+
+  // Expose methods to parent components
+  useImperativeHandle(ref, () => ({
+    polishAllTexts: async () => {
+      if (agentSettingListRef.current) {
+        await agentSettingListRef.current.polishAllTexts();
+      }
+    }
+  }));
 
   // 控制按钮状态和文本
-  const isNameValid = (agentTemp?.name?.length || 0) >= 2 || (agent?.name?.length || 0) >= 2
+  const isNameValid = (agentEdit?.name?.length || 0) >= 2
   const isDisabled = !isNameValid
-  const buttonText = agent?.agentId ? '保存' : '创建'
+  const buttonText = agentEdit?.agentId ? '保存' : '创建'
 
   return (
     <View className="pb-64">
@@ -27,12 +38,12 @@ export default React.memo(function Index({save}: {save: ()=> void}) {
       <View className="mb-20">
         <AgentContactCard></AgentContactCard>
       </View>
-      <AgentSettingList></AgentSettingList>
+      <AgentSettingList ref={agentSettingListRef}></AgentSettingList>
       <View className="py-20">
         <AgentKnowledgeLib></AgentKnowledgeLib>
       </View>
       <BottomBar>
-        <ButtonMain disabled={isDisabled} className="flex-1" onClick={save}>{buttonText}</ButtonMain>
+        <WemetaButton disabled={isDisabled} className="flex-1" onClick={save}>{buttonText}</WemetaButton>
       </BottomBar>
     </View>
   );

+ 66 - 4
src/pages/agent/hooks/useConfirms.tsx

@@ -4,7 +4,7 @@ import Taro from "@tarojs/taro";
 export const useConfirms = () => {
   const { showModal } = useModalStore((state) => state.actions);
   // 回退确认
-  const navbackConfirm = async () => {
+  const confirmNavBack = async (): Promise<boolean> => {
     return await new Promise((resolve)=> {
       showModal({
         content: <View className="text-black font-pingfangSCMedium font-medium text-14 leading-22">确定放弃创建智能体?</View>,
@@ -22,7 +22,7 @@ export const useConfirms = () => {
   }
 
 
-  const saveAvatarConfirm = async () => {
+  const confirmSaveAvatar = async ():Promise<boolean> => {
     return await new Promise((resolve)=> {
       showModal({
         content: <View className="text-black font-pingfangSCMedium font-medium text-14 leading-22">为你的智能体设置一个形象吧</View>,
@@ -39,10 +39,72 @@ export const useConfirms = () => {
       })
     })
   }
+  // 提示先创建智能体
+  const confirmCreateAgent = async ():Promise<boolean> => {
+    return await new Promise((resolve)=> {
+      showModal({
+        content: <View className="text-black font-pingfangSCMedium font-medium text-14 leading-22">在进行设置前需要先创建智能体</View>,
+        confirmText: "创建",
+        cancelText: "不创建",
+        onConfirm() {
+          Taro.showTabBar().catch(()=> {});
+          resolve(true)
+        },
+        onCancel() {
+          Taro.showTabBar().catch(()=> {});
+          resolve(false)
+        },
+      })
+    })
+  }
+
+  const confirmEditWebsite = async ():Promise<boolean> => {
+    return await new Promise((resolve)=> {
+      showModal({
+        content: <View className="flex items-center flex-col justify-center">
+              <View className="text-black font-pingfangSCMedium font-medium text-14 leading-22">已创建智能体,继续编辑微官网?</View>
+              <View className="text-gray-5 text-14 leading-22" style="max-width: 280px;">让商务伙伴在访问你的智能体时,可以更深入的了解你的企业和业务</View>
+          </View>,
+        confirmText: "编辑微官网",
+        cancelText: "暂时不编辑",
+        onConfirm() {
+          Taro.showTabBar().catch(()=> {});
+          resolve(true)
+        },
+        onCancel() {
+          Taro.showTabBar().catch(()=> {});
+          resolve(false)
+        },
+      })
+    })
+  }
+
+  const confirmPersonalityAndGreeting = async (personality?: string, greeting?: string):Promise<boolean> => {
+    const personalityText =  (!personality || personality?.length <= 0)  ? '人设': ''
+    const greetingText =  (!greeting || greeting?.length <= 0)  ? '、开场白': ''
+    return await new Promise((resolve)=> {
+      showModal({
+        content: <View className="text-black font-pingfangSCMedium font-medium text-14 leading-22">还没有设置{`${personalityText} ${greetingText}`}</View>,
+        confirmText: "自动生成",
+        cancelText: "暂不生成",
+        onConfirm() {
+          Taro.showTabBar().catch(()=> {});
+          resolve(true)
+        },
+        onCancel() {
+          Taro.showTabBar().catch(()=> {});
+          resolve(false)
+        },
+      })
+    })
+  }
 
 
   return {
-    navbackConfirm,
-    saveAvatarConfirm,
+    confirmEditWebsite,
+    confirmNavBack,
+    confirmSaveAvatar,
+    confirmCreateAgent,
+    confirmPersonalityAndGreeting,
   }
 }

+ 51 - 35
src/pages/agent/index.tsx

@@ -5,35 +5,47 @@ import PageCustom from "@/components/page-custom/index";
 import TabBarButtons from "@/components/wemeta-tabs/TabBarButtons";
 import AgentSetting from "./components/AgentSetting/";
 import AgentWebsite from "./components/AgentWebsite/";
-import { useModalStore } from "@/store/modalStore";
 import { useAgentStore, useAgentStoreActions } from "@/store/agentStore";
-import { useEffect, useState } from "react";
+import { useEffect, useState, useRef } from "react";
 import Taro, { useDidShow, useRouter } from "@tarojs/taro";
 import { useComponentStore } from "@/store/componentStore";
 import { useUserStore } from "@/store/userStore";
 import { useAppStore } from "@/store/appStore";
 import style from './index.module.less'
 import {restrictedPage} from '@/utils'
+import { useConfirms } from './hooks/useConfirms'
 
 export default function Index() {
   restrictedPage()
-  const { showModal } = useModalStore((state) => state.actions);
   const router = useRouter();
   const headerHeight = useAppStore((state) => state.headerHeight);
   const agentId = router.params.agentId;
-  const agent = useAgentStore((state) => state.agent);
-  const { clearMyAgent, fetchAgent, saveAgent } = useAgentStoreActions();
+  const agentEdit = useAgentStore((state) => state.agentEdit);
+  const { fetchAgent, saveAgent, updateEditAgent } = useAgentStoreActions();
   const { fetchMyEntList } = useUserStore();
   const { setComponentList } = useComponentStore();
+  const { confirmNavBack, confirmCreateAgent, confirmEditWebsite, confirmPersonalityAndGreeting, confirmSaveAvatar } = useConfirms();
   const [tabIndex, setTabIndex] = useState('1');
 
-  const handleTabIndexChange = (index: string) => {
+  // Create ref for AgentSetting component
+  const agentSettingRef = useRef<{ polishAllTexts: () => Promise<void> }>(null);
+
+  const handleTabIndexChange = async (index: string) => {
+    if(index === '2' && !agentEdit?.agentId){
+      const result = await confirmCreateAgent()
+      if(result){
+        // await saveAgent()
+        setTabIndex(index)
+      }
+      return
+    }
     setTabIndex(index);
   };
 
   const fetchData = async (agentId: string) => {
     const result = await fetchAgent(agentId);
     if (result) {
+      updateEditAgent(result)
       const components = result.components ?? []
       // 过滤掉没有 id 的组件防止有错误数据
       setComponentList(components.filter(c => !!c.data?.id), agentId);
@@ -52,49 +64,53 @@ export default function Index() {
     },
   ];
 
-  const agentTemp = useAgentStore(state=> state.agentTemp);
   const { fetchAgents } = useAgentStoreActions();
 
   useEffect(()=> {
     fetchAgents()
   }, [])
 
-  const handleSave  = async () =>{
-    await saveAgent()
-  }
-
-  const handleNavBack = async () => {
-    if(!agentTemp){
-      return true
+  const handleSave  = async () => {
+    if(!agentId && !agentEdit?.agentId){
+      if(!agentEdit?.avatarUrl){
+        const result  = await confirmSaveAvatar()
+        if(result){
+          return;
+        }
+      }
+      if(!agentEdit?.personality || !agentEdit?.greeting){
+        const result  = await confirmPersonalityAndGreeting(agentEdit?.personality, agentEdit?.greeting)
+        if(result){
+          if (agentSettingRef.current) {
+            if(agentEdit?.name && agentEdit?.name.length >= 2){
+              await agentSettingRef.current.polishAllTexts();
+            }
+          }
+          console.log(agentEdit,2222)
+        }else{
+          return;
+        }
+      }
     }
-    // 创建的智能体没有名字时拦截弹窗
-    if(!agentTemp.name){
-      const r = await new Promise((resolve)=> {
-        showModal({
-          content: <View className="text-black font-pingfangSCMedium font-medium text-14 leading-22">确定放弃创建智能体?</View>,
-          confirmText: "我再想想",
-          onConfirm() {
-            Taro.showTabBar().catch(()=> {});
-            resolve(true)
-          },
-          onCancel() {
-            Taro.showTabBar().catch(()=> {});
-            resolve(false)
-          },
-        })
-      })
 
-      return r
+    // await saveAgent()
+  }
+
+  const handleNavBack = async (): Promise<boolean | void> => {
+    confirmEditWebsite()
+    return false
+    // 创建 智能体没有名字时拦截弹窗
+    if(!agentEdit?.agentId && !agentEdit?.name){
+      const result = await confirmNavBack()
+      return !result
     }
+    return true
   }
 
   useDidShow(()=> {
     if(agentId){
       fetchData(agentId);
-    }else{
-      clearMyAgent();
     }
-
   })
 
   return (
@@ -116,7 +132,7 @@ export default function Index() {
         </View>
         <View className="pt-52">
           <View className={`${tabIndex === "1" ? "block" : "hidden"}`}>
-            <AgentSetting save={handleSave}></AgentSetting>
+            <AgentSetting ref={agentSettingRef} save={handleSave}></AgentSetting>
           </View>
           <View className={`${tabIndex === "2" ? "block" : "hidden"}`}>
             <View className="pt-36 pb-80">

+ 2 - 2
src/pages/contact-us/index.tsx

@@ -14,7 +14,7 @@ import { saveMyContact } from '@/service/user'
 import BottomBar from "@/components/BottomBar";
 import { isSuccess } from "@/utils";
 import Taro from "@tarojs/taro";
-import ButtonMain from "@/components/buttons/ButtonMain";
+import WemetaButton from "@/components/buttons/WemetaButton";
 
 export default function Index() {
 
@@ -109,7 +109,7 @@ export default function Index() {
 
       </View>
       <BottomBar>
-        <ButtonMain className="flex-1" disabled={isDisable} onClick={handleSubmit}>提 交</ButtonMain>
+        <WemetaButton className="flex-1" disabled={isDisable} onClick={handleSubmit}>提 交</WemetaButton>
 
       </BottomBar>
     </PageCustom>

+ 2 - 2
src/pages/editor-pages/editor-channels/index.tsx

@@ -9,7 +9,7 @@ import { useComponentStore } from "@/store/componentStore";
 import WemetaInput from "@/components/wemeta-input/index";
 import { EComponentType } from "@/consts/enum";
 import BottomBar from "@/components/BottomBar";
-import ButtonMain from "@/components/buttons/ButtonMain";
+import WemetaButton from "@/components/buttons/WemetaButton";
 import FormitemSingleImage from '@/components/Form/FormItemSingleImage';
 
 export default function Index() {
@@ -158,7 +158,7 @@ export default function Index() {
       </View>
 
       <BottomBar>
-        <ButtonMain className="flex-1" disabled={!shipingValue.videoId.length || !shipingValue.accountId.length} onClick={handleSubmit}>保存</ButtonMain>
+        <WemetaButton className="flex-1" disabled={!shipingValue.videoId.length || !shipingValue.accountId.length} onClick={handleSubmit}>保存</WemetaButton>
       </BottomBar>
 
       <Popup

+ 4 - 4
src/pages/editor-pages/editor-ent-name/index.tsx

@@ -3,7 +3,7 @@ import { View } from "@tarojs/components";
 
 import PageCustom from "@/components/page-custom/index";
 import NavBarNormal from "@/components/NavBarNormal/index";
-import ButtonMain from "@/components/buttons/ButtonMain";
+import WemetaButton from "@/components/buttons/WemetaButton";
 import BottomBar from "@/components/BottomBar";
 
 import WemetaTextarea from "@/components/wemeta-textarea/index";
@@ -12,8 +12,8 @@ import useEditContactCard from "@/hooks/useEditContactCard";
 export default function Index() {
   const agentContactCard = useAgentStore((state)=> state.agentContactCard)
   const {value, onChange, handleSubmit} = useEditContactCard('entName', agentContactCard?.entName)
-  
-  
+
+
 
   return (
     <PageCustom>
@@ -32,7 +32,7 @@ export default function Index() {
           />
         </View>
         <BottomBar>
-          <ButtonMain className="flex-1" disabled={!value.length} onClick={handleSubmit}>保存</ButtonMain>
+          <WemetaButton className="flex-1" disabled={!value.length} onClick={handleSubmit}>保存</WemetaButton>
         </BottomBar>
       </View>
     </PageCustom>

+ 15 - 15
src/pages/editor-pages/editor-greeting-questions/index.tsx

@@ -4,7 +4,7 @@ import { View } from "@tarojs/components";
 import PageCustom from "@/components/page-custom/index";
 import NavBarNormal from "@/components/NavBarNormal/index";
 import WemetaInput from "@/components/wemeta-input/index";
-import Taro, { useUnload } from "@tarojs/taro";
+import Taro, { nextTick, useUnload } from "@tarojs/taro";
 import { useAgentStore, useAgentStoreActions } from "@/store/agentStore";
 
 type InputField = {
@@ -14,10 +14,9 @@ type InputField = {
 };
 
 export default function Index() {
-  const agent = useAgentStore((state) => state.agent);
-  const agentCharacter = useAgentStore((state) => state.agentCharacter);
-  const { editAgentCharacter, fetchAgent } = useAgentStoreActions();
-  const questionGuides = agentCharacter?.questionGuides ?? [];
+  const agent = useAgentStore((state) => state.agentEdit);
+  const { fetchAgent, saveAgent, updateEditAgent } = useAgentStoreActions();
+  const questionGuides = agent?.questionGuides ?? [];
   const initialInputs: InputField[] = [
     { id: "1", value: "", title: "问题一" },
     { id: "2", value: "", title: "问题二" },
@@ -29,28 +28,29 @@ export default function Index() {
   });
   const [inputs, setInputs] = useState<InputField[]>(initialInputs);
   const handleChange = (id: string, newValue: string) => {
-    setInputs((prev) =>
-      prev.map((input) =>
+    setInputs((prev) =>{
+      const r = prev.map((input) =>
         input.id === id ? { ...input, value: newValue } : input
       )
-    );
+      return r
+    });
   };
   let loading = false
   const handleSubmit = async () => {
+    const r = {'questionGuides': inputs.map((item) => item.value).filter(item => item.length > 0)}
     if (!agent?.agentId) {
+      updateEditAgent(r);
+      Taro.navigateBack()
       return;
     }
-    if (!agentCharacter) {
-      return;
-    }
+
     if(loading){
       return;
     }
     loading = true
-    const result = await editAgentCharacter(agent.agentId, {
-      ...agentCharacter,
-      questionGuides: inputs.map((item) => item.value),
-    });
+
+    console.log(r)
+    const result = await saveAgent(r);
     loading = false
     if (result) {
       await fetchAgent(agent.agentId);

+ 0 - 5
src/pages/editor-pages/editor-greeting/index.config.ts

@@ -1,5 +0,0 @@
-export default definePageConfig({
-  navigationBarTitleText: '开场白',
-  "usingComponents": {},
-  navigationStyle: 'custom'
-})

+ 0 - 2
src/pages/editor-pages/editor-greeting/index.module.less

@@ -1,2 +0,0 @@
-
-

+ 0 - 45
src/pages/editor-pages/editor-greeting/index.tsx

@@ -1,45 +0,0 @@
-
-import { View } from "@tarojs/components";
-import PageCustom from "@/components/page-custom/index";
-import NavBarNormal from "@/components/NavBarNormal/index";
-import WemetaTextarea from "@/components/wemeta-textarea/index";
-import TextPolish from '@/components/TextPolish'
-import { useAgentStore } from "@/store/agentStore";
-import useEditAgent from "@/hooks/useEditAgent";
-import BottomBar from "@/components/BottomBar";
-import ButtonMain from "@/components/buttons/ButtonMain";
-export default function Index() {
-
-const agent = useAgentStore((state)=> state.agent)  
-const {handleSubmit, onChange, value, setValue} = useEditAgent('greeting', agent?.greeting ?? '')
-const onPolished = (text:string|null)=> {
-  if(text){
-    setValue(text)
-  }
-  
-}
-  return (
-    <PageCustom>
-      <NavBarNormal backText="开场白"></NavBarNormal>
-      <View className="flex flex-col items-center w-full">
-        <View className="w-full p-16">
-          <WemetaTextarea
-              value={value}
-              autoHeight
-              extraClass="min-h-[380px] max-h-[500]"
-              onBlur={(value: string) => onChange(value)}
-              onInput={(value: string) => onChange(value)}
-              placeholder="碰到TA之后,第一句话想说什么?"
-              maxlength={200}
-              autoFocus
-              extra={()=> <TextPolish text={value} type="greeting" onPolished={onPolished}/>}
-            />
-        </View>
-
-        <BottomBar>
-          <ButtonMain className="flex-1" disabled={!value.length} onClick={handleSubmit}>保存</ButtonMain>
-        </BottomBar>  
-      </View>
-    </PageCustom>
-  );
-}

+ 3 - 3
src/pages/editor-pages/editor-link-social/index.tsx

@@ -11,7 +11,7 @@ import { SocialMediaType } from "@/consts/socialMedia";
 import BottomBar from "@/components/BottomBar";
 import { EComponentType } from "@/consts/enum";
 import Popup from "@/components/popup/popup";
-import ButtonMain from "@/components/buttons/ButtonMain";
+import WemetaButton from "@/components/buttons/WemetaButton";
 export default function Index() {
   const router = useRouter();
   // 社交媒体类型
@@ -102,13 +102,13 @@ export default function Index() {
         </View>
       </View>
       <BottomBar>
-        <ButtonMain
+        <WemetaButton
           className="flex-1"
           disabled={!linkValue.length}
           onClick={handleSubmit}
         >
           保存
-        </ButtonMain>
+        </WemetaButton>
       </BottomBar>
       <Popup title={"获取视频号ID"} show={show} setShow={setShow}>
         <View className="flex flex-col gap-10 rounded-20 p-12 bg-white">

+ 5 - 5
src/pages/editor-pages/editor-link/index.tsx

@@ -5,7 +5,7 @@ import PageCustom from "@/components/page-custom/index";
 import NavBarNormal from "@/components/NavBarNormal/index";
 import WemetaTextarea from "@/components/wemeta-textarea/index";
 import WemetaInput from "@/components/wemeta-input/index";
-import ButtonMain from "@/components/buttons/ButtonMain";
+import WemetaButton from "@/components/buttons/WemetaButton";
 import FormitemSingleImage from '@/components/Form/FormItemSingleImage'
 import IconDeleteGray16 from "@/components/icon/IconDeleteGray16";
 
@@ -80,7 +80,7 @@ export default function Index() {
 
 
 
-  
+
 
   return (
     <PageCustom>
@@ -114,12 +114,12 @@ export default function Index() {
           <FormitemSingleImage url={linkPoster} setUrl={setLinkPoster} ></FormitemSingleImage>
         </View>
         <BottomBar>
-          <ButtonMain disabled={!linkValue.length} className="flex-1" onClick={handleSubmit}>保存</ButtonMain>
+          <WemetaButton disabled={!linkValue.length} className="flex-1" onClick={handleSubmit}>保存</WemetaButton>
         </BottomBar>
       </View>
-      
+
       <KnowledgePicker title="知识库-链接" types={[EKnowlegeTypes.web]} onPicked={onPicked} setShow={setShowPopup} show={showPopup}></KnowledgePicker>
-      
+
     </PageCustom>
   );
 }

+ 2 - 2
src/pages/editor-pages/editor-mini-program/index.tsx

@@ -11,7 +11,7 @@ import BottomBar from "@/components/BottomBar";
 import { useComponentStore } from "@/store/componentStore";
 import FormitemSingleImage from '@/components/Form/FormItemSingleImage';
 import { EComponentType } from "@/consts/enum";
-import ButtonMain from "@/components/buttons/ButtonMain";
+import WemetaButton from "@/components/buttons/WemetaButton";
 export default function Index() {
 
   let currentComponent = useComponentStore((state)=>  state.currentComponent);
@@ -121,7 +121,7 @@ export default function Index() {
       </View>
 
       <BottomBar>
-          <ButtonMain className="flex-1" disabled={!linkValue.shortLink.length} onClick={handleSubmit}>保存</ButtonMain>
+          <WemetaButton className="flex-1" disabled={!linkValue.shortLink.length} onClick={handleSubmit}>保存</WemetaButton>
         </BottomBar>
 
       <Popup

+ 4 - 4
src/pages/editor-pages/editor-name/index.tsx

@@ -3,7 +3,7 @@ import { View } from "@tarojs/components";
 
 import PageCustom from "@/components/page-custom/index";
 import NavBarNormal from "@/components/NavBarNormal/index";
-import ButtonMain from "@/components/buttons/ButtonMain";
+import WemetaButton from "@/components/buttons/WemetaButton";
 import BottomBar from "@/components/BottomBar";
 
 import WemetaTextarea from "@/components/wemeta-textarea/index";
@@ -12,8 +12,8 @@ import useEditContactCard from "@/hooks/useEditContactCard";
 export default function Index() {
   const agentContactCard = useAgentStore((state)=> state.agentContactCard)
   const {value, onChange, handleSubmit} = useEditContactCard('name', agentContactCard?.name)
-  
-  
+
+
 
   return (
     <PageCustom>
@@ -32,7 +32,7 @@ export default function Index() {
           />
         </View>
         <BottomBar>
-          <ButtonMain className="flex-1" disabled={!value.length} onClick={handleSubmit}>保存</ButtonMain>
+          <WemetaButton className="flex-1" disabled={!value.length} onClick={handleSubmit}>保存</WemetaButton>
         </BottomBar>
       </View>
     </PageCustom>

+ 0 - 49
src/pages/editor-pages/editor-personality/index.tsx

@@ -1,49 +0,0 @@
-import { View } from "@tarojs/components";
-
-import PageCustom from "@/components/page-custom/index";
-import NavBarNormal from "@/components/NavBarNormal/index";
-import ButtonMain from "@/components/buttons/ButtonMain";
-import BottomBar from "@/components/BottomBar";
-import WemetaTextarea from "@/components/wemeta-textarea/index";
-import TextPolish from '@/components/TextPolish'
-import { useAgentStore } from "@/store/agentStore";
-import useEditAgent from "@/hooks/useEditAgent";
-
-
-export default function Index() {
-  const agent = useAgentStore((state)=> state.agent)  
-  const {handleSubmit, onChange, value, setValue} = useEditAgent('personality', agent?.personality ?? '')
-  
-  const onPolished = (text:string|null)=> {
-    if(text){
-      setValue(text)
-    }
-    
-  }
-
-  return (
-    <PageCustom>
-      <NavBarNormal backText="人设"></NavBarNormal>
-      <View className="flex flex-col items-center w-full">
-      <View
-            className="w-full p-16 pb-120"
-          >
-            <WemetaTextarea
-              value={value}
-              autoHeight
-              extraClass="min-h-[380px] max-h-[500]"
-              onBlur={(value: string) => onChange(value)}
-              onInput={(value: string) => onChange(value)}
-              placeholder="示例:你是一位汽车销售人员,拥有专业的汽车相关知识,善于耐心的解答客户提出的每一个问题,并会主动邀请客户上门试驾。"
-              autoFocus
-              extra={()=> <TextPolish text={value} type="personality" onPolished={onPolished}/>}
-            />
-          </View>
-        
-        <BottomBar>
-          <ButtonMain className="flex-1" disabled={!value.length} onClick={handleSubmit}>保存</ButtonMain>
-        </BottomBar>
-      </View>
-    </PageCustom>
-  );
-}

+ 4 - 4
src/pages/editor-pages/editor-position/index.tsx

@@ -3,7 +3,7 @@ import { View } from "@tarojs/components";
 
 import PageCustom from "@/components/page-custom/index";
 import NavBarNormal from "@/components/NavBarNormal/index";
-import ButtonMain from "@/components/buttons/ButtonMain";
+import WemetaButton from "@/components/buttons/WemetaButton";
 import BottomBar from "@/components/BottomBar";
 
 import WemetaTextarea from "@/components/wemeta-textarea/index";
@@ -12,8 +12,8 @@ import useEditContactCard from "@/hooks/useEditContactCard";
 export default function Index() {
   const agentContactCard = useAgentStore((state)=> state.agentContactCard)
   const {value, onChange, handleSubmit} = useEditContactCard('position', agentContactCard?.position)
-  
-  
+
+
 
   return (
     <PageCustom>
@@ -32,7 +32,7 @@ export default function Index() {
           />
         </View>
         <BottomBar>
-          <ButtonMain className="flex-1" disabled={!value.length} onClick={handleSubmit}>保存</ButtonMain>
+          <WemetaButton className="flex-1" disabled={!value.length} onClick={handleSubmit}>保存</WemetaButton>
         </BottomBar>
       </View>
     </PageCustom>

+ 5 - 5
src/pages/editor-pages/editor-tel/index.tsx

@@ -5,17 +5,17 @@ import PageCustom from "@/components/page-custom/index";
 import NavBarNormal from "@/components/NavBarNormal/index";
 import { useComponentStore } from "@/store/componentStore";
 import WemetaTextarea from "@/components/wemeta-textarea/index";
-import ButtonMain from "@/components/buttons/ButtonMain";
+import WemetaButton from "@/components/buttons/WemetaButton";
 import BottomBar from "@/components/BottomBar";
 import { EComponentType } from "@/consts/enum";
 import Taro from "@tarojs/taro";
 export default function Index() {
-  
+
   let currentComponent = useComponentStore((state) => state.currentComponent);
   const { saveComponent } = useComponentStore();
   const loading = useComponentStore((state) => state.loading);
   const [value, setValue] = useState(currentComponent?.data?.text ?? "");
-  
+
 
   const onChange = (e: any) => {
     setValue(e);
@@ -43,7 +43,7 @@ export default function Index() {
     Taro.navigateBack();
   };
 
-  
+
 
   return (
     <PageCustom>
@@ -58,7 +58,7 @@ export default function Index() {
             />
         </View>
         <BottomBar>
-          <ButtonMain disabled={!value.length} className="flex-1" onClick={handleSubmit}>保存</ButtonMain>
+          <WemetaButton disabled={!value.length} className="flex-1" onClick={handleSubmit}>保存</WemetaButton>
         </BottomBar>
       </View>
     </PageCustom>

+ 11 - 11
src/pages/editor-pages/editor-textarea/index.tsx

@@ -3,31 +3,31 @@ import { View } from "@tarojs/components";
 import PageCustom from "@/components/page-custom/index";
 import NavBarNormal from "@/components/NavBarNormal/index";
 import BottomBar from "@/components/BottomBar";
-import ButtonMain from "@/components/buttons/ButtonMain";
+import WemetaButton from "@/components/buttons/WemetaButton";
 import { useComponentStore } from "@/store/componentStore";
 import Taro, { useUnload } from "@tarojs/taro";
 import WemetaTextarea from "@/components/wemeta-textarea/index";
 import { EComponentType } from "@/consts/enum";
 
 export default function Index() {
-  
+
   let currentComponent = useComponentStore((state)=>  state.currentComponent);
-  
+
   const { saveComponent } = useComponentStore();
   const loading = useComponentStore((state)=> state.loading);
   const [value, setValue] = useState<string>(currentComponent?.data?.text ?? '');
   const placehoder = currentComponent?.data?.placeholder ?? '点击编辑输入您的文本内容';
-  
+
 
   const handleSubmit = async () => {
-    
+
     if(loading){
       return;
     }
     if(!currentComponent?.data.id){
       return
     }
-    
+
     const c = {
       data: {
         text: value,
@@ -39,20 +39,20 @@ export default function Index() {
       type: EComponentType.text,
     };
 
-    
+
     await saveComponent(c)
 
     Taro.navigateBack()
   };
 
-  
+
   const onChange = (e: any) => {
     setValue(e);
   };
 
-  
 
-  
+
+
 
   return (
     <PageCustom bgColor="global-light-green-bg">
@@ -68,7 +68,7 @@ export default function Index() {
             />
         </View>
         <BottomBar>
-          <ButtonMain className="flex-1" disabled={!value.length} onClick={handleSubmit}>保存</ButtonMain>
+          <WemetaButton className="flex-1" disabled={!value.length} onClick={handleSubmit}>保存</WemetaButton>
         </BottomBar>
       </View>
     </PageCustom>

+ 9 - 9
src/pages/editor-pages/editor-title/index.tsx

@@ -3,7 +3,7 @@ import { View } from "@tarojs/components";
 
 import PageCustom from "@/components/page-custom/index";
 import NavBarNormal from "@/components/NavBarNormal/index";
-import ButtonMain from "@/components/buttons/ButtonMain";
+import WemetaButton from "@/components/buttons/WemetaButton";
 import { useComponentStore } from '@/store/componentStore'
 import BottomBar from "@/components/BottomBar";
 import WemetaTextarea from "@/components/wemeta-textarea/index";
@@ -13,8 +13,8 @@ export default function Index() {
   let currentComponent = useComponentStore((state)=>  state.currentComponent);
   const { saveComponent } = useComponentStore();
   const [value, setValue] = useState(currentComponent?.data?.text ?? '');
-  
-  
+
+
   const handleSubmit = async () => {
     if(!currentComponent?.data.id){
       return
@@ -33,7 +33,7 @@ export default function Index() {
       type: EComponentType.title,
     };
 
-    
+
     await saveComponent(c)
 
     Taro.navigateBack()
@@ -44,9 +44,9 @@ export default function Index() {
   };
 
 
-  
-  
-  
+
+
+
 
   return (
     <PageCustom bgColor="global-light-green-bg">
@@ -62,9 +62,9 @@ export default function Index() {
               maxlength={50}
             />
           </View>
-          
+
         <BottomBar>
-          <ButtonMain className="flex-1" disabled={!value.length} onClick={handleSubmit}>保存</ButtonMain>
+          <WemetaButton className="flex-1" disabled={!value.length} onClick={handleSubmit}>保存</WemetaButton>
         </BottomBar>
       </View>
     </PageCustom>

+ 3 - 3
src/pages/knowledge-item/components/ShareToEntPopup/index.tsx

@@ -15,7 +15,7 @@ import { TEntItem } from "@/types/user";
 import { isSuccess } from "@/utils";
 import EmptyData, { EmptyDataSubInfo } from "@/components/EmptyData";
 import BottomBar from "@/components/BottomBar";
-import ButtonMain from "@/components/buttons/ButtonMain";
+import WemetaButton from "@/components/buttons/WemetaButton";
 
 
 
@@ -148,9 +148,9 @@ export default function Index({
       {renderContent()}
 
       {(!!parsedEntList.length) ? <BottomBar>
-        <ButtonMain className="flex-1" disabled={!currentEnts.length} onClick={submit}>
+        <WemetaButton className="flex-1" disabled={!currentEnts.length} onClick={submit}>
           确定
-        </ButtonMain>
+        </WemetaButton>
       </BottomBar> : <></>}
     </Popup>
   );

+ 1 - 1
src/pages/voice/components/MyVoiceList/index.tsx

@@ -26,7 +26,7 @@ import BottomBar from "@/components/BottomBar";
 import { useAppStore } from "@/store/appStore";
 
 interface Props {
-  agent: TAgentDetail | null;
+  agent: Partial<TAgentDetail> | null;
   onPlay: (voice: any) => void;
   onSelect: (voice: any) => void;
 }

+ 4 - 4
src/pages/voice/components/ScrollVoiceList/index.tsx

@@ -4,7 +4,7 @@ import { EVoiceStatus, EVoiceType, TGender, TVoiceItem } from "@/types/voice";
 import VoiceList from '../VoiceList'
 import {
   getVoices,
-  cloneVoice as _cloneVoice,  
+  cloneVoice as _cloneVoice,
 } from "@/service/voice";
 import { useLoadMoreInfinite, createKey } from "@/utils/loadMoreInfinite";
 import { useVoiceStore } from "@/store/voiceStore";
@@ -19,12 +19,12 @@ export default function Index({
 }: {
   onPlay: (voice: any) => void;
   onSelect: (voice: any) => void;
-  agent: TAgentDetail | null;
+  agent: Partial<TAgentDetail> | null;
   key: string
   type?: EVoiceType
   gender?: TGender
 }) {
-  
+
   const {entId} = useVoiceStore()
 
   const fetcher = async ([_url, {pageSize, pageIndex}, [entId, type, gender]])=> {
@@ -33,7 +33,7 @@ export default function Index({
   }
   const { list, loadMore } = useLoadMoreInfinite<
     TVoiceItem[]
-  >(createKey(`api/${key}/${entId}${type}${gender}`, 20, [entId, type, gender]), fetcher);  
+  >(createKey(`api/${key}/${entId}${type}${gender}`, 20, [entId, type, gender]), fetcher);
   const onScrollToLower = ()=> {
     loadMore()
   }

+ 1 - 0
src/pages/voice/components/VoiceList/index.tsx

@@ -20,6 +20,7 @@ export default function Index({
 
 
   const handleSelect = async (voiceItem: TVoiceItem) => {
+    console.log(voiceItem,33)
     onSelect(voiceItem);
   };
 

+ 15 - 12
src/pages/voice/index.tsx

@@ -20,9 +20,8 @@ const VoiceTabs: React.FC<Props> = ({}) => {
     null
   );
 
-  const agent = useAgentStore((state) => state.agent);
-  const agentCharacter = useAgentStore((state) => state.agentCharacter);
-  const {editAgentCharacter} = useAgentStoreActions();
+  const agentEdit = useAgentStore((state) => state.agentEdit);
+  const { saveAgent, updateEditAgent } = useAgentStoreActions();
 
   const {
     getVoices,
@@ -33,16 +32,20 @@ const VoiceTabs: React.FC<Props> = ({}) => {
   // 获取女声列表
   useEffect(() => {
     getVoices()
-  }, [agent]);
+  }, [agentEdit]);
 
   // 保存默认 voiceId
   const saveAgentVoiceId = async (voiceItem: TVoiceItem) => {
-    if(!agent?.agentId || !voiceItem?.voiceId || !agentCharacter){
+    if(!voiceItem?.voiceId){
       return
     }
-    const result = await editAgentCharacter(agent?.agentId, {
-      ...agentCharacter,
-      voiceId: voiceItem.voiceId
+    if(!agentEdit?.agentId){
+      updateEditAgent({voiceId: voiceItem.voiceId, voiceName: voiceItem.voiceName})
+      return
+    }
+    const result = await saveAgent({
+      voiceId: voiceItem.voiceId,
+      voiceName: voiceItem.voiceName
     })
     console.log(result)
   }
@@ -69,7 +72,7 @@ const VoiceTabs: React.FC<Props> = ({}) => {
       children: (
         <View className="h-full">
           <MyVoiceList
-          agent={agent}
+          agent={agentEdit}
           onSelect={(item) => {
             setPlayerItem(item, "cloned");
           }}
@@ -86,7 +89,7 @@ const VoiceTabs: React.FC<Props> = ({}) => {
       children: (
         <View className="h-full bg-white">
           <ScrollVoiceList
-            agent={agent}
+            agent={agentEdit}
             key="ScrollVoiceList"
             onSelect={(item) => {
               setPlayerItem(item, "system");
@@ -106,7 +109,7 @@ const VoiceTabs: React.FC<Props> = ({}) => {
       children: (
         <View className="h-full bg-white">
           <ScrollVoiceList
-            agent={agent}
+            agent={agentEdit}
             key="femaleVoice"
             gender="female"
             onSelect={(item) => {
@@ -127,7 +130,7 @@ const VoiceTabs: React.FC<Props> = ({}) => {
       children: (
         <View className="h-full bg-white">
           <ScrollVoiceList
-            agent={agent}
+            agent={agentEdit}
             key="maleVoice"
             gender="male"
             onSelect={(item) => {

+ 1 - 18
src/service/agent.ts

@@ -17,24 +17,7 @@ export const getMyAgent = (agentId: string) => {
 
 // 获取创建智能体时的默认填充内容项
 export const getNewAgentInfo = () => {
-  return request.get<{
-    "address"?: string;
-    "avatarLogo"?: string;
-    "avatarUrl"?: string;
-    "email"?: string;
-    "enabledChatBg"?: boolean;
-    "enabledPersonalKb"?: boolean;
-    "entName"?: string;
-    "greeting"?: string;
-    "mobile"?: string;
-    "name"?: string;
-    "personality"?: string;
-    "position"?: string;
-    "qrCodeUrl"?: string;
-    "questionGuides"?: string[];
-    "voiceId"?: string;
-    "voiceName"?: string;
-  }>(`${bluebookAiAgent}api/v1/my/new/agent/info`)
+  return request.get<Partial<TAgentDetail>>(`${bluebookAiAgent}api/v1/my/new/agent/info`)
 }
 // 创建新智能体
 export const createNewAgent = (data: Omit<TAgentRequiredData, 'agentId'>) => {

+ 80 - 59
src/store/agentStore.ts

@@ -10,6 +10,7 @@ import {
   editAgentWebsite as _editAgentWebsite,
   createNewAgent as _createNewAgent,
   editAgent as _editAgent,
+  getNewAgentInfo,
 } from "@/service/agent";
 import {
   TAgentDetail,
@@ -21,12 +22,14 @@ import {
 } from "@/types/agent";
 import { isSuccess } from "@/utils";
 import Taro from "@tarojs/taro";
+import { TAvatarItem } from "@/service/storage";
 
 export interface AgentStoreState {
   agents: TAgent[];
-  agent: TAgentDetail | null;
-  defaultAgent: TAgentDetail | TAgent | null;
-  agentTemp: Omit<TAgentRequiredData, 'agentId'>; // 未创建智能体临时存储
+  agent: Partial<TAgentDetail> | null;
+  agentEdit: Partial<TAgentDetail> | null;
+  defaultAgent: Partial<TAgentDetail> | TAgent | null;
+  currentEditAvatar: TAvatarItem | null;
   // 无需登录查看 agent 信息
   agentProfile: TAgentDetail | null;
   agentContactCard: TAgentContactCard | null;// deprecated
@@ -35,14 +38,15 @@ export interface AgentStoreState {
   actions: {
     fetchAgents: () => Promise<TAgent[]>;
     // 请求智能体数据登录状态
-    fetchAgent: (agentId: string) => Promise<TAgentDetail | null>;
+    fetchAgent: (agentId: string) => Promise<Partial<TAgentDetail> | null>;
+    fetchDefaultNewAgentInfo: () => Promise<Partial<TAgentDetail> | null>;
     // 请求智能体数据非登录状态
     fetchAgentProfile: (
       agentId: string,
       shareKey?: string
     ) => Promise<TAgentDetail | null>;
     clearProfileAgent: () => void;
-    setDefaultAgent: (agentId: string) => Promise<TAgentDetail | null>;
+    setDefaultAgent: (agentId: string) => Promise<Partial<TAgentDetail> | null>;
     editAgentCharacter: (
       agentId: string,
       data: TEditAgentCharacter
@@ -53,23 +57,24 @@ export interface AgentStoreState {
       data: TComponentItem[]
     ) => Promise<boolean>;
     deleteAgent: (agentId: string) => Promise<void>;
-    updateAgentTemp: (updates: Partial<TAgentRequiredData>) => void;
-    clearAgentTemp: () => void;
-    saveAgent: () => Promise<TAgentDetail | null>;
+    updateEditAgent: (updates: Partial<TAgentDetail>) => void;
+    saveAgent: (agentFields?: Partial<TAgentDetail>) => Promise<Partial<TAgentDetail> | null>;
     resetData: () => void;
-    clearMyAgent: () => void;
+    clearEditAgent: () => void;
+    setCurrentEditAvatar: (avatar: TAvatarItem|null) => void;
   };
 }
 
 export const useAgentStore = create<AgentStoreState>((set, get) => ({
   agents: [],
   agent: null,
+  agentEdit: null,
   agentProfile: null,
   agentContactCard: null,
   defaultAgent: null,
   agentCharacter: null,
-  agentTemp: {},
   ents: [],
+  currentEditAvatar: null,
   actions: {
     resetData: () => {
       set({
@@ -99,28 +104,8 @@ export const useAgentStore = create<AgentStoreState>((set, get) => ({
       const result = isSuccess(response.status);
       if (result && response.data) {
         const agent = response.data;
-        const agentTempData: Omit<TAgentRequiredData, 'agentId'> = {
-          address: agent.address ?? undefined,
-          avatarLogo: agent.avatarLogo ?? undefined,
-          avatarUrl: agent.avatarUrl ?? undefined,
-          email: agent.email ?? undefined,
-          enabledChatBg: agent.enabledChatBg ?? undefined,
-          enabledPersonalKb: agent.enabledPersonalKb ?? undefined,
-          entId: agent.entId ? Number(agent.entId) : undefined,
-          entName: agent.entName ?? undefined,
-          greeting: agent.greeting ?? undefined,
-          mobile: agent.mobile ?? undefined,
-          name: agent.name ?? undefined,
-          personality: agent.personality ?? undefined,
-          position: agent.position ?? undefined,
-          qrCodeUrl: agent.qrCodeUrl ?? undefined,
-          questionGuides: agent.questionGuides ?? undefined,
-          voiceId: agent.voiceId ?? undefined,
-          voiceName: agent.voiceName ?? undefined,
-        };
         set({
           agent: agent,
-          agentTemp: agentTempData,
         });
 
         return response.data;
@@ -166,30 +151,33 @@ export const useAgentStore = create<AgentStoreState>((set, get) => ({
       }
       return null;
     },
-    saveAgent: async () => {
-      const { agent, agentTemp } = get();
+    saveAgent: async (agentFields = {} ) => {
+      const { agentEdit } = get();
 
       // 如果当前agent有agentId,则执行编辑操作
-      if (agent?.agentId) {
+      if (agentEdit?.agentId) {
         // 处理null值转换为undefined以符合TAgentRequiredData类型
+        const mixedAgent = {
+          ...agentEdit,
+          ...agentFields,
+        };
         const cleanAgent = {
-          ...agent,
-          address: agent.address ?? undefined,
-          email: agent.email ?? undefined,
-          entName: agent.entName ?? undefined,
-          mobile: agent.mobile ?? undefined,
-          name: agent.name ?? undefined,
-          position: agent.position ?? undefined,
-          qrCodeUrl: agent.qrCodeUrl ?? undefined,
-          avatarUrl: agent.avatarUrl ?? undefined,
-          avatarLogo: agent.avatarLogo ?? undefined,
-          entId: agent.entId ? Number(agent.entId) : undefined,
+          ...mixedAgent,
+          address: mixedAgent.address ?? undefined,
+          email: mixedAgent.email ?? undefined,
+          entName: mixedAgent.entName ?? undefined,
+          mobile: mixedAgent.mobile ?? undefined,
+          name: mixedAgent.name ?? undefined,
+          position: mixedAgent.position ?? undefined,
+          qrCodeUrl: mixedAgent.qrCodeUrl ?? undefined,
+          avatarUrl: mixedAgent.avatarUrl ?? undefined,
+          avatarLogo: mixedAgent.avatarLogo ?? undefined,
+          entId: mixedAgent.entId ? Number(mixedAgent.entId) : undefined,
         };
 
         const updateData: TAgentRequiredData = {
           ...cleanAgent,
-          ...agentTemp,
-          agentId: agent.agentId,
+          agentId: agentEdit.agentId,
         };
 
         const response = await _editAgent(updateData);
@@ -198,8 +186,6 @@ export const useAgentStore = create<AgentStoreState>((set, get) => ({
         if (result && response.data) {
           // 更新当前agent数据
           set({ agent: response.data });
-          // 清除临时数据
-          get().actions.clearAgentTemp();
           // 重新获取agents列表以更新缓存
           await get().actions.fetchAgents();
           return response.data;
@@ -207,11 +193,31 @@ export const useAgentStore = create<AgentStoreState>((set, get) => ({
         return null;
       } else {
         // 如果没有agentId,则创建新智能体
-        if (Object.keys(agentTemp).length === 0) {
+        if (!agentEdit) {
           return null;
         }
 
-        const response = await _createNewAgent(agentTemp);
+        const createData: Omit<TAgentRequiredData, 'agentId'> = {
+          address: agentEdit.address ?? undefined,
+          avatarLogo: agentEdit.avatarLogo ?? undefined,
+          avatarUrl: agentEdit.avatarUrl ?? undefined,
+          email: agentEdit.email ?? undefined,
+          enabledChatBg: agentEdit.enabledChatBg ?? undefined,
+          enabledPersonalKb: agentEdit.enabledPersonalKb ?? undefined,
+          entId: agentEdit.entId ? Number(agentEdit.entId) : undefined,
+          entName: agentEdit.entName ?? undefined,
+          greeting: agentEdit.greeting ?? undefined,
+          mobile: agentEdit.mobile ?? undefined,
+          name: agentEdit.name ?? undefined,
+          personality: agentEdit.personality ?? undefined,
+          position: agentEdit.position ?? undefined,
+          qrCodeUrl: agentEdit.qrCodeUrl ?? undefined,
+          questionGuides: agentEdit.questionGuides ?? undefined,
+          voiceId: agentEdit.voiceId ?? undefined,
+          voiceName: agentEdit.voiceName ?? undefined,
+        };
+
+        const response = await _createNewAgent(createData);
         const result = isSuccess(response.status);
 
         if (result && response.data) {
@@ -222,25 +228,21 @@ export const useAgentStore = create<AgentStoreState>((set, get) => ({
               agent: newAgent,
               defaultAgent: newAgent,
             }));
-            // 清除临时数据
-            get().actions.clearAgentTemp();
             return newAgent;
           }
         }
         return null;
       }
     },
-    updateAgentTemp: (updates: Partial<TAgentRequiredData>) => {
+    // 更新 agent 字段
+    updateEditAgent: async (updates: Partial<TAgentDetail>) => {
       set((state) => ({
-        agentTemp: {
-          ...state.agentTemp,
+        agentEdit: {
+          ...state.agentEdit,
           ...updates,
         },
       }));
     },
-    clearAgentTemp: () => {
-      set({ agentTemp: {} });
-    },
     // 编辑声音,人设,开场白,问题引导,知识库
     // deprecated
     editAgentCharacter: async (agentId: string, data: TEditAgentCharacter) => {
@@ -302,11 +304,30 @@ export const useAgentStore = create<AgentStoreState>((set, get) => ({
         }
       }
     },
-    clearMyAgent: () => {
+    setCurrentEditAvatar: (avatarItem) => {
+      set({
+        currentEditAvatar: avatarItem,
+      });
+    },
+    clearAgent: () => {
       set({
         agent: null,
       });
     },
+    fetchDefaultNewAgentInfo: async () => {
+      const response = await getNewAgentInfo()
+      if (isSuccess(response.status)) {
+        // set({
+        //   agentEdit: response.data,
+        // });
+      }
+      return response.data
+    },
+    clearEditAgent: async () => {
+      set({
+        agentEdit: null,
+      });
+    },
   }
 }));
 

+ 3 - 4
src/store/componentStore.ts

@@ -1,7 +1,6 @@
 import { create } from "zustand";
 import {
   editAgentWebsite as _editAgentWebsite,
-  editAgentAvatar,
   editAgentWebsite,
 } from "@/service/agent";
 import { TComponentItem } from "@/types/agent";
@@ -68,14 +67,14 @@ export const useComponentStore = create<ComponentState>((set, get) => ({
     set({ agentId, components: sorted, maxIndex: getMaxIndex(sorted) });
   },
   insertComponent: async (list: TComponentItem[]) => {
-    
+
     const insertIndex = get().insertIndex;
     let _components = get().components.sort(sortComponentsByIndex);
     console.log("current components list:", _components);
     const _componentsLen = _components.length;
 
     console.log("insertIndex:", insertIndex);
-    
+
     if (insertIndex === -1) {
       console.log("顶部插入");
       // 顶部插入, 原组件列表所有 index + list.length
@@ -189,7 +188,7 @@ export const useComponentStore = create<ComponentState>((set, get) => ({
       components: filtered,
     });
     set({loading: false})
-    
+
     if (isSuccess(status)) {
       set({ components: filtered });
       return true;