index.tsx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import { MyIcon } from '@/global';
  2. import { HomeOutlined } from '@ant-design/icons';
  3. import { SelectLang as UmiSelectLang, useModel } from '@umijs/max';
  4. import { Button, Dropdown, MenuProps, Space, Tour } from 'antd';
  5. import { useEffect, useRef, useState } from 'react';
  6. import DraggableButton from '../DraggableButton';
  7. import MenuChange from '../MenuChange';
  8. export type SiderTheme = 'light' | 'dark';
  9. export const SelectLang = () => {
  10. return (
  11. <UmiSelectLang
  12. style={{
  13. padding: 4,
  14. }}
  15. />
  16. );
  17. };
  18. export const Question = () => {
  19. const { initialState, setInitialState } = useModel('@@initialState');
  20. const ref = useRef(null);
  21. const [open, setOpen] = useState<boolean>(false);
  22. useEffect(() => {
  23. let isOne = localStorage.getItem('isOne');
  24. if (!isOne && initialState?.menuType === 'miniApp' && !open) {
  25. console.log('111111');
  26. setOpen(true);
  27. }
  28. }, [initialState?.menuType, open]);
  29. const items: MenuProps['items'] = [
  30. // { key: "1", label: <Space><MyIcon type='icon-liangdu' />跟随系统</Space> },
  31. {
  32. key: '2',
  33. label: (
  34. <Space>
  35. <MyIcon type="icon-brightj2" />
  36. 亮色模式
  37. </Space>
  38. ),
  39. },
  40. {
  41. key: '3',
  42. label: (
  43. <Space>
  44. <MyIcon type="icon-yejing" />
  45. 暗色模式
  46. </Space>
  47. ),
  48. },
  49. ];
  50. const onClick: MenuProps['onClick'] = ({ key }: any) => {
  51. localStorage.setItem('navTheme', key);
  52. setInitialState({ ...initialState, navTheme: key } as any);
  53. };
  54. return (
  55. <Space size={[0, 0]}>
  56. <Dropdown menu={{ items, onClick }}>
  57. {initialState?.navTheme === '2' ? (
  58. <MyIcon type="icon-brightj2" />
  59. ) : (
  60. <MyIcon type="icon-yejing" />
  61. )}
  62. </Dropdown>
  63. {initialState?.menuType === 'miniApp' && (
  64. <DraggableButton ref={ref}>
  65. <MenuChange menuType="distributor" data={null}>
  66. <Button type="primary" shape="circle">
  67. <HomeOutlined />
  68. </Button>
  69. </MenuChange>
  70. </DraggableButton>
  71. )}
  72. <Tour
  73. open={open}
  74. onClose={() => {
  75. setOpen(false);
  76. localStorage.setItem('isOne', '1');
  77. }}
  78. steps={[
  79. {
  80. title: '返回主页',
  81. description: (
  82. <>
  83. {' '}
  84. <Button type="primary" shape="circle">
  85. <HomeOutlined />
  86. </Button>{' '}
  87. 可随意拖动位置,点击可从当前页面返回到分销商平台主页!
  88. </>
  89. ),
  90. target: () => ref.current,
  91. },
  92. ]}
  93. />
  94. </Space>
  95. );
  96. };