index.tsx 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. import { useState } from "react";
  2. import { View } from "@tarojs/components";
  3. import style from "./index.module.less";
  4. import TagCertificated from "@/components/tag-certificated";
  5. import IconSwapBlack from "@/components/icon/icon-swap-black";
  6. import IconChatWhite from "@/components/icon/icon-chat-white";
  7. import IconQRCodeBlack from "@/components/icon/icon-qrcode-black";
  8. import IconSendBlack from "@/components/icon/icon-send-black";
  9. import IconEditBlack from "@/components/icon/icon-edit-black";
  10. import IconMoreBlack from "@/components/icon/IconMoreBlack";
  11. import ContactIcon from '@/components/ContactIcon'
  12. import { useIsLogin } from "@/xiaolanbenlib/hooks/data/useAuth";
  13. import AgentSwap from "../AgentSwap/index";
  14. import AgentQRCode from "../AgentQRcode/index";
  15. import SharePopup from "@/components/custom-share/SharePopup";
  16. import Taro from "@tarojs/taro";
  17. import PopupSheets from "@/components/popup/popup-sheets";
  18. import { useModalStore } from "@/store/modalStore";
  19. import { TAgentDetail } from "@/types/agent";
  20. import { useAgentStore } from "@/store/agentStore";
  21. import LoginPopup from "@/components/LoginPopup";
  22. interface IProps {
  23. agent: TAgentDetail,
  24. isVisitor: boolean, // 是否是访问他人智能体
  25. }
  26. export default ({agent, isVisitor}: IProps) => {
  27. const [showAgentSwap, setShowAgentSwap] = useState(false);
  28. const [showAgentQRcode, setShowAgentQRcode] = useState(false);
  29. const [showPopup, setShowPopup] = useState(false);
  30. const [showShare, setShowShare] = useState(false);
  31. const [showLogin, setShowLogin] = useState(false);
  32. const { deleteAgent } = useAgentStore()
  33. const {showModal,} = useModalStore()
  34. const isLogin = useIsLogin();
  35. const handleClick = ()=> {
  36. // 如果是未登录状态下想要去聊天, 则弹窗登录
  37. if(!isLogin){
  38. return setShowLogin(true);
  39. }
  40. // 如果是已经下线的智能体,显示提示信息
  41. if(agent.status === 'deleted'){
  42. showModal({
  43. content: <View className="w-200">{agent.deletedTip}</View>,
  44. showCancelButton: false,
  45. onConfirm() {
  46. Taro.showTabBar().catch(()=> {});
  47. },
  48. onCancel() {
  49. Taro.showTabBar().catch(()=> {});
  50. },
  51. })
  52. return
  53. }
  54. Taro.navigateTo({
  55. url: `/pages/chat/index?agentId=${agent.agentId}&isVisitor=${isVisitor}`,
  56. });
  57. }
  58. const confirmDelete = async () => {
  59. if(agent?.agentId){
  60. await deleteAgent(agent.agentId)
  61. }
  62. }
  63. const renderValue = (value?: string | null)=> {
  64. return value?.length ? value : '-'
  65. }
  66. // 允许更多操作,非企业智能体且非访问者身份
  67. const enableMoreAction = !agent?.isEnt && !isVisitor
  68. // 是自己的智能体或者有二维码地址
  69. const enableQrcode = !isVisitor || !!agent?.qrCodeUrl?.length
  70. return (
  71. <View className="relative w-full">
  72. <View className={style.topBarContainer}>
  73. <View className={style.topBar}>
  74. <View className="px-8 mb-16">
  75. <View className="flex items-start mb-24">
  76. <View className="flex flex-col flex-1">
  77. <View className="flex items-end gap-8">
  78. <View className="text-24 font-medium leading-32 truncate max-w-180">{agent?.name}</View>
  79. <View className="text-12 leading-20">{agent?.position ?? ''}</View>
  80. </View>
  81. <View className="flex items-center gap-2">
  82. <View className="text-12 leading-20 truncate max-w-[188px]">
  83. {agent?.entName ?? '暂未填写企业'}
  84. </View>
  85. {agent?.isEnt && <TagCertificated />}
  86. </View>
  87. </View>
  88. {!isVisitor && <View
  89. className={style.boxButton}
  90. onClick={() => {
  91. setShowAgentSwap(true);
  92. }}
  93. >
  94. <IconSwapBlack />
  95. </View>}
  96. </View>
  97. <View className="flex items-center gap-8">
  98. {/* 和TA聊聊 */}
  99. <View className="flex-1">
  100. <View
  101. className="button-rounded button-primary"
  102. onClick={handleClick}
  103. >
  104. <IconChatWhite />
  105. 和TA聊聊
  106. </View>
  107. </View>
  108. {/* 二维码 */}
  109. {enableQrcode && <View
  110. className={style.boxButton}
  111. onClick={() => {
  112. setShowAgentQRcode(true);
  113. }}
  114. >
  115. <IconQRCodeBlack />
  116. </View>}
  117. {/* 智能体分享 */}
  118. <View
  119. className={style.boxButton}
  120. onClick={() => {
  121. setShowShare(true);
  122. }}
  123. >
  124. <IconSendBlack />
  125. </View>
  126. {/* 编辑智能体 */}
  127. {!isVisitor && <View
  128. className={style.boxButton}
  129. onClick={() => {
  130. Taro.navigateTo({ url: `/pages/agent/index?agentId=${agent?.agentId}` });
  131. }}
  132. >
  133. <IconEditBlack />
  134. </View>}
  135. {/* 更多操作 */}
  136. {enableMoreAction && <View className={style.boxButton} onClick={()=> {
  137. setShowPopup(true)
  138. }}>
  139. <IconMoreBlack />
  140. </View>}
  141. </View>
  142. </View>
  143. <View className="rounded-12 bg-white p-20">
  144. <View className="text-14 leading-22 font-medium border-b border-b-gray h-34 mb-22">
  145. 联系方式
  146. </View>
  147. <View className="flex flex-col gap-20 text-12 leading-20">
  148. <View className="flex items-center gap-12">
  149. <ContactIcon type="phone" actived={!!agent?.mobile}/>
  150. <View>{renderValue(agent?.mobile)}</View>
  151. </View>
  152. <View className="flex items-center gap-12">
  153. <ContactIcon type="mail" actived={!!agent?.email}/>
  154. <View>{renderValue(agent?.email)}</View>
  155. </View>
  156. <View className="flex items-center gap-12">
  157. <ContactIcon type="location" actived={!!agent?.address}/>
  158. <View>{renderValue(agent?.address)}</View>
  159. </View>
  160. </View>
  161. </View>
  162. </View>
  163. </View>
  164. {/* 切换智能体弹窗 */}
  165. {!isVisitor && <AgentSwap show={showAgentSwap} setShow={setShowAgentSwap}></AgentSwap>}
  166. {/* 二维码弹窗 */}
  167. <AgentQRCode isVisitor={isVisitor} show={showAgentQRcode} setShow={setShowAgentQRcode} />
  168. {/* 分享弹窗 */}
  169. {agent && <SharePopup
  170. show={showShare}
  171. setShow={setShowShare}
  172. agent={agent}
  173. ></SharePopup>}
  174. {/* 删除弹层 */}
  175. <PopupSheets
  176. setShow={setShowPopup}
  177. show={showPopup}
  178. content={[
  179. {item: <View className="text-12 font-normal text-gray-45">删除后所有数据将被清空,且无法恢复</View>},
  180. {item:'删除', type: 'warn', onClick: ()=> {
  181. setShowPopup(false);
  182. setTimeout(()=> {
  183. Taro.hideTabBar();
  184. },300)
  185. showModal({
  186. content: <>确认删除该智能体?</>,
  187. onConfirm() {
  188. confirmDelete()
  189. Taro.showTabBar().catch(()=> {});
  190. },
  191. onCancel() {
  192. Taro.showTabBar().catch(()=> {});
  193. },
  194. })
  195. }},
  196. ]}
  197. >
  198. </PopupSheets>
  199. {/* 登录弹窗 */}
  200. <LoginPopup showPopup={showLogin} setShowPopup={setShowLogin}></LoginPopup>
  201. </View>
  202. );
  203. };