Commit a437b1da by 程默

tabbar页面兼容

parent 3579d1b3
<template>
<div class="domain">
<view class="ant-daipinglun">1</view>
<!-- <goods-list id="goodsList"></goods-list> -->
<div v-for="(item,index) in pageData" :key="index">
<div v-if="item.componentCode=='banner'">
<div v-for="(item, index) in pageData" :key="index">
<div v-if="item.componentCode == 'banner'">
baaaa
<banner :datas="item"></banner>
</div>
<div v-else-if="item.componentCode=='goods-list'">
<div v-else-if="item.componentCode == 'goods-list'">
<goods-list :datas="item"></goods-list>
</div>
</div>
......@@ -13,7 +15,7 @@
src="http://cdn.mayi888.com/public/jpg/33ff0efc-96b5-4044-a65a-07799dfe98e1.jpg?x-oss-process=image/resize,limit_1,w_750"
></image>
<van-button type="primary">按钮</van-button>
<view class="ant-bofang">1</view> -->
-->
<!-- ----瀑布流开始---- -->
<!-- <waterfall-flow id="waterfallFlow"></waterfall-flow> -->
<!-- ----瀑布流结束---- -->
......@@ -26,6 +28,8 @@
</template>
<script>
import { setTabBarActive, checkTabbarPage } from "../../utils/mayi.js";
export default {
data() {
return {
......@@ -43,11 +47,16 @@ export default {
};
}
},
onShow() {
setTabBarActive.bind(this)(checkTabbarPage('/'));
},
methods: {
init(pageList) {
setTabBarActive.bind(this)(checkTabbarPage('/'));
this.pageInfo = pageList.filter((item) => item.pageCode == 1)[0];
this.pageData = JSON.parse(this.pageInfo.pageData);
console.log('36',this.pageData)
console.log("36", this.pageData);
},
},
};
......@@ -55,7 +64,7 @@ export default {
<style>
.domain {
text-align: center;
/* text-align: center; */
/* padding-top: 50%; */
}
</style>
\ No newline at end of file
......@@ -79,15 +79,6 @@ export default {
this.options = options;
Object.assign(this.$data, this.$options.data());
console.log(
wx.getStorageSync("sessionid"),
options,
"index------",
this.shopId,
"-----",
wx.getStorageSync("openid"),
this.shopId
);
//获取openId
wx.login({
success: res => {
......@@ -109,21 +100,7 @@ export default {
//检测登录态
this.checkLogin();
console.log(this.params,6666666)
this.options = options;
console.log('-------1',options.scene)
console.log(this.options)
console.log('-------link',this.mpApp.globalData.tabBarPageLink)
// tabbar 跳转
// if (this.mpApp.globalData.tabBarPageLink) {
// this.page = this.mpApp.globalData.tabBarPageLink;
// this.mpApp.globalData.tabBarPageLink=''
// }
// if (options.from && options.from == "tabbar") {
// this.page = decodeURIComponent(options.backpath);
// }
// ---------
if (options.share) {
//来自分享
this.link = decodeURIComponent(options.share);
......@@ -327,6 +304,19 @@ export default {
}
this.init();
},
onShow(){
let ss=wx.getStorageSync("sessionid");
if (ss && !this.params.includes("sessionid")) {
this.params +=`&sessionid=${ss}`
}
console.log(this.getTabBar,'312')
if (typeof this.getTabBar === 'function' &&
this.getTabBar()) {
this.getTabBar().setData({
selected: this.index
})
}
},
methods: {
init() {
// 获取小程序开启的订阅消息配置
......
......@@ -27,12 +27,14 @@
<script>
import { serialize } from "@/utils/index";
import { checkTabbarPage } from "@/utils/mayi";
import { wx_decode } from "@/utils/wxIndex.js";
import login from "@/api/login";
import shop from "@/api/shop";
import indexApi from "@/api/index.js";
var WXBizDataCrypt = require("@/utils/WXBizDataCrypt");
export default {
name:'login',
components: {
// card
},
......@@ -315,12 +317,25 @@ export default {
delta: 1
});
}else{
wx.reLaunch({
let parseLink=decodeURIComponent(this.backPath);
let isTabbarIndex =checkTabbarPage(parseLink)
console.log('32111',isTabbarIndex,parseLink)
wx.navigateBack()
return
if(isTabbarIndex>-1){
wx.navigateBack()
// wx.switchTab({
// url: parseLink == '/' ? '/pages/home/main' : `/pages/tabBar${isTabbarIndex}/main`,
// })
}else{
wx.redirectTo({
url: `../index/main?from=login&backpath=${
this.backPath
}&params=${encodeURIComponent(this.backParams)}`
});
}
}
},
getPhoneNumber(e) {
wx.checkSession({
......
......@@ -3,28 +3,39 @@
-->
<template>
<div>
{{ pageUrl }}
<web-view :src="pageUrl" @error="handleError"></web-view>
</div>
</template>
<script>
import { getUrlofLink } from "../../utils/mayi.js";
import {
getUrlofLink,
setTabBarActive,
checkTabbarPage,
} from "../../utils/mayi.js";
export default {
data() {
return {
link: process.env.BASE_URL,
page: "/",
params: "?mixid=" + this.$store.state.mixid,
index:1
index: 1,
ss: "",
};
},
computed: {
pageUrl() {
return this.link + this.page + this.params;
return this.link + this.page + this.params + this.ss;
},
},
onLoad(options) {
let ss = wx.getStorageSync("sessionid");
this.ss = ss ? `&sessionid=${ss}` : "";
// tabbar 跳转
let homeIndex = checkTabbarPage("/");
homeIndex != 0 && homeIndex==this.index && (this.index = 0);
if (this.mpApp.globalData.footerVal.componentData.list[this.index].link) {
this.page = getUrlofLink(
this.mpApp.globalData.footerVal.componentData.list[this.index].link
......@@ -32,20 +43,13 @@ export default {
this.mpApp.globalData.tabBarPageLink = "";
}
},
onShow(){
console.log('show')
if (this.mpApp.globalData.footerVal.componentData.list[this.index].link) {
this.page = getUrlofLink(
this.mpApp.globalData.footerVal.componentData.list[this.index].link
);
this.mpApp.globalData.tabBarPageLink = "";
onShow() {
let ss = wx.getStorageSync("sessionid");
if (!this.ss && ss) {
this.ss = `&sessionid=${ss}`;
}
// if (typeof this.getTabBar === 'function' &&
// this.getTabBar()) {
// this.getTabBar().setData({
// selected: 0
// })
// }
setTabBarActive.bind(this)(this.index);
},
methods: {
handleError(data) {
......
......@@ -3,28 +3,39 @@
-->
<template>
<div>
{{ pageUrl }}
<web-view :src="pageUrl" @error="handleError"></web-view>
</div>
</template>
<script>
import { getUrlofLink } from "../../utils/mayi.js";
import {
getUrlofLink,
setTabBarActive,
checkTabbarPage,
} from "../../utils/mayi.js";
export default {
data() {
return {
link: process.env.BASE_URL,
page: "/",
params: "?mixid=" + this.$store.state.mixid,
index:2
index: 2,
ss: "",
};
},
computed: {
pageUrl() {
return this.link + this.page + this.params;
return this.link + this.page + this.params + this.ss;
},
},
onLoad(options) {
let ss = wx.getStorageSync("sessionid");
this.ss = ss ? `&sessionid=${ss}` : "";
// tabbar 跳转
let homeIndex = checkTabbarPage("/");
homeIndex != 0 && homeIndex==this.index && (this.index = 0);
if (this.mpApp.globalData.footerVal.componentData.list[this.index].link) {
this.page = getUrlofLink(
this.mpApp.globalData.footerVal.componentData.list[this.index].link
......@@ -32,14 +43,14 @@ export default {
this.mpApp.globalData.tabBarPageLink = "";
}
},
// onShow(){
// if (typeof this.getTabBar === 'function' &&
// this.getTabBar()) {
// this.getTabBar().setData({
// selected: 0
// })
// }
// },
onShow() {
let ss = wx.getStorageSync("sessionid");
if (!this.ss && ss) {
this.ss = `&sessionid=${ss}`;
}
setTabBarActive.bind(this)(this.index);
},
methods: {
handleError(data) {
wx.showLoading({
......
......@@ -3,28 +3,39 @@
-->
<template>
<div>
{{ pageUrl }}
<web-view :src="pageUrl" @error="handleError"></web-view>
</div>
</template>
<script>
import { getUrlofLink } from "../../utils/mayi.js";
import {
getUrlofLink,
setTabBarActive,
checkTabbarPage,
} from "../../utils/mayi.js";
export default {
data() {
return {
link: process.env.BASE_URL,
page: "/",
params: "?mixid=" + this.$store.state.mixid,
index:3
index: 3,
ss: "",
};
},
computed: {
pageUrl() {
return this.link + this.page + this.params;
return this.link + this.page + this.params + this.ss;
},
},
onLoad(options) {
let ss = wx.getStorageSync("sessionid");
this.ss = ss ? `&sessionid=${ss}` : "";
// tabbar 跳转
let homeIndex = checkTabbarPage("/");
homeIndex != 0 && homeIndex==this.index && (this.index = 0);
if (this.mpApp.globalData.footerVal.componentData.list[this.index].link) {
this.page = getUrlofLink(
this.mpApp.globalData.footerVal.componentData.list[this.index].link
......@@ -32,14 +43,14 @@ export default {
this.mpApp.globalData.tabBarPageLink = "";
}
},
// onShow(){
// if (typeof this.getTabBar === 'function' &&
// this.getTabBar()) {
// this.getTabBar().setData({
// selected: 0
// })
// }
// },
onShow() {
let ss = wx.getStorageSync("sessionid");
if (!this.ss && ss) {
this.ss = `&sessionid=${ss}`;
}
setTabBarActive.bind(this)(this.index);
},
methods: {
handleError(data) {
wx.showLoading({
......
......@@ -3,28 +3,39 @@
-->
<template>
<div>
{{ pageUrl }}
<web-view :src="pageUrl" @error="handleError"></web-view>
</div>
</template>
<script>
import { getUrlofLink } from "../../utils/mayi.js";
import {
getUrlofLink,
setTabBarActive,
checkTabbarPage,
} from "../../utils/mayi.js";
export default {
data() {
return {
link: process.env.BASE_URL,
page: "/",
params: "?mixid=" + this.$store.state.mixid,
index:4
index: 4,
ss: "",
};
},
computed: {
pageUrl() {
return this.link + this.page + this.params;
return this.link + this.page + this.params + this.ss;
},
},
onLoad(options) {
let ss = wx.getStorageSync("sessionid");
this.ss = ss ? `&sessionid=${ss}` : "";
// tabbar 跳转
let homeIndex = checkTabbarPage("/");
homeIndex != 0 && homeIndex==this.index && (this.index = 0);
if (this.mpApp.globalData.footerVal.componentData.list[this.index].link) {
this.page = getUrlofLink(
this.mpApp.globalData.footerVal.componentData.list[this.index].link
......@@ -32,14 +43,14 @@ export default {
this.mpApp.globalData.tabBarPageLink = "";
}
},
// onShow(){
// if (typeof this.getTabBar === 'function' &&
// this.getTabBar()) {
// this.getTabBar().setData({
// selected: 0
// })
// }
// },
onShow() {
let ss = wx.getStorageSync("sessionid");
if (!this.ss && ss) {
this.ss = `&sessionid=${ss}`;
}
setTabBarActive.bind(this)(this.index);
},
methods: {
handleError(data) {
wx.showLoading({
......
......@@ -3,13 +3,24 @@ export function getUrlofLink(data) {
return data.link
}
// 全局跳转
export function $themeToLink(data) {
let app = getApp()
let footerVal = app.globalData.footerVal.componentData.list;
console.log('393939', footerVal)
// 全局跳转 data:link数据 option:是否为底部栏触发
export function $themeToLink(data, option) {
let type = data.type;
// 点击底部栏
if (option) {
let parseLink = getUrlofLink(data);
let isTabbarIndex =checkTabbarPage(parseLink );
// 替换首页位置
isTabbarIndex=isTabbarIndex==0?checkTabbarPage('/'):isTabbarIndex
wx.switchTab({
url: parseLink == '/' ? '/pages/home/main' : `/pages/tabBar${isTabbarIndex}/main`,
})
console.log(option, data)
return
}
// 历史数据
if (type == undefined || type == 'undefined') {
if (data.length > 0) {
......@@ -17,17 +28,16 @@ export function $themeToLink(data) {
}
return
}
// 底部导航跳转
let parseLink = getUrlofLink(data)
let isFooter = footerVal.findIndex(item => {
return item.link.link == parseLink
})
if (isFooter > -1) {
wx.switchTab({
url: parseLink == '/' ? '/pages/home/main' : `/pages/tabBar${isFooter}/main`,
})
return
}
// let parseLink=getUrlofLink(data)
// let isTabbarIndex =checkTabbarPage(parseLink )
// if (isTabbarIndex>-1) {
// wx.switchTab({
// url: parseLink == '/' ? '/pages/home/main' : `/pages/tabBar${isTabbarIndex}/main`,
// })
// return
// }
// -----------------
......@@ -83,4 +93,26 @@ function toPage(backPath, backParams) {
});
}
// check url是否为底部栏配置项
\ No newline at end of file
// check 链接是否为底部导航栏页面 返回索引
export function checkTabbarPage(link) {
let app = getApp()
if (!app.globalData.footerVal) return -1
let footerVal = app.globalData.footerVal.componentData.list;
let isFooter = footerVal.findIndex(item => {
return item.link.link == link
})
return isFooter
}
// 当前底部栏选中项
export function setTabBarActive(data) {
console.log(this, 'this', data)
if (data < 0 || !this.$mp.page) return
if (typeof this.$mp.page.getTabBar === 'function' &&
this.$mp.page.getTabBar()) {
this.$mp.page.getTabBar().setData({
selected: data
})
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment