index.jsx 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import {Image, View} from '@tarojs/components';
  2. import cameraIcon from '@assets/goods/camera.svg';
  3. import classNames from 'classnames';
  4. import {usePreview} from './hooks';
  5. export default function Upload({files, onDelete, onAdd}) {
  6. const onClick = usePreview(files);
  7. return (
  8. <View className='my-3 bg-white px-4 py-2'>
  9. <View className='w-full grid grid-cols-3 gap-2'>
  10. {files.map(function(url, idx) {
  11. return (
  12. <View
  13. key={url}
  14. className='w-full pt-[100%] relative rounded-md overflow-hidden'
  15. >
  16. <View
  17. className={classNames(
  18. 'absolute top-0 left-0 right-0 bottom-0 bg-gray-200',
  19. 'flex justify-center items-center',
  20. 'bg-cover bg-no-repeat bg-center',
  21. )}
  22. style={{
  23. backgroundImage: `url(${url})`,
  24. }}
  25. onClick={onClick(idx)}
  26. onLongPress={onDelete(idx)}
  27. />
  28. </View>
  29. );
  30. })}
  31. <View className='w-full pt-[100%] relative rounded-md overflow-hidden'>
  32. <View
  33. className={classNames(
  34. 'absolute top-0 left-0 right-0 bottom-0 bg-gray-200',
  35. 'flex justify-center items-center',
  36. )}
  37. onClick={onAdd}
  38. >
  39. <Image src={cameraIcon} mode='widthFix' className='w-8' />
  40. </View>
  41. </View>
  42. </View>
  43. </View>
  44. );
  45. }