index.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. const dayjs=require('../utils/dayjs.min.js')
  2. dayjs.locale('zh-cn')
  3. // 引入全局配置的图片资源地址
  4. import {globalImgUrls} from "../utils/config"
  5. import store from '@/store'
  6. import {defaultTabBarListConfig} from '@/utils/config.js'
  7. // const tabbarPathList=['pages/voice/voice','pages/roadShow/video/list','pages/video/videoList','pages/report/report','pages/question/question']
  8. const tabbarPathList=defaultTabBarListConfig.map(item=>item.pagePath)
  9. module.exports = {
  10. watch: {
  11. tabbarList(){
  12. this.handleSetTabBarItem()
  13. }
  14. },
  15. computed: {
  16. tabbarList(){
  17. return store.state.user.tabbarList
  18. },
  19. userInfo(){//个人信息
  20. return this.$store.state.user.userInfo
  21. }
  22. },
  23. filters: {
  24. /**
  25. * 活动时间格式化
  26. * @param {2021-11-12T09:25:01+08:00} start 开始时间
  27. * @param 2021-11-12T09:25:01+08:00 end 结束时间
  28. * @returns 2020-06-04 15:30-16:30 星期一
  29. */
  30. formatActivityTime(start,end){
  31. const week=dayjs(start).format('dddd');
  32. const day=dayjs(start).format('YYYY-MM-DD');
  33. const startTime=dayjs(start).format('HH:mm');
  34. const endTime=dayjs(end).format('HH:mm');
  35. return `${day} ${startTime}-${endTime} ${week}`
  36. },
  37. /**
  38. * 格式化音频显示时间
  39. * @param 120 时长整数秒
  40. * @returns 02:09
  41. */
  42. formatVoiceTime(e){
  43. let minus=parseInt(e/60)
  44. let sec=parseInt(e%60)
  45. return `${minus>9?minus:'0'+minus}分${sec>9?sec:'0'+sec}秒`
  46. },
  47. /**
  48. * 报告时间格式化
  49. */
  50. formatReportTime(e){
  51. return dayjs(e).format('YYYY-MM-DD')
  52. }
  53. },
  54. data() {
  55. return {
  56. globalImgUrls:globalImgUrls,// 图片资源
  57. globalBgMusic:uni.getBackgroundAudioManager(),
  58. globalRecorder:uni.getRecorderManager(),//录音
  59. };
  60. },
  61. onLoad(options) {
  62. console.log('mixin onLoad',options);
  63. const page = this.$mp&&this.$mp.page
  64. console.log('当前页面路由',page.route);
  65. uni.getSystemInfo({
  66. success: function (res) {
  67. console.log('宽度:',res.windowWidth);
  68. console.log('设备:',res.platform);
  69. if(page.route=='pages/login'||page.route=='pages/pc') return
  70. if (res.windowWidth > 750||['windows','mac'].includes(res.platform)) {
  71. const params=options
  72. let paramsStr=`xcxPath=${decodeURIComponent(page.route)}`
  73. for(const key in params){
  74. paramsStr=`${paramsStr}&${key}=${params[key]}`
  75. }
  76. console.log('进入pc');
  77. uni.reLaunch({
  78. url: `/pages/pc?${paramsStr}&platform_source=xcx`,
  79. });
  80. }
  81. },
  82. fail:function(res){
  83. }
  84. })
  85. },
  86. onShow(){
  87. this.handleActivityListPageRefresh()
  88. const page = this.$mp&&this.$mp.page;
  89. if(page&&tabbarPathList.includes(page.route)){
  90. this.$store.dispatch('getTabBar')
  91. }
  92. this.handleSetTabBarItem()
  93. },
  94. methods: {
  95. // 设置tabbar的选中态
  96. handleSetTabBarItem(){
  97. const page = this.$mp&&this.$mp.page;
  98. const tabbarList=this.$store.state.user.tabbarList
  99. if(!page||tabbarList.length==0) return
  100. let selected=page.route
  101. // 如果用户的tabbar 改变了 并且他点击的tabbar选项正好不存在了 则重定向到第一个tabbar
  102. let temarr=tabbarList.map(item=>item.pagePath)
  103. if(tabbarPathList.includes(selected)&&!temarr.includes(selected)){
  104. selected=tabbarList[0].pagePath
  105. uni.switchTab({ url: `/${selected}` })
  106. }
  107. if(tabbarPathList.includes(page.route)){
  108. if (page&&typeof page.getTabBar === "function" && page.getTabBar()) {
  109. page.getTabBar().setData({
  110. selected: selected,
  111. list:tabbarList
  112. });
  113. }
  114. }
  115. },
  116. // 控制是否刷新活动列表页
  117. handleActivityListPageRefresh(){
  118. const page = this.$mp&&this.$mp.page;
  119. if(page&&page.route&&page.route=='pages/activity/activity') return
  120. if(page&&page.route&&tabbarPathList.includes(page.route)){
  121. this.$store.commit('setActivityListPageRefreshStatus', true)
  122. }else{
  123. this.$store.commit('setActivityListPageRefreshStatus', false)
  124. }
  125. },
  126. //全局检测用户是否绑定过方法(用户点击前的判断或者其他时候的判断)
  127. checkUserIsBind(){
  128. return new Promise((resovle,reject)=>{
  129. if(store.state.user.userInfo.is_bind===0){
  130. wx.showModal({
  131. title: '温馨提示',
  132. content: '为了优化您的用户体验,\n 请登录后查看更多信息!',
  133. confirmText:'去登录',
  134. cancelColor:'#666',
  135. confirmColor:'#E6B77D',
  136. success: function (res) {
  137. if (res.confirm) {
  138. console.log('用户点击确定');
  139. uni.reLaunch({
  140. url:'/pages/login'
  141. })
  142. } else if (res.cancel) {
  143. console.log('用户点击取消');
  144. }
  145. }
  146. });
  147. reject()
  148. }else{
  149. resovle('不用登录')
  150. }
  151. })
  152. }
  153. },
  154. };