index.tsx 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import { View } from "@tarojs/components";
  2. import { More } from "@nutui/icons-react-taro";
  3. import { ActionSheet } from "@nutui/nutui-react-taro";
  4. import { useState } from "react";
  5. import { interactionApi } from "../../api/interaction";
  6. import { navigateTo } from "@tarojs/taro";
  7. export default function MoreButton({
  8. postIndex,
  9. followeeId,
  10. postId,
  11. postItem,
  12. onClick,
  13. }: {
  14. postIndex: number;
  15. followeeId: number;
  16. postId: number;
  17. postItem: any;
  18. onClick?: (postIndex: number) => void;
  19. }) {
  20. const [showMore, setShowMore] = useState(false);
  21. const moreOptions = [
  22. {
  23. name: "不喜欢该动态",
  24. value: "post_dislike",
  25. },
  26. {
  27. name: "不喜欢该作者",
  28. value: "author_dislike",
  29. },
  30. {
  31. name: "举报该动态",
  32. value: "post_report",
  33. },
  34. ];
  35. const handleSelectMore = (item: any) => {
  36. const { value } = item;
  37. if (value === "post_dislike") {
  38. interactionApi({
  39. target_type: "post",
  40. target_id: postId,
  41. interaction_type: "dislike",
  42. });
  43. onClick && onClick(postIndex);
  44. } else if (value === "author_dislike") {
  45. interactionApi({
  46. target_type: "author",
  47. target_id: followeeId,
  48. interaction_type: "dislike",
  49. });
  50. onClick && onClick(postIndex);
  51. } else if (value === "post_report") {
  52. navigateTo({
  53. url: `/pages/report/index?target_type=post&target_id=${postId}`,
  54. // events: {
  55. // onBack: (data) => console.log("返回数据:", data),
  56. // onUpdate: (data) => console.log("更新数据:", data),
  57. // },
  58. // success: function (res) {
  59. // // 通过eventChannel向被打开页面传送数据
  60. // console.log("===");
  61. // res.eventChannel.emit("init", postItem);
  62. // },
  63. });
  64. }
  65. setShowMore(false);
  66. };
  67. return (
  68. <>
  69. <View
  70. onClick={(e) => {
  71. e.stopPropagation();
  72. setShowMore(true);
  73. }}
  74. >
  75. <More size={12} color="#949494" />
  76. </View>
  77. <ActionSheet
  78. visible={showMore}
  79. cancelText="取消"
  80. options={moreOptions}
  81. onSelect={handleSelectMore}
  82. onCancel={() => {
  83. setShowMore(false);
  84. }}
  85. />
  86. </>
  87. );
  88. }