App.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <script>
  2. import {
  3. onBackPress
  4. } from "@dcloudio/uni-app"
  5. import {
  6. toast,
  7. getUserIdentity
  8. } from "@/utils/common";
  9. import {
  10. banbenImpinfo
  11. } from "@/api/login.js"
  12. import cacheManager from "@/utils/cacheManager.js";
  13. import {
  14. useIsCanBack
  15. } from "@/store/isCanBack.js"
  16. export default {
  17. // creat by wgy 0619 生命周期 钩子
  18. onLaunch: function() {
  19. // #ifdef APP-PLUS
  20. // 有auth
  21. if (cacheManager.get('auth')) {
  22. banbenImpinfo({}).then(res => {
  23. if (res.code == 0) {
  24. if (res.data.chanpinId != 0) {
  25. if (cacheManager.get('xuexi-shuxue')) {
  26. cacheManager.remove("xuexi-shuxue")
  27. }
  28. // 预防丢失
  29. cacheManager.updateObject("auth",{
  30. banbenId:res.data.banbenId,
  31. chanpinId:res.data.chanpinId,
  32. danyuanId:res.data.danyuanId,
  33. dengjiId:res.data.dengjiId,
  34. })
  35. uni.switchTab({
  36. url: `/pages/chanpinneirong/index`,
  37. success() {
  38. plus.navigator.closeSplashscreen();
  39. }
  40. })
  41. } else {
  42. // 没学过
  43. uni.switchTab({
  44. url: `/pages/chanpinXuanze/index`,
  45. success() {
  46. plus.navigator.closeSplashscreen();
  47. }
  48. })
  49. }
  50. }
  51. }).catch(() => {
  52. toast("App.vue,banbenImpinfo接口错误")
  53. cacheManager.clearAll()
  54. return false
  55. })
  56. } else {
  57. cacheManager.clearAll()
  58. uni.reLaunch({
  59. url: '/pages/login/index',
  60. success() {
  61. plus.navigator.closeSplashscreen();
  62. }
  63. });
  64. }
  65. // #endif
  66. },
  67. onShow: function() {
  68. // #ifdef APP-PLUS
  69. const webview = plus.webview.currentWebview();
  70. plus.key.addEventListener('backbutton', () => {
  71. const store = useIsCanBack();
  72. if (!store.isCanBack) {
  73. event.preventDefault();
  74. return false
  75. } else {
  76. return true
  77. }
  78. });
  79. // #endif
  80. },
  81. onHide: function() {
  82. }
  83. }
  84. </script>
  85. <style lang="scss">
  86. /* 公共样式 */
  87. @import '/common/styles/index.scss';
  88. // 小米字体、思源黑体、苹果平方、数字字体、通用无衬线字体
  89. body,
  90. html,
  91. #app {
  92. font-family: "MiSans", "PingFang SC", sans-serif;
  93. margin: 0;
  94. padding: 0;
  95. box-sizing: border-box;
  96. }
  97. </style>