ipanel-rnapp-ajb-base 1.0.21 → 1.0.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import React, {useState, useEffect} from 'react';
1
+ import React, { useState, useEffect } from "react";
2
2
  import {
3
3
  Alert,
4
4
  View,
@@ -9,23 +9,23 @@ import {
9
9
  NativeModules,
10
10
  ImageBackground,
11
11
  Image,
12
- } from 'react-native';
13
- import {createBottomTabNavigator} from '@react-navigation/bottom-tabs';
12
+ } from "react-native";
13
+ import { createBottomTabNavigator } from "@react-navigation/bottom-tabs";
14
14
 
15
15
  // 线上本地调试环境文件
16
- import env from '../.local_dev/env';
17
- import LocalDevPage from '../.local_dev/DemoPage';
16
+ import env from "../.local_dev/env";
17
+ import LocalDevPage from "../.local_dev/DemoPage";
18
18
 
19
- import CustomTabBar from '../components/common/CustomTabBar';
20
- import UseMessageManager from '../hooks/useMessageManager';
21
- import ShopMessageManager from '../hooks/shopMessageManager';
19
+ import CustomTabBar from "../components/common/CustomTabBar";
20
+ import UseMessageManager from "../hooks/useMessageManager";
21
+ import ShopMessageManager from "../hooks/shopMessageManager";
22
22
 
23
- import {getAreaOperatorModules, refreshToken} from '../api';
24
- import {replace} from '../utils/RootNavigation';
25
- import useAddress2 from '../hooks/useAddress2';
26
- import {useSafeArea} from 'react-native-safe-area-context';
23
+ import { getAreaOperatorModules, refreshToken } from "../api";
24
+ import { replace } from "../utils/RootNavigation";
25
+ import useAddress2 from "../hooks/useAddress2";
26
+ import { useSafeArea } from "react-native-safe-area-context";
27
27
 
28
- const {storage, px} = global.base;
28
+ const { storage, px } = global.base;
29
29
  const appName = NativeModules?.RNToNativeEmitter?.appName;
30
30
 
31
31
  const Tab = createBottomTabNavigator();
@@ -34,65 +34,65 @@ async function getNavigationPackages() {
34
34
  let packages = [];
35
35
 
36
36
  // 根据currentOperator动态返回packages
37
- const accountData = await storage.get('accountData');
38
- const accountType = await storage.get('accountType');
37
+ const accountData = await storage.get("accountData");
38
+ const accountType = await storage.get("accountType");
39
39
  const currentOperator = await storage.get(
40
- `${accountData?.account?.account_id || ''}currentOperator`,
40
+ `${accountData?.account?.account_id || ""}currentOperator`
41
41
  );
42
42
  let areaOperatorId =
43
- currentOperator && currentOperator.id ? currentOperator.id : 'common';
44
- console.log('currentOperator', currentOperator);
43
+ currentOperator && currentOperator.id ? currentOperator.id : "common";
44
+ console.log("currentOperator", currentOperator);
45
45
 
46
- if (appName?.includes('安电工') || accountType === 'adg') {
46
+ if (appName?.includes("安电工") || accountType === "adg") {
47
47
  // 写死特殊区域运营商adg,加载安电工专属模块
48
- areaOperatorId = 'adg';
48
+ areaOperatorId = "adg";
49
49
  }
50
50
 
51
51
  // 从网络加载最新导航模块
52
52
  const res = await getAreaOperatorModules({
53
53
  platform: Platform.OS,
54
54
  areaOperatorId,
55
- }).catch(err => {
55
+ }).catch((err) => {
56
56
  console.log(err);
57
57
  });
58
58
  if (!res || res.code !== 0) {
59
- console.log('warn: 网络加载底部导航模块失败,取storage中存的上次的版本');
59
+ console.log("warn: 网络加载底部导航模块失败,取storage中存的上次的版本");
60
60
  // 从网络加载失败则取storage中存的上次的版本
61
- packages = await global.base.storage.get('base.navigationPackages');
61
+ packages = await global.base.storage.get("base.navigationPackages");
62
62
  } else {
63
- console.log('网络加载底部导航模块成功!');
63
+ console.log("网络加载底部导航模块成功!");
64
64
  packages = res.data || [];
65
65
  await storage.set(
66
- 'areaOperatorModules',
67
- packages.map(item => {
66
+ "areaOperatorModules",
67
+ packages.map((item) => {
68
68
  return {
69
69
  moduleName: item.moduleName,
70
70
  moduleChineseName: item.moduleChineseName,
71
71
  version: item.version,
72
72
  };
73
- }),
73
+ })
74
74
  );
75
- packages.forEach(pack => {
75
+ packages.forEach((pack) => {
76
76
  switch (pack.moduleName) {
77
- case 'tvShare':
78
- pack.icon = 'tv-outline';
79
- pack.activeIcon = 'tv';
77
+ case "tvShare":
78
+ pack.icon = "tv-outline";
79
+ pack.activeIcon = "tv";
80
80
  break;
81
- case 'smartHome':
82
- pack.icon = 'ios-home-outline';
83
- pack.activeIcon = 'ios-home';
81
+ case "smartHome":
82
+ pack.icon = "ios-home-outline";
83
+ pack.activeIcon = "ios-home";
84
84
  break;
85
- case 'shop':
86
- pack.icon = 'card-outline';
87
- pack.activeIcon = 'card';
85
+ case "shop":
86
+ pack.icon = "card-outline";
87
+ pack.activeIcon = "card";
88
88
  break;
89
- case 'panYuGovData':
90
- pack.icon = 'newspaper-outline';
91
- pack.activeIcon = 'newspaper';
89
+ case "panYuGovData":
90
+ pack.icon = "newspaper-outline";
91
+ pack.activeIcon = "newspaper";
92
92
  break;
93
- case 'myProfile':
94
- pack.icon = 'person-outline';
95
- pack.activeIcon = 'person';
93
+ case "myProfile":
94
+ pack.icon = "person-outline";
95
+ pack.activeIcon = "person";
96
96
  break;
97
97
  }
98
98
  });
@@ -102,51 +102,51 @@ async function getNavigationPackages() {
102
102
  // global.base.navigationPackages = packages;
103
103
  // console.log('成功从网络中读取最新底部导航模块');
104
104
  // save to local
105
- await global.base.storage.set('base.navigationPackages', packages);
105
+ await global.base.storage.set("base.navigationPackages", packages);
106
106
  } else {
107
107
  // 兜底
108
- console.log('warn: 网络和本地加载底部导航模块都异常,加载兜底模块...');
108
+ console.log("warn: 网络和本地加载底部导航模块都异常,加载兜底模块...");
109
109
  packages = global.base.initialNavigationPackages;
110
110
  }
111
111
 
112
112
  return packages;
113
113
  }
114
114
 
115
- function HomeTabScreen({navigation, route}) {
115
+ function HomeTabScreen({ navigation, route }) {
116
116
  const [tabScreens, setTabScreens] = useState([]);
117
- const [initialRouteName, setInitialRouteName] = useState('');
118
- const {updateDataFromNetwork} = useAddress2();
117
+ const [initialRouteName, setInitialRouteName] = useState("");
118
+ const { updateDataFromNetwork } = useAddress2();
119
119
  const redirect = route.params?.redirect;
120
120
 
121
121
  const init = async () => {
122
122
  let tabs = [];
123
123
 
124
- console.log('env:', env);
124
+ console.log("env:", env);
125
125
 
126
- if (env !== '__BASE_SINGLETON_MODE__') {
126
+ if (env !== "__BASE_SINGLETON_MODE__") {
127
127
  let packages = await getNavigationPackages();
128
128
 
129
129
  const flag = await global.base
130
130
  .loadPackages({
131
131
  packages,
132
132
  })
133
- .catch(errors => {
133
+ .catch((errors) => {
134
134
  console.log(JSON.stringify(errors));
135
135
  });
136
136
 
137
137
  if (!flag) {
138
138
  // 加载包失败
139
- Alert.alert('网络繁忙');
139
+ Alert.alert("网络繁忙");
140
140
  return;
141
141
  }
142
142
 
143
- const componentPromises = packages.map(pack => {
143
+ const componentPromises = packages.map((pack) => {
144
144
  return global.base.getRemoteComponentByName(pack.moduleName);
145
145
  });
146
146
 
147
147
  const components = await Promise.all(componentPromises);
148
- components.forEach(component => {
149
- typeof component?.registerStackScreens === 'function' &&
148
+ components.forEach((component) => {
149
+ typeof component?.registerStackScreens === "function" &&
150
150
  component.registerStackScreens();
151
151
  });
152
152
 
@@ -157,8 +157,8 @@ function HomeTabScreen({navigation, route}) {
157
157
  options: {
158
158
  title: pack.moduleChineseName,
159
159
  headerShown: false,
160
- icon: pack.icon || 'menu-outline',
161
- activeIcon: pack.activeIcon || 'menu',
160
+ icon: pack.icon || "menu-outline",
161
+ activeIcon: pack.activeIcon || "menu",
162
162
  iconUri: pack.moduleIcon,
163
163
  activeIconUri: pack.moduleFocusIcon,
164
164
  moduleAlias: pack.moduleAlias,
@@ -168,41 +168,41 @@ function HomeTabScreen({navigation, route}) {
168
168
  } else {
169
169
  // 单业务包开发调试环境
170
170
  const component = await global.base.getRemoteComponentByName(
171
- '__BASE_SINGLETON_MODE_APP__',
171
+ "__BASE_SINGLETON_MODE_APP__"
172
172
  );
173
- typeof component?.registerStackScreens === 'function' &&
173
+ typeof component?.registerStackScreens === "function" &&
174
174
  component.registerStackScreens();
175
175
  tabs = [
176
176
  {
177
- name: 'asJumpPage',
177
+ name: "asJumpPage",
178
178
  component: LocalDevPage,
179
179
  options: {
180
- title: '作为独立页面',
180
+ title: "作为独立页面",
181
181
  headerShown: false,
182
182
  },
183
183
  },
184
184
  {
185
- name: 'asMenuPage',
185
+ name: "asMenuPage",
186
186
  component: component,
187
187
  options: {
188
- title: '作为导航页面',
188
+ title: "作为导航页面",
189
189
  headerShown: false,
190
190
  },
191
191
  },
192
192
  ];
193
193
  }
194
194
 
195
- setInitialRouteName('');
195
+ setInitialRouteName("");
196
196
  setTabScreens([]);
197
197
  setTimeout(() => {
198
198
  // 智能家居tab index
199
199
  global.base.smartHomeTabIndex = tabs.findIndex(
200
- screen => screen.name === 'smartHome',
200
+ (screen) => screen.name === "smartHome"
201
201
  );
202
- if (tabs.find(screen => screen.name === 'panYuGovData')) {
203
- setInitialRouteName('panYuGovData');
204
- } else if (tabs.find(screen => screen.name === 'apartment')) {
205
- setInitialRouteName('apartment');
202
+ if (tabs.find((screen) => screen.name === "panYuGovData")) {
203
+ setInitialRouteName("panYuGovData");
204
+ } else if (tabs.find((screen) => screen.name === "apartment")) {
205
+ setInitialRouteName("apartment");
206
206
  } else if (global.base.smartHomeTabIndex > -1) {
207
207
  setInitialRouteName(tabs[global.base.smartHomeTabIndex].name);
208
208
  } else {
@@ -215,26 +215,26 @@ function HomeTabScreen({navigation, route}) {
215
215
  global.base.reloadNavigation = init;
216
216
 
217
217
  useEffect(() => {
218
- console.log(redirect ? '重定向进来' : '登录进来');
218
+ console.log(redirect ? "重定向进来" : "登录进来");
219
219
  (async () => {
220
220
  if (redirect) {
221
221
  await checkToken();
222
222
  }
223
223
 
224
- if (env === '__BASE_SINGLETON_MODE__') {
224
+ if (env === "__BASE_SINGLETON_MODE__") {
225
225
  // 单业务包开发调试环境
226
226
  global.base.navigateModule({
227
- operatorId: 'ipanel',
228
- moduleName: '__BASE_SINGLETON_MODE_APP__',
227
+ operatorId: "ipanel",
228
+ moduleName: "__BASE_SINGLETON_MODE_APP__",
229
229
  });
230
230
  }
231
231
 
232
- const accountType = await storage.get('accountType');
232
+ const accountType = await storage.get("accountType");
233
233
  global.base.accountType = accountType;
234
- if (accountType !== 'adg' && redirect) {
234
+ if (accountType !== "adg" && redirect) {
235
235
  await updateDataFromNetwork({
236
236
  refreshAddress: true,
237
- }).catch(err => {});
237
+ }).catch((err) => {});
238
238
  }
239
239
  init();
240
240
  })();
@@ -242,34 +242,34 @@ function HomeTabScreen({navigation, route}) {
242
242
 
243
243
  // 刷新token
244
244
  const checkToken = async () => {
245
- const access_token = await storage.get('accessToken');
246
- const refresh_token = await storage.get('refreshToken');
245
+ const access_token = await storage.get("accessToken");
246
+ const refresh_token = await storage.get("refreshToken");
247
247
  const logout = () => {
248
- Alert.alert('登录过期,请重新登录!', '', [
248
+ Alert.alert("登录过期,请重新登录!", "", [
249
249
  {
250
- text: '好',
250
+ text: "好",
251
251
  onPress: async () => {
252
- await storage.set('accessToken', null);
253
- await storage.set('refreshToken', null);
254
- await storage.set('homedAccessToken', null);
255
- replace('Login');
252
+ await storage.set("accessToken", null);
253
+ await storage.set("refreshToken", null);
254
+ await storage.set("homedAccessToken", null);
255
+ replace("Login");
256
256
  },
257
257
  },
258
258
  ]);
259
259
  };
260
260
  try {
261
- const accountType = await storage.get('accountType');
261
+ const accountType = await storage.get("accountType");
262
262
  const res = await refreshToken(
263
263
  {
264
264
  access_token,
265
265
  refresh_token,
266
266
  },
267
- accountType,
267
+ accountType
268
268
  );
269
269
  if (res.code === 0) {
270
- console.log('刷新token', res);
271
- await storage.set('accessToken', res.result.access_token);
272
- await storage.set('refreshToken', res.result.refresh_token);
270
+ console.log("刷新token", res);
271
+ await storage.set("accessToken", res.result.access_token);
272
+ await storage.set("refreshToken", res.result.refresh_token);
273
273
  } else {
274
274
  logout();
275
275
  }
@@ -307,26 +307,28 @@ function HomeTabScreen({navigation, route}) {
307
307
  global.base.shopMessageManager.getOnlineUser = getOnlineUser;
308
308
  global.base.shopMessageManager.sendShopImMessage = sendShopImMessage;
309
309
  global.base.shopMessageManager.getConnectStatus = getConnectStatus;
310
- const renderCustomTabBar = props => {
310
+ const renderCustomTabBar = (props) => {
311
311
  return <CustomTabBar {...props} />;
312
312
  };
313
313
  const insets = useSafeArea();
314
314
  return (
315
- <View style={{flex: 1}}>
315
+ <View style={{ flex: 1 }}>
316
316
  {tabScreens.length > 0 ? (
317
317
  <View
318
318
  style={{
319
319
  paddingBottom: insets.bottom,
320
- backgroundColor: '#fff',
320
+ backgroundColor: "#fff",
321
321
  flex: 1,
322
- }}>
322
+ }}
323
+ >
323
324
  <Tab.Navigator
324
325
  initialRouteName={initialRouteName}
325
326
  backBehavior="initialRoute"
326
- tabBar={props => renderCustomTabBar(props)}
327
+ tabBar={(props) => renderCustomTabBar(props)}
327
328
  screenOptions={{
328
- headerTitleAlign: 'center',
329
- }}>
329
+ headerTitleAlign: "center",
330
+ }}
331
+ >
330
332
  {tabScreens.map((item, index) => (
331
333
  <Tab.Screen
332
334
  name={item.name}
@@ -341,19 +343,20 @@ function HomeTabScreen({navigation, route}) {
341
343
  <ImageBackground
342
344
  style={styles.loadingView}
343
345
  source={
344
- appName === '禺乐慧家'
345
- ? require('../assets/img/launch_bg_panyu.png')
346
- : require('../assets/img/launch_bg.png')
347
- }>
346
+ ["禺乐慧家", "悦慧家"].includes(appName)
347
+ ? require("../assets/img/launch_bg_panyu.png")
348
+ : require("../assets/img/launch_bg.png")
349
+ }
350
+ >
348
351
  {/*<Text style={styles.loadingText}>*/}
349
352
  {/* 欢迎使用{appName.includes('安电工') ? '安电工' : '爱家宝'}*/}
350
353
  {/*</Text>*/}
351
354
  {/*<ActivityIndicator size="large" />*/}
352
355
  <Image
353
356
  source={
354
- appName === '禺乐慧家'
355
- ? require('../assets/img/launch_logo_panyu.png')
356
- : require('../assets/img/launch_logo.png')
357
+ ["禺乐慧家", "悦慧家"].includes(appName)
358
+ ? require("../assets/img/launch_logo_panyu.png")
359
+ : require("../assets/img/launch_logo.png")
357
360
  }
358
361
  style={{
359
362
  width: px(231),
@@ -364,9 +367,9 @@ function HomeTabScreen({navigation, route}) {
364
367
  />
365
368
  <Image
366
369
  source={
367
- appName === '禺乐慧家'
368
- ? require('../assets/img/launch_text_panyu.png')
369
- : require('../assets/img/launch_text.png')
370
+ ["禺乐慧家", "悦慧家"].includes(appName)
371
+ ? require("../assets/img/launch_text_panyu.png")
372
+ : require("../assets/img/launch_text.png")
370
373
  }
371
374
  style={{
372
375
  width: px(687),
@@ -385,8 +388,8 @@ function HomeTabScreen({navigation, route}) {
385
388
  const styles = StyleSheet.create({
386
389
  loadingView: {
387
390
  flex: 1,
388
- alignItems: 'center',
389
- justifyContent: 'center',
391
+ alignItems: "center",
392
+ justifyContent: "center",
390
393
  // backgroundColor: '#fff',
391
394
  },
392
395
  loadingText: {