App.vue 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <script>
  2. import $api from 'static/js/api.js';
  3. import $app from 'static/js/app.js';
  4. export default {
  5. onLaunch: function(options) {
  6. console.log('App Launch')
  7. // 判断用户是否通过分销码进入------------------------------------------------------
  8. if (options.scene === 1011|| options.scene === 1012||options.scene === 1013) {
  9. const decodedUrl = decodeURIComponent(options.query.q);
  10. const urlParts = decodedUrl.split('?');
  11. if (urlParts.length > 1) {
  12. const queryParams = urlParts[1];
  13. const paramPairs = queryParams.split('&');
  14. const resultObj = {};
  15. paramPairs.forEach(pair => {
  16. const [key, value] = pair.split('=');
  17. resultObj[key] = value;
  18. });
  19. const adminUserId = resultObj['adminUserId'];
  20. uni.setStorageSync('ADMIN_USERID', adminUserId);
  21. console.info(uni.getStorageSync('ADMIN_USERID'),'---用户通过扫码进入')
  22. }
  23. }
  24. },
  25. onShow: function(options) {
  26. // 判断用户是否通过分销码进入------------------------------------------------------
  27. if (options.scene === 1011||options.scene === 1012||options.scene === 1013) {
  28. const decodedUrl = decodeURIComponent(options.query.q);
  29. const urlParts = decodedUrl.split('?');
  30. if (urlParts.length > 1) {
  31. const queryParams = urlParts[1];
  32. const paramPairs = queryParams.split('&');
  33. const resultObj = {};
  34. paramPairs.forEach(pair => {
  35. const [key, value] = pair.split('=');
  36. resultObj[key] = value;
  37. });
  38. const adminUserId = resultObj['adminUserId'];
  39. uni.setStorageSync('ADMIN_USERID', adminUserId);
  40. console.info(uni.getStorageSync('ADMIN_USERID'),'---用户通过扫码进入')
  41. }
  42. }
  43. // 自动更新管理-------------------------------------------------------------------
  44. const updateManager = uni.getUpdateManager();
  45. updateManager.onUpdateReady(function(res) {
  46. uni.showModal({
  47. title: '更新提示',
  48. content: '新版本已经准备好,是否重启应用?',
  49. success(res) {
  50. if (res.confirm) updateManager.applyUpdate();
  51. }
  52. });
  53. });
  54. updateManager.onUpdateFailed(function(res) {
  55. uni.showModal({
  56. title: '更新失败',
  57. content: '小程序已有新版本,请稍后重试更新!',
  58. showCancel: false
  59. });
  60. });
  61. // 自动登录用户-------------------------------------------------------------------
  62. const userInfo = $app.storage.get("USER_INFO");
  63. if (!userInfo) $api.login();
  64. },
  65. onHide: function() {
  66. console.log('App Hide')
  67. }
  68. }
  69. </script>
  70. <style>
  71. /*每个页面公共css */
  72. @import "components/ax/ax.css";
  73. @import "static/css/app.css";
  74. </style>