zhengyiming
2 天以前 add9b3bb61fcc337b02c15e7973967d670e7d3be
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
import { TabBarPageRouter } from '@/constants';
import Taro from '@tarojs/taro';
import { useSystemStoreWithOut } from '@/stores/modules/system';
import { query2object, object2query } from '@life-payment/utils';
import { blLifeRecharge } from './blLifeRecharge';
 
export function goBack(delta = 1) {
  const pages = Taro.getCurrentPages();
 
  const systemStore = useSystemStoreWithOut();
 
  if (pages.length > 1) {
    Taro.navigateBack({ delta: delta });
  } else {
    RouteHelper.switchTab({
      url: Object.values(TabBarPageRouter)[systemStore.activeTab],
    });
  }
}
 
export function goHome() {
  const systemStore = useSystemStoreWithOut();
  systemStore.setTabIndex(0);
  RouteHelper.switchTab({
    url: TabBarPageRouter['Home'],
  });
}
 
export function pathAddExtraParam(path: string, object: Record<string, string | number>) {
  console.log('path: ', path, object);
  const pathList = path.split('?');
  if (pathList.length > 1) {
    const query = query2object(pathList[1]);
    for (const key in object) {
      query[key] = object[key] as any;
    }
    return `${pathList[0]}?${object2query(query)}`;
  } else {
    return `${pathList[0]}?${object2query(object)}`;
  }
}
 
export class RouteHelper {
  static switchTab(option: Taro.switchTab.Option) {
    return Taro.switchTab({
      ...option,
      url: pathAddExtraParam(option.url, { channelId: blLifeRecharge.accountModel.channlesNum }),
    });
  }
 
  static navigateTo(option: Taro.navigateTo.Option) {
    return Taro.navigateTo({
      ...option,
      url: pathAddExtraParam(option.url, { channelId: blLifeRecharge.accountModel.channlesNum }),
    });
  }
 
  static redirectTo(option: Taro.redirectTo.Option) {
    return Taro.redirectTo({
      ...option,
      url: pathAddExtraParam(option.url, { channelId: blLifeRecharge.accountModel.channlesNum }),
    });
  }
}