index.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. * 格式化音频显示时间
  37. * @param 120 时长整数秒
  38. * @returns 02:09
  39. */
  40. formatVoiceTime(e){
  41. let minus=parseInt(e/60)
  42. let sec=parseInt(e%60)
  43. return `${minus>9?minus:'0'+minus}分${sec>9?sec:'0'+sec}秒`
  44. },
  45. /**
  46. * 报告时间格式化
  47. */
  48. formatReportTime(e){
  49. return moment(e).format('YYYY.MM.DD HH:mm')
  50. }
  51. },
  52. data() {
  53. return {
  54. globalImgUrls:globalImgUrls,// 图片资源
  55. globalBgMusic:uni.getBackgroundAudioManager()
  56. };
  57. },
  58. onLoad() {},
  59. onShow(){
  60. this.handleActivityListPageRefresh()
  61. const page = this.$mp&&this.$mp.page;
  62. if(page&&tabbarPathList.includes(page.route)){
  63. this.$store.dispatch('getTabBar')
  64. }
  65. this.handleSetTabBarItem()
  66. },
  67. methods: {
  68. // 设置tabbar的选中态
  69. handleSetTabBarItem(){
  70. const page = this.$mp&&this.$mp.page;
  71. const tabbarList=this.$store.state.user.tabbarList
  72. if(!page||tabbarList.length==0) return
  73. let selected=page.route
  74. // 如果用户的tabbar 改变了 并且他点击的tabbar选项正好不存在了 则重定向到第一个tabbar
  75. let temarr=tabbarList.map(item=>item.pagePath)
  76. if(tabbarPathList.includes(selected)&&!temarr.includes(selected)){
  77. selected=tabbarList[0].pagePath
  78. uni.switchTab({ url: `/${selected}` })
  79. }
  80. if(tabbarPathList.includes(page.route)){
  81. if (page&&typeof page.getTabBar === "function" && page.getTabBar()) {
  82. page.getTabBar().setData({
  83. selected: selected,
  84. list:tabbarList
  85. });
  86. }
  87. }
  88. },
  89. // 控制是否刷新活动列表页
  90. handleActivityListPageRefresh(){
  91. const page = this.$mp&&this.$mp.page;
  92. if(page&&page.route&&page.route=='pages/activity/activity') return
  93. if(page&&page.route&&tabbarPathList.includes(page.route)){
  94. this.$store.commit('setActivityListPageRefreshStatus', true)
  95. }else{
  96. this.$store.commit('setActivityListPageRefreshStatus', false)
  97. }
  98. },
  99. },
  100. };