xref: /MusicFree/src/pages/home/components/drawer/index.tsx (revision b4c389f44ac4dad056e7314478fadd2eca82a4b1)
1359f51feS猫头猫import React, {memo} from 'react';
25589cdf3S猫头猫import {BackHandler, Platform, StyleSheet, View} from 'react-native';
3bf6e62f2S猫头猫import rpx from '@/utils/rpx';
4bf6e62f2S猫头猫import {DrawerContentScrollView} from '@react-navigation/drawer';
51119c2eaS猫头猫import ListItem from '@/components/base/listItem';
6*b4c389f4Smaotoumaoimport {ROUTE_PATH, useNavigate} from '@/core/router';
719dc08ecS猫头猫import ThemeText from '@/components/base/themeText';
819dc08ecS猫头猫import PageBackground from '@/components/base/pageBackground';
9c7676810S猫头猫import DeviceInfo from 'react-native-device-info';
105589cdf3S猫头猫import deviceInfoModule from 'react-native-device-info';
119cd1998bS猫头猫import NativeUtils from '@/native/utils';
12359f51feS猫头猫import {useTimingClose} from '@/utils/timingClose';
13359f51feS猫头猫import timeformat from '@/utils/timeformat';
14c15039e2S猫头猫import {showPanel} from '@/components/panels/usePanel';
151119c2eaS猫头猫import Divider from '@/components/base/divider';
165500cea7S猫头猫import TrackPlayer from '@/core/trackPlayer';
176f73e807S猫头猫import {checkUpdateAndShowResult} from '@/hooks/useCheckUpdate.ts';
185589cdf3S猫头猫import {IIconName} from '@/components/base/icon.tsx';
19bf6e62f2S猫头猫
20359f51feS猫头猫const ITEM_HEIGHT = rpx(108);
215589cdf3S猫头猫
225589cdf3S猫头猫interface ISettingOptions {
235589cdf3S猫头猫    icon: IIconName;
245589cdf3S猫头猫    title: string;
255589cdf3S猫头猫    onPress?: () => void;
265589cdf3S猫头猫}
275589cdf3S猫头猫
28f7a931fdS猫头猫function HomeDrawer(props: any) {
29e7fa3837S猫头猫    const navigate = useNavigate();
30bf6e62f2S猫头猫    function navigateToSetting(settingType: string) {
31e7fa3837S猫头猫        navigate(ROUTE_PATH.SETTING, {
32bf6e62f2S猫头猫            type: settingType,
33bf6e62f2S猫头猫        });
34bf6e62f2S猫头猫    }
353ee62d1bS猫头猫
365589cdf3S猫头猫    const basicSetting: ISettingOptions[] = [
373ee62d1bS猫头猫        {
385589cdf3S猫头猫            icon: 'cog-8-tooth',
393ee62d1bS猫头猫            title: '基本设置',
403ee62d1bS猫头猫            onPress: () => {
413ee62d1bS猫头猫                navigateToSetting('basic');
423ee62d1bS猫头猫            },
433ee62d1bS猫头猫        },
443ee62d1bS猫头猫        {
455589cdf3S猫头猫            icon: 'javascript',
46b3a3a048S猫头猫            title: '插件管理',
473ee62d1bS猫头猫            onPress: () => {
483ee62d1bS猫头猫                navigateToSetting('plugin');
493ee62d1bS猫头猫            },
503ee62d1bS猫头猫        },
513ee62d1bS猫头猫        {
525589cdf3S猫头猫            icon: 't-shirt-outline',
533ee62d1bS猫头猫            title: '主题设置',
543ee62d1bS猫头猫            onPress: () => {
553ee62d1bS猫头猫                navigateToSetting('theme');
563ee62d1bS猫头猫            },
573ee62d1bS猫头猫        },
585589cdf3S猫头猫    ];
59359f51feS猫头猫
605589cdf3S猫头猫    const otherSetting: ISettingOptions[] = [
613ee62d1bS猫头猫        {
625589cdf3S猫头猫            icon: 'circle-stack',
633ee62d1bS猫头猫            title: '备份与恢复',
64dec7a5f8S猫头猫            onPress: () => {
65dec7a5f8S猫头猫                navigateToSetting('backup');
66dec7a5f8S猫头猫            },
673ee62d1bS猫头猫        },
6813cebe63S猫头猫    ];
6913cebe63S猫头猫
7013cebe63S猫头猫    if (Platform.OS === 'android') {
7113cebe63S猫头猫        otherSetting.push({
725589cdf3S猫头猫            icon: 'shield-keyhole-outline',
7309528755S猫头猫            title: '权限管理',
7409528755S猫头猫            onPress: () => {
7509528755S猫头猫                navigate(ROUTE_PATH.PERMISSIONS);
7609528755S猫头猫            },
7713cebe63S猫头猫        });
7813cebe63S猫头猫    }
793ee62d1bS猫头猫
80bf6e62f2S猫头猫    return (
8165fc5a50S猫头猫        <>
824060c00aS猫头猫            <PageBackground />
834060c00aS猫头猫            <DrawerContentScrollView {...[props]} style={style.scrollWrapper}>
84bf6e62f2S猫头猫                <View style={style.header}>
85dec7a5f8S猫头猫                    <ThemeText fontSize="appbar" fontWeight="bold">
86dec7a5f8S猫头猫                        {DeviceInfo.getApplicationName()}
87dec7a5f8S猫头猫                    </ThemeText>
88b882a19dS猫头猫                    {/* <IconButton icon={'qrcode-scan'} size={rpx(36)} /> */}
89bf6e62f2S猫头猫                </View>
901119c2eaS猫头猫                <View style={style.card}>
915589cdf3S猫头猫                    <ListItem withHorizontalPadding heightType="smallest">
921119c2eaS猫头猫                        <ListItem.ListItemText
931119c2eaS猫头猫                            fontSize="subTitle"
941119c2eaS猫头猫                            fontWeight="bold">
951119c2eaS猫头猫                            设置
961119c2eaS猫头猫                        </ListItem.ListItemText>
971119c2eaS猫头猫                    </ListItem>
983ee62d1bS猫头猫                    {basicSetting.map(item => (
99bf6e62f2S猫头猫                        <ListItem
1005589cdf3S猫头猫                            withHorizontalPadding
101359f51feS猫头猫                            key={item.title}
1021119c2eaS猫头猫                            onPress={item.onPress}>
1031119c2eaS猫头猫                            <ListItem.ListItemIcon
1041119c2eaS猫头猫                                icon={item.icon}
1051119c2eaS猫头猫                                width={rpx(48)}
106359f51feS猫头猫                            />
1071119c2eaS猫头猫                            <ListItem.Content title={item.title} />
1081119c2eaS猫头猫                        </ListItem>
109359f51feS猫头猫                    ))}
1101119c2eaS猫头猫                </View>
1111119c2eaS猫头猫                <View style={style.card}>
1125589cdf3S猫头猫                    <ListItem withHorizontalPadding heightType="smallest">
1131119c2eaS猫头猫                        <ListItem.ListItemText
1141119c2eaS猫头猫                            fontSize="subTitle"
1151119c2eaS猫头猫                            fontWeight="bold">
1161119c2eaS猫头猫                            其他
1171119c2eaS猫头猫                        </ListItem.ListItemText>
1181119c2eaS猫头猫                    </ListItem>
119359f51feS猫头猫                    <CountDownItem />
120359f51feS猫头猫                    {otherSetting.map(item => (
121359f51feS猫头猫                        <ListItem
1225589cdf3S猫头猫                            withHorizontalPadding
1233ee62d1bS猫头猫                            key={item.title}
1241119c2eaS猫头猫                            onPress={item.onPress}>
1251119c2eaS猫头猫                            <ListItem.ListItemIcon
1261119c2eaS猫头猫                                icon={item.icon}
1271119c2eaS猫头猫                                width={rpx(48)}
1284060c00aS猫头猫                            />
1291119c2eaS猫头猫                            <ListItem.Content title={item.title} />
1301119c2eaS猫头猫                        </ListItem>
1313ee62d1bS猫头猫                    ))}
1321119c2eaS猫头猫                </View>
1331119c2eaS猫头猫
134a22fe20fS猫头猫                <View style={style.card}>
1355589cdf3S猫头猫                    <ListItem withHorizontalPadding heightType="smallest">
136a22fe20fS猫头猫                        <ListItem.ListItemText
137a22fe20fS猫头猫                            fontSize="subTitle"
138a22fe20fS猫头猫                            fontWeight="bold">
139a22fe20fS猫头猫                            软件
140a22fe20fS猫头猫                        </ListItem.ListItemText>
141a22fe20fS猫头猫                    </ListItem>
142a22fe20fS猫头猫
143a22fe20fS猫头猫                    <ListItem
1445589cdf3S猫头猫                        withHorizontalPadding
145a22fe20fS猫头猫                        key={'update'}
146a22fe20fS猫头猫                        onPress={() => {
147a22fe20fS猫头猫                            checkUpdateAndShowResult(true);
148a22fe20fS猫头猫                        }}>
149a22fe20fS猫头猫                        <ListItem.ListItemIcon
1505589cdf3S猫头猫                            icon={'arrow-path'}
151a22fe20fS猫头猫                            width={rpx(48)}
152a22fe20fS猫头猫                        />
153a22fe20fS猫头猫                        <ListItem.Content title="检查更新" />
154a22fe20fS猫头猫                        <ListItem.ListItemText
155a22fe20fS猫头猫                            position="right"
156a22fe20fS猫头猫                            fontSize="subTitle">
1576f57784cS猫头猫                            {`当前版本: ${deviceInfoModule.getVersion()}`}
158a22fe20fS猫头猫                        </ListItem.ListItemText>
159a22fe20fS猫头猫                    </ListItem>
160a22fe20fS猫头猫                    <ListItem
1615589cdf3S猫头猫                        withHorizontalPadding
162a22fe20fS猫头猫                        key={'about'}
163a22fe20fS猫头猫                        onPress={() => {
164a22fe20fS猫头猫                            navigateToSetting('about');
165a22fe20fS猫头猫                        }}>
166a22fe20fS猫头猫                        <ListItem.ListItemIcon
1675589cdf3S猫头猫                            icon={'information-circle'}
168a22fe20fS猫头猫                            width={rpx(48)}
169a22fe20fS猫头猫                        />
170a22fe20fS猫头猫                        <ListItem.Content
171a22fe20fS猫头猫                            title={`关于 ${deviceInfoModule.getApplicationName()}`}
172a22fe20fS猫头猫                        />
173a22fe20fS猫头猫                    </ListItem>
174a22fe20fS猫头猫                </View>
175a22fe20fS猫头猫
1761119c2eaS猫头猫                <Divider />
1771119c2eaS猫头猫                <ListItem
1785589cdf3S猫头猫                    withHorizontalPadding
1796bdd7a42S猫头猫                    onPress={() => {
1806bdd7a42S猫头猫                        // 仅安卓生效
1816bdd7a42S猫头猫                        BackHandler.exitApp();
1826bdd7a42S猫头猫                    }}>
1830be848bcS猫头猫                    <ListItem.ListItemIcon
1840be848bcS猫头猫                        icon={'home-outline'}
1850be848bcS猫头猫                        width={rpx(48)}
1860be848bcS猫头猫                    />
1876bdd7a42S猫头猫                    <ListItem.Content title={'返回桌面'} />
1886bdd7a42S猫头猫                </ListItem>
1896bdd7a42S猫头猫                <ListItem
1905589cdf3S猫头猫                    withHorizontalPadding
191e2257bd6S猫头猫                    onPress={async () => {
1925500cea7S猫头猫                        await TrackPlayer.reset();
193e2257bd6S猫头猫                        NativeUtils.exitApp();
194bf6e62f2S猫头猫                    }}>
1955589cdf3S猫头猫                    <ListItem.ListItemIcon
1965589cdf3S猫头猫                        icon={'power-outline'}
1975589cdf3S猫头猫                        width={rpx(48)}
1985589cdf3S猫头猫                    />
1991119c2eaS猫头猫                    <ListItem.Content title={'退出应用'} />
2001119c2eaS猫头猫                </ListItem>
201bf6e62f2S猫头猫            </DrawerContentScrollView>
20265fc5a50S猫头猫        </>
203bf6e62f2S猫头猫    );
204bf6e62f2S猫头猫}
205bf6e62f2S猫头猫
206f7a931fdS猫头猫export default memo(HomeDrawer, () => true);
207f7a931fdS猫头猫
208bf6e62f2S猫头猫const style = StyleSheet.create({
209bf6e62f2S猫头猫    wrapper: {
210bf6e62f2S猫头猫        flex: 1,
211bf6e62f2S猫头猫        backgroundColor: '#999999',
212bf6e62f2S猫头猫    },
213bf6e62f2S猫头猫    scrollWrapper: {
214bf6e62f2S猫头猫        paddingTop: rpx(12),
215bf6e62f2S猫头猫    },
216bf6e62f2S猫头猫
217bf6e62f2S猫头猫    header: {
21894b17902S猫头猫        height: rpx(120),
219bf6e62f2S猫头猫        width: '100%',
220bf6e62f2S猫头猫        flexDirection: 'row',
221bf6e62f2S猫头猫        justifyContent: 'space-between',
222bf6e62f2S猫头猫        alignItems: 'center',
22394b17902S猫头猫        marginLeft: rpx(24),
224bf6e62f2S猫头猫    },
225bf6e62f2S猫头猫    card: {
226359f51feS猫头猫        marginBottom: rpx(24),
227bf6e62f2S猫头猫    },
228dec7a5f8S猫头猫    cardContent: {
2294060c00aS猫头猫        paddingHorizontal: 0,
230dec7a5f8S猫头猫    },
2311119c2eaS猫头猫
232359f51feS猫头猫    /** 倒计时 */
233359f51feS猫头猫    countDownText: {
234359f51feS猫头猫        height: ITEM_HEIGHT,
235359f51feS猫头猫        textAlignVertical: 'center',
236359f51feS猫头猫    },
237bf6e62f2S猫头猫});
238359f51feS猫头猫
239359f51feS猫头猫function _CountDownItem() {
240359f51feS猫头猫    const countDown = useTimingClose();
241359f51feS猫头猫
242359f51feS猫头猫    return (
243359f51feS猫头猫        <ListItem
2445589cdf3S猫头猫            withHorizontalPadding
245359f51feS猫头猫            onPress={() => {
246359f51feS猫头猫                showPanel('TimingClose');
2471119c2eaS猫头猫            }}>
2485589cdf3S猫头猫            <ListItem.ListItemIcon icon="alarm-outline" width={rpx(48)} />
2491119c2eaS猫头猫            <ListItem.Content title="定时关闭" />
2501119c2eaS猫头猫            <ListItem.ListItemText position="right" fontSize="subTitle">
251359f51feS猫头猫                {countDown ? timeformat(countDown) : ''}
2521119c2eaS猫头猫            </ListItem.ListItemText>
2531119c2eaS猫头猫        </ListItem>
254359f51feS猫头猫    );
255359f51feS猫头猫}
256359f51feS猫头猫
257359f51feS猫头猫const CountDownItem = memo(_CountDownItem, () => true);
258