import {mapState} from 'vuex'; import Tools from '@/common/tools.js'; export default{ data() { return{ } }, computed:{ ...mapState('userInfo',{ userInfo: (state) => state.userInfo, addrInfo: (state) => state.addrInfo, }), //isOpen 为字符串'1或0' // ...mapState('baseConfig',{ // isOpen: (state) => state.isOpen // }), }, methods: { hasInfo(){ // console.log("mixinx.js----",this.userInfo,Boolean(Object.keys(this.userInfo).length > 0),this.userInfo.id) return this.userInfo && Boolean(Object.keys(this.userInfo).length > 0) && this.userInfo.id; }, /** * 跳转再封装,不支持复杂传参。 * const openAnimation=['slide-in-right','slide-in-left','slide-in-top','slide-in-bottom','pop-in','fade-in','zoom-out','zoom-fade-out','none']; * const closeAnimation=['slide-out-right','slide-out-left','slide-out-top','slide-out-bottom','pop-out','fade-out','zoom-in','zoom-fade-in','none']; * animationDuration:500, * animationType:openAnimation[~~(Math.random()*openAnimation.length-1)], * */ navTo(path, params = {}, opt={}) { //params不能{a:JSON.stringify...} if(Tools.inAction('navTo',this)){ return; } if(!path){ // Tools.msg('您跳转地址不存在哦~') return; } opt={type:'push',isCheckLogin:false ,...opt}; //opt传一值补全 if(opt.isCheckLogin && !this.hasInfo()){ uni.navigateTo({ url:'/pages/login/login?toPath='+path }) return; } let objParams = params; let navObj={ push:'navigateTo', replace:'redirectTo', replaceAll:'reLaunch', pushTab:'switchTab', } let pathUrl=path; if(objParams && typeof objParams ==='object' && Object.keys(objParams).length > 0){ let pathArr=[]; Object.keys(objParams).forEach(k =>{ pathArr.push(`${k}=${objParams[k]}`); }) pathUrl = path +'?'+pathArr.join('&'); } // console.log('---',uni[navObj[opt.type]],pathUrl) uni[navObj[opt.type]]({ url:pathUrl }) }, goBack(delta=1) { if (getCurrentPages().length < 2 && 'undefined' !== typeof __wxConfig) { let url = '/' + __wxConfig.pages[0] return uni.redirectTo({url}) } uni.navigateBack({ delta }); }, // stopPrevent(){}, // developing(){ // Tools.msg('开发中....') // }, // goDownload(){ // this.navTo('/pages/index/download') // }, }, }