App.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. cacheManager.updateObject("auth",{
  29. banbenId:res.data.banbenId,
  30. chanpinId:res.data.chanpinId,
  31. danyuanId:res.data.danyuanId,
  32. dengjiId:res.data.dengjiId,
  33. })
  34. uni.switchTab({
  35. url: `/pages/chanpinneirong/index`,
  36. success() {
  37. plus.navigator.closeSplashscreen();
  38. }
  39. })
  40. } else {
  41. // 没学过
  42. uni.switchTab({
  43. url: `/pages/chanpinXuanze/index`,
  44. success() {
  45. plus.navigator.closeSplashscreen();
  46. }
  47. })
  48. }
  49. }
  50. }).catch(() => {
  51. toast("App.vue,banbenImpinfo接口错误")
  52. cacheManager.clearAll()
  53. return false
  54. })
  55. } else {
  56. cacheManager.clearAll()
  57. uni.reLaunch({
  58. url: '/pages/login/index',
  59. success() {
  60. plus.navigator.closeSplashscreen();
  61. }
  62. });
  63. }
  64. // #endif
  65. },
  66. onShow: function() {
  67. // #ifdef APP-PLUS
  68. const webview = plus.webview.currentWebview();
  69. plus.key.addEventListener('backbutton', () => {
  70. const store = useIsCanBack();
  71. if (!store.isCanBack) {
  72. event.preventDefault();
  73. return false
  74. } else {
  75. return true
  76. }
  77. });
  78. // #endif
  79. },
  80. onHide: function() {
  81. }
  82. }
  83. </script>
  84. <style lang="scss">
  85. /* 公共样式 */
  86. @import '/common/styles/index.scss';
  87. // 西文、雅黑、黑体、宋体
  88. body,
  89. html,
  90. #app {
  91. font-family: "Helvetica Neue", "Microsoft YaHei", "SimHei", "SimSun", "Arial", sans-serif;
  92. margin: 0;
  93. padding: 0;
  94. box-sizing: border-box;
  95. }
  96. </style>