1import React, {memo} from 'react'; 2import {StyleSheet, View} from 'react-native'; 3import rpx from '@/utils/rpx'; 4import {DrawerContentScrollView} from '@react-navigation/drawer'; 5import {Button, Card} from 'react-native-paper'; 6import ListItem from '@/components/base/listItem'; 7import {ROUTE_PATH, useNavigate} from '@/entry/router'; 8import ThemeText from '@/components/base/themeText'; 9import PageBackground from '@/components/base/pageBackground'; 10import DeviceInfo from 'react-native-device-info'; 11import NativeUtils from '@/native/utils'; 12import MusicQueue from '@/core/musicQueue'; 13import {useTimingClose} from '@/utils/timingClose'; 14import usePanel from '@/components/panels/usePanel'; 15import timeformat from '@/utils/timeformat'; 16 17const ITEM_HEIGHT = rpx(108); 18export default function HomeDrawer(props: any) { 19 const navigate = useNavigate(); 20 function navigateToSetting(settingType: string) { 21 navigate(ROUTE_PATH.SETTING, { 22 type: settingType, 23 }); 24 } 25 26 const basicSetting = [ 27 { 28 icon: 'cog-outline', 29 title: '基本设置', 30 onPress: () => { 31 navigateToSetting('basic'); 32 }, 33 }, 34 { 35 icon: 'language-javascript', 36 title: '插件设置', 37 onPress: () => { 38 navigateToSetting('plugin'); 39 }, 40 }, 41 { 42 icon: 'tshirt-v-outline', 43 title: '主题设置', 44 onPress: () => { 45 navigateToSetting('theme'); 46 }, 47 }, 48 ] as const; 49 50 const otherSetting = [ 51 { 52 icon: 'backup-restore', 53 title: '备份与恢复', 54 onPress: () => { 55 navigateToSetting('backup'); 56 }, 57 }, 58 { 59 icon: 'information-outline', 60 title: '关于', 61 onPress: () => { 62 navigateToSetting('about'); 63 }, 64 }, 65 ] as const; 66 67 return ( 68 <> 69 <PageBackground /> 70 <DrawerContentScrollView {...[props]} style={style.scrollWrapper}> 71 <View style={style.header}> 72 <ThemeText fontSize="appbar" fontWeight="bold"> 73 {DeviceInfo.getApplicationName()} 74 </ThemeText> 75 {/* <IconButton icon={'qrcode-scan'} size={rpx(36)} /> */} 76 </View> 77 <Card style={style.card}> 78 <Card.Title 79 title={ 80 <ThemeText fontSize="description">设置</ThemeText> 81 } 82 /> 83 <Card.Content style={style.cardContent}> 84 {basicSetting.map(item => ( 85 <ListItem 86 itemHeight={ITEM_HEIGHT} 87 key={item.title} 88 left={{ 89 icon: { 90 name: item.icon, 91 size: 'normal', 92 fontColor: 'normal', 93 }, 94 width: rpx(48), 95 }} 96 title={item.title} 97 onPress={item.onPress} 98 /> 99 ))} 100 </Card.Content> 101 </Card> 102 <Card style={style.card}> 103 <Card.Title 104 title={ 105 <ThemeText fontSize="description">其他</ThemeText> 106 } 107 /> 108 <Card.Content style={style.cardContent}> 109 <CountDownItem /> 110 {otherSetting.map(item => ( 111 <ListItem 112 itemHeight={ITEM_HEIGHT} 113 key={item.title} 114 left={{ 115 icon: { 116 name: item.icon, 117 size: 'normal', 118 fontColor: 'normal', 119 }, 120 width: rpx(48), 121 }} 122 title={item.title} 123 onPress={item.onPress} 124 /> 125 ))} 126 </Card.Content> 127 </Card> 128 <View style={style.bottom}> 129 <Button 130 onPress={async () => { 131 await MusicQueue.reset(); 132 NativeUtils.exitApp(); 133 }}> 134 <ThemeText>退出</ThemeText> 135 </Button> 136 </View> 137 </DrawerContentScrollView> 138 </> 139 ); 140} 141 142const style = StyleSheet.create({ 143 wrapper: { 144 flex: 1, 145 backgroundColor: '#999999', 146 }, 147 scrollWrapper: { 148 paddingTop: rpx(12), 149 }, 150 151 header: { 152 height: rpx(120), 153 width: '100%', 154 flexDirection: 'row', 155 justifyContent: 'space-between', 156 alignItems: 'center', 157 marginLeft: rpx(24), 158 }, 159 card: { 160 backgroundColor: '#eeeeee22', 161 marginBottom: rpx(24), 162 }, 163 cardContent: { 164 paddingHorizontal: 0, 165 }, 166 bottom: { 167 height: rpx(100), 168 flexDirection: 'row', 169 alignItems: 'center', 170 justifyContent: 'flex-end', 171 }, 172 /** 倒计时 */ 173 countDownText: { 174 height: ITEM_HEIGHT, 175 textAlignVertical: 'center', 176 }, 177}); 178 179function _CountDownItem() { 180 const countDown = useTimingClose(); 181 const {showPanel} = usePanel(); 182 183 return ( 184 <ListItem 185 title="定时关闭" 186 onPress={() => { 187 showPanel('TimingClose'); 188 }} 189 left={{ 190 icon: { 191 name: 'timer-outline', 192 size: 'normal', 193 fontColor: 'normal', 194 }, 195 width: rpx(48), 196 }} 197 itemHeight={ITEM_HEIGHT} 198 right={() => ( 199 <ThemeText style={style.countDownText} fontSize="subTitle"> 200 {countDown ? timeformat(countDown) : ''} 201 </ThemeText> 202 )} 203 /> 204 ); 205} 206 207const CountDownItem = memo(_CountDownItem, () => true); 208