import Taro from '@tarojs/taro';
|
import { TabBarPageRouter } from '@/constants';
|
import { useSystemStore } from '@/stores/modules/system';
|
import { useAppStore } from '@/stores/modules/app';
|
import { isInAlipay } from '@/utils/env';
|
|
export function useSwitchTab() {
|
const systemStore = useSystemStore();
|
|
const switchTab = (option: Taro.switchTab.Option) => {
|
const index = Object.values(TabBarPageRouter).findIndex((x) => option.url.includes(x));
|
console.log('index: ', index);
|
systemStore.setTabIndex(index);
|
Taro.switchTab(option);
|
};
|
return switchTab;
|
}
|
|
// export function useFirstEnter() {
|
// const systemStore = useSystemStore();
|
// const { isFirstEnter } = storeToRefs(systemStore);
|
// console.log('isFirstEnter: ', isFirstEnter);
|
|
// onMounted(() => {
|
// systemStore.setIsFirstEnter(false);
|
// });
|
|
// return { isFirstEnter };
|
// }
|
|
export function useFocus() {
|
const isFocus = ref(false);
|
|
Taro.useDidShow(() => {
|
isFocus.value = true;
|
});
|
|
Taro.useDidHide(() => {
|
isFocus.value = false;
|
});
|
|
return {
|
isFocus,
|
};
|
}
|
|
export function useTabRouteEnhance() {
|
const appStore = useAppStore();
|
const { latestRoute } = storeToRefs(appStore);
|
|
const router = Taro.useRouter();
|
|
Taro.useDidShow(() => {
|
const isTabbarPage = Object.values(TabBarPageRouter).some((x) =>
|
latestRoute.value.toLowerCase().includes(x.toLowerCase())
|
);
|
if (isTabbarPage) {
|
Taro.reLaunch({
|
url: router.path,
|
success() {
|
appStore.setLatestRoute('');
|
},
|
});
|
}
|
});
|
|
Taro.useDidHide(() => {
|
appStore.setLatestRoute(router.path);
|
});
|
}
|