ipanel-rnapp-ajb-base 1.0.21 → 1.0.24

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.
Binary file
Binary file
package/app/base.js CHANGED
@@ -1,10 +1,10 @@
1
- import {NativeModules, Platform} from 'react-native';
1
+ import { NativeModules, Platform } from "react-native";
2
2
  // 引入兼容本地运行开发测试的额外处理
3
- import {getRemoteComponentByName} from './.local_dev/polyfill';
3
+ import { getRemoteComponentByName } from "./.local_dev/polyfill";
4
4
 
5
- import eventBus, {EVENTS} from './eventBus';
6
- import storage from './storage';
7
- import http, {homedHttp} from './utils/http';
5
+ import eventBus, { EVENTS } from "./eventBus";
6
+ import storage from "./storage";
7
+ import http, { homedHttp } from "./utils/http";
8
8
  import {
9
9
  navigate,
10
10
  push,
@@ -12,13 +12,13 @@ import {
12
12
  goBack,
13
13
  pop,
14
14
  popToTop,
15
- } from './utils/RootNavigation';
16
- import scaleSize from './utils/scaleSize';
17
- import * as styles from './utils/StyleComposite';
18
- import config from './utils/config';
19
- import * as commonComponents from './components/index';
20
- import {getModuleVersionInfo} from './api';
21
- import applyPermissions from './utils/applyPermissions';
15
+ } from "./utils/RootNavigation";
16
+ import scaleSize from "./utils/scaleSize";
17
+ import * as styles from "./utils/StyleComposite";
18
+ import config from "./utils/config";
19
+ import * as commonComponents from "./components/index";
20
+ import { getModuleVersionInfo } from "./api";
21
+ import applyPermissions from "./utils/applyPermissions";
22
22
  import {
23
23
  getUserLocation,
24
24
  genMsg,
@@ -27,10 +27,10 @@ import {
27
27
  appReport,
28
28
  updateHomedToken,
29
29
  checkToken,
30
- } from './utils/common';
31
- import * as dialogs from './utils/registerDialog';
30
+ } from "./utils/common";
31
+ import * as dialogs from "./utils/registerDialog";
32
32
 
33
- import env from './.local_dev/env';
33
+ import env from "./.local_dev/env";
34
34
 
35
35
  // 注册全局命名空间 base
36
36
  global.base = {};
@@ -52,13 +52,18 @@ global.base.px = scaleSize;
52
52
  global.base.messageManager = {
53
53
  messages: [],
54
54
  wsRef: null,
55
+ sessionId: "",
55
56
 
56
57
  isConnected: function () {
57
58
  return !!global.base.messageManager.wsRef.current;
58
59
  },
59
60
 
61
+ setSessionId: function (sid) {
62
+ global.base.messageManager.sessionId = sid;
63
+ },
64
+
60
65
  sendMessage: async function (message) {
61
- console.log('ws.send');
66
+ console.log("ws.send", message);
62
67
  global.base.messageManager.wsRef.current &&
63
68
  global.base.messageManager.wsRef.current.send(JSON.stringify(message));
64
69
  eventBus.emit(EVENTS.MESSAGE.ADD, message);
@@ -66,17 +71,17 @@ global.base.messageManager = {
66
71
 
67
72
  updateMessageToStorage: async function (message) {
68
73
  const oldMsgIndex = global.base.messageManager.messages.findIndex(
69
- msg => msg.MsgId === message.MsgId,
74
+ (msg) => msg.MsgId === message.MsgId
70
75
  );
71
76
  if (oldMsgIndex === -1) {
72
- console.error('不存在的消息,msgId=', message.MsgId);
77
+ console.error("不存在的消息,msgId=", message.MsgId);
73
78
  return;
74
79
  }
75
80
 
76
81
  global.base.messageManager.messages.splice(oldMsgIndex, 1, message);
77
82
 
78
83
  // save to local
79
- await storage.set('messageList', global.base.messageManager.messages);
84
+ await storage.set("messageList", global.base.messageManager.messages);
80
85
  },
81
86
 
82
87
  genMsg,
@@ -115,8 +120,8 @@ const isLocalDev = !NativeModules.RNToNativeEmitter?.isMultiBundle;
115
120
  global.base.loadPackages = function loadPackages(data, packageLoadCallback) {
116
121
  return new Promise((resolve, reject) => {
117
122
  if (!isLocalDev) {
118
- const load = pack => {
119
- return new Promise(_reslove => {
123
+ const load = (pack) => {
124
+ return new Promise((_reslove) => {
120
125
  NativeModules.RNToNativeEmitter.loadPackage(
121
126
  {
122
127
  package: pack,
@@ -124,20 +129,20 @@ global.base.loadPackages = function loadPackages(data, packageLoadCallback) {
124
129
  function (error, packageName) {
125
130
  console.log(error, packageName);
126
131
 
127
- typeof packageLoadCallback === 'function' &&
132
+ typeof packageLoadCallback === "function" &&
128
133
  packageLoadCallback(error, packageName);
129
134
 
130
135
  _reslove({
131
136
  error,
132
137
  packageName,
133
138
  });
134
- },
139
+ }
135
140
  );
136
141
  });
137
142
  };
138
143
 
139
- Promise.all(data.packages.map(pack => load(pack))).then(datas => {
140
- const errors = datas.filter(item => !!item.error);
144
+ Promise.all(data.packages.map((pack) => load(pack))).then((datas) => {
145
+ const errors = datas.filter((item) => !!item.error);
141
146
  if (errors.length > 0) {
142
147
  reject(errors);
143
148
  } else {
@@ -156,12 +161,12 @@ global.base.getRemoteComponentByName = getRemoteComponentByName;
156
161
 
157
162
  // 各个业务包App.js中需要主动调用全局注册页面函数registerGlobalStackScreens,将该业务包中需要全屏覆盖的页面注册到全局栈路由中
158
163
  // 其中ScreenName格式要求规范为jsappName_screenName
159
- global.base.registerGlobalStackScreens = screens => {
164
+ global.base.registerGlobalStackScreens = (screens) => {
160
165
  // todo 检测componentName不能为业务模块名,避免同一个模块名既被用于导航,又被用于全局独立页面动态路由注册跳转。两个路由名重复的话可能会导致跳转到导航路由,而没法跳到独立页面?
161
- global.base.eventBus.emit('addDynamicScreens', {
166
+ global.base.eventBus.emit("addDynamicScreens", {
162
167
  ...screens,
163
168
  });
164
- return new Promise(resolve => setTimeout(resolve));
169
+ return new Promise((resolve) => setTimeout(resolve));
165
170
  };
166
171
 
167
172
  /**
@@ -172,23 +177,23 @@ global.base.registerGlobalStackScreens = screens => {
172
177
  */
173
178
  global.base.registerRemoteComponentGlobalStackScreen = async (
174
179
  componentName,
175
- screenOptions,
180
+ screenOptions
176
181
  ) => {
177
182
  // todo 检测componentName不能为业务模块名,避免同一个模块名既被用于导航,又被用于全局独立页面动态路由注册跳转。两个路由名重复的话可能会导致跳转到导航路由,而没法跳到独立页面?
178
183
 
179
184
  const component = await getRemoteComponentByName(componentName);
180
185
  component.registerStackScreens && component.registerStackScreens();
181
186
  if (component) {
182
- global.base.eventBus.emit('addDynamicScreens', {
187
+ global.base.eventBus.emit("addDynamicScreens", {
183
188
  [componentName]: {
184
189
  component,
185
190
  screenOptions,
186
191
  },
187
192
  });
188
- return new Promise(resolve =>
193
+ return new Promise((resolve) =>
189
194
  setTimeout(() => {
190
195
  resolve(true);
191
- }),
196
+ })
192
197
  );
193
198
  } else {
194
199
  return false;
@@ -202,35 +207,37 @@ global.base.getIPanelCloudDomain = () => {
202
207
 
203
208
  // 获取当前家庭云家服务实例名(如a2),跟当前登录的ipanelcloud用户有关
204
209
  global.base.getHomeCloudServiceInstanceName = async () => {
205
- const activeAddr = await storage.get('activeAddr');
206
- const sub_domain = activeAddr?.sub_domain
207
- return sub_domain ? sub_domain : (NativeModules?.RNToNativeEmitter?.appName === '禺乐慧家'
208
- ? 'a21'
209
- : 'a2');
210
+ const activeAddr = await storage.get("activeAddr");
211
+ const sub_domain = activeAddr?.sub_domain;
212
+ return sub_domain
213
+ ? sub_domain
214
+ : ["禺乐慧家", "悦慧家"].includes(NativeModules?.RNToNativeEmitter?.appName)
215
+ ? "a21"
216
+ : "a2";
210
217
  };
211
218
 
212
219
  // 获取当前`homed`域名(`正式homed用户`域名优先于`homed游客`域名)
213
220
  global.base.getHomedDomain = async () => {
214
- const activeAddr = await storage.get('activeAddr');
221
+ const activeAddr = await storage.get("activeAddr");
215
222
  if (activeAddr?.domain) {
216
223
  // console.log('正式homed用户域名', activeAddr.domain);
217
224
  return activeAddr.domain;
218
225
  }
219
226
 
220
- const opHomedConfig = await storage.get('operatorHomedConfig');
227
+ const opHomedConfig = await storage.get("operatorHomedConfig");
221
228
  if (opHomedConfig && opHomedConfig.domain) {
222
229
  // console.log('游客homed域名', opHomedConfig.domain);
223
230
  return opHomedConfig.domain;
224
231
  }
225
232
 
226
- return 'homed.tv';
233
+ return "homed.tv";
227
234
  };
228
235
 
229
236
  // 获取当前`homed accesstoken`(`正式homed用户accesstoken`优先于`homed游客accesstoken`)
230
237
  global.base.getHomedToken = async () => {
231
238
  return (
232
- (await storage.get('homedAccessToken')) ||
233
- (await storage.get('homedTouristAccessToken'))
239
+ (await storage.get("homedAccessToken")) ||
240
+ (await storage.get("homedTouristAccessToken"))
234
241
  );
235
242
  };
236
243
 
@@ -242,8 +249,8 @@ global.base.reload = async () => {
242
249
 
243
250
  // 获取app唯一标识
244
251
  global.base.getAppId = () => {
245
- return new Promise(resolve => {
246
- if (Platform.OS === 'ios') {
252
+ return new Promise((resolve) => {
253
+ if (Platform.OS === "ios") {
247
254
  resolve(NativeModules?.RNToNativeEmitter.appID);
248
255
  } else {
249
256
  // 安卓api
@@ -257,21 +264,21 @@ global.base.getAppId = () => {
257
264
  };
258
265
 
259
266
  // 获取当前打包的bundle信息
260
- global.base.getBundleInfo = moduleName => {
261
- return new Promise(resolve => {
267
+ global.base.getBundleInfo = (moduleName) => {
268
+ return new Promise((resolve) => {
262
269
  if (NativeModules?.RNToNativeEmitter?.getBundleInfo) {
263
270
  NativeModules.RNToNativeEmitter.getBundleInfo(
264
271
  moduleName,
265
272
  function (err, data) {
266
273
  if (err) {
267
- console.log('getBundleInfo--err', err);
274
+ console.log("getBundleInfo--err", err);
268
275
  resolve();
269
276
  return;
270
277
  }
271
- console.log('getBundleInfo--data', typeof data, data);
278
+ console.log("getBundleInfo--data", typeof data, data);
272
279
 
273
280
  // 兼容处理
274
- if (typeof data === 'string') {
281
+ if (typeof data === "string") {
275
282
  try {
276
283
  data = JSON.parse(data);
277
284
  resolve(data);
@@ -283,7 +290,7 @@ global.base.getBundleInfo = moduleName => {
283
290
  // object
284
291
  resolve(data);
285
292
  }
286
- },
293
+ }
287
294
  );
288
295
  } else {
289
296
  resolve();
@@ -302,7 +309,7 @@ global.base.navigateModule = async ({
302
309
  if (global.base.DynamicStackScreens[moduleName]) {
303
310
  const module = await getRemoteComponentByName(moduleName);
304
311
  if (module) {
305
- console.log('模块已被加载并注册过,直接跳转');
312
+ console.log("模块已被加载并注册过,直接跳转");
306
313
  // 如果已加载并注册过,直接跳转
307
314
  if (isReplace) {
308
315
  replace(screenName || moduleName, params);
@@ -312,20 +319,20 @@ global.base.navigateModule = async ({
312
319
  return true;
313
320
  }
314
321
  }
315
- console.log('模块未被加载过,先加载注册再跳转');
322
+ console.log("模块未被加载过,先加载注册再跳转");
316
323
 
317
- if (env !== '__BASE_SINGLETON_MODE__') {
324
+ if (env !== "__BASE_SINGLETON_MODE__") {
318
325
  const result = await getModuleVersionInfo({
319
326
  platform: Platform.OS,
320
327
  operatorId,
321
328
  moduleName,
322
- }).catch(err => {
329
+ }).catch((err) => {
323
330
  console.log(err);
324
331
  });
325
- console.log(result, 'getModuleVersionInfo');
332
+ console.log(result, "getModuleVersionInfo");
326
333
  if (!result || result.code !== 0) {
327
- global.toast.showToast('加载失败');
328
- console.log('加载失败');
334
+ global.toast.showToast("加载失败");
335
+ console.log("加载失败");
329
336
  return false;
330
337
  }
331
338
 
@@ -335,13 +342,13 @@ global.base.navigateModule = async ({
335
342
  .loadPackages({
336
343
  packages,
337
344
  })
338
- .catch(errors => {
345
+ .catch((errors) => {
339
346
  console.log(JSON.stringify(errors));
340
347
  });
341
348
 
342
349
  if (!flag) {
343
- global.toast.showToast('网络繁忙');
344
- console.log('网络繁忙');
350
+ global.toast.showToast("网络繁忙");
351
+ console.log("网络繁忙");
345
352
  return false;
346
353
  }
347
354
 
@@ -351,7 +358,7 @@ global.base.navigateModule = async ({
351
358
  headerShown: false,
352
359
  });
353
360
 
354
- console.log('registerFlag', registerFlag);
361
+ console.log("registerFlag", registerFlag);
355
362
 
356
363
  if (registerFlag) {
357
364
  if (isReplace) {
@@ -364,7 +371,7 @@ global.base.navigateModule = async ({
364
371
  // 单业务包开发调试环境
365
372
  const registerFlag =
366
373
  await global.base.registerRemoteComponentGlobalStackScreen(moduleName, {
367
- title: '',
374
+ title: "",
368
375
  headerShown: false,
369
376
  });
370
377
 
@@ -1,14 +1,15 @@
1
- import React from 'react';
2
- import {Divider} from '@rneui/themed';
1
+ import React from "react";
2
+ import { Divider } from "@rneui/themed";
3
3
  import {
4
4
  View,
5
5
  Text,
6
6
  StyleSheet,
7
7
  TouchableOpacity,
8
8
  Dimensions,
9
- } from 'react-native';
10
- import {WebView} from 'react-native-webview';
11
- import px from '../../../utils/scaleSize';
9
+ } from "react-native";
10
+ import { WebView } from "react-native-webview";
11
+ import DeviceInfo from "react-native-device-info";
12
+ import px from "../../../utils/scaleSize";
12
13
  const ProtocolDialog = ({
13
14
  type,
14
15
  url,
@@ -16,10 +17,10 @@ const ProtocolDialog = ({
16
17
  handleOneAgree,
17
18
  dialogTitle,
18
19
  }) => {
19
- const agree = type => {
20
+ const agree = (type) => {
20
21
  handleOneAgree(type);
21
22
  };
22
- const disagree = type => {
23
+ const disagree = (type) => {
23
24
  handleOneDisagree(type);
24
25
  };
25
26
  return (
@@ -32,7 +33,7 @@ const ProtocolDialog = ({
32
33
  ) : (
33
34
  <></>
34
35
  )}
35
- <View style={{flex: 1}}>
36
+ <View style={{ flex: 1 }}>
36
37
  <WebView
37
38
  style={{}}
38
39
  source={{
@@ -45,7 +46,8 @@ const ProtocolDialog = ({
45
46
  <TouchableOpacity
46
47
  style={styles.agreeBtn}
47
48
  activeOpacity={0.7}
48
- onPress={() => agree(type)}>
49
+ onPress={() => agree(type)}
50
+ >
49
51
  <Text style={styles.agreeBtnText}>同意</Text>
50
52
  </TouchableOpacity>
51
53
  </View>
@@ -53,7 +55,8 @@ const ProtocolDialog = ({
53
55
  <TouchableOpacity
54
56
  style={styles.disagreeBtn}
55
57
  activeOpacity={0.7}
56
- onPress={() => disagree(type)}>
58
+ onPress={() => disagree(type)}
59
+ >
57
60
  <Text style={styles.disagreeBtnText}>不同意</Text>
58
61
  </TouchableOpacity>
59
62
  </View>
@@ -62,32 +65,51 @@ const ProtocolDialog = ({
62
65
  );
63
66
  };
64
67
 
68
+ let agreementConfirmContent = {
69
+ position: "absolute",
70
+ height: Dimensions.get("window").height * 0.85,
71
+ left: px(75),
72
+ right: px(75),
73
+ top: Dimensions.get("window").height * 0.1,
74
+ backgroundColor: "#fff",
75
+ paddingBottom: 0,
76
+ borderRadius: px(29),
77
+ };
78
+ let disagreeBtnHeight = px(132);
79
+ let disagreeBtnFontSize = px(52);
80
+
81
+ if (DeviceInfo.getBrand() === "Allwinner") {
82
+ agreementConfirmContent = {
83
+ position: "absolute",
84
+ height: Dimensions.get("window").height * 0.85,
85
+ left: px(75),
86
+ right: px(75),
87
+ top: Dimensions.get("window").height * 0.1,
88
+ backgroundColor: "#fff",
89
+ paddingBottom: 0,
90
+ borderRadius: px(29),
91
+ };
92
+ disagreeBtnHeight = px(50);
93
+ disagreeBtnFontSize = px(26);
94
+ }
95
+
65
96
  const styles = StyleSheet.create({
66
97
  agreementMask: {
67
- position: 'absolute',
98
+ position: "absolute",
68
99
  left: 0,
69
100
  top: 0,
70
101
  bottom: 0,
71
102
  right: 0,
72
103
  zIndex: 2,
73
- backgroundColor: 'rgba(0,0,0,0.7)',
74
- },
75
- agreementConfirmContent: {
76
- position: 'absolute',
77
- height: Dimensions.get('window').height * 0.7,
78
- left: px(75),
79
- right: px(75),
80
- top: Dimensions.get('window').height * 0.15,
81
- backgroundColor: '#fff',
82
- paddingBottom: 0,
83
- borderRadius: px(29),
104
+ backgroundColor: "rgba(0,0,0,0.7)",
84
105
  },
106
+ agreementConfirmContent,
85
107
  agreementConfirmHead: {
86
108
  marginTop: px(52),
87
109
  marginBottom: px(34),
88
110
  },
89
111
  headerLeft: {
90
- position: 'absolute',
112
+ position: "absolute",
91
113
  top: 15,
92
114
  left: 10,
93
115
  zIndex: 2,
@@ -98,7 +120,7 @@ const styles = StyleSheet.create({
98
120
  },
99
121
  agreementConfirmTitleBox: {
100
122
  // flex: 1,
101
- position: 'absolute',
123
+ position: "absolute",
102
124
  top: 10,
103
125
  bottom: 0,
104
126
  left: 0,
@@ -108,22 +130,22 @@ const styles = StyleSheet.create({
108
130
  agreementConfirmTitle: {
109
131
  fontSize: 20,
110
132
  // lineHeight: 50,
111
- color: '#000',
112
- textAlign: 'center',
133
+ color: "#000",
134
+ textAlign: "center",
113
135
  // paddingTop: 20,
114
136
  },
115
137
  agreementConfirmText: {
116
138
  fontSize: px(40),
117
139
  lineHeight: px(69),
118
- color: '#333',
140
+ color: "#333",
119
141
  marginHorizontal: px(40),
120
142
  },
121
143
  agreementConfirmImportantText: {
122
- color: 'rgba(234, 96, 0, 1)',
144
+ color: "rgba(234, 96, 0, 1)",
123
145
  },
124
146
  agreementButtons: {
125
147
  // justifyContent: 'center',
126
- alignItems: 'center',
148
+ alignItems: "center",
127
149
 
128
150
  // marginTop: px(12),
129
151
  // flexDirection: 'row',
@@ -132,29 +154,29 @@ const styles = StyleSheet.create({
132
154
  },
133
155
  disagreeBtn: {
134
156
  width: px(850),
135
- height: px(132),
136
- justifyContent: 'center',
137
- alignItems: 'center',
157
+ height: disagreeBtnHeight,
158
+ justifyContent: "center",
159
+ alignItems: "center",
138
160
  },
139
161
  disagreeBtnText: {
140
- color: '#666',
141
- fontSize: px(52),
142
- textAlign: 'center',
143
- fontWeight: '400',
162
+ color: "#666",
163
+ fontSize: disagreeBtnFontSize,
164
+ textAlign: "center",
165
+ fontWeight: "400",
144
166
  },
145
167
  agreeBtn: {
146
168
  width: px(850),
147
- height: px(132),
148
- justifyContent: 'center',
149
- alignItems: 'center',
150
- backgroundColor: '#E86003',
169
+ height: disagreeBtnHeight,
170
+ justifyContent: "center",
171
+ alignItems: "center",
172
+ backgroundColor: "#E86003",
151
173
  borderRadius: px(23),
152
174
  },
153
175
  agreeBtnText: {
154
- color: '#fff',
155
- fontSize: px(52),
156
- textAlign: 'center',
157
- fontWeight: '600',
176
+ color: "#fff",
177
+ fontSize: disagreeBtnFontSize,
178
+ textAlign: "center",
179
+ fontWeight: "600",
158
180
  },
159
181
  });
160
182
  export default ProtocolDialog;