xref: /MusicFree/src/pages/home/components/drawer/index.tsx (revision 1119c2ea435417cd5c53719f91691ff2b1aa8670)
1359f51feS猫头猫import React, {memo} from 'react';
2e2257bd6S猫头猫import {StyleSheet, View} from 'react-native';
3bf6e62f2S猫头猫import rpx from '@/utils/rpx';
4bf6e62f2S猫头猫import {DrawerContentScrollView} from '@react-navigation/drawer';
5*1119c2eaS猫头猫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';
16*1119c2eaS猫头猫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>
78*1119c2eaS猫头猫                <View style={style.card}>
79*1119c2eaS猫头猫                    <ListItem withHorizonalPadding heightType="small">
80*1119c2eaS猫头猫                        <ListItem.ListItemText
81*1119c2eaS猫头猫                            fontSize="subTitle"
82*1119c2eaS猫头猫                            fontWeight="bold">
83*1119c2eaS猫头猫                            设置
84*1119c2eaS猫头猫                        </ListItem.ListItemText>
85*1119c2eaS猫头猫                    </ListItem>
863ee62d1bS猫头猫                    {basicSetting.map(item => (
87bf6e62f2S猫头猫                        <ListItem
88*1119c2eaS猫头猫                            withHorizonalPadding
89359f51feS猫头猫                            key={item.title}
90*1119c2eaS猫头猫                            onPress={item.onPress}>
91*1119c2eaS猫头猫                            <ListItem.ListItemIcon
92*1119c2eaS猫头猫                                icon={item.icon}
93*1119c2eaS猫头猫                                width={rpx(48)}
94359f51feS猫头猫                            />
95*1119c2eaS猫头猫                            <ListItem.Content title={item.title} />
96*1119c2eaS猫头猫                        </ListItem>
97359f51feS猫头猫                    ))}
98*1119c2eaS猫头猫                </View>
99*1119c2eaS猫头猫                <View style={style.card}>
100*1119c2eaS猫头猫                    <ListItem withHorizonalPadding heightType="small">
101*1119c2eaS猫头猫                        <ListItem.ListItemText
102*1119c2eaS猫头猫                            fontSize="subTitle"
103*1119c2eaS猫头猫                            fontWeight="bold">
104*1119c2eaS猫头猫                            其他
105*1119c2eaS猫头猫                        </ListItem.ListItemText>
106*1119c2eaS猫头猫                    </ListItem>
107359f51feS猫头猫                    <CountDownItem />
108359f51feS猫头猫                    {otherSetting.map(item => (
109359f51feS猫头猫                        <ListItem
110*1119c2eaS猫头猫                            withHorizonalPadding
1113ee62d1bS猫头猫                            key={item.title}
112*1119c2eaS猫头猫                            onPress={item.onPress}>
113*1119c2eaS猫头猫                            <ListItem.ListItemIcon
114*1119c2eaS猫头猫                                icon={item.icon}
115*1119c2eaS猫头猫                                width={rpx(48)}
1164060c00aS猫头猫                            />
117*1119c2eaS猫头猫                            <ListItem.Content title={item.title} />
118*1119c2eaS猫头猫                        </ListItem>
1193ee62d1bS猫头猫                    ))}
120*1119c2eaS猫头猫                </View>
121*1119c2eaS猫头猫
122*1119c2eaS猫头猫                <Divider />
123*1119c2eaS猫头猫                <ListItem
124*1119c2eaS猫头猫                    withHorizonalPadding
125e2257bd6S猫头猫                    onPress={async () => {
126e2257bd6S猫头猫                        await MusicQueue.reset();
127e2257bd6S猫头猫                        NativeUtils.exitApp();
128bf6e62f2S猫头猫                    }}>
129*1119c2eaS猫头猫                    <ListItem.ListItemIcon icon={'power'} width={rpx(48)} />
130*1119c2eaS猫头猫                    <ListItem.Content title={'退出应用'} />
131*1119c2eaS猫头猫                </ListItem>
132bf6e62f2S猫头猫            </DrawerContentScrollView>
13365fc5a50S猫头猫        </>
134bf6e62f2S猫头猫    );
135bf6e62f2S猫头猫}
136bf6e62f2S猫头猫
137f7a931fdS猫头猫export default memo(HomeDrawer, () => true);
138f7a931fdS猫头猫
139bf6e62f2S猫头猫const style = StyleSheet.create({
140bf6e62f2S猫头猫    wrapper: {
141bf6e62f2S猫头猫        flex: 1,
142bf6e62f2S猫头猫        backgroundColor: '#999999',
143bf6e62f2S猫头猫    },
144bf6e62f2S猫头猫    scrollWrapper: {
145bf6e62f2S猫头猫        paddingTop: rpx(12),
146bf6e62f2S猫头猫    },
147bf6e62f2S猫头猫
148bf6e62f2S猫头猫    header: {
14994b17902S猫头猫        height: rpx(120),
150bf6e62f2S猫头猫        width: '100%',
151bf6e62f2S猫头猫        flexDirection: 'row',
152bf6e62f2S猫头猫        justifyContent: 'space-between',
153bf6e62f2S猫头猫        alignItems: 'center',
15494b17902S猫头猫        marginLeft: rpx(24),
155bf6e62f2S猫头猫    },
156bf6e62f2S猫头猫    card: {
157bf6e62f2S猫头猫        backgroundColor: '#eeeeee22',
158359f51feS猫头猫        marginBottom: rpx(24),
159bf6e62f2S猫头猫    },
160dec7a5f8S猫头猫    cardContent: {
1614060c00aS猫头猫        paddingHorizontal: 0,
162dec7a5f8S猫头猫    },
163*1119c2eaS猫头猫
164359f51feS猫头猫    /** 倒计时 */
165359f51feS猫头猫    countDownText: {
166359f51feS猫头猫        height: ITEM_HEIGHT,
167359f51feS猫头猫        textAlignVertical: 'center',
168359f51feS猫头猫    },
169bf6e62f2S猫头猫});
170359f51feS猫头猫
171359f51feS猫头猫function _CountDownItem() {
172359f51feS猫头猫    const countDown = useTimingClose();
173359f51feS猫头猫
174359f51feS猫头猫    return (
175359f51feS猫头猫        <ListItem
176*1119c2eaS猫头猫            withHorizonalPadding
177359f51feS猫头猫            onPress={() => {
178359f51feS猫头猫                showPanel('TimingClose');
179*1119c2eaS猫头猫            }}>
180*1119c2eaS猫头猫            <ListItem.ListItemIcon icon="timer-outline" width={rpx(48)} />
181*1119c2eaS猫头猫            <ListItem.Content title="定时关闭" />
182*1119c2eaS猫头猫            <ListItem.ListItemText position="right" fontSize="subTitle">
183359f51feS猫头猫                {countDown ? timeformat(countDown) : ''}
184*1119c2eaS猫头猫            </ListItem.ListItemText>
185*1119c2eaS猫头猫        </ListItem>
186359f51feS猫头猫    );
187359f51feS猫头猫}
188359f51feS猫头猫
189359f51feS猫头猫const CountDownItem = memo(_CountDownItem, () => true);
190