app.tsx 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. import { Component, PropsWithChildren } from 'react'
  2. import './app.scss'
  3. import '@/context/locales/index'
  4. import { Provider, useDispatch } from 'react-redux'
  5. import store from './store/store'
  6. import { View } from '@tarojs/components'
  7. import GlobalModal from './components/layout/GlobalModal'
  8. import Taro from '@tarojs/taro'
  9. import { getInfoSuccess } from './store/user'
  10. import { uploadLocalPushInfo } from './features/trackTimeDuration/actions/TrackTimeActions'
  11. import { kIsAndroid } from './utils/tools'
  12. // import { StatusBar } from 'react-native'
  13. // import jgPush from './utils/push.rn'
  14. // import 'taro-ui/dist/style/index.scss'
  15. let LogBox;
  16. let StatusBar;
  17. let ActionSheetProvider;
  18. let SafeAreaView;
  19. let messaging;
  20. if (process.env.TARO_ENV == 'rn') {
  21. LogBox = require("react-native").LogBox
  22. StatusBar = require("react-native").StatusBar
  23. SafeAreaView = require("react-native").SafeAreaView
  24. ActionSheetProvider = require('@expo/react-native-action-sheet').ActionSheetProvider
  25. messaging = require('@react-native-firebase/messaging').default
  26. }
  27. const App: React.FC<PropsWithChildren> = ({ children }) => {
  28. // const dispatch = useDispatch();
  29. Taro.setStorage({ key: 'showedDisqualifiedAlert', data: false })
  30. // if (process.env.TARO_ENV == 'rn') {
  31. // global.language = 'en'
  32. // PushNotification.configure({
  33. // // onRegister: function (token) {
  34. // // console.log('TOKEN:', token);
  35. // // },
  36. // onNotification: function (notification) {
  37. // console.log('NOTIFICATION:', notification);
  38. // setTimeout(() => {
  39. // uploadLocalPushInfo(notification)
  40. // }, 3000)
  41. // // notification.finish(PushNotificationIOS.FetchResult.NoData);
  42. // },
  43. // // permissions: {
  44. // // alert: true,
  45. // // badge: true,
  46. // // sound: true,
  47. // // },
  48. // // popInitialNotification: true,
  49. // // requestPermissions: true,
  50. // });
  51. // // messaging().setBackgroundMessageHandler(async remoteMessage => {
  52. // // console.log('Message is handled in the background!', remoteMessage);
  53. // // });
  54. // // alert(Intl.DateTimeFormat().resolvedOptions().timeZone)
  55. // }
  56. if (process.env.TARO_ENV == 'rn') {
  57. global.language = 'en'
  58. }
  59. if (process.env.TARO_ENV == 'weapp') {
  60. global.language = 'zh'
  61. var value = Taro.getStorageSync('language')
  62. if (value) {
  63. // Do something with return value
  64. global.language = value
  65. }
  66. loadWXCache()
  67. global.isDebug = Taro.getStorageSync('isDebug')
  68. const updateManager = Taro.getUpdateManager()
  69. updateManager.onUpdateReady(function () {
  70. Taro.showModal({
  71. title: '更新提示',
  72. content: '新版本已经准备好,是否重启应用?',
  73. showCancel: false,
  74. success: function (res) {
  75. if (res.confirm) {
  76. updateManager.applyUpdate();
  77. }
  78. }
  79. });
  80. });
  81. updateManager.onUpdateFailed(function () {
  82. // 新版本下载失败
  83. Taro.showModal({
  84. title: '已经有新版本喽~',
  85. content: '请您删除当前小程序,到微信 “发现-小程序” 页,重新搜索打开哦~',
  86. showCancel: false,
  87. });
  88. });
  89. }
  90. else {
  91. //关闭其中某些yellow警告
  92. loadRNCache()
  93. LogBox.ignoreLogs(['Warning: ...']); // Ignore log notification by message
  94. LogBox.ignoreAllLogs();//Ignore all log notifications
  95. // const test = require('./utils/push').default
  96. // test()
  97. // jgPush()
  98. // const JPush = require('jpush-react-native')
  99. // JPush.init({ appKey: "4fcc3e237eec4c4fb804ad49", channel: "dev", production: false });
  100. // //连接状态
  101. // JPush.addConnectEventListener(result => {
  102. // console.log(result)
  103. // })
  104. // console.log('rn jpush init')
  105. // //通知回调
  106. // var notificationListener = result => {
  107. // console.log("notificationListener:" + JSON.stringify(result))
  108. // alert(JSON.stringify(result))
  109. // };
  110. // JPush.addNotificationListener(notificationListener);
  111. // //本地通知回调
  112. // var localNotificationListener = result => {
  113. // console.log("localNotificationListener:" + JSON.stringify(result))
  114. // };
  115. // JPush.addLocalNotificationListener(localNotificationListener);
  116. // //自定义消息回调
  117. // var customMessageListener = result => {
  118. // console.log("customMessageListener:" + JSON.stringify(result))
  119. // };
  120. // JPush.addCustomMessageListener(customMessageListener);
  121. // //应用内消息回调
  122. // JPush.pageEnterTo("HomePage") // 进入首页,当页面退出时请调用 JPush.pageLeave('HomePage')
  123. // var inappMessageListener = result => {
  124. // console.log("inappMessageListener:" + JSON.stringify(result))
  125. // alert(JSON.stringify(result))
  126. // };
  127. // JPush.addInappMessageListener(inappMessageListener);
  128. // //tag alias事件回调
  129. // var tagAliasListener = result => {
  130. // console.log("tagAliasListener:" + JSON.stringify(result))
  131. // };
  132. // JPush.addTagAliasListener(tagAliasListener);
  133. // //手机号码事件回调
  134. // var mobileNumberListener = result => {
  135. // console.log("mobileNumberListener:" + JSON.stringify(result))
  136. // };
  137. // JPush.addMobileNumberListener(mobileNumberListener);
  138. }
  139. function loadWXCache() {
  140. // var showDayRing = Taro.getStorageSync('showDayRing') || false;
  141. // var showNightRing = Taro.getStorageSync('showNightRing') || false;
  142. // dispatch(showDay(showDayRing))
  143. // dispatch(showNight(showNightRing))
  144. // var gps = Taro.getStorageSync('gps')
  145. // if (gps) {
  146. // global.locationDetail = JSON.parse(gps)
  147. // }
  148. var userData = Taro.getStorageSync('userData')
  149. if (userData) {
  150. global.token = JSON.parse(userData).token
  151. // dispatch(getInfoSuccess(JSON.parse(userData)));
  152. }
  153. }
  154. async function loadRNCache() {
  155. var userData = await getStorage('userData')
  156. if (userData) {
  157. global.token = JSON.parse(userData).token
  158. }
  159. // else {
  160. // //测试直接登录
  161. // global.token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiJhY2NvdW50Iiwic3ViIjoiMTE0Nzg0NGE5NDIyODk1MmE5Zjc2OTdjYWJjYmU3Y2UiLCJpc3MiOiJmYXN0Iiwibmlja25hbWUiOiJGYXN0ZXIiLCJ0eXAiOiJCZWFyZXIiLCJzZXNzaW9uX3N0YXRlIjoiZWQxMGY5Yzk1YjcxMjdhZThlZjU5ZDI4MTFlNWI1MWUiLCJleHAiOjE3NDY2NzIyMDYsImlhdCI6MTcxNTEzNjIwNn0.fbVPua1K9eDteWqrDBjaB8l8MrchwCp_JiuwQ222wU0'
  162. // }
  163. }
  164. async function getStorage(key: string) {
  165. try {
  166. const res = await Taro.getStorage({ key });
  167. return res.data;
  168. } catch {
  169. return '';
  170. }
  171. }
  172. if (process.env.TARO_ENV == 'rn') {
  173. return <ActionSheetProvider>
  174. <Provider store={store}>
  175. <StatusBar barStyle='light-content' backgroundColor="#000" />
  176. {children}
  177. </Provider>
  178. </ActionSheetProvider>
  179. }
  180. return <Provider store={store}>
  181. {children}
  182. </Provider>
  183. }
  184. // class App extends Component<PropsWithChildren> {
  185. // componentDidMount () {}
  186. // componentDidShow () {}
  187. // componentDidHide () {}
  188. // // this.props.children 是将要会渲染的页面
  189. // render () {
  190. // return this.props.children
  191. // }
  192. // }
  193. export default App