xref: /MusicFree/src/pages/home/components/drawer/index.tsx (revision 6bdd7a42b825ecb52ce59cdaf1e4f49f696710ae)
1359f51feS猫头猫import React, {memo} from 'react';
2*6bdd7a42S猫头猫import {StyleSheet, View, BackHandler} from 'react-native';
3bf6e62f2S猫头猫import rpx from '@/utils/rpx';
4bf6e62f2S猫头猫import {DrawerContentScrollView} from '@react-navigation/drawer';
51119c2eaS猫头猫import ListItem from '@/components/base/listItem';
6e7fa3837S猫头猫import {ROUTE_PATH, useNavigate} from '@/entry/router';
719dc08ecS猫头猫import ThemeText from '@/components/base/themeText';
819dc08ecS猫头猫import PageBackground from '@/components/base/pageBackground';
9c7676810S猫头猫import DeviceInfo from 'react-native-device-info';
109cd1998bS猫头猫import NativeUtils from '@/native/utils';
11e2257bd6S猫头猫import MusicQueue from '@/core/musicQueue';
12359f51feS猫头猫import {useTimingClose} from '@/utils/timingClose';
13c15039e2S猫头猫
14359f51feS猫头猫import timeformat from '@/utils/timeformat';
15c15039e2S猫头猫import {showPanel} from '@/components/panels/usePanel';
161119c2eaS猫头猫import Divider from '@/components/base/divider';
17bf6e62f2S猫头猫
18359f51feS猫头猫const ITEM_HEIGHT = rpx(108);
19f7a931fdS猫头猫function HomeDrawer(props: any) {
20e7fa3837S猫头猫    const navigate = useNavigate();
21bf6e62f2S猫头猫    function navigateToSetting(settingType: string) {
22e7fa3837S猫头猫        navigate(ROUTE_PATH.SETTING, {
23bf6e62f2S猫头猫            type: settingType,
24bf6e62f2S猫头猫        });
25bf6e62f2S猫头猫    }
263ee62d1bS猫头猫
273ee62d1bS猫头猫    const basicSetting = [
283ee62d1bS猫头猫        {
293ee62d1bS猫头猫            icon: 'cog-outline',
303ee62d1bS猫头猫            title: '基本设置',
313ee62d1bS猫头猫            onPress: () => {
323ee62d1bS猫头猫                navigateToSetting('basic');
333ee62d1bS猫头猫            },
343ee62d1bS猫头猫        },
353ee62d1bS猫头猫        {
363ee62d1bS猫头猫            icon: 'language-javascript',
373ee62d1bS猫头猫            title: '插件设置',
383ee62d1bS猫头猫            onPress: () => {
393ee62d1bS猫头猫                navigateToSetting('plugin');
403ee62d1bS猫头猫            },
413ee62d1bS猫头猫        },
423ee62d1bS猫头猫        {
433ee62d1bS猫头猫            icon: 'tshirt-v-outline',
443ee62d1bS猫头猫            title: '主题设置',
453ee62d1bS猫头猫            onPress: () => {
463ee62d1bS猫头猫                navigateToSetting('theme');
473ee62d1bS猫头猫            },
483ee62d1bS猫头猫        },
49359f51feS猫头猫    ] as const;
50359f51feS猫头猫
51359f51feS猫头猫    const otherSetting = [
523ee62d1bS猫头猫        {
533ee62d1bS猫头猫            icon: 'backup-restore',
543ee62d1bS猫头猫            title: '备份与恢复',
55dec7a5f8S猫头猫            onPress: () => {
56dec7a5f8S猫头猫                navigateToSetting('backup');
57dec7a5f8S猫头猫            },
583ee62d1bS猫头猫        },
590cffb46aS猫头猫        {
600cffb46aS猫头猫            icon: 'information-outline',
610cffb46aS猫头猫            title: '关于',
620cffb46aS猫头猫            onPress: () => {
630cffb46aS猫头猫                navigateToSetting('about');
640cffb46aS猫头猫            },
650cffb46aS猫头猫        },
663ee62d1bS猫头猫    ] as const;
673ee62d1bS猫头猫
68bf6e62f2S猫头猫    return (
6965fc5a50S猫头猫        <>
704060c00aS猫头猫            <PageBackground />
714060c00aS猫头猫            <DrawerContentScrollView {...[props]} style={style.scrollWrapper}>
72bf6e62f2S猫头猫                <View style={style.header}>
73dec7a5f8S猫头猫                    <ThemeText fontSize="appbar" fontWeight="bold">
74dec7a5f8S猫头猫                        {DeviceInfo.getApplicationName()}
75dec7a5f8S猫头猫                    </ThemeText>
76b882a19dS猫头猫                    {/* <IconButton icon={'qrcode-scan'} size={rpx(36)} /> */}
77bf6e62f2S猫头猫                </View>
781119c2eaS猫头猫                <View style={style.card}>
791119c2eaS猫头猫                    <ListItem withHorizonalPadding heightType="small">
801119c2eaS猫头猫                        <ListItem.ListItemText
811119c2eaS猫头猫                            fontSize="subTitle"
821119c2eaS猫头猫                            fontWeight="bold">
831119c2eaS猫头猫                            设置
841119c2eaS猫头猫                        </ListItem.ListItemText>
851119c2eaS猫头猫                    </ListItem>
863ee62d1bS猫头猫                    {basicSetting.map(item => (
87bf6e62f2S猫头猫                        <ListItem
881119c2eaS猫头猫                            withHorizonalPadding
89359f51feS猫头猫                            key={item.title}
901119c2eaS猫头猫                            onPress={item.onPress}>
911119c2eaS猫头猫                            <ListItem.ListItemIcon
921119c2eaS猫头猫                                icon={item.icon}
931119c2eaS猫头猫                                width={rpx(48)}
94359f51feS猫头猫                            />
951119c2eaS猫头猫                            <ListItem.Content title={item.title} />
961119c2eaS猫头猫                        </ListItem>
97359f51feS猫头猫                    ))}
981119c2eaS猫头猫                </View>
991119c2eaS猫头猫                <View style={style.card}>
1001119c2eaS猫头猫                    <ListItem withHorizonalPadding heightType="small">
1011119c2eaS猫头猫                        <ListItem.ListItemText
1021119c2eaS猫头猫                            fontSize="subTitle"
1031119c2eaS猫头猫                            fontWeight="bold">
1041119c2eaS猫头猫                            其他
1051119c2eaS猫头猫                        </ListItem.ListItemText>
1061119c2eaS猫头猫                    </ListItem>
107359f51feS猫头猫                    <CountDownItem />
108359f51feS猫头猫                    {otherSetting.map(item => (
109359f51feS猫头猫                        <ListItem
1101119c2eaS猫头猫                            withHorizonalPadding
1113ee62d1bS猫头猫                            key={item.title}
1121119c2eaS猫头猫                            onPress={item.onPress}>
1131119c2eaS猫头猫                            <ListItem.ListItemIcon
1141119c2eaS猫头猫                                icon={item.icon}
1151119c2eaS猫头猫                                width={rpx(48)}
1164060c00aS猫头猫                            />
1171119c2eaS猫头猫                            <ListItem.Content title={item.title} />
1181119c2eaS猫头猫                        </ListItem>
1193ee62d1bS猫头猫                    ))}
1201119c2eaS猫头猫                </View>
1211119c2eaS猫头猫
1221119c2eaS猫头猫                <Divider />
1231119c2eaS猫头猫                <ListItem
1241119c2eaS猫头猫                    withHorizonalPadding
125*6bdd7a42S猫头猫                    onPress={() => {
126*6bdd7a42S猫头猫                        // 仅安卓生效
127*6bdd7a42S猫头猫                        BackHandler.exitApp();
128*6bdd7a42S猫头猫                    }}>
129*6bdd7a42S猫头猫                    <ListItem.ListItemIcon icon={'home-outline'} width={rpx(48)} />
130*6bdd7a42S猫头猫                    <ListItem.Content title={'返回桌面'} />
131*6bdd7a42S猫头猫                </ListItem>
132*6bdd7a42S猫头猫                <ListItem
133*6bdd7a42S猫头猫                    withHorizonalPadding
134e2257bd6S猫头猫                    onPress={async () => {
135e2257bd6S猫头猫                        await MusicQueue.reset();
136e2257bd6S猫头猫                        NativeUtils.exitApp();
137bf6e62f2S猫头猫                    }}>
1381119c2eaS猫头猫                    <ListItem.ListItemIcon icon={'power'} width={rpx(48)} />
1391119c2eaS猫头猫                    <ListItem.Content title={'退出应用'} />
1401119c2eaS猫头猫                </ListItem>
141bf6e62f2S猫头猫            </DrawerContentScrollView>
14265fc5a50S猫头猫        </>
143bf6e62f2S猫头猫    );
144bf6e62f2S猫头猫}
145bf6e62f2S猫头猫
146f7a931fdS猫头猫export default memo(HomeDrawer, () => true);
147f7a931fdS猫头猫
148bf6e62f2S猫头猫const style = StyleSheet.create({
149bf6e62f2S猫头猫    wrapper: {
150bf6e62f2S猫头猫        flex: 1,
151bf6e62f2S猫头猫        backgroundColor: '#999999',
152bf6e62f2S猫头猫    },
153bf6e62f2S猫头猫    scrollWrapper: {
154bf6e62f2S猫头猫        paddingTop: rpx(12),
155bf6e62f2S猫头猫    },
156bf6e62f2S猫头猫
157bf6e62f2S猫头猫    header: {
15894b17902S猫头猫        height: rpx(120),
159bf6e62f2S猫头猫        width: '100%',
160bf6e62f2S猫头猫        flexDirection: 'row',
161bf6e62f2S猫头猫        justifyContent: 'space-between',
162bf6e62f2S猫头猫        alignItems: 'center',
16394b17902S猫头猫        marginLeft: rpx(24),
164bf6e62f2S猫头猫    },
165bf6e62f2S猫头猫    card: {
166359f51feS猫头猫        marginBottom: rpx(24),
167bf6e62f2S猫头猫    },
168dec7a5f8S猫头猫    cardContent: {
1694060c00aS猫头猫        paddingHorizontal: 0,
170dec7a5f8S猫头猫    },
1711119c2eaS猫头猫
172359f51feS猫头猫    /** 倒计时 */
173359f51feS猫头猫    countDownText: {
174359f51feS猫头猫        height: ITEM_HEIGHT,
175359f51feS猫头猫        textAlignVertical: 'center',
176359f51feS猫头猫    },
177bf6e62f2S猫头猫});
178359f51feS猫头猫
179359f51feS猫头猫function _CountDownItem() {
180359f51feS猫头猫    const countDown = useTimingClose();
181359f51feS猫头猫
182359f51feS猫头猫    return (
183359f51feS猫头猫        <ListItem
1841119c2eaS猫头猫            withHorizonalPadding
185359f51feS猫头猫            onPress={() => {
186359f51feS猫头猫                showPanel('TimingClose');
1871119c2eaS猫头猫            }}>
1881119c2eaS猫头猫            <ListItem.ListItemIcon icon="timer-outline" width={rpx(48)} />
1891119c2eaS猫头猫            <ListItem.Content title="定时关闭" />
1901119c2eaS猫头猫            <ListItem.ListItemText position="right" fontSize="subTitle">
191359f51feS猫头猫                {countDown ? timeformat(countDown) : ''}
1921119c2eaS猫头猫            </ListItem.ListItemText>
1931119c2eaS猫头猫        </ListItem>
194359f51feS猫头猫    );
195359f51feS猫头猫}
196359f51feS猫头猫
197359f51feS猫头猫const CountDownItem = memo(_CountDownItem, () => true);
198