123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- const moment=require('../utils/moment-with-locales.min')
- moment.locale('zh-cn');
- // 引入全局配置的图片资源地址
- import {globalImgUrls} from "../utils/config"
- import store from '@/store'
- const tabbarPathList=['pages/activity/activity','pages/buy/buy','pages/chart/chart','pages/user/user','pages/report/report']
- module.exports = {
- watch: {
- tabbarList(){
- this.handleSetTabBarItem()
- }
- },
- computed: {
- tabbarList(){
- return store.state.user.tabbarList
- },
- userInfo(){//个人信息
- return this.$store.state.user.userInfo
- }
- },
- filters: {
- /**
- * 活动时间格式化
- * @param {2021-11-12T09:25:01+08:00} start 开始时间
- * @param 2021-11-12T09:25:01+08:00 end 结束时间
- * @returns 2020-06-04 15:30-16:30 星期一
- */
- formatActivityTime(start,end){
- const week=moment(start).format('dddd');
- const day=moment(start).format('YYYY-MM-DD');
- const startTime=moment(start).format('HH:mm');
- const endTime=moment(end).format('HH:mm');
- return `${day} ${startTime}-${endTime} ${week}`
- },
- /**
- * 格式化音频显示时间
- * @param 120 时长整数秒
- * @returns 02:09
- */
- formatVoiceTime(e){
- let minus=parseInt(e/60)
- let sec=parseInt(e%60)
- return `${minus>9?minus:'0'+minus}分${sec>9?sec:'0'+sec}秒`
- },
- /**
- * 报告时间格式化
- */
- formatReportTime(e){
- return moment(e).format('YYYY.MM.DD HH:mm')
- }
- },
- data() {
- return {
- globalImgUrls:globalImgUrls,// 图片资源
- globalBgMusic:uni.getBackgroundAudioManager()
- };
- },
- onLoad() {},
- onShow(){
- this.handleActivityListPageRefresh()
- const page = this.$mp&&this.$mp.page;
- if(page&&tabbarPathList.includes(page.route)){
- this.$store.dispatch('getTabBar')
- }
- this.handleSetTabBarItem()
- },
- methods: {
- // 设置tabbar的选中态
- handleSetTabBarItem(){
- const page = this.$mp&&this.$mp.page;
- const tabbarList=this.$store.state.user.tabbarList
- if(!page||tabbarList.length==0) return
-
- let selected=page.route
- // 如果用户的tabbar 改变了 并且他点击的tabbar选项正好不存在了 则重定向到第一个tabbar
- let temarr=tabbarList.map(item=>item.pagePath)
- if(tabbarPathList.includes(selected)&&!temarr.includes(selected)){
- selected=tabbarList[0].pagePath
- uni.switchTab({ url: `/${selected}` })
- }
- if(tabbarPathList.includes(page.route)){
- if (page&&typeof page.getTabBar === "function" && page.getTabBar()) {
- page.getTabBar().setData({
- selected: selected,
- list:tabbarList
- });
- }
- }
- },
- // 控制是否刷新活动列表页
- handleActivityListPageRefresh(){
- const page = this.$mp&&this.$mp.page;
- if(page&&page.route&&page.route=='pages/activity/activity') return
-
- if(page&&page.route&&tabbarPathList.includes(page.route)){
- this.$store.commit('setActivityListPageRefreshStatus', true)
- }else{
- this.$store.commit('setActivityListPageRefreshStatus', false)
- }
- },
- },
- };
|