import { mapState, mapGetters } from 'vuex' var app = getApp(); export const myMixin = { data() { return { loading: false, // 头部数据 top: 0, navHeight: 0, navIndex: 0, hearHeight: "0", tabArr: [0], navList: [], shopData: {}, event_rul: app.globalData.event_url, bgColor: false, boxHeight: 0, // 要减去的高度 mgtHeight: 0, // 代替 margin 的高度 timeupe: null, } }, computed: { ...mapState(['opt','navFixed','navHeightTop']), ...mapGetters(['getHeardHeight']) }, mounted() { this.setNavHeight() this.getData() this.timeupe = setTimeout(() => { this.styleMgtop() }, 100) }, beforeDestroy() { clearTimeout(this.timeupe) }, watch:{ navFixed: { handler(newValue, oldValue) { this.bgColor = newValue }, immediate: true, deep: true, }, }, methods: { getData: function () { const that = this; that.loading = true; uni.getStorage({ key: "header_data", success: function(res){ that.shopData = res.data; console.log("打印shopData============",that.shopData) if(that.shopData.headTitle) { that.shopData.headTitle.map((item)=> { that.navList.push(item.text); }) } }, }) }, setNavHeight() { let elemetn // #ifdef MP-WEIXIN let menuButtonInfo = uni.getMenuButtonBoundingClientRect() uni.getSystemInfo({ success: (res) => { if (res) { elemetn = res.statusBarHeight } }, }) // #endif // #ifdef MP-WEIXIN this.navHeight = menuButtonInfo.bottom + menuButtonInfo.top - elemetn // console.log(menuButtonInfo,elemetn, 'navheight') // #endif // #ifndef MP this.navHeight = 60 // #endif // const vr = uni.getSystemInfoSync(); }, styleMgtop() { let query = uni.createSelectorQuery().in(this); query.select(".top-mg").boundingClientRect(); query.exec((res) => { if(res[0] != null) { this.mgtHeight = res[0].height this.boxHeight = (this.mgtHeight + this.getHeardHeight) + 'px' } }); }, navHeadSelect(e, h, hh) { this.hearHeight = this.navHeight + h + 15 + 'px' this.top = '-' + (hh - (this.navHeight + h + 15)) + 'px' this.navIndex = e; if(this.tabArr.indexOf(e) < 0){ this.tabArr.push(e); } }, }, }