index.js 2.6 KB

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