index.tsx 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. import { useState } from "react";
  2. import { View, Text } 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 IconDelete from "@/components/icon/IconDelete";
  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 { useAgentStoreActions } 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, updateEditAgent } = useAgentStoreActions();
  33. const {showModal} = useModalStore((state) => state.actions);
  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();
  47. }
  48. })
  49. return
  50. }
  51. Taro.navigateTo({
  52. url: `/pages/chat/index?agentId=${agent.agentId}&isVisitor=${isVisitor}`,
  53. });
  54. }
  55. const handleEdit = ()=> {
  56. updateEditAgent(agent)
  57. Taro.navigateTo({ url: `/pages/agent/index?agentId=${agent?.agentId}` });
  58. }
  59. const confirmDelete = async () => {
  60. if(agent?.agentId){
  61. await deleteAgent(agent.agentId)
  62. }
  63. }
  64. const renderValue = (value: string | null | undefined, defaultValue: string)=> {
  65. return value?.length ? value : <Text className="text-12 text-black-50">{defaultValue}</Text>
  66. }
  67. // 允许删除操作,非企业智能体且非访问者身份
  68. const enableDeleteAction = !agent?.isEnt && !isVisitor
  69. // 是自己的智能体或者有二维码地址
  70. const enableQrcode = !isVisitor || !!agent?.qrCodeUrl?.length
  71. const handleDelete = ()=> {
  72. Taro.hideTabBar();
  73. showModal({
  74. content: <>确认删除该智能体?</>,
  75. onConfirm() {
  76. confirmDelete()
  77. }
  78. })
  79. }
  80. return (
  81. <View className="relative w-full">
  82. <View className={style.topBarContainer}>
  83. <View className={style.topBar}>
  84. <View className="px-8 mb-16">
  85. <View className="flex items-start mb-24">
  86. <View className="flex flex-col flex-1 gap-8">
  87. <View className="flex items-end gap-8">
  88. <View className="text-24 font-medium leading-22 truncate max-w-180">{agent?.name}</View>
  89. <View className="text-12 leading-20 text-black-60">{agent?.position ?? (isVisitor ? '' :'暂未填职业')}</View>
  90. </View>
  91. <View className="flex items-center gap-4">
  92. <View className="text-12 leading-20 text-black-60 truncate max-w-[188px]">
  93. {agent?.entName ?? (isVisitor ? '' :'暂未填写企业')}
  94. </View>
  95. {agent?.isEnt && <TagCertificated />}
  96. </View>
  97. </View>
  98. {!isVisitor && <View
  99. className={style.boxButton}
  100. onClick={() => {
  101. setShowAgentSwap(true);
  102. }}
  103. >
  104. <IconSwapBlack />
  105. </View>}
  106. </View>
  107. <View className="flex items-center gap-8">
  108. {/* 和TA聊聊 */}
  109. <View className="flex-1">
  110. <View
  111. className="button-rounded button-text-medium button-primary"
  112. onClick={handleClick}
  113. >
  114. <IconChatWhite />
  115. 和TA聊聊
  116. </View>
  117. </View>
  118. {/* 二维码 */}
  119. {enableQrcode && <View
  120. className={style.boxButton}
  121. onClick={() => {
  122. setShowAgentQRcode(true);
  123. }}
  124. >
  125. <IconQRCodeBlack />
  126. </View>}
  127. {/* 删除 */}
  128. {enableDeleteAction && <View className={style.boxButton} onClick={handleDelete}>
  129. <IconDelete color="black" />
  130. </View>}
  131. {/* 智能体分享 */}
  132. <View
  133. className={style.boxButton}
  134. onClick={() => {
  135. setShowShare(true);
  136. }}
  137. >
  138. <IconSendBlack />
  139. </View>
  140. {/* 编辑智能体 */}
  141. {!isVisitor && <View
  142. className={style.boxButton}
  143. onClick={handleEdit}
  144. >
  145. <IconEditBlack />
  146. </View>}
  147. </View>
  148. </View>
  149. {/* 联系方式 */}
  150. <View className="rounded-12 bg-white p-20">
  151. <View className="flex flex-col gap-20 text-12 leading-20">
  152. <View className="flex items-center gap-12">
  153. <ContactIcon type="phone" actived={!!agent?.mobile}/>
  154. <View>{renderValue(agent?.mobile, '暂未填写手机号')}</View>
  155. </View>
  156. <View className="flex items-center gap-12">
  157. <ContactIcon type="mail" actived={!!agent?.email}/>
  158. <View>{renderValue(agent?.email, '暂未填写邮箱')}</View>
  159. </View>
  160. <View className="flex items-center gap-12">
  161. <ContactIcon type="location" actived={!!agent?.address}/>
  162. <View>{renderValue(agent?.address, '暂未填写地址')}</View>
  163. </View>
  164. </View>
  165. </View>
  166. </View>
  167. </View>
  168. {/* 切换智能体弹窗 */}
  169. {!isVisitor && <AgentSwap show={showAgentSwap} setShow={setShowAgentSwap}></AgentSwap>}
  170. {/* 二维码弹窗 */}
  171. <AgentQRCode isVisitor={isVisitor} agent={agent} show={showAgentQRcode} setShow={setShowAgentQRcode} />
  172. {/* 分享弹窗 */}
  173. {agent && <SharePopup
  174. show={showShare}
  175. setShow={setShowShare}
  176. agent={agent}
  177. ></SharePopup>}
  178. {/* 删除弹层 */}
  179. {/* <PopupSheets
  180. setShow={setShowPopup}
  181. show={showPopup}
  182. content={[
  183. {item: <View className="text-12 font-normal text-gray-4">删除后所有数据将被清空,且无法恢复</View>},
  184. {item:'删除', type: 'warn'},
  185. ]}
  186. >
  187. </PopupSheets> */}
  188. {/* 登录弹窗 */}
  189. <LoginPopup showPopup={showLogin} setShowPopup={setShowLogin}></LoginPopup>
  190. </View>
  191. );
  192. };