mixin.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import {mapState} from 'vuex';
  2. import Tools from '@/common/tools.js';
  3. export default{
  4. data() {
  5. return{
  6. }
  7. },
  8. computed:{
  9. ...mapState('userInfo',{
  10. userInfo: (state) => state.userInfo
  11. }),
  12. //isOpen 为字符串'1或0'
  13. // ...mapState('baseConfig',{
  14. // isOpen: (state) => state.isOpen
  15. // }),
  16. },
  17. methods: {
  18. hasInfo(){
  19. // console.log("mixinx.js----",this.userInfo,Boolean(Object.keys(this.userInfo).length > 0),this.userInfo.id)
  20. return this.userInfo && Boolean(Object.keys(this.userInfo).length > 0) && this.userInfo.id;
  21. },
  22. // checkIsAuth(){
  23. // return new Promise( async (resolve,reject)=>{
  24. // if(this.userInfo.is_auth === 2){
  25. // resolve(true);
  26. // return;
  27. // }
  28. // let userInfo = await this.$store.dispatch('user/getUserInfo');
  29. // if(userInfo.is_auth === 2){
  30. // resolve(true);
  31. // }else if(userInfo.is_auth === 0){
  32. // this.$tools.msg('您尚未实名认证')
  33. // reject(false);
  34. // }else if(userInfo.is_auth === 1){
  35. // this.$tools.msg('您实名认证审核中..')
  36. // reject(false);
  37. // }else if(userInfo.is_auth === -1){
  38. // this.$tools.msg('您实名未通过,请重新申请')
  39. // reject(false);
  40. // }
  41. // })
  42. // },
  43. /**
  44. * 跳转再封装,不支持复杂传参。
  45. * const openAnimation=['slide-in-right','slide-in-left','slide-in-top','slide-in-bottom','pop-in','fade-in','zoom-out','zoom-fade-out','none'];
  46. * const closeAnimation=['slide-out-right','slide-out-left','slide-out-top','slide-out-bottom','pop-out','fade-out','zoom-in','zoom-fade-in','none'];
  47. * animationDuration:500,
  48. * animationType:openAnimation[~~(Math.random()*openAnimation.length-1)],
  49. *
  50. */
  51. navTo(path, params = {}, opt={}) {
  52. //params不能{a:JSON.stringify...}
  53. if(Tools.inAction('navTo',this)){
  54. return;
  55. }
  56. if(!path){
  57. // Tools.msg('您跳转地址不存在哦~')
  58. return;
  59. }
  60. opt={type:'push',isCheckLogin:false ,...opt}; //opt传一值补全
  61. if(opt.isCheckLogin && !this.hasInfo()){
  62. uni.navigateTo({
  63. url:'/pages/login/login'
  64. })
  65. return;
  66. }
  67. let objParams = params;
  68. let navObj={
  69. push:'navigateTo',
  70. replace:'redirectTo',
  71. replaceAll:'reLaunch',
  72. pushTab:'switchTab',
  73. }
  74. let pathUrl=path;
  75. if(objParams && typeof objParams ==='object' && Object.keys(objParams).length > 0){
  76. let pathArr=[];
  77. Object.keys(objParams).forEach(k =>{
  78. pathArr.push(`${k}=${objParams[k]}`);
  79. })
  80. pathUrl = path +'?'+pathArr.join('&');
  81. }
  82. // console.log('---',uni[navObj[opt.type]],pathUrl)
  83. uni[navObj[opt.type]]({
  84. url:pathUrl
  85. })
  86. },
  87. goBack() {
  88. if (getCurrentPages().length < 2 && 'undefined' !== typeof __wxConfig) {
  89. let url = '/' + __wxConfig.pages[0]
  90. return uni.redirectTo({url})
  91. }
  92. uni.navigateBack({
  93. delta: 1
  94. });
  95. },
  96. // stopPrevent(){},
  97. // developing(){
  98. // Tools.msg('开发中....')
  99. // },
  100. // goDownload(){
  101. // this.navTo('/pages/index/download')
  102. // },
  103. },
  104. }