index.tsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. import React, { useState } from 'react'
  2. import styles from './index.module.scss'
  3. import { Radio } from 'antd'
  4. import { TextArea, Input, Button, Toast } from 'antd-mobile'
  5. import http from '@/utils/axios'
  6. const TYPE = ['回答不相关', '回答不完整', '答案错误', '无法回答问题', '其他']
  7. interface HelpImproveProps {
  8. question: string
  9. answer: string
  10. onClose: () => void
  11. }
  12. function HelpImprove({ question, answer, onClose }: HelpImproveProps) {
  13. const [type, setType] = useState<string>('')
  14. const [suggest, setSuggest] = useState<string>('')
  15. const [userName, setUserName] = useState<string>('')
  16. const [phone, setPhone] = useState<string>('')
  17. const [isSubmitting, setIsSubmitting] = useState(false)
  18. const handleSubmit = async () => {
  19. if (!type) {
  20. Toast.show({
  21. icon: 'fail',
  22. content: '请选择反馈类型'
  23. })
  24. return
  25. }
  26. setIsSubmitting(true)
  27. try {
  28. const response = await http.post('/show/aiSave', {
  29. answer,
  30. phone,
  31. question,
  32. suggest,
  33. type,
  34. userName
  35. })
  36. if (response.code === 0) {
  37. Toast.show({
  38. icon: 'success',
  39. content: '提交成功'
  40. })
  41. onClose()
  42. }
  43. } catch (error) {
  44. console.error('提交失败:', error)
  45. } finally {
  46. setIsSubmitting(false)
  47. }
  48. }
  49. const handleCancel = () => {
  50. onClose()
  51. }
  52. return (
  53. <div className={styles.helpImprove}>
  54. <div className={styles.helpImproveContent}>
  55. <h3>AI问答反馈</h3>
  56. <div className={styles.helpImproveDialog}>
  57. <div>
  58. <span>原问题:</span>
  59. <p>{question}</p>
  60. </div>
  61. <div>
  62. <span>原回答:</span>
  63. <p>{answer}</p>
  64. </div>
  65. </div>
  66. <div className={styles.helpImproveType}>
  67. <p>反馈类型</p>
  68. <Radio.Group buttonStyle='outline' value={type} onChange={e => setType(e.target.value)}>
  69. {TYPE.map(item => (
  70. <Radio key={item} value={item}>
  71. {item}
  72. </Radio>
  73. ))}
  74. </Radio.Group>
  75. </div>
  76. <TextArea
  77. className={styles.helpImproveTextarea}
  78. placeholder='请输入您的建议,不超过200个字'
  79. maxLength={200}
  80. value={suggest}
  81. onChange={val => setSuggest(val)}
  82. />
  83. <div className={styles.helpImproveLine}>
  84. <label>您的称呼</label>
  85. <Input
  86. className={styles.helpImproveInput}
  87. placeholder='请输入内容,不超过20个字'
  88. maxLength={20}
  89. value={userName}
  90. onChange={val => setUserName(val)}
  91. />
  92. </div>
  93. <div className={styles.helpImproveLine}>
  94. <label>联系方式</label>
  95. <Input
  96. type='tel'
  97. className={styles.helpImproveInput}
  98. placeholder='请输入内容,不超过20个字'
  99. maxLength={20}
  100. value={phone}
  101. onChange={val => setPhone(val)}
  102. />
  103. </div>
  104. <div className={styles.helpImproveFooter}>
  105. <Button
  106. className={styles.helpImproveSubmit}
  107. onClick={handleSubmit}
  108. loading={isSubmitting}
  109. >
  110. 提交
  111. </Button>
  112. <Button className={styles.helpImproveCancel} onClick={handleCancel}>
  113. 取消
  114. </Button>
  115. </div>
  116. </div>
  117. </div>
  118. )
  119. }
  120. const MemoHelpImprove = React.memo(HelpImprove)
  121. export default MemoHelpImprove