xref: /MusicFree/src/pages/home/components/drawer/index.tsx (revision 359f51fe6c368c70b4395826d20fdba838ef884b)
1*359f51feS猫头猫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';
5b882a19dS猫头猫import {Button, Card} from 'react-native-paper';
619dc08ecS猫头猫import ListItem from '@/components/base/listItem';
7e7fa3837S猫头猫import {ROUTE_PATH, useNavigate} from '@/entry/router';
819dc08ecS猫头猫import ThemeText from '@/components/base/themeText';
919dc08ecS猫头猫import PageBackground from '@/components/base/pageBackground';
10c7676810S猫头猫import DeviceInfo from 'react-native-device-info';
119cd1998bS猫头猫import NativeUtils from '@/native/utils';
12e2257bd6S猫头猫import MusicQueue from '@/core/musicQueue';
13*359f51feS猫头猫import {useTimingClose} from '@/utils/timingClose';
14*359f51feS猫头猫import usePanel from '@/components/panels/usePanel';
15*359f51feS猫头猫import timeformat from '@/utils/timeformat';
16bf6e62f2S猫头猫
17*359f51feS猫头猫const ITEM_HEIGHT = rpx(108);
184060c00aS猫头猫export default function HomeDrawer(props: any) {
19e7fa3837S猫头猫    const navigate = useNavigate();
20bf6e62f2S猫头猫    function navigateToSetting(settingType: string) {
21e7fa3837S猫头猫        navigate(ROUTE_PATH.SETTING, {
22bf6e62f2S猫头猫            type: settingType,
23bf6e62f2S猫头猫        });
24bf6e62f2S猫头猫    }
253ee62d1bS猫头猫
263ee62d1bS猫头猫    const basicSetting = [
273ee62d1bS猫头猫        {
283ee62d1bS猫头猫            icon: 'cog-outline',
293ee62d1bS猫头猫            title: '基本设置',
303ee62d1bS猫头猫            onPress: () => {
313ee62d1bS猫头猫                navigateToSetting('basic');
323ee62d1bS猫头猫            },
333ee62d1bS猫头猫        },
343ee62d1bS猫头猫        {
353ee62d1bS猫头猫            icon: 'language-javascript',
363ee62d1bS猫头猫            title: '插件设置',
373ee62d1bS猫头猫            onPress: () => {
383ee62d1bS猫头猫                navigateToSetting('plugin');
393ee62d1bS猫头猫            },
403ee62d1bS猫头猫        },
413ee62d1bS猫头猫        {
423ee62d1bS猫头猫            icon: 'tshirt-v-outline',
433ee62d1bS猫头猫            title: '主题设置',
443ee62d1bS猫头猫            onPress: () => {
453ee62d1bS猫头猫                navigateToSetting('theme');
463ee62d1bS猫头猫            },
473ee62d1bS猫头猫        },
48*359f51feS猫头猫    ] as const;
49*359f51feS猫头猫
50*359f51feS猫头猫    const otherSetting = [
513ee62d1bS猫头猫        {
523ee62d1bS猫头猫            icon: 'backup-restore',
533ee62d1bS猫头猫            title: '备份与恢复',
54dec7a5f8S猫头猫            onPress: () => {
55dec7a5f8S猫头猫                navigateToSetting('backup');
56dec7a5f8S猫头猫            },
573ee62d1bS猫头猫        },
580cffb46aS猫头猫        {
590cffb46aS猫头猫            icon: 'information-outline',
600cffb46aS猫头猫            title: '关于',
610cffb46aS猫头猫            onPress: () => {
620cffb46aS猫头猫                navigateToSetting('about');
630cffb46aS猫头猫            },
640cffb46aS猫头猫        },
653ee62d1bS猫头猫    ] as const;
663ee62d1bS猫头猫
67bf6e62f2S猫头猫    return (
6865fc5a50S猫头猫        <>
694060c00aS猫头猫            <PageBackground />
704060c00aS猫头猫            <DrawerContentScrollView {...[props]} style={style.scrollWrapper}>
71bf6e62f2S猫头猫                <View style={style.header}>
72dec7a5f8S猫头猫                    <ThemeText fontSize="appbar" fontWeight="bold">
73dec7a5f8S猫头猫                        {DeviceInfo.getApplicationName()}
74dec7a5f8S猫头猫                    </ThemeText>
75b882a19dS猫头猫                    {/* <IconButton icon={'qrcode-scan'} size={rpx(36)} /> */}
76bf6e62f2S猫头猫                </View>
77bf6e62f2S猫头猫                <Card style={style.card}>
78bf6e62f2S猫头猫                    <Card.Title
798b51f01aS猫头猫                        title={
80dec7a5f8S猫头猫                            <ThemeText fontSize="description">设置</ThemeText>
814060c00aS猫头猫                        }
824060c00aS猫头猫                    />
83dec7a5f8S猫头猫                    <Card.Content style={style.cardContent}>
843ee62d1bS猫头猫                        {basicSetting.map(item => (
85bf6e62f2S猫头猫                            <ListItem
86*359f51feS猫头猫                                itemHeight={ITEM_HEIGHT}
87*359f51feS猫头猫                                key={item.title}
88*359f51feS猫头猫                                left={{
89*359f51feS猫头猫                                    icon: {
90*359f51feS猫头猫                                        name: item.icon,
91*359f51feS猫头猫                                        size: 'normal',
92*359f51feS猫头猫                                        fontColor: 'normal',
93*359f51feS猫头猫                                    },
94*359f51feS猫头猫                                    width: rpx(48),
95*359f51feS猫头猫                                }}
96*359f51feS猫头猫                                title={item.title}
97*359f51feS猫头猫                                onPress={item.onPress}
98*359f51feS猫头猫                            />
99*359f51feS猫头猫                        ))}
100*359f51feS猫头猫                    </Card.Content>
101*359f51feS猫头猫                </Card>
102*359f51feS猫头猫                <Card style={style.card}>
103*359f51feS猫头猫                    <Card.Title
104*359f51feS猫头猫                        title={
105*359f51feS猫头猫                            <ThemeText fontSize="description">其他</ThemeText>
106*359f51feS猫头猫                        }
107*359f51feS猫头猫                    />
108*359f51feS猫头猫                    <Card.Content style={style.cardContent}>
109*359f51feS猫头猫                        <CountDownItem />
110*359f51feS猫头猫                        {otherSetting.map(item => (
111*359f51feS猫头猫                            <ListItem
112*359f51feS猫头猫                                itemHeight={ITEM_HEIGHT}
1133ee62d1bS猫头猫                                key={item.title}
1143ee62d1bS猫头猫                                left={{
1153ee62d1bS猫头猫                                    icon: {
1163ee62d1bS猫头猫                                        name: item.icon,
1173ee62d1bS猫头猫                                        size: 'normal',
1183ee62d1bS猫头猫                                        fontColor: 'normal',
1193ee62d1bS猫头猫                                    },
1203ee62d1bS猫头猫                                    width: rpx(48),
1213ee62d1bS猫头猫                                }}
1223ee62d1bS猫头猫                                title={item.title}
1234060c00aS猫头猫                                onPress={item.onPress}
1244060c00aS猫头猫                            />
1253ee62d1bS猫头猫                        ))}
126bf6e62f2S猫头猫                    </Card.Content>
127bf6e62f2S猫头猫                </Card>
128bf6e62f2S猫头猫                <View style={style.bottom}>
129bf6e62f2S猫头猫                    <Button
130e2257bd6S猫头猫                        onPress={async () => {
131e2257bd6S猫头猫                            await MusicQueue.reset();
132e2257bd6S猫头猫                            NativeUtils.exitApp();
133bf6e62f2S猫头猫                        }}>
134e2257bd6S猫头猫                        <ThemeText>退出</ThemeText>
135bf6e62f2S猫头猫                    </Button>
136bf6e62f2S猫头猫                </View>
137bf6e62f2S猫头猫            </DrawerContentScrollView>
13865fc5a50S猫头猫        </>
139bf6e62f2S猫头猫    );
140bf6e62f2S猫头猫}
141bf6e62f2S猫头猫
142bf6e62f2S猫头猫const style = StyleSheet.create({
143bf6e62f2S猫头猫    wrapper: {
144bf6e62f2S猫头猫        flex: 1,
145bf6e62f2S猫头猫        backgroundColor: '#999999',
146bf6e62f2S猫头猫    },
147bf6e62f2S猫头猫    scrollWrapper: {
148bf6e62f2S猫头猫        paddingTop: rpx(12),
149bf6e62f2S猫头猫    },
150bf6e62f2S猫头猫
151bf6e62f2S猫头猫    header: {
15294b17902S猫头猫        height: rpx(120),
153bf6e62f2S猫头猫        width: '100%',
154bf6e62f2S猫头猫        flexDirection: 'row',
155bf6e62f2S猫头猫        justifyContent: 'space-between',
156bf6e62f2S猫头猫        alignItems: 'center',
15794b17902S猫头猫        marginLeft: rpx(24),
158bf6e62f2S猫头猫    },
159bf6e62f2S猫头猫    card: {
160bf6e62f2S猫头猫        backgroundColor: '#eeeeee22',
161*359f51feS猫头猫        marginBottom: rpx(24),
162bf6e62f2S猫头猫    },
163dec7a5f8S猫头猫    cardContent: {
1644060c00aS猫头猫        paddingHorizontal: 0,
165dec7a5f8S猫头猫    },
166bf6e62f2S猫头猫    bottom: {
167bf6e62f2S猫头猫        height: rpx(100),
168bf6e62f2S猫头猫        flexDirection: 'row',
169bf6e62f2S猫头猫        alignItems: 'center',
170bf6e62f2S猫头猫        justifyContent: 'flex-end',
171bf6e62f2S猫头猫    },
172*359f51feS猫头猫    /** 倒计时 */
173*359f51feS猫头猫    countDownText: {
174*359f51feS猫头猫        height: ITEM_HEIGHT,
175*359f51feS猫头猫        textAlignVertical: 'center',
176*359f51feS猫头猫    },
177bf6e62f2S猫头猫});
178*359f51feS猫头猫
179*359f51feS猫头猫function _CountDownItem() {
180*359f51feS猫头猫    const countDown = useTimingClose();
181*359f51feS猫头猫    const {showPanel} = usePanel();
182*359f51feS猫头猫
183*359f51feS猫头猫    return (
184*359f51feS猫头猫        <ListItem
185*359f51feS猫头猫            title="定时关闭"
186*359f51feS猫头猫            onPress={() => {
187*359f51feS猫头猫                showPanel('TimingClose');
188*359f51feS猫头猫            }}
189*359f51feS猫头猫            left={{
190*359f51feS猫头猫                icon: {
191*359f51feS猫头猫                    name: 'timer-outline',
192*359f51feS猫头猫                    size: 'normal',
193*359f51feS猫头猫                    fontColor: 'normal',
194*359f51feS猫头猫                },
195*359f51feS猫头猫                width: rpx(48),
196*359f51feS猫头猫            }}
197*359f51feS猫头猫            itemHeight={ITEM_HEIGHT}
198*359f51feS猫头猫            right={() => (
199*359f51feS猫头猫                <ThemeText style={style.countDownText} fontSize="subTitle">
200*359f51feS猫头猫                    {countDown ? timeformat(countDown) : ''}
201*359f51feS猫头猫                </ThemeText>
202*359f51feS猫头猫            )}
203*359f51feS猫头猫        />
204*359f51feS猫头猫    );
205*359f51feS猫头猫}
206*359f51feS猫头猫
207*359f51feS猫头猫const CountDownItem = memo(_CountDownItem, () => true);
208