fix(底部TabBar): 点击后,按钮激活状态下,不变颜色
This commit is contained in:
@@ -5,6 +5,58 @@ import {
|
|||||||
Weixin
|
Weixin
|
||||||
} from 'common/js/wx-jssdk.js';
|
} from 'common/js/wx-jssdk.js';
|
||||||
|
|
||||||
|
|
||||||
|
// 当前最新的tabBar.list (参见pages.json 中的tabBar.list 配置)
|
||||||
|
export const systemTabBarList = [
|
||||||
|
'/pages/index/index',
|
||||||
|
'/pages_goods/category',
|
||||||
|
'/pages_tool/contact/contact',
|
||||||
|
'/pages_tool/member/index'
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 适配子包路径
|
||||||
|
* @param {string} url
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
export const adaptSubpackageUrl = (url) => {
|
||||||
|
/**
|
||||||
|
* 特别注意:
|
||||||
|
* 由于老版本或者后台系统服务未同步更新可以作为tabBarList的最新分包路径。历史遗留问题,需要与当前最新分包机制版本保持一致。
|
||||||
|
* 系统当前的支持tarbarList(包含动态tabBar),注意这是实际分包后的路径
|
||||||
|
* 根据匹配映射关系,修改url为实际分包后的路径
|
||||||
|
*/
|
||||||
|
// 定义前缀映射表
|
||||||
|
const urlPrefixMap = {
|
||||||
|
'/pages/goods/': '/pages_goods/',
|
||||||
|
'/pages/contact/': '/pages_tool/contact/',
|
||||||
|
'/pages/member/': '/pages_tool/member/',
|
||||||
|
'/pages/vr': '/pages_tool/vr/'
|
||||||
|
};
|
||||||
|
|
||||||
|
// 构建正则表达式
|
||||||
|
const regex = new RegExp(
|
||||||
|
Object.keys(urlPrefixMap).map(key =>
|
||||||
|
key.replace(/\//g, '\\/').replace(/\*/g, '.*')
|
||||||
|
).join('|'),
|
||||||
|
'g'
|
||||||
|
);
|
||||||
|
|
||||||
|
// 替换函数
|
||||||
|
function replacePrefix(str) {
|
||||||
|
return str.replace(regex, match => {
|
||||||
|
for (const [oldPrefix, newPrefix] of Object.entries(urlPrefixMap)) {
|
||||||
|
if (match.startsWith(oldPrefix)) {
|
||||||
|
return match.replace(oldPrefix, newPrefix);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return match; // 默认返回原匹配
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return replacePrefix(url);
|
||||||
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
/**
|
/**
|
||||||
* 页面跳转
|
* 页面跳转
|
||||||
@@ -15,52 +67,10 @@ export default {
|
|||||||
redirectTo(to, param, mode) {
|
redirectTo(to, param, mode) {
|
||||||
let url = to;
|
let url = to;
|
||||||
|
|
||||||
// 当前最新的tabBar.list (参见pages.json 中的tabBar.list 配置)
|
|
||||||
const systemTabBarList = [
|
|
||||||
'/pages/index/index',
|
|
||||||
'/pages_goods/category',
|
|
||||||
'/pages_tool/contact/contact',
|
|
||||||
'/pages_tool/member/index'
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 特别注意:
|
|
||||||
* 由于老版本或者后台系统服务未同步更新可以作为tabBarList的最新分包路径。历史遗留问题,需要与当前最新分包机制版本保持一致。
|
|
||||||
* 系统当前的支持tarbarList(包含动态tabBar),注意这是实际分包后的路径
|
|
||||||
* 根据匹配映射关系,修改url为实际分包后的路径
|
|
||||||
*/
|
|
||||||
// 定义前缀映射表
|
|
||||||
const urlPrefixMap = {
|
|
||||||
'/pages/goods/': '/pages_goods/',
|
|
||||||
'/pages/contact/': '/pages_tool/contact/',
|
|
||||||
'/pages/member/': '/pages_tool/member/',
|
|
||||||
'/pages/vr': '/pages_tool/vr/'
|
|
||||||
};
|
|
||||||
|
|
||||||
// 构建正则表达式
|
|
||||||
const regex = new RegExp(
|
|
||||||
Object.keys(urlPrefixMap).map(key =>
|
|
||||||
key.replace(/\//g, '\\/').replace(/\*/g, '.*')
|
|
||||||
).join('|'),
|
|
||||||
'g'
|
|
||||||
);
|
|
||||||
|
|
||||||
// 替换函数
|
|
||||||
function replacePrefix(str) {
|
|
||||||
return str.replace(regex, match => {
|
|
||||||
for (const [oldPrefix, newPrefix] of Object.entries(urlPrefixMap)) {
|
|
||||||
if (match.startsWith(oldPrefix)) {
|
|
||||||
return match.replace(oldPrefix, newPrefix);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return match; // 默认返回原匹配
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('redirectTo', to, param, mode);
|
|
||||||
// 替换url中的前缀
|
// 替换url中的前缀
|
||||||
url = replacePrefix(url);
|
console.log('redirectTo', to, param, mode);
|
||||||
console.log('replacePrefix', url);
|
url = adaptSubpackageUrl(url);
|
||||||
|
console.log('adaptSubpackageUrl', url);
|
||||||
|
|
||||||
if (param != undefined) {
|
if (param != undefined) {
|
||||||
Object.keys(param).forEach(function (key) {
|
Object.keys(param).forEach(function (key) {
|
||||||
|
|||||||
@@ -59,6 +59,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import { adaptSubpackageUrl } from '@/common/js/util.js'
|
||||||
import DiyMinx from './minx.js'
|
import DiyMinx from './minx.js'
|
||||||
// 底部导航栏
|
// 底部导航栏
|
||||||
export default {
|
export default {
|
||||||
@@ -82,10 +83,7 @@ export default {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
let currentPage = getCurrentPages()[getCurrentPages().length - 1];
|
this.updateCurrentRoute();
|
||||||
if (currentPage && currentPage.route) {
|
|
||||||
this.currentRoute = currentPage.route;
|
|
||||||
}
|
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
if (!this.$store.state.cartPosition) {
|
if (!this.$store.state.cartPosition) {
|
||||||
let query = uni.createSelectorQuery().in(this);
|
let query = uni.createSelectorQuery().in(this);
|
||||||
@@ -101,6 +99,10 @@ export default {
|
|||||||
}).exec();
|
}).exec();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
// 监听页面显示事件,更新当前路由
|
||||||
|
this.$on('hook:onShow', () => {
|
||||||
|
this.updateCurrentRoute();
|
||||||
|
});
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
cartChange() {
|
cartChange() {
|
||||||
@@ -124,24 +126,34 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
// 更新当前路由
|
||||||
|
updateCurrentRoute() {
|
||||||
|
let currentPage = getCurrentPages()[getCurrentPages().length - 1];
|
||||||
|
if (currentPage && currentPage.route) {
|
||||||
|
this.currentRoute = currentPage.route;
|
||||||
|
}
|
||||||
|
},
|
||||||
redirectTo(link) {
|
redirectTo(link) {
|
||||||
this.$emit('callback');
|
this.$emit('callback');
|
||||||
this.$util.diyRedirectTo(link);
|
this.$util.diyRedirectTo(link);
|
||||||
},
|
},
|
||||||
verify(link) {
|
verify(link) {
|
||||||
if (link == null || link == '' || !link.wap_url) return false;
|
if (link == null || link == '' || !link.wap_url) return false;
|
||||||
if (this.name) {
|
|
||||||
var url = this.currentRoute + '?name=' + this.name;
|
// 标准化路径格式,确保比较的一致性
|
||||||
} else {
|
let currentPageRoute = this.currentRoute ? '/' + this.currentRoute : '';
|
||||||
var url = this.currentRoute;
|
let linkUrl = link.wap_url;
|
||||||
}
|
|
||||||
|
|
||||||
// 首页特殊处理
|
// 首页特殊处理
|
||||||
if (link.wap_url == '/pages/index/index' && this.name == 'DIY_VIEW_INDEX') {
|
if (linkUrl === '/pages/index/index' && this.name === 'DIY_VIEW_INDEX') {
|
||||||
return true;
|
|
||||||
} else if (url && link.wap_url.indexOf(url) != -1) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 精确匹配当前路径
|
||||||
|
if (adaptSubpackageUrl(linkUrl) === currentPageRoute) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user