app.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { Component } from 'react'
  2. import tool from './common/tool'
  3. import Taro, { getCurrentInstance } from '@tarojs/taro'
  4. // import 'taro-ui/dist/style/index.scss'
  5. import './app.less'
  6. class App extends Component {
  7. $instance = getCurrentInstance()
  8. componentDidMount () { }
  9. componentDidShow () {
  10. }
  11. onLaunch () {
  12. // 保持屏幕常亮
  13. Taro.setKeepScreenOn({
  14. keepScreenOn: true
  15. })
  16. // 获取路由参数
  17. let params = this.$instance.router.params
  18. if (params.scene) {
  19. let _scene = decodeURIComponent(params.scene)
  20. const arr = _scene.split("=");
  21. const result1 = arr[1].split("&")[0]; // 去掉第二个等号后面的"&"符号
  22. const result2 = arr[2]; // 第三个等号后面的内容
  23. Taro.setStorageSync('channel_name', result1)
  24. Taro.setStorageSync('source_name', result2)
  25. }
  26. let item = params
  27. if (params.c) {
  28. Taro.setStorageSync('channel_name', item.c)
  29. }
  30. if (params.s) {
  31. Taro.setStorageSync('source_name', item.s)
  32. }
  33. console.log('app启动');
  34. if (!Taro.getStorageSync('session_key')) {
  35. tool.toLogin();
  36. }else{
  37. tool.reportLogin()
  38. }
  39. Taro.setKeepScreenOn({
  40. keepScreenOn: true
  41. })
  42. }
  43. componentDidHide () { }
  44. render () {
  45. // this.props.children 是将要会渲染的页面
  46. return this.props.children
  47. }
  48. }
  49. export default App