xref: /MusicFree/src/pages/home/components/drawer/index.tsx (revision a22fe20fec36f6663a9f0517917d68661349bfca)
1359f51feS猫头猫import React, {memo} from 'react';
26bdd7a42S猫头猫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';
11359f51feS猫头猫import {useTimingClose} from '@/utils/timingClose';
12359f51feS猫头猫import timeformat from '@/utils/timeformat';
13c15039e2S猫头猫import {showPanel} from '@/components/panels/usePanel';
141119c2eaS猫头猫import Divider from '@/components/base/divider';
155500cea7S猫头猫import TrackPlayer from '@/core/trackPlayer';
16*a22fe20fS猫头猫import deviceInfoModule from 'react-native-device-info';
17*a22fe20fS猫头猫import {checkUpdateAndShowResult} from '@/hooks/useCheckUpdate';
18bf6e62f2S猫头猫
19359f51feS猫头猫const ITEM_HEIGHT = rpx(108);
20f7a931fdS猫头猫function HomeDrawer(props: any) {
21e7fa3837S猫头猫    const navigate = useNavigate();
22bf6e62f2S猫头猫    function navigateToSetting(settingType: string) {
23e7fa3837S猫头猫        navigate(ROUTE_PATH.SETTING, {
24bf6e62f2S猫头猫            type: settingType,
25bf6e62f2S猫头猫        });
26bf6e62f2S猫头猫    }
273ee62d1bS猫头猫
283ee62d1bS猫头猫    const basicSetting = [
293ee62d1bS猫头猫        {
303ee62d1bS猫头猫            icon: 'cog-outline',
313ee62d1bS猫头猫            title: '基本设置',
323ee62d1bS猫头猫            onPress: () => {
333ee62d1bS猫头猫                navigateToSetting('basic');
343ee62d1bS猫头猫            },
353ee62d1bS猫头猫        },
363ee62d1bS猫头猫        {
373ee62d1bS猫头猫            icon: 'language-javascript',
38b3a3a048S猫头猫            title: '插件管理',
393ee62d1bS猫头猫            onPress: () => {
403ee62d1bS猫头猫                navigateToSetting('plugin');
413ee62d1bS猫头猫            },
423ee62d1bS猫头猫        },
433ee62d1bS猫头猫        {
443ee62d1bS猫头猫            icon: 'tshirt-v-outline',
453ee62d1bS猫头猫            title: '主题设置',
463ee62d1bS猫头猫            onPress: () => {
473ee62d1bS猫头猫                navigateToSetting('theme');
483ee62d1bS猫头猫            },
493ee62d1bS猫头猫        },
50359f51feS猫头猫    ] as const;
51359f51feS猫头猫
52359f51feS猫头猫    const otherSetting = [
533ee62d1bS猫头猫        {
543ee62d1bS猫头猫            icon: 'backup-restore',
553ee62d1bS猫头猫            title: '备份与恢复',
56dec7a5f8S猫头猫            onPress: () => {
57dec7a5f8S猫头猫                navigateToSetting('backup');
58dec7a5f8S猫头猫            },
593ee62d1bS猫头猫        },
603ee62d1bS猫头猫    ] as const;
613ee62d1bS猫头猫
62bf6e62f2S猫头猫    return (
6365fc5a50S猫头猫        <>
644060c00aS猫头猫            <PageBackground />
654060c00aS猫头猫            <DrawerContentScrollView {...[props]} style={style.scrollWrapper}>
66bf6e62f2S猫头猫                <View style={style.header}>
67dec7a5f8S猫头猫                    <ThemeText fontSize="appbar" fontWeight="bold">
68dec7a5f8S猫头猫                        {DeviceInfo.getApplicationName()}
69dec7a5f8S猫头猫                    </ThemeText>
70b882a19dS猫头猫                    {/* <IconButton icon={'qrcode-scan'} size={rpx(36)} /> */}
71bf6e62f2S猫头猫                </View>
721119c2eaS猫头猫                <View style={style.card}>
73*a22fe20fS猫头猫                    <ListItem withHorizonalPadding heightType="smallest">
741119c2eaS猫头猫                        <ListItem.ListItemText
751119c2eaS猫头猫                            fontSize="subTitle"
761119c2eaS猫头猫                            fontWeight="bold">
771119c2eaS猫头猫                            设置
781119c2eaS猫头猫                        </ListItem.ListItemText>
791119c2eaS猫头猫                    </ListItem>
803ee62d1bS猫头猫                    {basicSetting.map(item => (
81bf6e62f2S猫头猫                        <ListItem
821119c2eaS猫头猫                            withHorizonalPadding
83359f51feS猫头猫                            key={item.title}
841119c2eaS猫头猫                            onPress={item.onPress}>
851119c2eaS猫头猫                            <ListItem.ListItemIcon
861119c2eaS猫头猫                                icon={item.icon}
871119c2eaS猫头猫                                width={rpx(48)}
88359f51feS猫头猫                            />
891119c2eaS猫头猫                            <ListItem.Content title={item.title} />
901119c2eaS猫头猫                        </ListItem>
91359f51feS猫头猫                    ))}
921119c2eaS猫头猫                </View>
931119c2eaS猫头猫                <View style={style.card}>
94*a22fe20fS猫头猫                    <ListItem withHorizonalPadding heightType="smallest">
951119c2eaS猫头猫                        <ListItem.ListItemText
961119c2eaS猫头猫                            fontSize="subTitle"
971119c2eaS猫头猫                            fontWeight="bold">
981119c2eaS猫头猫                            其他
991119c2eaS猫头猫                        </ListItem.ListItemText>
1001119c2eaS猫头猫                    </ListItem>
101359f51feS猫头猫                    <CountDownItem />
102359f51feS猫头猫                    {otherSetting.map(item => (
103359f51feS猫头猫                        <ListItem
1041119c2eaS猫头猫                            withHorizonalPadding
1053ee62d1bS猫头猫                            key={item.title}
1061119c2eaS猫头猫                            onPress={item.onPress}>
1071119c2eaS猫头猫                            <ListItem.ListItemIcon
1081119c2eaS猫头猫                                icon={item.icon}
1091119c2eaS猫头猫                                width={rpx(48)}
1104060c00aS猫头猫                            />
1111119c2eaS猫头猫                            <ListItem.Content title={item.title} />
1121119c2eaS猫头猫                        </ListItem>
1133ee62d1bS猫头猫                    ))}
1141119c2eaS猫头猫                </View>
1151119c2eaS猫头猫
116*a22fe20fS猫头猫                <View style={style.card}>
117*a22fe20fS猫头猫                    <ListItem withHorizonalPadding heightType="smallest">
118*a22fe20fS猫头猫                        <ListItem.ListItemText
119*a22fe20fS猫头猫                            fontSize="subTitle"
120*a22fe20fS猫头猫                            fontWeight="bold">
121*a22fe20fS猫头猫                            软件
122*a22fe20fS猫头猫                        </ListItem.ListItemText>
123*a22fe20fS猫头猫                    </ListItem>
124*a22fe20fS猫头猫
125*a22fe20fS猫头猫                    <ListItem
126*a22fe20fS猫头猫                        withHorizonalPadding
127*a22fe20fS猫头猫                        key={'update'}
128*a22fe20fS猫头猫                        onPress={() => {
129*a22fe20fS猫头猫                            checkUpdateAndShowResult(true);
130*a22fe20fS猫头猫                        }}>
131*a22fe20fS猫头猫                        <ListItem.ListItemIcon
132*a22fe20fS猫头猫                            icon={'update'}
133*a22fe20fS猫头猫                            width={rpx(48)}
134*a22fe20fS猫头猫                        />
135*a22fe20fS猫头猫                        <ListItem.Content title="检查更新" />
136*a22fe20fS猫头猫                        <ListItem.ListItemText
137*a22fe20fS猫头猫                            position="right"
138*a22fe20fS猫头猫                            fontSize="subTitle">
139*a22fe20fS猫头猫                            {deviceInfoModule.getVersion()}
140*a22fe20fS猫头猫                        </ListItem.ListItemText>
141*a22fe20fS猫头猫                    </ListItem>
142*a22fe20fS猫头猫                    <ListItem
143*a22fe20fS猫头猫                        withHorizonalPadding
144*a22fe20fS猫头猫                        key={'about'}
145*a22fe20fS猫头猫                        onPress={() => {
146*a22fe20fS猫头猫                            navigateToSetting('about');
147*a22fe20fS猫头猫                        }}>
148*a22fe20fS猫头猫                        <ListItem.ListItemIcon
149*a22fe20fS猫头猫                            icon={'information-outline'}
150*a22fe20fS猫头猫                            width={rpx(48)}
151*a22fe20fS猫头猫                        />
152*a22fe20fS猫头猫                        <ListItem.Content
153*a22fe20fS猫头猫                            title={`关于 ${deviceInfoModule.getApplicationName()}`}
154*a22fe20fS猫头猫                        />
155*a22fe20fS猫头猫                    </ListItem>
156*a22fe20fS猫头猫                </View>
157*a22fe20fS猫头猫
1581119c2eaS猫头猫                <Divider />
1591119c2eaS猫头猫                <ListItem
1601119c2eaS猫头猫                    withHorizonalPadding
1616bdd7a42S猫头猫                    onPress={() => {
1626bdd7a42S猫头猫                        // 仅安卓生效
1636bdd7a42S猫头猫                        BackHandler.exitApp();
1646bdd7a42S猫头猫                    }}>
1650be848bcS猫头猫                    <ListItem.ListItemIcon
1660be848bcS猫头猫                        icon={'home-outline'}
1670be848bcS猫头猫                        width={rpx(48)}
1680be848bcS猫头猫                    />
1696bdd7a42S猫头猫                    <ListItem.Content title={'返回桌面'} />
1706bdd7a42S猫头猫                </ListItem>
1716bdd7a42S猫头猫                <ListItem
1726bdd7a42S猫头猫                    withHorizonalPadding
173e2257bd6S猫头猫                    onPress={async () => {
1745500cea7S猫头猫                        await TrackPlayer.reset();
175e2257bd6S猫头猫                        NativeUtils.exitApp();
176bf6e62f2S猫头猫                    }}>
1771119c2eaS猫头猫                    <ListItem.ListItemIcon icon={'power'} width={rpx(48)} />
1781119c2eaS猫头猫                    <ListItem.Content title={'退出应用'} />
1791119c2eaS猫头猫                </ListItem>
180bf6e62f2S猫头猫            </DrawerContentScrollView>
18165fc5a50S猫头猫        </>
182bf6e62f2S猫头猫    );
183bf6e62f2S猫头猫}
184bf6e62f2S猫头猫
185f7a931fdS猫头猫export default memo(HomeDrawer, () => true);
186f7a931fdS猫头猫
187bf6e62f2S猫头猫const style = StyleSheet.create({
188bf6e62f2S猫头猫    wrapper: {
189bf6e62f2S猫头猫        flex: 1,
190bf6e62f2S猫头猫        backgroundColor: '#999999',
191bf6e62f2S猫头猫    },
192bf6e62f2S猫头猫    scrollWrapper: {
193bf6e62f2S猫头猫        paddingTop: rpx(12),
194bf6e62f2S猫头猫    },
195bf6e62f2S猫头猫
196bf6e62f2S猫头猫    header: {
19794b17902S猫头猫        height: rpx(120),
198bf6e62f2S猫头猫        width: '100%',
199bf6e62f2S猫头猫        flexDirection: 'row',
200bf6e62f2S猫头猫        justifyContent: 'space-between',
201bf6e62f2S猫头猫        alignItems: 'center',
20294b17902S猫头猫        marginLeft: rpx(24),
203bf6e62f2S猫头猫    },
204bf6e62f2S猫头猫    card: {
205359f51feS猫头猫        marginBottom: rpx(24),
206bf6e62f2S猫头猫    },
207dec7a5f8S猫头猫    cardContent: {
2084060c00aS猫头猫        paddingHorizontal: 0,
209dec7a5f8S猫头猫    },
2101119c2eaS猫头猫
211359f51feS猫头猫    /** 倒计时 */
212359f51feS猫头猫    countDownText: {
213359f51feS猫头猫        height: ITEM_HEIGHT,
214359f51feS猫头猫        textAlignVertical: 'center',
215359f51feS猫头猫    },
216bf6e62f2S猫头猫});
217359f51feS猫头猫
218359f51feS猫头猫function _CountDownItem() {
219359f51feS猫头猫    const countDown = useTimingClose();
220359f51feS猫头猫
221359f51feS猫头猫    return (
222359f51feS猫头猫        <ListItem
2231119c2eaS猫头猫            withHorizonalPadding
224359f51feS猫头猫            onPress={() => {
225359f51feS猫头猫                showPanel('TimingClose');
2261119c2eaS猫头猫            }}>
2271119c2eaS猫头猫            <ListItem.ListItemIcon icon="timer-outline" width={rpx(48)} />
2281119c2eaS猫头猫            <ListItem.Content title="定时关闭" />
2291119c2eaS猫头猫            <ListItem.ListItemText position="right" fontSize="subTitle">
230359f51feS猫头猫                {countDown ? timeformat(countDown) : ''}
2311119c2eaS猫头猫            </ListItem.ListItemText>
2321119c2eaS猫头猫        </ListItem>
233359f51feS猫头猫    );
234359f51feS猫头猫}
235359f51feS猫头猫
236359f51feS猫头猫const CountDownItem = memo(_CountDownItem, () => true);
237