app.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. //app.js
  2. App({
  3. onLaunch: function () {
  4. //隐藏系统tabbar
  5. wx.hideTabBar();
  6. //获取设备信息
  7. this.getSystemInfo();
  8. // 登录
  9. wx.login({
  10. success: res => {
  11. // 发送 res.code 到后台换取 openId, sessionKey, unionId
  12. }
  13. })
  14. // 获取用户信息
  15. wx.getSetting({
  16. success: res => {
  17. if (res.authSetting['scope.userInfo']) {
  18. // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
  19. wx.getUserInfo({
  20. success: res => {
  21. // 可以将 res 发送给后台解码出 unionId
  22. this.globalData.userInfo = res.userInfo
  23. // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
  24. // 所以此处加入 callback 以防止这种情况
  25. if (this.userInfoReadyCallback) {
  26. this.userInfoReadyCallback(res)
  27. }
  28. }
  29. })
  30. }
  31. }
  32. })
  33. },
  34. onShow: function () {
  35. //隐藏系统tabbar
  36. wx.hideTabBar();
  37. },
  38. getSystemInfo: function () {
  39. let t = this;
  40. wx.getSystemInfo({
  41. success: function (res) {
  42. t.globalData.systemInfo = res;
  43. }
  44. });
  45. },
  46. editTabbar: function () {
  47. let tabbar = this.globalData.tabBar;
  48. let currentPages = getCurrentPages();
  49. let _this = currentPages[currentPages.length - 1];
  50. let pagePath = _this.route;
  51. (pagePath.indexOf('/') != 0) && (pagePath = '/' + pagePath);
  52. for (let i in tabbar.list) {
  53. tabbar.list[i].selected = false;
  54. (tabbar.list[i].pagePath == pagePath) && (tabbar.list[i].selected = true);
  55. }
  56. _this.setData({
  57. tabbar: tabbar
  58. });
  59. },
  60. globalData: {
  61. systemInfo: null,//客户端设备信息
  62. userInfo: null,
  63. tabBar: {
  64. "backgroundColor": "#ffffff",
  65. "color": "#979795",
  66. "selectedColor": "#1c1c1b",
  67. "list": [
  68. {
  69. "pagePath": "/pages/one/one",
  70. "iconPath": "icon/icon_mine.png",
  71. "selectedIconPath": "icon/icon_mine_HL.png",
  72. "text": "第一"
  73. },
  74. {
  75. "pagePath": "/pages/index/index",
  76. "iconPath": "icon/icon_home.png",
  77. "selectedIconPath": "icon/icon_home_HL.png",
  78. "text": "首页"
  79. },
  80. {
  81. "pagePath": "/pages/middle/middle",
  82. "iconPath": "icon/icon_release.png",
  83. "isSpecial": true,
  84. "text": "发布"
  85. },
  86. {
  87. "pagePath": "/pages/mine/mine",
  88. "iconPath": "icon/icon_mine.png",
  89. "selectedIconPath": "icon/icon_mine_HL.png",
  90. "text": "我的"
  91. },
  92. {
  93. "pagePath": "/pages/two/two",
  94. "iconPath": "icon/icon_mine.png",
  95. "selectedIconPath": "icon/icon_mine_HL.png",
  96. "text": "最后"
  97. }
  98. ]
  99. }
  100. }
  101. })