index.js 2.4 KB

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