Commit a437b1da by 程默

tabbar页面兼容

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