set.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. import React, {Component} from 'react';
  2. import {
  3. Text,
  4. View,
  5. TouchableOpacity,
  6. SafeAreaView,
  7. ScrollView,
  8. DeviceEventEmitter,
  9. StyleSheet,
  10. } from 'react-native';
  11. import {
  12. WhiteSpace,
  13. Modal,
  14. Switch,
  15. List,
  16. WingBlank,
  17. } from '@ant-design/react-native';
  18. import public_css from '../../source/css/public_css';
  19. import {rightArrowIcon} from '../../source/icon/icon';
  20. import {SvgXml} from 'react-native-svg';
  21. import {ClearAll} from '../../data/storage';
  22. export default class set extends Component {
  23. constructor(props) {
  24. super(props);
  25. this.props.navigation.dangerouslyGetParent().setOptions({
  26. tabBarVisible: false,
  27. });
  28. this.state = {
  29. noticeCheck: true,
  30. };
  31. }
  32. render() {
  33. return (
  34. <SafeAreaView style={public_css.body}>
  35. <ScrollView>
  36. <WhiteSpace />
  37. <WingBlank>
  38. <List>
  39. <List.Item
  40. style={styles.notice}
  41. extra={
  42. <Switch
  43. checked={this.state.noticeCheck}
  44. onChange={() => this.noticeCheckChange()}
  45. />
  46. }>
  47. <Text style={styles.noticeText}>推送通知</Text>
  48. </List.Item>
  49. </List>
  50. </WingBlank>
  51. <WhiteSpace />
  52. <WingBlank>
  53. <TouchableOpacity onPress={() => this.cleanCache()}>
  54. <View style={styles.cache}>
  55. <View style={styles.cacheView}>
  56. <Text style={styles.cacheText}>清除缓存</Text>
  57. </View>
  58. <View>
  59. <SvgXml height={18} xml={rightArrowIcon()} />
  60. </View>
  61. </View>
  62. </TouchableOpacity>
  63. </WingBlank>
  64. <WhiteSpace />
  65. </ScrollView>
  66. </SafeAreaView>
  67. );
  68. }
  69. // 推送通知切换
  70. noticeCheckChange = () => {
  71. this.setState({
  72. noticeCheck: !this.state.noticeCheck,
  73. });
  74. };
  75. // 清空缓存
  76. cleanCache = () => {
  77. Modal.alert('清除缓存', '是否确认要清除缓存!', [
  78. {
  79. text: '取消',
  80. onPress: () => console.log('cancel'),
  81. style: 'cancel',
  82. },
  83. {text: '确认', onPress: () => this.cleanAll()},
  84. ]);
  85. };
  86. // 清空本地缓存
  87. cleanAll = async () => {
  88. await ClearAll();
  89. DeviceEventEmitter.emit('updateCompany');
  90. this.props.route.params.refresh(false);
  91. this.props.navigation.goBack();
  92. };
  93. }
  94. const styles = StyleSheet.create({
  95. notice: {
  96. backgroundColor: '#F7F7F7',
  97. },
  98. noticeText: {
  99. color: '#393939',
  100. fontWeight: 'bold',
  101. fontSize: 15,
  102. },
  103. cache: {
  104. flexDirection: 'row',
  105. alignItems: 'center',
  106. justifyContent: 'space-between',
  107. height: 45,
  108. backgroundColor: '#F7F7F7',
  109. },
  110. cacheView: {
  111. marginLeft: 15,
  112. },
  113. cacheText: {
  114. color: '#393939',
  115. fontWeight: 'bold',
  116. fontSize: 15,
  117. },
  118. });