App.vue 2.1 KB

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