fix(底部TabBar): 点击后,按钮激活状态下,不变颜色

This commit is contained in:
2025-12-29 17:47:32 +08:00
parent d5b46b4086
commit 366c4e4cd0
2 changed files with 79 additions and 57 deletions

View File

@@ -5,24 +5,21 @@ import {
Weixin Weixin
} from 'common/js/wx-jssdk.js'; } from 'common/js/wx-jssdk.js';
export default {
/**
* 页面跳转
* @param {string} to 跳转链接 /pages/idnex/index
* @param {Object} param 参数 {key : value, ...}
* @param {string} mode 模式
*/
redirectTo(to, param, mode) {
let url = to;
// 当前最新的tabBar.list (参见pages.json 中的tabBar.list 配置) // 当前最新的tabBar.list (参见pages.json 中的tabBar.list 配置)
const systemTabBarList = [ export const systemTabBarList = [
'/pages/index/index', '/pages/index/index',
'/pages_goods/category', '/pages_goods/category',
'/pages_tool/contact/contact', '/pages_tool/contact/contact',
'/pages_tool/member/index' '/pages_tool/member/index'
]; ];
/**
* 适配子包路径
* @param {string} url
* @returns
*/
export const adaptSubpackageUrl = (url) => {
/** /**
* 特别注意: * 特别注意:
* 由于老版本或者后台系统服务未同步更新可以作为tabBarList的最新分包路径。历史遗留问题需要与当前最新分包机制版本保持一致。 * 由于老版本或者后台系统服务未同步更新可以作为tabBarList的最新分包路径。历史遗留问题需要与当前最新分包机制版本保持一致。
@@ -57,10 +54,23 @@ export default {
}); });
} }
console.log('redirectTo', to, param, mode); return replacePrefix(url);
}
export default {
/**
* 页面跳转
* @param {string} to 跳转链接 /pages/idnex/index
* @param {Object} param 参数 {key : value, ...}
* @param {string} mode 模式
*/
redirectTo(to, param, mode) {
let url = to;
// 替换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) {

View File

@@ -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;
} }
} }