index.tsx 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import { View, Image } from "@tarojs/components"
  2. import { TSocialMediaItem } from '@/types/index'
  3. import style from './index.module.less'
  4. import Taro from "@tarojs/taro"
  5. import closeIcon from '@/images/icon-close-8.png';
  6. import IconCorrect from '@/images/svgs/website/IconCorrect.svg'
  7. import Popup from "@/components/popup/popup";
  8. interface Props {
  9. setShow: (show: boolean)=>void
  10. show: boolean,
  11. link: string,
  12. mediaItem: TSocialMediaItem,
  13. }
  14. export default ({show, setShow, link, mediaItem}:Props)=> {
  15. let iconClassName = `${mediaItem.className}`
  16. let title = mediaItem.label
  17. const handleCopy = (e: any)=> {
  18. e.stopPropagation();
  19. // 手动复制并 toast 提示
  20. if(link){
  21. Taro.setClipboardData({
  22. data: link,
  23. success(){
  24. Taro.showToast({
  25. title: '复制成功',
  26. icon: 'none'
  27. })
  28. },fail(res) {
  29. console.log(res)
  30. Taro.showToast({
  31. title: '复制失败',
  32. icon: 'none'
  33. })
  34. },
  35. })
  36. }
  37. }
  38. // 默认打开就复制
  39. if(show){
  40. Taro.setClipboardData({
  41. data: link,
  42. success(){
  43. Taro.hideToast();
  44. },
  45. })
  46. }
  47. return <Popup
  48. show={show}
  49. setShow={setShow}
  50. >
  51. <View className={style.container}>
  52. <View className={style.content}>
  53. <View className={style.iconCorrect}>
  54. <Image src={IconCorrect} className="w-28 h-40"></Image>
  55. </View>
  56. <View className="text-center text-black leading-32 font-medium text-24">链接已复制</View>
  57. <View className={style.copyTips}>复制内容到浏览器或使用对应软件搜索</View>
  58. <View className={style.linkRow}>
  59. <View className={`${style.logo} ${iconClassName}`}></View>
  60. <View className={style.infoRow}>
  61. <View className={style.title}>{title}</View>
  62. <View className={style.link}>{link}</View>
  63. </View>
  64. <View className={style.copyButton} onClick={handleCopy}>复制链接</View>
  65. </View>
  66. </View>
  67. </View>
  68. </Popup>
  69. }