wupengfei
7 天以前 14368e8a09c4b5793d0975f85e36a4c1d410ca36
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import Taro from '@tarojs/taro';
import { TabBarPageRouterForCheck } from '@/constants';
import { useSystemStore } from '@/stores/modules/system';
import { useAppStore } from '@/stores/modules/app';
import { isInAlipay } from '@/utils/env';
import { useLifeRechargeContext } from '@life-payment/core-vue';
import { getRouterPath } from '@life-payment/utils';
import { pathAddExtraParam } from '@/utils';
 
export function useSwitchTab() {
  const systemStore = useSystemStore();
 
  const switchTab = (option: Taro.switchTab.Option) => {
    const index = Object.values(TabBarPageRouterForCheck).findIndex((x) => option.url.includes(x));
    console.log('index: ', index);
    systemStore.setTabIndex(index);
    RouteHelper.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 { blLifeRecharge } = useLifeRechargeContext();
 
  const router = Taro.useRouter();
 
  const channelId = router.params?.channelId ?? '';
  console.log('router: params', router, blLifeRecharge.accountModel.channlesNum);
 
  Taro.useTabItemTap((item) => {
    Taro.reLaunch({
      url: pathAddExtraParam(item.pagePath, { channelId: blLifeRecharge.accountModel.channlesNum }),
      success() {
        appStore.setLatestRoute('');
      },
    });
  });
 
  Taro.useDidShow(() => {
    const isTabbarPage = Object.values(TabBarPageRouterForCheck).some((x) =>
      latestRoute.value.toLowerCase().includes(x.toLowerCase())
    );
    // const currentIsTabbarPage = Object.values(TabBarPageRouterForCheck).some((x) =>
    //   getRouterPath(router.path).toLowerCase().includes(x.toLowerCase())
    // );
    // if (currentIsTabbarPage && blLifeRecharge.accountModel.channlesNum && !channelId) {
    //   Taro.reLaunch({
    //     url: pathAddExtraParam(router.path, { channelId: blLifeRecharge.accountModel.channlesNum }),
    //     success() {
    //       appStore.setLatestRoute('');
    //     },
    //   });
    //   return;
    // }
    if (isTabbarPage && isInAlipay) {
      Taro.reLaunch({
        url: router.path,
        success() {
          appStore.setLatestRoute('');
        },
      });
    }
  });
 
  Taro.useDidHide(() => {
    appStore.setLatestRoute(router.path);
  });
}