App.vue 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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) {
  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('adminUserId', adminUserId);
  21. }
  22. }
  23. },
  24. onShow: function() {
  25. // 自动更新管理-------------------------------------------------------------------
  26. const updateManager = uni.getUpdateManager();
  27. updateManager.onUpdateReady(function(res) {
  28. uni.showModal({
  29. title: '更新提示',
  30. content: '新版本已经准备好,是否重启应用?',
  31. success(res) {
  32. if (res.confirm) updateManager.applyUpdate();
  33. }
  34. });
  35. });
  36. updateManager.onUpdateFailed(function(res) {
  37. uni.showModal({
  38. title: '更新失败',
  39. content: '小程序已有新版本,请稍后重试更新!',
  40. showCancel: false
  41. });
  42. });
  43. // 自动登录用户-------------------------------------------------------------------
  44. const userInfo = $app.storage.get("USER_INFO");
  45. if (!userInfo) $api.login();
  46. },
  47. onHide: function() {
  48. console.log('App Hide')
  49. }
  50. }
  51. </script>
  52. <style>
  53. /*每个页面公共css */
  54. @import "components/ax/ax.css";
  55. @import "static/css/app.css";
  56. </style>