import { defineStore } from 'pinia'; import { ref } from 'vue'; export const useTabbarStore = defineStore('tabbar', () => { // 当前选中的 tab 索引 const currentIndex = ref(0); // 首页是否显示回到顶部 const showBackTop = ref(false); // 滚动阈值(超过这个值显示回到顶部) const scrollThreshold = 300; // 设置当前 tab 索引 const setCurrentIndex = (index) => { currentIndex.value = index; }; // 设置是否显示回到顶部 const setShowBackTop = (show) => { showBackTop.value = show; }; // 根据页面路径获取 tab 索引 const getIndexByPath = (path) => { const tabPaths = [ '/pages/index/index', '/pages/goods_cate/goods_cate', '/pages/order_addcart/order_addcart', '/pages/user/index' ]; return tabPaths.findIndex(p => path.includes(p.replace('/pages/', ''))); }; return { currentIndex, showBackTop, scrollThreshold, setCurrentIndex, setShowBackTop, getIndexByPath }; });