app.tsx 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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. global.hideRingIcon = true
  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. if (value == 'wechat') {
  65. const isZh = Taro.getAppBaseInfo?Taro.getAppBaseInfo().language == 'zh_CN':'zh_CN'
  66. global.language = isZh ? 'zh' : 'en'
  67. }
  68. else {
  69. global.language = value
  70. }
  71. }
  72. else {
  73. const isZh = Taro.getAppBaseInfo?Taro.getAppBaseInfo().language == 'zh_CN':'zh_CN'
  74. global.language = isZh ? 'zh' : 'en'
  75. }
  76. loadWXCache()
  77. global.isDebug = Taro.getStorageSync('isDebug')
  78. const updateManager = Taro.getUpdateManager()
  79. updateManager.onUpdateReady(function () {
  80. Taro.showModal({
  81. title: '更新提示',
  82. content: '新版本已经准备好,是否重启应用?',
  83. showCancel: false,
  84. success: function (res) {
  85. if (res.confirm) {
  86. updateManager.applyUpdate();
  87. }
  88. }
  89. });
  90. });
  91. updateManager.onUpdateFailed(function () {
  92. // 新版本下载失败
  93. Taro.showModal({
  94. title: '已经有新版本喽~',
  95. content: '请您删除当前小程序,到微信 “发现-小程序” 页,重新搜索打开哦~',
  96. showCancel: false,
  97. });
  98. });
  99. }
  100. else {
  101. //关闭其中某些yellow警告
  102. loadRNCache()
  103. LogBox.ignoreLogs(['Warning: ...']); // Ignore log notification by message
  104. LogBox.ignoreAllLogs();//Ignore all log notifications
  105. // const test = require('./utils/push').default
  106. // test()
  107. // jgPush()
  108. // const JPush = require('jpush-react-native')
  109. // JPush.init({ appKey: "4fcc3e237eec4c4fb804ad49", channel: "dev", production: false });
  110. // //连接状态
  111. // JPush.addConnectEventListener(result => {
  112. // console.log(result)
  113. // })
  114. // console.log('rn jpush init')
  115. // //通知回调
  116. // var notificationListener = result => {
  117. // console.log("notificationListener:" + JSON.stringify(result))
  118. // alert(JSON.stringify(result))
  119. // };
  120. // JPush.addNotificationListener(notificationListener);
  121. // //本地通知回调
  122. // var localNotificationListener = result => {
  123. // console.log("localNotificationListener:" + JSON.stringify(result))
  124. // };
  125. // JPush.addLocalNotificationListener(localNotificationListener);
  126. // //自定义消息回调
  127. // var customMessageListener = result => {
  128. // console.log("customMessageListener:" + JSON.stringify(result))
  129. // };
  130. // JPush.addCustomMessageListener(customMessageListener);
  131. // //应用内消息回调
  132. // JPush.pageEnterTo("HomePage") // 进入首页,当页面退出时请调用 JPush.pageLeave('HomePage')
  133. // var inappMessageListener = result => {
  134. // console.log("inappMessageListener:" + JSON.stringify(result))
  135. // alert(JSON.stringify(result))
  136. // };
  137. // JPush.addInappMessageListener(inappMessageListener);
  138. // //tag alias事件回调
  139. // var tagAliasListener = result => {
  140. // console.log("tagAliasListener:" + JSON.stringify(result))
  141. // };
  142. // JPush.addTagAliasListener(tagAliasListener);
  143. // //手机号码事件回调
  144. // var mobileNumberListener = result => {
  145. // console.log("mobileNumberListener:" + JSON.stringify(result))
  146. // };
  147. // JPush.addMobileNumberListener(mobileNumberListener);
  148. }
  149. function loadWXCache() {
  150. // var showDayRing = Taro.getStorageSync('showDayRing') || false;
  151. // var showNightRing = Taro.getStorageSync('showNightRing') || false;
  152. // dispatch(showDay(showDayRing))
  153. // dispatch(showNight(showNightRing))
  154. // var gps = Taro.getStorageSync('gps')
  155. // if (gps) {
  156. // global.locationDetail = JSON.parse(gps)
  157. // }
  158. var userData = Taro.getStorageSync('userData')
  159. if (userData) {
  160. global.token = JSON.parse(userData).token
  161. // dispatch(getInfoSuccess(JSON.parse(userData)));
  162. }
  163. }
  164. async function loadRNCache() {
  165. var userData = await getStorage('userData')
  166. if (userData) {
  167. global.token = JSON.parse(userData).token
  168. }
  169. // else {
  170. // //测试直接登录
  171. // global.token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiJhY2NvdW50Iiwic3ViIjoiMTE0Nzg0NGE5NDIyODk1MmE5Zjc2OTdjYWJjYmU3Y2UiLCJpc3MiOiJmYXN0Iiwibmlja25hbWUiOiJGYXN0ZXIiLCJ0eXAiOiJCZWFyZXIiLCJzZXNzaW9uX3N0YXRlIjoiZWQxMGY5Yzk1YjcxMjdhZThlZjU5ZDI4MTFlNWI1MWUiLCJleHAiOjE3NDY2NzIyMDYsImlhdCI6MTcxNTEzNjIwNn0.fbVPua1K9eDteWqrDBjaB8l8MrchwCp_JiuwQ222wU0'
  172. // }
  173. }
  174. async function getStorage(key: string) {
  175. try {
  176. const res = await Taro.getStorage({ key });
  177. return res.data;
  178. } catch {
  179. return '';
  180. }
  181. }
  182. if (process.env.TARO_ENV == 'rn') {
  183. return <ActionSheetProvider>
  184. <Provider store={store}>
  185. <StatusBar barStyle='light-content' backgroundColor="#000" />
  186. {children}
  187. </Provider>
  188. </ActionSheetProvider>
  189. }
  190. return <Provider store={store}>
  191. {children}
  192. </Provider>
  193. }
  194. // class App extends Component<PropsWithChildren> {
  195. // componentDidMount () {}
  196. // componentDidShow () {}
  197. // componentDidHide () {}
  198. // // this.props.children 是将要会渲染的页面
  199. // render () {
  200. // return this.props.children
  201. // }
  202. // }
  203. export default App