App.vue 2.0 KB

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