app.tsx 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import Taro, { useLaunch } from "@tarojs/taro";
  2. import { PropsWithChildren } from "react";
  3. import "./app.less";
  4. import { useAppStoreActions } from "./store/appStore";
  5. import { generateRandomId } from '@/utils/index'
  6. import {LOGIN_ID_STORAGE_KEY } from '@/xiaolanbenlib/constant'
  7. import dayjs from "dayjs";
  8. import 'dayjs/locale/zh-cn'
  9. import relativeTime from 'dayjs/plugin/relativeTime'
  10. dayjs.locale('zh-cn');
  11. dayjs.extend(relativeTime)
  12. if (process.env.TARO_ENV == "h5") {
  13. const VConsole = require("vconsole");
  14. new VConsole();
  15. }
  16. function App({ children }: PropsWithChildren<any>) {
  17. const { setSystemInfo } = useAppStoreActions();
  18. useLaunch((options) => {
  19. console.log("App launched.", options.query);
  20. const updateManager = Taro.getUpdateManager();
  21. updateManager.onCheckForUpdate(function (res) {
  22. // 请求完新版本信息的回调
  23. console.log("需要更新: ", res.hasUpdate);
  24. });
  25. updateManager.onUpdateReady(function () {
  26. Taro.showModal({
  27. title: "更新提示",
  28. content: "新版本已经准备好,是否重启应用?",
  29. success: function (res) {
  30. if (res.confirm) {
  31. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  32. updateManager.applyUpdate();
  33. }
  34. },
  35. });
  36. });
  37. updateManager.onUpdateFailed(function () {
  38. // 新版本下载失败
  39. });
  40. const res = Taro.getSystemInfoSync()
  41. setSystemInfo(res);
  42. // console.log(a.miniProgram)
  43. // Taro.getSystemInfoAsync({
  44. // success(res) {
  45. // },
  46. // });
  47. const uuid = generateRandomId()
  48. console.log(uuid)
  49. Taro.setStorageSync(LOGIN_ID_STORAGE_KEY, uuid) // 打开小程序时创建 login_uuid
  50. });
  51. return <>{children}</>;
  52. }
  53. export default App;