app.tsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. // import { Component, PropsWithChildren } from 'react'
  2. // class App extends Component<PropsWithChildren> {
  3. // componentDidMount () {}
  4. // componentDidShow () {}
  5. // componentDidHide () {}
  6. // render () {
  7. // // this.props.children 是将要会渲染的页面
  8. // return this.props.children
  9. // }
  10. // }
  11. // export default App
  12. import { PropsWithChildren } from "react";
  13. import { useRequest } from "ahooks";
  14. import { Provider as ReduxProvider } from "react-redux";
  15. import Taro, { useDidShow } from "@tarojs/taro";
  16. import { WebView } from "@tarojs/components";
  17. import StorageUtil, { EStorage } from "@/utils/storageUtil";
  18. import AppContext from "./context/appContext";
  19. import ReduxUtil from "./utils/reduxUtil";
  20. import RouteUtil from "./utils/routeUtil";
  21. import UserHelper from "./helper/userHelper";
  22. import "./app.scss";
  23. interface IAppProps {}
  24. const App = (props: PropsWithChildren<IAppProps>) => {
  25. const result = useRequest(Taro.getSystemInfo);
  26. useRequest(() => {
  27. return UserHelper.cacheTabMenu();
  28. });
  29. useDidShow((options: any) => {
  30. console.log("This is Options", options);
  31. let jumpUrls = "";
  32. if (options.query?.source) {
  33. switch (options.query?.source) {
  34. case "app": {
  35. if (options.query?.platform) {
  36. switch (options.query?.platform) {
  37. case "cyqb":
  38. jumpUrls = "https://mp.weixin.qq.com/s/TBP2VhzYRaMWf_CWbo5mBA";
  39. break;
  40. case "hrqb":
  41. jumpUrls = "https://mp.weixin.qq.com/s/JJrWlgaA1lvIBAp7eNZjxg";
  42. break;
  43. default:
  44. // 默认惠融钱包的文章
  45. jumpUrls = "https://mp.weixin.qq.com/s/JJrWlgaA1lvIBAp7eNZjxg";
  46. break;
  47. }
  48. }
  49. break;
  50. }
  51. case "gxh": {
  52. jumpUrls = "https://mp.weixin.qq.com/s/RvsITI6t7_T-2UFC2pJvww";
  53. break;
  54. }
  55. case "wallet": {
  56. jumpUrls = "https://mp.weixin.qq.com/s/M-lkx1MTMRv2p7v-6ZFykg";
  57. break;
  58. }
  59. }
  60. RouteUtil.toWebViewPage({
  61. url: jumpUrls,
  62. });
  63. } else if (options.query?.openUrl) {
  64. RouteUtil.toWebViewPage({
  65. url: options.query?.openUrl,
  66. });
  67. }
  68. // if (options.query?.source === "app" && options.query?.platform) {
  69. // let jumpUrls = "";
  70. // switch (options.query?.platform) {
  71. // case "cyqb":
  72. // jumpUrls = "https://mp.weixin.qq.com/s/TBP2VhzYRaMWf_CWbo5mBA";
  73. // break;
  74. // case "hrqb":
  75. // jumpUrls = "https://mp.weixin.qq.com/s/JJrWlgaA1lvIBAp7eNZjxg";
  76. // break;
  77. // default:
  78. // // 默认惠融钱包的文章
  79. // jumpUrls = "https://mp.weixin.qq.com/s/JJrWlgaA1lvIBAp7eNZjxg";
  80. // break;
  81. // }
  82. // }
  83. if (StorageUtil.get(EStorage.channelCode)) {
  84. StorageUtil.remove(EStorage.channelCode);
  85. }
  86. if (options.query?.channelCode) {
  87. StorageUtil.set(EStorage.channelCode, options.query?.channelCode);
  88. }
  89. const channelCode = extractChannelCodeValue(options.query);
  90. if (channelCode) {
  91. StorageUtil.set(EStorage.channelCode, channelCode);
  92. }
  93. });
  94. const extractChannelCodeValue = (query: any) => {
  95. for (let key in query) {
  96. if (key.includes("?channelCode")) {
  97. return query[key];
  98. }
  99. }
  100. return null;
  101. };
  102. return (
  103. // (appContext.systemInfo?.screenHeight || 0) - (appContext.systemInfo?.safeArea?.bottom || 0);
  104. <AppContext.Provider
  105. value={{
  106. systemInfo: result.data,
  107. screenSize: {
  108. width: result.data?.screenWidth || 0,
  109. height: result.data?.screenHeight || 0,
  110. },
  111. padding: {
  112. // top: result.data?.safeArea?.top || 0,
  113. top: 0,
  114. bottom:
  115. (result.data?.screenHeight || 0) -
  116. (result.data?.safeArea?.bottom || 0),
  117. },
  118. }}
  119. >
  120. <WebView src="https://mp.weixin.qq.com/s/4umQqPbPGfCgXqCizeXqKA"></WebView>
  121. <ReduxProvider store={ReduxUtil.store}>{props.children}</ReduxProvider>
  122. </AppContext.Provider>
  123. );
  124. };
  125. export default App;