app.tsx 6.9 KB

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