App.vue 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <script lang="ts">
  2. import {body} from "@/utils/https";
  3. import {groupByKey} from "@/utils/common";
  4. export default <any>{
  5. globalData: {
  6. token: "",
  7. user: {},
  8. isLogin: false,
  9. last: {},
  10. device: {},
  11. deviceId: null,
  12. manualLogout: false
  13. },
  14. onLaunch() {
  15. console.log("onLaunch clean token")
  16. let device = uni.getWindowInfo();
  17. uni.removeStorageSync("token")
  18. let initGlobalData = {
  19. token: "",
  20. user: {},
  21. isLogin: false,
  22. last: {},
  23. device: {
  24. windowWidth:device.windowWidth,
  25. windowHeight:device.windowHeight,
  26. screenTop: device.screenTop,
  27. windowTop: device.windowTop,
  28. },
  29. deviceId: null,
  30. manualLogout: false
  31. }
  32. this.globalData = Object.assign({}, initGlobalData)
  33. body(`/dict/list`).then((res: any) => {
  34. if (res) {
  35. let dicts = res.map((k: any) => {
  36. let {code, name, value, color} = k;
  37. return {code, name, value, color}
  38. })
  39. let dictMap = groupByKey(dicts, "code");
  40. uni.setStorage({key: 'dict', data: dictMap})
  41. }
  42. })
  43. // this.globalData.token = fetchToken();
  44. },
  45. onShow(options: any) {
  46. console.log("app onShow", options)
  47. let device = uni.getWindowInfo();
  48. let backup = uni.getStorageSync('backup')
  49. // console.log("backup", backup)
  50. this.globalData = Object.assign({}, this.globalData, {
  51. device: {
  52. windowWidth: device.windowWidth,
  53. windowHeight: device.windowHeight,
  54. screenTop: device.screenTop,
  55. windowTop: device.windowTop,
  56. }
  57. }, backup)
  58. console.log("backup", this.globalData)
  59. },
  60. onHide() {
  61. console.log("app onHide", getApp<any>().globalData)
  62. //backup
  63. let backup = {...getApp<any>().globalData}
  64. uni.setStorageSync('backup', backup)
  65. },
  66. onPageNotFound() {
  67. uni.switchTab({
  68. url: "/pages/index/index",
  69. });
  70. },
  71. };
  72. </script>
  73. <style lang="scss">
  74. @import '@climblee/uv-ui/index.scss';
  75. @import './custom.scss';
  76. </style>