index.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. const _Http = getApp().globalData.http;
  2. Component({
  3. lifetimes: {
  4. ready: function () {
  5. if (this.data.count == 1) return;
  6. if (wx.getStorageSync('userauth') != 0) {
  7. //判断页面 以免一直触发
  8. const pages = getCurrentPages(),
  9. prevPage = pages[pages.length - 1];
  10. if (prevPage.route == 'pages/login/selectSite' || prevPage.route.includes('pages/tabbar/')) this.setData({
  11. Permission: ['首页', '信息', '我的']
  12. })
  13. }
  14. },
  15. },
  16. data: {
  17. active: 'home',
  18. Permission: ['首页', '信息', '我的'], //可看模块
  19. tabbarList: [{
  20. icon: 'icon-a-biaoqianlanshouyexuanzhong',
  21. acicon: 'icon-a-biaoqianlanshouyexuanzhong',
  22. text: '首页',
  23. url: '/pages/tabbar/home/index',
  24. name: 'home'
  25. },
  26. {
  27. icon: 'icon-a-biaoqianlanxiaoxi',
  28. acicon: 'icon-a-biaoqianlanxiaoxixuanzhong',
  29. text: '信息',
  30. url: '/pages/tabbar/message/index',
  31. name: 'message'
  32. },
  33. {
  34. icon: 'icon-a-biaoqianlanwode',
  35. acicon: 'icon-a-biaoqianlanwodexuanzhong',
  36. text: '我的',
  37. url: '/pages/tabbar/mine/index',
  38. name: 'mine'
  39. }
  40. ],
  41. },
  42. methods: {
  43. onChange(event) {
  44. let active = event.detail,
  45. obj = this.data.tabbarList.find(v => v.name == active);
  46. wx.switchTab({
  47. url: obj.url
  48. });
  49. this.setData({
  50. active
  51. });
  52. },
  53. init() {
  54. const page = getCurrentPages().pop();
  55. let obj = this.data.tabbarList.find(item => item.url === `/${page.route}`);
  56. this.setData({
  57. active: obj.name
  58. });
  59. //socket
  60. if (!getApp().globalData.socketEstablish) getApp().initSocket();
  61. if (!getApp().globalData.socketCallback) getApp().globalData.socketCallback = this.unReadMessageCount.bind(this);
  62. this.setUnReadMessageCount(getApp().globalData.fcount);
  63. },
  64. /* 设置未读数量 */
  65. setUnReadMessageCount(fcount) {
  66. let i = this.data.tabbarList.findIndex(v => v.text == '信息');
  67. this.setData({
  68. [`tabbarList[${i}].fcount`]: fcount
  69. })
  70. },
  71. /* 更新信息数量 */
  72. unReadMessageCount() {
  73. _Http.basic({
  74. "classname": "system.message.Message",
  75. "method": "unReadMessageCount",
  76. "content": {
  77. nocache: true
  78. }
  79. }, false).then(res => {
  80. console.log('信息数量', res)
  81. if (res.msg != '成功') return;
  82. let fcount = res.data.fcount > 99 ? '99+' : res.data.fcount;
  83. if (res.data.fcount == 0) fcount = "";
  84. getApp().globalData.fcount = fcount;
  85. this.setUnReadMessageCount(fcount);
  86. })
  87. }
  88. },
  89. })