index.tsx 927 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { View } from "@tarojs/components";
  2. import IconStarColor from "@/components/icon/icon-star-color";
  3. import { textPolishing } from '@/service/agent'
  4. import { isSuccess } from "@/utils";
  5. import Taro from "@tarojs/taro";
  6. interface Props {
  7. text: string;
  8. type: "personality" | "greeting"
  9. onPolished: (text:string|null) => void
  10. }
  11. const Index = ({
  12. text,
  13. type,
  14. onPolished
  15. }: Props) => {
  16. const handleClick = async () => {
  17. // console.log('请求服务端润色')
  18. Taro.showLoading()
  19. const response = await textPolishing({
  20. content: text,
  21. type: type
  22. })
  23. Taro.hideLoading()
  24. if(isSuccess(response.status)){
  25. onPolished(response.data?.content)
  26. }
  27. }
  28. return (
  29. <View className="flex items-center gap-4" onClick={handleClick}>
  30. <IconStarColor></IconStarColor>{" "}
  31. <View className="gradient-text">润色</View>
  32. </View>
  33. );
  34. };
  35. export default Index;