messageUtils.ts 1015 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { EContentType, TAnyMessage } from "@/types/bot";
  2. import Taro from "@tarojs/taro";
  3. export function formatMessageItem(item: TAnyMessage){
  4. if (item.contentType === EContentType.AiseekQA) {
  5. try {
  6. const contentJson = JSON.parse(item.content as string);
  7. item.content = contentJson.answer.text;
  8. // 把消息详情放入统一 body 中
  9. item.body = {
  10. ...item,
  11. content: contentJson,
  12. contentType: EContentType.AiseekQA,
  13. };
  14. } catch (e) {
  15. // console.error(e)
  16. }
  17. }
  18. return item;
  19. }
  20. export const handleCopy = (e: any, textStr: string) => {
  21. e.stopPropagation();
  22. // 手动复制并 toast 提示
  23. if (textStr) {
  24. Taro.setClipboardData({
  25. data: textStr,
  26. success() {
  27. Taro.showToast({
  28. title: "复制成功",
  29. icon: "none",
  30. });
  31. },
  32. fail(res) {
  33. console.log(res);
  34. Taro.showToast({
  35. title: "复制失败",
  36. icon: "none",
  37. });
  38. },
  39. });
  40. }
  41. };