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','pages/question/question'] 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') } }, data() { return { globalImgUrls:globalImgUrls,// 图片资源 globalBgMusic:uni.getBackgroundAudioManager(), globalRecorder:uni.getRecorderManager(),//录音 }; }, onLoad(options) { console.log('mixin onLoad',options); const page = this.$mp&&this.$mp.page console.log('当前页面路由',page.route); uni.getSystemInfo({ success: function (res) { console.log('宽度:',res.windowWidth); console.log('设备:',res.platform); if(page.route=='pages/login'||page.route=='pages/pc') return if (res.windowWidth > 600||['windows','mac'].includes(res.platform)) { const params=options let paramsStr=`xcxPath=${decodeURIComponent(page.route)}` for(const key in params){ paramsStr=`${paramsStr}&${key}=${params[key]}` } console.log('进入pc'); uni.reLaunch({ url: `/pages/pc?${paramsStr}`, }); } }, fail:function(res){ } }) }, 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) } }, }, };