CollectionScreen.jsx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import * as WebBrowser from 'expo-web-browser';
  2. import * as React from 'react';
  3. import { Div, Button, Image, Text, Avatar } from 'react-native-magnus';
  4. import { ScrollView } from 'react-native-gesture-handler';
  5. import { useTranslation } from 'react-i18next';
  6. import { useRequest } from '@umijs/hooks';
  7. import useModel from 'flooks';
  8. import User from '../../flooks/User'; // detail模块通用方法
  9. import Header from '../../components/Header';
  10. import MerchantCom from '../Main/Home/MerchantCom';
  11. export default function CollectionScreen() {
  12. const { t } = useTranslation();
  13. const { id } = useModel(User, ['id']);
  14. const [Collection, setCollection] = React.useState([]);
  15. const CollectionRequest = useRequest(
  16. () => {
  17. const params = {
  18. query: {
  19. userId: id,
  20. page: 0,
  21. size: 100,
  22. },
  23. };
  24. const urls = Object.keys(params).map((item) => {
  25. return `${item}=${encodeURI(JSON.stringify(params[item]))}`;
  26. });
  27. return `/myCollection/all?${urls.join('&')}`;
  28. },
  29. {
  30. refreshDeps: [id],
  31. onSuccess: (result) => {
  32. setCollection(result.content || []);
  33. },
  34. }
  35. );
  36. return (
  37. <>
  38. <Header title={t('wo-de-shou-cang')} />
  39. <ScrollView
  40. contentContainerStyle={{ backgroundColor: '#fff', flexGrow: 1 }}
  41. >
  42. {Collection.length === 0 && (
  43. <Div p={10}>
  44. <Text color="gray300" textAlign="center">
  45. {t('zan-wu-shu-ju')}
  46. </Text>
  47. </Div>
  48. )}
  49. {Collection.map((item) => {
  50. return (
  51. <MerchantCom
  52. key={item.id}
  53. CollectionId={item.id}
  54. isCollection
  55. info={item.merchant}
  56. freash={CollectionRequest.run}
  57. />
  58. );
  59. })}
  60. </ScrollView>
  61. </>
  62. );
  63. }