"use strict"; const common_vendor = require("../../common/vendor.js"); const _sfc_main$1 = { name: "AdminTabBar", data() { return { currentPath: "", tabList: [ { pagePath: "/pages/component/admin_home", text: "首页", icon: "/static/logo.png", selectedIcon: "/static/111.png" }, { pagePath: "/pages/component/role_management", text: "角色管理", icon: "/static/logo.png", selectedIcon: "/static/111.png" }, { pagePath: "/pages/component/admin_my", text: "我的", icon: "/static/logo.png", selectedIcon: "/static/111.png" } ] }; }, methods: { switchTab(path) { this.currentPath = path; common_vendor.index.__f__("log", "at wxcomponents/admin-tabr/admin-tabar.vue:54", path); common_vendor.index.switchTab({ url: path, fail: () => { common_vendor.index.navigateTo({ url: path }); } }); this.currentPath = path; }, // 初始化当前页面路径 initCurrentPath() { const pages = getCurrentPages(); if (pages.length > 0) { const currentPage = pages[pages.length - 1]; this.currentPath = `/${currentPage.route}`; } } }, mounted() { this.initCurrentPath(); }, onShow() { this.initCurrentPath(); } }; function _sfc_render$1(_ctx, _cache, $props, $setup, $data, $options) { return { a: common_vendor.f($data.tabList, (item, index, i0) => { return { a: $data.currentPath === item.pagePath ? item.selectedIcon : item.icon, b: common_vendor.t(item.text), c: index, d: $data.currentPath === item.pagePath ? 1 : "", e: common_vendor.o(($event) => $options.switchTab(item.pagePath), index) }; }) }; } const AdminTabBar = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main$1, [["render", _sfc_render$1], ["__scopeId", "data-v-74645b33"]]); const _sfc_main = { name: "UserTabBar", data() { return { currentTab: "/pages/component/home", tabList: [ { pagePath: "/pages/component/home", text: "首页", iconPath: "/static/logo.png", selectedIconPath: "/static/logo.png" }, { pagePath: "/pages/component/recycle", text: "回收", iconPath: "/static/logo.png", selectedIconPath: "/static/logo.png" }, { pagePath: "/pages/component/my", text: "我的", iconPath: "/static/logo.png", selectedIconPath: "/static/logo.png" } ] }; }, methods: { switchTab(path) { if (this.currentTab === path) return; const oldPath = this.currentTab; this.currentTab = path; common_vendor.index.switchTab({ url: path, success: () => { common_vendor.index.__f__("log", "at wxcomponents/user-tabar/user-tabar.vue:60", "切换成功"); }, fail: () => { common_vendor.index.navigateTo({ url: path, success: () => { common_vendor.index.__f__("log", "at wxcomponents/user-tabar/user-tabar.vue:67", "导航成功"); }, fail: () => { this.currentTab = oldPath; common_vendor.index.__f__("log", "at wxcomponents/user-tabar/user-tabar.vue:72", "切换失败"); } }); } }); }, updateCurrentTab() { const pages = getCurrentPages(); if (pages.length > 0) { const currentPage = pages[pages.length - 1]; const newPath = "/" + currentPage.route; if (this.currentTab !== newPath) { this.currentTab = newPath; } } } }, created() { this.updateCurrentTab(); }, onShow() { this.updateCurrentTab(); }, onLoad() { this.updateCurrentTab(); } }; function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) { return { a: common_vendor.f($data.tabList, (item, index, i0) => { return { a: $data.currentTab === item.pagePath ? item.selectedIconPath : item.iconPath, b: common_vendor.t(item.text), c: index, d: $data.currentTab === item.pagePath ? 1 : "", e: common_vendor.o(($event) => $options.switchTab(item.pagePath), index) }; }) }; } const UserTabBar = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-d2bf226b"]]); const tabBarMixin = { components: { AdminTabBar, UserTabBar }, data() { return { userRole: "", isTabBarVisible: true, currentPath: "", tabBarIndex: 0 }; }, computed: { isAdmin() { return this.userRole === "admin"; }, shouldShowTabBar() { const tabBarPages = [ "/pages/component/admin_home", "/pages/component/role_management", "/pages/component/admin_my" ]; return tabBarPages.includes(this.currentPath); } }, methods: { async checkUserRole() { try { const userInfo = common_vendor.index.getStorageSync("userInfo"); if (userInfo && userInfo.role) { this.userRole = userInfo.role; } else { this.userRole = "user"; } } catch (e) { common_vendor.index.__f__("error", "at pages/mixins/tabBarMixin.js:40", "获取用户角色失败:", e); this.userRole = "user"; } }, updateCurrentPath() { const pages = getCurrentPages(); if (pages.length > 0) { const currentPage = pages[pages.length - 1]; common_vendor.index.__f__("log", "at pages/mixins/tabBarMixin.js:48", currentPage, "text"); this.currentPath = "/" + currentPage.route; this.isTabBarVisible = this.shouldShowTabBar; common_vendor.index.__f__("log", "at pages/mixins/tabBarMixin.js:51", "当前页面路径:", this.currentPath); } }, hideTabBar() { this.isTabBarVisible = false; }, showTabBar() { this.isTabBarVisible = this.shouldShowTabBar; }, switchTab(index) { const routes = ["pages/index/index", "pages/role-management/role-management", "pages/my/my"]; if (!this.isAdmin && index === 1) { common_vendor.index.showToast({ title: "无权限访问", icon: "none" }); return; } this.tabBarIndex = index; common_vendor.index.switchTab({ url: "/" + routes[index] }); } }, onShow() { this.checkUserRole(); this.updateCurrentPath(); const pages = getCurrentPages(); const currentPage = pages[pages.length - 1]; const route = currentPage.route; const routes = ["pages/index/index", "pages/role-management/role-management", "pages/my/my"]; this.tabBarIndex = routes.findIndex((r) => r === route); }, onLoad() { this.checkUserRole(); this.updateCurrentPath(); }, mounted() { this.checkUserRole(); this.updateCurrentPath(); } }; exports.tabBarMixin = tabBarMixin; //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/mixins/tabBarMixin.js.map