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); 18function 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 142export default memo(HomeDrawer, () => true); 143 144const style = StyleSheet.create({ 145 wrapper: { 146 flex: 1, 147 backgroundColor: '#999999', 148 }, 149 scrollWrapper: { 150 paddingTop: rpx(12), 151 }, 152 153 header: { 154 height: rpx(120), 155 width: '100%', 156 flexDirection: 'row', 157 justifyContent: 'space-between', 158 alignItems: 'center', 159 marginLeft: rpx(24), 160 }, 161 card: { 162 backgroundColor: '#eeeeee22', 163 marginBottom: rpx(24), 164 }, 165 cardContent: { 166 paddingHorizontal: 0, 167 }, 168 bottom: { 169 height: rpx(100), 170 flexDirection: 'row', 171 alignItems: 'center', 172 justifyContent: 'flex-end', 173 }, 174 /** 倒计时 */ 175 countDownText: { 176 height: ITEM_HEIGHT, 177 textAlignVertical: 'center', 178 }, 179}); 180 181function _CountDownItem() { 182 const countDown = useTimingClose(); 183 const {showPanel} = usePanel(); 184 185 return ( 186 <ListItem 187 title="定时关闭" 188 onPress={() => { 189 showPanel('TimingClose'); 190 }} 191 left={{ 192 icon: { 193 name: 'timer-outline', 194 size: 'normal', 195 fontColor: 'normal', 196 }, 197 width: rpx(48), 198 }} 199 itemHeight={ITEM_HEIGHT} 200 right={() => ( 201 <ThemeText style={style.countDownText} fontSize="subTitle"> 202 {countDown ? timeformat(countDown) : ''} 203 </ThemeText> 204 )} 205 /> 206 ); 207} 208 209const CountDownItem = memo(_CountDownItem, () => true); 210