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