wupengfei
6 小时以前 47047d626ea8fab28c04e6534fe6ffa3dc61de69
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import Taro from '@tarojs/taro';
import { defineStore } from 'pinia';
import { store } from '@/stores';
import * as settingsServices from '@12333/services/apiV2/settings';
 
export interface Options {
  path: string;
  scene: number;
  query: object;
  shareTicket: string;
  referrerInfo: object;
  tabIndex: number;
  IPhoneXPadding: number;
  navHeight: number;
  safeAreaTop: number;
  buttonBottom: number;
 
  redirectPath: string;
  isTabSwitch: boolean;
  isFirstEnter: boolean;
  isWeappCheck: boolean;
}
 
export const useSystemStore = defineStore({
  id: 'app-system',
  /** 状态 */
  state: () => ({
    options: {} as Options,
 
    activeTab: 0,
 
    info: {} as Taro.getSystemInfoSync.Result,
 
    designWidth: 750,
 
    screenHeight: 0,
    screenWidth: 0,
    pageHeightWithTab: 0,
    pageHeight: 0,
 
    IPhoneXPadding: 0,
 
    navHeight: 0,
    bottomNavHeight: 0,
 
    safeAreaTop: 0,
 
    navigationBarHeight: 0,
    //右上角胶囊按钮高度
    menuButtonHeight: 0,
    menuButtonWidth: 0,
    menuButtonRightDistance: 0,
    menuButtonTop: 0,
 
    isFirstEnter: true,
 
    isWeappCheck: true,
  }),
 
  actions: {
    async getAppConfig() {
      try {
        let res = await settingsServices.getWxmpSettings({});
        this.isWeappCheck = res.wxmpAuditInProcess;
      } catch (error) {}
    },
 
    init(options: Options) {
      this.options = options; // 放一下页面相关的数据例如scene等 页面高度之类的不存!
    },
 
    setInfo(info: Taro.getSystemInfoSync.Result) {
      this.info = info;
      console.log('info: ', info);
 
      this.setNavigationBarHeight(info);
 
      this.screenHeight = info.screenHeight;
      this.screenWidth = info.screenWidth;
 
      this.IPhoneXPadding = info.screenHeight - info.safeArea.bottom;
      this.navHeight = info.statusBarHeight + this.navigationBarHeight;
 
      this.safeAreaTop = info.safeArea.top;
 
      const scale = info.screenWidth / this.designWidth;
 
      /**
       * 100为底部tabber的高度
       */
      this.bottomNavHeight = 118 * scale;
 
      this.pageHeight = info.screenHeight - this.navHeight - this.IPhoneXPadding; // 无底部tabber
      this.pageHeightWithTab = this.pageHeight - this.bottomNavHeight; // 有底部tabber
    },
 
    setNavigationBarHeight(systemInfo: Taro.getSystemInfoSync.Result) {
      const { right, height, width, top } = Taro.getMenuButtonBoundingClientRect();
 
      let navigationBarHeight = 0;
 
      if (systemInfo.platform === 'android') {
        navigationBarHeight = 48;
      } else {
        navigationBarHeight = 44;
      }
      this.menuButtonHeight = height;
      this.menuButtonWidth = width;
      this.menuButtonTop = top;
      this.menuButtonRightDistance = systemInfo.screenWidth - right;
      this.navigationBarHeight = navigationBarHeight;
    },
 
    setTabIndex(tabIndex: number) {
      this.activeTab = tabIndex;
    },
 
    setIsFirstEnter(isFirstEnter: boolean) {
      this.isFirstEnter = isFirstEnter;
    },
  },
});
 
// Need to be used outside the setup
export function useSystemStoreWithOut() {
  return useSystemStore(store);
}