app.tsx 6.8 KB

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