FileBs.tsx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import { AvatarIcon } from "@/components/bs-icons/avatar";
  2. import { WordIcon } from "@/components/bs-icons/office";
  3. import { checkSassUrl } from "@/pages/ChatAppPage/components/FileView";
  4. import { downloadFile } from "@/util/utils";
  5. import { useTranslation } from "react-i18next";
  6. import npcIcon from "../../../assets/npc/npcIcon.png";
  7. import nengliIcon from "../../../assets/npc/nengliIcon.png";
  8. import { TitleIconBg } from "../cardComponent";
  9. // 颜色列表
  10. const colorList = [
  11. "#666",
  12. "#FF5733",
  13. "#3498DB",
  14. "#27AE60",
  15. "#E74C3C",
  16. "#9B59B6",
  17. "#F1C40F",
  18. "#34495E",
  19. "#16A085",
  20. "#E67E22",
  21. "#95A5A6"
  22. ]
  23. export default function FileBs({ data,flow_type }) {
  24. const { t } = useTranslation()
  25. const avatarColor = colorList[(data.sender?.split('').reduce((num, s) => num + s.charCodeAt(), 0) || 0) % colorList.length]
  26. // download file
  27. const handleDownloadFile = (file) => {
  28. const url = file?.file_url
  29. url && downloadFile(checkSassUrl(url), file?.file_name)
  30. }
  31. return <div className="flex w-full py-1">
  32. <div className="w-fit min-h-8 rounded-2xl px-6 py-4 max-w-[90%]">
  33. {data.sender && <p className="text-primary text-xs mb-2" style={{ background: avatarColor }}>{data.sender}</p>}
  34. <div className="flex gap-2 ">
  35. {data.flow_id && <TitleIconBg className="w-[40px] h-[40px]" img={data.avatar_img} id={data.avatar_color ? data.avatar_color : data.flow_id} ><img src={data.avatar_img ? data.avatar_img : (flow_type == "assistant" ? npcIcon : nengliIcon)} alt="" /></TitleIconBg>}
  36. {/* <div className="w-6 h-6 min-w-6 flex justify-center items-center rounded-full" style={{ background: avatarColor }} ><AvatarIcon /></div> */}
  37. <div
  38. className="flex gap-2 w-52 shadow-sm bg-[#1a1a1a] px-4 py-2 rounded-sm cursor-pointer"
  39. onClick={() => handleDownloadFile(data.files[0])}
  40. >
  41. <div className="flex items-center text-[#43AFD2]"><WordIcon /></div>
  42. <div>
  43. <h1 className="text-sm font-bold text-[#43AFD2]">{data.files[0]?.file_name}</h1>
  44. <p className="text-xs text-[#666] mt-1">点击下载</p>
  45. </div>
  46. </div>
  47. </div>
  48. </div>
  49. </div>
  50. };