From 5ea9d3db88d20c58f447c34a6e897e01ba082f45 Mon Sep 17 00:00:00 2001 From: gongfuxiang Date: Tue, 26 Sep 2023 14:54:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=BB=E9=A2=98=E5=BA=95=E9=83=A8=E8=8F=9C?= =?UTF-8?q?=E5=8D=95=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App.vue | 103 +++++++++++++++++++++++++++++++++++++---------------- pages.json | 10 +++--- 2 files changed, 78 insertions(+), 35 deletions(-) diff --git a/App.vue b/App.vue index 977df456..97b44f3e 100644 --- a/App.vue +++ b/App.vue @@ -92,7 +92,7 @@ // 蓝色 blue #1677ff // 棕色 brown #8B4513 // 紫色 purple #623cec - default_theme: 'purple', + default_theme: 'brown', }, /** * 启动参数处理 @@ -1749,6 +1749,37 @@ }, 100); } }, + + // 获取主题色值 + // is_light 是否获取浅主色(false, true) + get_theme_color(is_light = false) { + let color_obj = { + // 主色 + yellow: '#f6c133', // 黄色 + red: '#ff0036', // 红色 + black: '#333333', // 黑色 + blue: '#1677ff', // 蓝色 + green: '#20a53a', // 绿色 + orange: '#fe6f04', // 橙色 + brown: '#8B4513', // 棕色 + purple: '#623cec', // 紫色 + + // 浅主色 + yellow_light: '#ffebd2', // 黄色 + red_light: '#ffdbe2', // 红色 + black_light: '#dcdcdc', // 黑色 + blue_light: '#d1e4ff', // 蓝色 + green_light: '#cce8d2', // 绿色 + orange_light: '#fde4d1', // 橙色 + brown_light: '#eadcd2', // 棕色 + purple_light: '#d6cbfb', // 紫色 + }; + var theme = this.get_theme_value(); + if (is_light) { + theme += '_light'; + } + return color_obj[theme]; + }, // 获取主题 get_theme_value() { @@ -1807,35 +1838,45 @@ } }, - // 获取主题色值 - // is_light 是否获取浅主色(false, true) - get_theme_color(is_light = false) { - let color_obj = { - // 主色 - yellow: '#f6c133', // 黄色 - red: '#ff0036', // 红色 - black: '#333333', // 黑色 - blue: '#1677ff', // 蓝色 - green: '#20a53a', // 绿色 - orange: '#fe6f04', // 橙色 - brown: '#8B4513', // 棕色 - purple: '#623cec', // 紫色 - - // 浅主色 - yellow_light: '#ffebd2', // 黄色 - red_light: '#ffdbe2', // 红色 - black_light: '#dcdcdc', // 黑色 - blue_light: '#d1e4ff', // 蓝色 - green_light: '#cce8d2', // 绿色 - orange_light: '#fde4d1', // 橙色 - brown_light: '#eadcd2', // 棕色 - purple_light: '#d6cbfb', // 紫色 - }; + // 底部菜单设置 + set_tabbar() { + // 当前主题 var theme = this.get_theme_value(); - if (is_light) { - theme += '_light'; - } - return color_obj[theme]; + + // 整体样式 + uni.setTabBarStyle({ + selectedColor: this.get_theme_color(), + }); + + // 菜单 + uni.setTabBarItem({ + index: 0, + pagePath: 'pages/index/index', + iconPath: 'static/images/common/tabbar/home.png', + selectedIconPath: 'static/images/'+theme+'/tabbar/home.png', + text: '首页' + }); + uni.setTabBarItem({ + index: 1, + pagePath: 'pages/goods-category/goods-category', + iconPath: 'static/images/common/tabbar/category.png', + selectedIconPath: 'static/images/'+theme+'/tabbar/category.png', + text: '分类' + }); + uni.setTabBarItem({ + index: 2, + pagePath: 'pages/cart/cart', + iconPath: 'static/images/common/tabbar/cart.png', + selectedIconPath: 'static/images/'+theme+'/tabbar/cart.png', + text: '购物车' + }); + uni.setTabBarItem({ + index: 3, + pagePath: 'pages/user/user', + iconPath: 'static/images/common/tabbar/user.png', + selectedIconPath: 'static/images/'+theme+'/tabbar/user.png', + text: '我的' + }); }, // 数组分组 @@ -1889,7 +1930,7 @@ } else { return uri + separator + key + '=' + value; } - }, + } }, // 初始化完成时触发(全局只触发一次) onLaunch(params) {}, @@ -1909,6 +1950,8 @@ // #endif // 引入主题 this.globalData.require_theme(); + // 设置底部菜单 + this.globalData.set_tabbar(); }, // 从前台进入后台 onHide() { diff --git a/pages.json b/pages.json index 1713e574..ccbf08f1 100644 --- a/pages.json +++ b/pages.json @@ -973,30 +973,30 @@ }, "tabBar": { "color": "#8a8a8a", - "selectedColor": "#f6c133", + "selectedColor": "#8a8a8a", "backgroundColor": "#fff", "list": [{ "pagePath": "pages/index/index", "iconPath": "static/images/common/tabbar/home.png", - "selectedIconPath": "static/images/yellow/tabbar/home.png", + "selectedIconPath": "static/images/common/tabbar/home.png", "text": "首页" }, { "pagePath": "pages/goods-category/goods-category", "iconPath": "static/images/common/tabbar/category.png", - "selectedIconPath": "static/images/yellow/tabbar/category.png", + "selectedIconPath": "static/images/common/tabbar/category.png", "text": "分类" }, { "pagePath": "pages/cart/cart", "iconPath": "static/images/common/tabbar/cart.png", - "selectedIconPath": "static/images/yellow/tabbar/cart.png", + "selectedIconPath": "static/images/common/tabbar/cart.png", "text": "购物车" }, { "pagePath": "pages/user/user", "iconPath": "static/images/common/tabbar/user.png", - "selectedIconPath": "static/images/yellow/tabbar/user.png", + "selectedIconPath": "static/images/common/tabbar/user.png", "text": "我的" } ]