index.tsx 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. import { Text, View } from "@tarojs/components";
  2. import { postDetailApi, reportApi } from "../../api/post";
  3. import {
  4. showToast,
  5. navigateBack,
  6. useDidShow,
  7. getCurrentInstance,
  8. } from "@tarojs/taro";
  9. import { useState } from "react";
  10. import "./index.scss";
  11. import {
  12. Button,
  13. Col,
  14. Form,
  15. FormItem,
  16. Image,
  17. Radio,
  18. Row,
  19. TextArea,
  20. NavBar,
  21. } from "@nutui/nutui-react-taro";
  22. import { ArrowLeft } from "@nutui/icons-react-taro";
  23. const Report = () => {
  24. const [form] = Form.useForm();
  25. const reportType = Form.useWatch("report_type", form);
  26. const [postData, setPostData] = useState<any>(null);
  27. useDidShow(() => {
  28. const { target_type, target_id } =
  29. getCurrentInstance()?.router?.params || {};
  30. if (target_type === "post") {
  31. getPostDetail(Number(target_id));
  32. }
  33. });
  34. // 获取帖子详情
  35. const getPostDetail = (target_id: number) => {
  36. postDetailApi({ id: target_id }).then((res: any) => {
  37. if (res.code === 200) {
  38. setPostData(res.data);
  39. }
  40. });
  41. };
  42. // 提交
  43. const submit = () => {
  44. const params = form.getFieldsValue(true);
  45. if (params.report_type === "9") {
  46. if (!params.reason) {
  47. showToast({ title: "请输入理由", icon: "none" });
  48. return;
  49. }
  50. }
  51. params.target_type = "post";
  52. params.target_id = postData.id;
  53. reportApi(params).then((res: any) => {
  54. if (res.code === 200) {
  55. showToast({ title: "举报成功", icon: "success" });
  56. setTimeout(() => {
  57. navigateBack();
  58. }, 1500);
  59. }
  60. });
  61. };
  62. return (
  63. <>
  64. <NavBar
  65. back={
  66. <>
  67. <ArrowLeft />
  68. 返回
  69. </>
  70. }
  71. onBackClick={(e) => {
  72. e.preventDefault();
  73. navigateBack({ delta: 1 });
  74. }}
  75. >
  76. 举报
  77. </NavBar>
  78. <View className="p-[10px] report">
  79. {postData ? (
  80. <>
  81. <View className="text-[14px] text-[#333]">
  82. 举报{" "}
  83. <Text className="text-[#595cab]">
  84. {" "}
  85. @{postData.user.nickname || postData.user.username}
  86. </Text>{" "}
  87. 的动态
  88. </View>
  89. <View className="p-[10px] mt-[15px] flex items-start bg-[#f4f4f4] rounded-[10px]">
  90. <Image
  91. height="70"
  92. width="70"
  93. className="mr-[10px] rounded-[20px] bg-[#595cab]"
  94. src={postData.media_url[0].src}
  95. ></Image>
  96. <View className="text-[14px] text-[#807b83]">
  97. <Text className="text-[#595cab]">
  98. {" "}
  99. @{postData.user.nickname || postData.user.username}
  100. </Text>
  101. {":"}
  102. {postData.content}
  103. </View>
  104. </View>
  105. <Form form={form} onFinish={() => submit()}>
  106. <View className="mt-[15px]">
  107. <Text className="text-[20px] font-[800] text-[#333]">
  108. 举报理由
  109. </Text>
  110. <View className="mt-[10px]">
  111. <FormItem name="report_type">
  112. <Radio.Group>
  113. <Row>
  114. <Col span={12} className="nut-grid-square">
  115. <Radio value="1" className="radio-item">
  116. 人身攻击
  117. </Radio>
  118. </Col>
  119. <Col span={12} className="nut-grid-square">
  120. <Radio value="2" className="radio-item">
  121. 淫秽色情
  122. </Radio>
  123. </Col>
  124. <Col span={12} className="nut-grid-square">
  125. <Radio value="3" className="radio-item">
  126. 违法信息
  127. </Radio>
  128. </Col>
  129. <Col span={12} className="nut-grid-square">
  130. <Radio value="4" className="radio-item">
  131. 有害信息
  132. </Radio>
  133. </Col>
  134. <Col span={12} className="nut-grid-square">
  135. <Radio value="5" className="radio-item">
  136. 垃圾广告
  137. </Radio>
  138. </Col>
  139. <Col span={12} className="nut-grid-square">
  140. <Radio value="6" className="radio-item">
  141. 侵权抄袭
  142. </Radio>
  143. </Col>
  144. <Col span={12} className="nut-grid-square">
  145. <Radio value="7" className="radio-item">
  146. 诈骗
  147. </Radio>
  148. </Col>
  149. <Col span={12} className="nut-grid-square">
  150. <Radio value="8" className="radio-item">
  151. 未成年人相关举报
  152. </Radio>
  153. </Col>
  154. <Col span={12} className="nut-grid-square">
  155. <Radio value="9" className="radio-item">
  156. 其他
  157. </Radio>
  158. </Col>
  159. </Row>
  160. </Radio.Group>
  161. </FormItem>
  162. </View>
  163. {reportType === "9" && (
  164. <>
  165. <FormItem name="reason">
  166. <TextArea
  167. placeholder="请输入理由(必填)"
  168. className="textarea-item"
  169. onChange={(value) => console.log("change", value)}
  170. onBlur={() => console.log("blur")}
  171. onFocus={() => console.log("focus")}
  172. />
  173. </FormItem>
  174. </>
  175. )}
  176. </View>
  177. <FormItem>
  178. <Button
  179. block
  180. type="primary"
  181. disabled={!reportType}
  182. onClick={() => form.submit()}
  183. >
  184. 提交
  185. </Button>
  186. </FormItem>
  187. </Form>
  188. </>
  189. ) : (
  190. <></>
  191. )}
  192. </View>
  193. </>
  194. );
  195. };
  196. export default Report;