index.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. const moment=require('../utils/moment-with-locales.min')
  2. moment.locale('zh-cn');
  3. // 引入全局配置的图片资源地址
  4. import {globalImgUrls} from "../utils/config"
  5. import store from '@/store'
  6. const tabbarPathList=['pages/activity/activity','pages/buy/buy','pages/chart/chart','pages/user/user','pages/report/report']
  7. module.exports = {
  8. watch: {
  9. tabbarList(){
  10. this.handleSetTabBarItem()
  11. }
  12. },
  13. computed: {
  14. tabbarList(){
  15. return store.state.user.tabbarList
  16. },
  17. userInfo(){//个人信息
  18. return this.$store.state.user.userInfo
  19. }
  20. },
  21. filters: {
  22. /**
  23. * 活动时间格式化
  24. * @param {2021-11-12T09:25:01+08:00} start 开始时间
  25. * @param 2021-11-12T09:25:01+08:00 end 结束时间
  26. * @returns 2020-06-04 15:30-16:30 星期一
  27. */
  28. formatActivityTime(start,end){
  29. const week=moment(start).format('dddd');
  30. const day=moment(start).format('YYYY-MM-DD');
  31. const startTime=moment(start).format('HH:mm');
  32. const endTime=moment(end).format('HH:mm');
  33. return `${day} ${startTime}-${endTime} ${week}`
  34. }
  35. },
  36. data() {
  37. return {
  38. globalImgUrls:globalImgUrls,// 图片资源
  39. globalBgMusic:uni.getBackgroundAudioManager()
  40. };
  41. },
  42. onLoad() {},
  43. onShow(){
  44. this.handleActivityListPageRefresh()
  45. this.$store.dispatch('getTabBar')
  46. this.handleSetTabBarItem()
  47. },
  48. methods: {
  49. // 设置tabbar的选中态
  50. handleSetTabBarItem(){
  51. const page = this.$mp&&this.$mp.page;
  52. const tabbarList=this.$store.state.user.tabbarList
  53. if(!page||tabbarList.length==0) return
  54. let selected=page.route
  55. // 如果用户的tabbar 改变了 并且他点击的tabbar选项正好不存在了 则重定向到第一个tabbar
  56. let temarr=tabbarList.map(item=>item.pagePath)
  57. if(tabbarPathList.includes(selected)&&!temarr.includes(selected)){
  58. selected=tabbarList[0].pagePath
  59. uni.switchTab({ url: `/${selected}` })
  60. }
  61. if(tabbarPathList.includes(page.route)){
  62. if (page&&typeof page.getTabBar === "function" && page.getTabBar()) {
  63. page.getTabBar().setData({
  64. selected: selected,
  65. list:tabbarList
  66. });
  67. }
  68. }
  69. },
  70. // 控制是否刷新活动列表页
  71. handleActivityListPageRefresh(){
  72. const page = this.$mp&&this.$mp.page;
  73. if(page&&page.route&&page.route=='pages/activity/activity') return
  74. if(page&&page.route&&tabbarPathList.includes(page.route)){
  75. this.$store.commit('setActivityListPageRefreshStatus', true)
  76. }else{
  77. this.$store.commit('setActivityListPageRefreshStatus', false)
  78. }
  79. },
  80. },
  81. };