123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- import eventEmitter from '../../utils/eventEmitter'
- import { isPhoneX } from './../../utils/tools'
- import $router from './../../utils/routes'
- let app = getApp()
- Component({
- /**
- * 组件的属性列表
- */
- properties: {
- inactiveColor: {
- type: String,
- value: '#79868F'
- },
- activeColor: {
- type: String,
- value: '#1FE4DC'
- }
- },
- /**
- * 组件的初始数据
- */
- data: {
- active: 0,
- tabItems: [
- {
- title: '首页',
- url: 'home',
- icon: {
- normal: '/assets/images/tabs/home.svg',
- active: '/assets/images/tabs/home-active.svg'
- }
- },
- // {
- // title: '直播',
- // url: 'live',
- // icon: {
- // normal: '/assets/images/tabs/live.svg',
- // active: '/assets/images/tabs/home-active.svg'
- // }
- // },
- {
- title: '发现',
- url: 'find',
- icon: {
- normal: '/assets/images/tabs/find.svg',
- active: '/assets/images/tabs/home-active.svg'
- }
- },
- {
- title: '消息',
- url: 'chatList',
- info: app.globalData.unViewMsg,
- icon: {
- normal: '/assets/images/tabs/msg.svg',
- active: '/assets/images/tabs/msg-active.svg'
- }
- },
- {
- title: '我的',
- url: 'my',
- icon: {
- normal: '/assets/images/tabs/my.svg',
- active: '/assets/images/tabs/my-active.svg'
- }
- },
- ],
- isPhoneX: false
- },
- attached: function() {
- },
- pageLifetimes: {
- show () {
-
- const currentRoute = getCurrentPages()[0].route
- const { tabItems } = this.data
- tabItems[2].info = app.globalData.unViewMsg
- tabItems.forEach((item, index) => {
- if ($router.tabRoutes[item.url] && $router.tabRoutes[item.url].indexOf(currentRoute) !== -1) {
- this.setData({
- active: index,
- tabItems: tabItems,
- })
- }
- })
- isPhoneX().then(res => {
- this.setData({
- isPhoneX: res
- })
- })
- this.init()
- },
- hide () {
- getApp().getIMHandler().removeOnReceiveMessageListener({listener: this.fn})
- }
- },
-
- /**
- * 组件的方法列表
- */
- methods: {
- onChange(e) {
- const index = e.detail, { tabItems } = this.data
- $router.push(tabItems[index].url)
- // wx.switchTab({
- // url: tabItems[index].url,
- // })
- },
- init () {
- this.fn = (msg) => {
-
- const { tabItems } = this.data
- app.globalData.unViewMsg = app.globalData.unViewMsg ? app.globalData.unViewMsg+1 : 1
- tabItems[3].info = app.globalData.unViewMsg
- this.setData({
- tabItems
- })
- app.getNewMessage(msg)
- }
- getApp().getIMHandler().setOnReceiveMessageListener({
- listener: this.fn
- });
- }
- }
- })
|