ipanel-rnapp-ajb-base 1.0.0
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.
- package/app/.local_dev/DemoPage.js +46 -0
- package/app/.local_dev/env.js +1 -0
- package/app/.local_dev/polyfill.js +83 -0
- package/app/App.js +485 -0
- package/app/api/homedApi.js +42 -0
- package/app/api/index.js +2 -0
- package/app/api/ipanelCloudApi.js +796 -0
- package/app/assets/img/add.png +0 -0
- package/app/assets/img/add_img.png +0 -0
- package/app/assets/img/album.png +0 -0
- package/app/assets/img/album2.png +0 -0
- package/app/assets/img/album3.png +0 -0
- package/app/assets/img/album@2x.png +0 -0
- package/app/assets/img/album@3x.png +0 -0
- package/app/assets/img/audioRecordBar.png +0 -0
- package/app/assets/img/bootom_bar_bg.png +0 -0
- package/app/assets/img/close.png +0 -0
- package/app/assets/img/computer.png +0 -0
- package/app/assets/img/confirm.png +0 -0
- package/app/assets/img/delete_pic.png +0 -0
- package/app/assets/img/disabled.png +0 -0
- package/app/assets/img/goBack.png +0 -0
- package/app/assets/img/goBack2.png +0 -0
- package/app/assets/img/ischeck.png +0 -0
- package/app/assets/img/launch_bg.png +0 -0
- package/app/assets/img/launch_bg_panyu.png +0 -0
- package/app/assets/img/launch_logo.png +0 -0
- package/app/assets/img/launch_logo_panyu.png +0 -0
- package/app/assets/img/launch_text.png +0 -0
- package/app/assets/img/launch_text_panyu.png +0 -0
- package/app/assets/img/link.png +0 -0
- package/app/assets/img/login_bg.png +0 -0
- package/app/assets/img/login_bg_new.png +0 -0
- package/app/assets/img/login_left.png +0 -0
- package/app/assets/img/login_right.png +0 -0
- package/app/assets/img/nocheck.png +0 -0
- package/app/assets/img/personal.png +0 -0
- package/app/assets/img/photo.png +0 -0
- package/app/assets/img/photo@2x.png +0 -0
- package/app/assets/img/photo@3x.png +0 -0
- package/app/assets/img/protocol_checked.png +0 -0
- package/app/assets/img/qiehuan.png +0 -0
- package/app/assets/img/scan_border_bottom_left.png +0 -0
- package/app/assets/img/scan_border_bottom_right.png +0 -0
- package/app/assets/img/scan_border_top_left.png +0 -0
- package/app/assets/img/scan_border_top_right.png +0 -0
- package/app/assets/img/scan_move.png +0 -0
- package/app/assets/img/szjt.png +0 -0
- package/app/assets/img/tab.png +0 -0
- package/app/assets/img/tykz.png +0 -0
- package/app/assets/img/update_bg.png +0 -0
- package/app/assets/img/video.png +0 -0
- package/app/assets/img/video@2x.png +0 -0
- package/app/assets/img/video@3x.png +0 -0
- package/app/assets/img/worker.png +0 -0
- package/app/assets/img/wx.png +0 -0
- package/app/assets/img/ykq.png +0 -0
- package/app/assets/img/zfb.png +0 -0
- package/app/base.js +342 -0
- package/app/components/VersionUpdateConfirm.js +117 -0
- package/app/components/common/AccordionCell/index.js +67 -0
- package/app/components/common/ActionPicker/BasicPicker.js +136 -0
- package/app/components/common/ActionPicker/index.js +106 -0
- package/app/components/common/AddressPicker/index.js +211 -0
- package/app/components/common/Card/index.js +19 -0
- package/app/components/common/Cell/index.js +381 -0
- package/app/components/common/CustomDialog/index.js +120 -0
- package/app/components/common/CustomTabBar/index.js +157 -0
- package/app/components/common/CustomTabBar_bak/TabBarInput.js +210 -0
- package/app/components/common/CustomTabBar_bak/index.js +832 -0
- package/app/components/common/DateTimingPicker/index.js +254 -0
- package/app/components/common/Dialog/Notify.js +36 -0
- package/app/components/common/Dialog/baseDialog.js +146 -0
- package/app/components/common/Dialog/index.js +113 -0
- package/app/components/common/Dialog/prompt.js +145 -0
- package/app/components/common/Dialog/quickSelect.js +54 -0
- package/app/components/common/Dialog/select.js +125 -0
- package/app/components/common/Dialog/styles.js +167 -0
- package/app/components/common/Loading/index.js +71 -0
- package/app/components/common/LoginType/index.js +171 -0
- package/app/components/common/LoginType/protocol.js +160 -0
- package/app/components/common/Notify/index.js +68 -0
- package/app/components/common/OnceTouchable/index.js +33 -0
- package/app/components/common/PaymentPicker/index.js +264 -0
- package/app/components/common/ProductOrderPicker/index.js +524 -0
- package/app/components/common/ScreenBackHeader/index.js +144 -0
- package/app/components/common/ScrollPicker/index.js +232 -0
- package/app/components/common/SelectPicker/index.js +171 -0
- package/app/components/common/SmsCodeInput/index.js +93 -0
- package/app/components/common/SmsCodeInput/indexNew.js +101 -0
- package/app/components/common/Steps/index.js +126 -0
- package/app/components/common/Tag/index.js +17 -0
- package/app/components/common/Toast/index.js +103 -0
- package/app/components/common/WeekDaysPicker/index.js +196 -0
- package/app/components/index.js +8 -0
- package/app/components/iot/AddDeviceActionSheet/index.js +934 -0
- package/app/components/iot/AddressActionSheet/index.js +91 -0
- package/app/components/iot/RoomActionSheet/index.js +205 -0
- package/app/components/iot/ViewDeviceActionSheet/index.js +834 -0
- package/app/components/sheets.js +30 -0
- package/app/eventBus/index.js +54 -0
- package/app/hooks/checkLogin.js +30 -0
- package/app/hooks/shopMessageManager.js +308 -0
- package/app/hooks/useAddress.js +179 -0
- package/app/hooks/useAddress2.js +587 -0
- package/app/hooks/useDebounceFn.js +6 -0
- package/app/hooks/useDynamicPackages.js +22 -0
- package/app/hooks/useKeyboard.js +25 -0
- package/app/hooks/useLatest.js +10 -0
- package/app/hooks/useMessageManager.js +368 -0
- package/app/hooks/useNavigationFocus.js +19 -0
- package/app/hooks/useUser.js +56 -0
- package/app/screens/BaseScreen.js +389 -0
- package/app/screens/CommonScreens/BindPhoneScreen/index.js +179 -0
- package/app/screens/CommonScreens/BossScreen/index.js +138 -0
- package/app/screens/CommonScreens/DeviceAnswerDetailScreen/index.js +50 -0
- package/app/screens/CommonScreens/DeviceFeedbackScreen/index.js +365 -0
- package/app/screens/CommonScreens/EditInvoiceTitleScreen/index.js +279 -0
- package/app/screens/CommonScreens/FamilyDetailScreen/index.js +421 -0
- package/app/screens/CommonScreens/InvoiceTitleListScreen/index.js +118 -0
- package/app/screens/CommonScreens/OperatorSelectScreen/index.js +315 -0
- package/app/screens/CommonScreens/PersonalScreen/index.js +348 -0
- package/app/screens/CommonScreens/ScanQRCodeScreen/index.js +407 -0
- package/app/screens/CommonScreens/TvAlbumScreen/index.js +407 -0
- package/app/screens/LoginScreen/OpenLogSheet.js +241 -0
- package/app/screens/LoginScreen/index.js +920 -0
- package/app/screens/LoginScreen/indexNew.js +1354 -0
- package/app/screens/ResePassword/index.js +364 -0
- package/app/screens/SbkScreen.js +19 -0
- package/app/screens/WebviewScreen.js +41 -0
- package/app/storage/index.js +166 -0
- package/app/utils/EventEmitter.js +43 -0
- package/app/utils/RootNavigation.js +32 -0
- package/app/utils/SBK_plugin/convert.js +90 -0
- package/app/utils/SBK_plugin/convertStatus.js +250 -0
- package/app/utils/SBK_plugin/eventProcess.js +339 -0
- package/app/utils/SBK_plugin/index.js +32 -0
- package/app/utils/SBK_plugin/ipanelDeviceToSbkDevice.js +68 -0
- package/app/utils/SBK_plugin/sbk_defs.js +191 -0
- package/app/utils/StyleComposite.js +37 -0
- package/app/utils/applyPermissions.js +251 -0
- package/app/utils/bundleUpdater.js +46 -0
- package/app/utils/common.js +380 -0
- package/app/utils/config.js +47 -0
- package/app/utils/errCodes.js +3 -0
- package/app/utils/homedData.js +57 -0
- package/app/utils/http.js +178 -0
- package/app/utils/notice.js +15 -0
- package/app/utils/priceConversion.js +30 -0
- package/app/utils/registerDialog.js +90 -0
- package/app/utils/scaleSize.js +12 -0
- package/app/utils/soundPlayer.js +85 -0
- package/bin/local-dev.js +7 -0
- package/index.js +8 -0
- package/package.json +18 -0
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
import {Alert, Platform} from 'react-native';
|
|
2
|
+
import Geolocation from 'react-native-geolocation-service';
|
|
3
|
+
import UUIDGenerator from 'react-native-uuid-generator';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
homedGet,
|
|
7
|
+
obtainThirdToken,
|
|
8
|
+
getUserList,
|
|
9
|
+
ACCOUNT_SERVICE,
|
|
10
|
+
reportBigData,
|
|
11
|
+
getUserInfo,
|
|
12
|
+
getAccessToken,
|
|
13
|
+
refreshToken,
|
|
14
|
+
} from '../api';
|
|
15
|
+
import storage from '../storage';
|
|
16
|
+
import eventBus, {EVENTS} from '../eventBus';
|
|
17
|
+
import applyPermissions from './applyPermissions';
|
|
18
|
+
import {replace} from './RootNavigation';
|
|
19
|
+
|
|
20
|
+
async function updateHomedToken() {
|
|
21
|
+
const accountData = await storage.get('accountData');
|
|
22
|
+
const activeAddr = await storage.get('activeAddr');
|
|
23
|
+
const res = await getUserInfo();
|
|
24
|
+
const userList = res.result?.user_list || [];
|
|
25
|
+
const currentUser = userList.find(
|
|
26
|
+
item => item.user_id === accountData?.user.user_id,
|
|
27
|
+
);
|
|
28
|
+
const bindList = currentUser?.bind_list || [];
|
|
29
|
+
console.log(bindList, 'bindList');
|
|
30
|
+
const homedConfig = bindList.find(item => item.third_type === 'homed');
|
|
31
|
+
console.log(activeAddr?.domain, 'domain');
|
|
32
|
+
if (homedConfig && activeAddr?.domain) {
|
|
33
|
+
const tokenRes = await getAccessToken(
|
|
34
|
+
{
|
|
35
|
+
userName: homedConfig.third_id,
|
|
36
|
+
deviceType: 1,
|
|
37
|
+
},
|
|
38
|
+
activeAddr?.domain,
|
|
39
|
+
).catch(err => {});
|
|
40
|
+
console.log(tokenRes, 'tokenRes');
|
|
41
|
+
if (tokenRes && tokenRes.ret === 0) {
|
|
42
|
+
// 如果能获取到homed token,说明当前登录的家庭成员开通(绑定)了homed业务
|
|
43
|
+
await storage.set('homedAccessToken', tokenRes.access_token);
|
|
44
|
+
const userListRes = await getUserList({}).catch(() => {});
|
|
45
|
+
if (userListRes?.ret === 0) {
|
|
46
|
+
const list = userListRes.user_list || [];
|
|
47
|
+
await storage.set(
|
|
48
|
+
'homedHomeMembers',
|
|
49
|
+
list.filter(item => item.user_id !== userListRes.bind_user_id),
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
} else {
|
|
53
|
+
// global.toast.showToast(tokenRes?.ret_message || '获取homedtoken失败');
|
|
54
|
+
// 置空
|
|
55
|
+
await storage.set('homedAccessToken', '');
|
|
56
|
+
}
|
|
57
|
+
} else {
|
|
58
|
+
await storage.set('homedAccessToken', '');
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// const params = {
|
|
62
|
+
// third_type: 'homed',
|
|
63
|
+
// address_id: addressId,
|
|
64
|
+
// user_id: userId,
|
|
65
|
+
// };
|
|
66
|
+
// const tokenRes = await obtainThirdToken(params);
|
|
67
|
+
// // console.log("params", params);
|
|
68
|
+
// console.log('更新homed token:', tokenRes);
|
|
69
|
+
//
|
|
70
|
+
// if (tokenRes && tokenRes.code === 0) {
|
|
71
|
+
// // 如果能获取到homed token,说明当前登录的家庭成员开通(绑定)了homed业务
|
|
72
|
+
// await storage.set('homedAccessToken', tokenRes.result.third_token);
|
|
73
|
+
// const userListRes = await getUserList({}).catch(() => {});
|
|
74
|
+
// if (userListRes?.ret === 0) {
|
|
75
|
+
// const list = userListRes.user_list || [];
|
|
76
|
+
// await storage.set(
|
|
77
|
+
// 'homedHomeMembers',
|
|
78
|
+
// list.filter(item => item.user_id !== userListRes.bind_user_id),
|
|
79
|
+
// );
|
|
80
|
+
// }
|
|
81
|
+
// } else {
|
|
82
|
+
// // 置空
|
|
83
|
+
// await storage.set('homedAccessToken', '');
|
|
84
|
+
// }
|
|
85
|
+
//
|
|
86
|
+
// eventBus.emit(EVENTS.HOMED.TOKEN_CHANGE);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// 初始化当前运营商对应的homed游客账号
|
|
90
|
+
// TODO 在用户个人信息切换运营商后需要同步调用该函数初始化新的运营商的homed游客账号及token
|
|
91
|
+
async function initOperatorHomedTouristAccount(opHomedConfig) {
|
|
92
|
+
await storage.set('operatorHomedConfig', opHomedConfig);
|
|
93
|
+
|
|
94
|
+
await homedGet(
|
|
95
|
+
`https://access.${opHomedConfig.domain}/account/user/register`,
|
|
96
|
+
{
|
|
97
|
+
username: opHomedConfig.touristUsername,
|
|
98
|
+
groupid: opHomedConfig.touristGroupId,
|
|
99
|
+
accounttype: 1,
|
|
100
|
+
iconid: 1,
|
|
101
|
+
pwd: '1bbd886460827015e5d605ed44252251', // md5("11111111")
|
|
102
|
+
},
|
|
103
|
+
).catch(e => {
|
|
104
|
+
console.log('Error: homed游客注册请求失败', e);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
await updateHomedTouristToken();
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// 更新homed游客token
|
|
111
|
+
async function updateHomedTouristToken() {
|
|
112
|
+
const opHomedConfig = await storage.get('operatorHomedConfig');
|
|
113
|
+
|
|
114
|
+
const result = await homedGet(
|
|
115
|
+
`https://access.${opHomedConfig.domain}/account/login`,
|
|
116
|
+
{
|
|
117
|
+
deviceno: opHomedConfig.touristUsername,
|
|
118
|
+
account: opHomedConfig.touristUsername,
|
|
119
|
+
devicetype: 3,
|
|
120
|
+
accounttype: 2,
|
|
121
|
+
pwd: '1bbd886460827015e5d605ed44252251', // md5("11111111")
|
|
122
|
+
},
|
|
123
|
+
).catch(e => {
|
|
124
|
+
console.log('Error: homed游客登录请求失败', e);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
if (result && result.ret === 0) {
|
|
128
|
+
console.log('homedTouristAccessToken:', result.access_token);
|
|
129
|
+
await storage.set('homedTouristAccessToken', result.access_token);
|
|
130
|
+
} else {
|
|
131
|
+
await storage.set('homedTouristAccessToken', '');
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
async function getCurrentPosition() {
|
|
136
|
+
return new Promise((resolve, reject) => {
|
|
137
|
+
Geolocation.getCurrentPosition(resolve, reject, {
|
|
138
|
+
enableHighAccuracy: false,
|
|
139
|
+
timeout: 5000,
|
|
140
|
+
maximumAge: 600000, // ms
|
|
141
|
+
forceLocationManager: true, // 不设置这个的话会自动走谷歌gps接口,经常超时(小米)
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
async function getUserLocation() {
|
|
147
|
+
if (Platform.OS === 'ios') {
|
|
148
|
+
await Geolocation.requestAuthorization('whenInUse');
|
|
149
|
+
return getCurrentPosition();
|
|
150
|
+
} else {
|
|
151
|
+
// try {
|
|
152
|
+
// let granted = await PermissionsAndroid.request(
|
|
153
|
+
// PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION /* ,
|
|
154
|
+
// {
|
|
155
|
+
// title: "App Geolocation Permission",
|
|
156
|
+
// message: "App needs access to your phone's location.",
|
|
157
|
+
// } */,
|
|
158
|
+
// );
|
|
159
|
+
// if (granted === PermissionsAndroid.RESULTS.GRANTED) {
|
|
160
|
+
// return getCurrentPosition();
|
|
161
|
+
// } else {
|
|
162
|
+
// throw new Error('Location permission not granted!!!!');
|
|
163
|
+
// }
|
|
164
|
+
// } catch (e) {
|
|
165
|
+
// console.log(e);
|
|
166
|
+
// }
|
|
167
|
+
const granted = await applyPermissions.location();
|
|
168
|
+
if (granted) {
|
|
169
|
+
try {
|
|
170
|
+
return getCurrentPosition();
|
|
171
|
+
} catch (e) {
|
|
172
|
+
throw new Error('Location permission not granted!!!!');
|
|
173
|
+
}
|
|
174
|
+
} else {
|
|
175
|
+
throw new Error('Location permission not granted!!!!');
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const MSG_TYPES = {
|
|
181
|
+
TEXT: 'text',
|
|
182
|
+
IMAGE: 'image',
|
|
183
|
+
VOICE: 'voice',
|
|
184
|
+
VIDEO: 'video',
|
|
185
|
+
EVENT: 'event',
|
|
186
|
+
TEMPLATE: 'template',
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
const MSG_EVENT_TYPES = {
|
|
190
|
+
GEO: 'geo', // 上报地理位置信息
|
|
191
|
+
PUSH_WEATHER: 'push_weather', // 请求云端推送天气消息
|
|
192
|
+
SET_DEVICE_TIMING_CONTROL: 'set_device_timing_control', // 设置一个设备控制任务(notify task)
|
|
193
|
+
CANCEL_DEVICE_TIMING_CONTROL: 'cancel_device_timing_control', // 取消某个设备控制任务(delete task)
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
// 快速构成智能客服消息对象
|
|
197
|
+
async function genMsg(type, msgType, payload) {
|
|
198
|
+
// todo 检查入参格式
|
|
199
|
+
const payloadKey =
|
|
200
|
+
msgType.slice(0, 1).toUpperCase() + msgType.slice(1).toLowerCase();
|
|
201
|
+
|
|
202
|
+
const id = await UUIDGenerator.getRandomUUID();
|
|
203
|
+
|
|
204
|
+
const baseMsg = {
|
|
205
|
+
MsgType: msgType,
|
|
206
|
+
[payloadKey]: payload,
|
|
207
|
+
MsgId: id.replace(/-/g, ''),
|
|
208
|
+
};
|
|
209
|
+
const activeAddr = await storage.get('activeAddr');
|
|
210
|
+
const accountData = await storage.get('accountData');
|
|
211
|
+
|
|
212
|
+
if (type === 'send') {
|
|
213
|
+
// 当前用户发出
|
|
214
|
+
baseMsg.FromUserId = accountData.user.user_id;
|
|
215
|
+
baseMsg.FromAddrId = activeAddr.address_id;
|
|
216
|
+
baseMsg.ToUserId = 'client';
|
|
217
|
+
baseMsg.ToAddrId = activeAddr.address_id;
|
|
218
|
+
} else if (type === 'get') {
|
|
219
|
+
// 当前用户收到
|
|
220
|
+
baseMsg.FromUserId = 'client';
|
|
221
|
+
baseMsg.FromAddrId = activeAddr.address_id;
|
|
222
|
+
baseMsg.ToUserId = accountData.user.user_id;
|
|
223
|
+
baseMsg.ToAddrId = activeAddr.address_id;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return baseMsg;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function preZero(num, digit = 2) {
|
|
230
|
+
num = num.toString();
|
|
231
|
+
while (num.length < digit) {
|
|
232
|
+
num = '0' + num;
|
|
233
|
+
}
|
|
234
|
+
return num;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function isDef(val) {
|
|
238
|
+
return typeof val !== 'undefined';
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// 商城客服消息对象
|
|
242
|
+
async function shopGenMsg(
|
|
243
|
+
type,
|
|
244
|
+
message_prop,
|
|
245
|
+
inputText,
|
|
246
|
+
seq_id,
|
|
247
|
+
recver_id,
|
|
248
|
+
conversation_id = 'ipanel',
|
|
249
|
+
) {
|
|
250
|
+
// todo 检查入参格式
|
|
251
|
+
const accountData = await storage.get('accountData');
|
|
252
|
+
if (type === 1000) {
|
|
253
|
+
// 发消息
|
|
254
|
+
const client_msg_id = generate_uuid();
|
|
255
|
+
let params = {
|
|
256
|
+
client_msg_id: client_msg_id,
|
|
257
|
+
server_msg_id: 0,
|
|
258
|
+
conversation_id, // 会话
|
|
259
|
+
sender_id: accountData?.user?.user_id, // 802eed8f01b14c1d90a9112787ddaf49
|
|
260
|
+
recver_id, // 接收消息的人
|
|
261
|
+
nick_name: accountData?.user?.nickname, // 发送方 zhanghaoyy
|
|
262
|
+
face_url: accountData?.user?.icon_url
|
|
263
|
+
? `${ACCOUNT_SERVICE}/icon?file=${
|
|
264
|
+
accountData?.user?.icon_url
|
|
265
|
+
}&time=${new Date().getTime()}`
|
|
266
|
+
: '',
|
|
267
|
+
message_prop: message_prop,
|
|
268
|
+
message_data: inputText,
|
|
269
|
+
};
|
|
270
|
+
let proto = {
|
|
271
|
+
id: seq_id,
|
|
272
|
+
type: 1000, // 1000 request 2000 response
|
|
273
|
+
ecode: 0,
|
|
274
|
+
emessage: '',
|
|
275
|
+
route: 'message_post',
|
|
276
|
+
data: JSON.stringify(params),
|
|
277
|
+
};
|
|
278
|
+
return proto;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// 协议
|
|
283
|
+
const generate_uuid = () => {
|
|
284
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
|
285
|
+
var r = (Math.random() * 16) | 0,
|
|
286
|
+
v = c === 'x' ? r : (r & 0x3) | 0x8;
|
|
287
|
+
return v.toString(16);
|
|
288
|
+
});
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
// APP大数据上报:https://git.ipanel.cn/1/wdoc/?p=YjM4MmY1MW.2【iPanelCloud后台管理工作组/ipanel_collect_report_data_doc】
|
|
292
|
+
async function appReport(tag, extraData = {}) {
|
|
293
|
+
const token = await storage.get('accessToken');
|
|
294
|
+
if (!token) {
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
const appID = await global.base.getAppId();
|
|
298
|
+
if (!appID) {
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
const accountData = await storage.get('accountData');
|
|
303
|
+
|
|
304
|
+
const data = {
|
|
305
|
+
upTime: Date.now(),
|
|
306
|
+
deviceId: appID,
|
|
307
|
+
userId: accountData?.user?.user_id,
|
|
308
|
+
accountId: accountData?.account?.account_id,
|
|
309
|
+
appTermType:
|
|
310
|
+
Platform.OS === 'ios'
|
|
311
|
+
? 2020 // IOS设备应用
|
|
312
|
+
: Platform.OS === 'android'
|
|
313
|
+
? 2010 // Android设备应用
|
|
314
|
+
: 2000, // 无法确定Android还是IOS,报2000
|
|
315
|
+
...extraData,
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
const res = await reportBigData(tag, appID, data).catch(err => {
|
|
319
|
+
console.log('reportBigData', err);
|
|
320
|
+
});
|
|
321
|
+
console.log('reportBigData', tag, res);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
const checkToken = async () => {
|
|
325
|
+
const access_token = await storage.get('accessToken');
|
|
326
|
+
const refresh_token = await storage.get('refreshToken');
|
|
327
|
+
|
|
328
|
+
const logout = () => {
|
|
329
|
+
Alert.alert('登录过期,请重新登录!', '', [
|
|
330
|
+
{
|
|
331
|
+
text: '好',
|
|
332
|
+
onPress: async () => {
|
|
333
|
+
await storage.set('accessToken', null);
|
|
334
|
+
await storage.set('refreshToken', null);
|
|
335
|
+
await storage.set('homedAccessToken', null);
|
|
336
|
+
replace('Login');
|
|
337
|
+
},
|
|
338
|
+
},
|
|
339
|
+
]);
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
return new Promise(async resolve => {
|
|
343
|
+
try {
|
|
344
|
+
const accountType = await storage.get('accountType');
|
|
345
|
+
const res = await refreshToken(
|
|
346
|
+
{
|
|
347
|
+
access_token,
|
|
348
|
+
refresh_token,
|
|
349
|
+
},
|
|
350
|
+
accountType,
|
|
351
|
+
);
|
|
352
|
+
if (res.code === 0) {
|
|
353
|
+
console.log('刷新token', res);
|
|
354
|
+
await storage.set('accessToken', res.result.access_token);
|
|
355
|
+
await storage.set('refreshToken', res.result.refresh_token);
|
|
356
|
+
resolve(true);
|
|
357
|
+
} else {
|
|
358
|
+
resolve(false);
|
|
359
|
+
logout();
|
|
360
|
+
}
|
|
361
|
+
} catch (e) {
|
|
362
|
+
resolve(false);
|
|
363
|
+
logout();
|
|
364
|
+
}
|
|
365
|
+
});
|
|
366
|
+
};
|
|
367
|
+
|
|
368
|
+
export {
|
|
369
|
+
updateHomedToken,
|
|
370
|
+
initOperatorHomedTouristAccount,
|
|
371
|
+
getUserLocation,
|
|
372
|
+
MSG_TYPES,
|
|
373
|
+
MSG_EVENT_TYPES,
|
|
374
|
+
genMsg,
|
|
375
|
+
preZero,
|
|
376
|
+
isDef,
|
|
377
|
+
shopGenMsg,
|
|
378
|
+
appReport,
|
|
379
|
+
checkToken,
|
|
380
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import {NativeModules} from 'react-native';
|
|
2
|
+
|
|
3
|
+
// dev/alpha/release
|
|
4
|
+
const envVersion = NativeModules?.RNToNativeEmitter?.serverCluster || 'alpha';
|
|
5
|
+
// NativeModules?.RNToNativeEmitter?.serverCluster || 'dev'; /*本地测试*/
|
|
6
|
+
// `ipanelcloud`域名(因APP是`开发版`、`测试版`或`正式版`而不同)
|
|
7
|
+
|
|
8
|
+
const appName = NativeModules?.RNToNativeEmitter?.appName;
|
|
9
|
+
|
|
10
|
+
console.log('当前app名称', appName);
|
|
11
|
+
|
|
12
|
+
let IPANEL_CLOUD_DOMAIN;
|
|
13
|
+
if (appName === '禺乐慧家') {
|
|
14
|
+
IPANEL_CLOUD_DOMAIN = 'szjtyfw.panyu.gd.cn';
|
|
15
|
+
} else {
|
|
16
|
+
switch (envVersion) {
|
|
17
|
+
case 'release':
|
|
18
|
+
IPANEL_CLOUD_DOMAIN = 'ipanelcloud.ipanel.cn'; // 正式集群
|
|
19
|
+
break;
|
|
20
|
+
case 'dev':
|
|
21
|
+
IPANEL_CLOUD_DOMAIN = 'dev.ipanelcloud2.ipanel.cn'; // 开发集群
|
|
22
|
+
break;
|
|
23
|
+
default: // alpha
|
|
24
|
+
IPANEL_CLOUD_DOMAIN = 'ipanelcloud2.ipanel.cn'; // 测试集群
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const config = {
|
|
30
|
+
IPANEL_CLOUD_DOMAIN,
|
|
31
|
+
IPANEL_CLOUD_BASE_URI: `https://${IPANEL_CLOUD_DOMAIN}:50443`,
|
|
32
|
+
IPANEL_CLOUD_WSS_URI: `wss://${IPANEL_CLOUD_DOMAIN}:50443`,
|
|
33
|
+
IPANEL_CLOUD_BASE_ADG_URI:
|
|
34
|
+
envVersion === 'dev'
|
|
35
|
+
? `http://${IPANEL_CLOUD_DOMAIN}:50080`
|
|
36
|
+
: `https://${IPANEL_CLOUD_DOMAIN}:50443`,
|
|
37
|
+
// 禺乐慧家模块版本相关api跟着公司alpha走
|
|
38
|
+
PANYU_MODULE_VERSION_URI: 'https://ipanelcloud2.ipanel.cn:50443',
|
|
39
|
+
|
|
40
|
+
// 模拟配置本地测试用的app版本号,用于模拟执行一些依赖app版本的逻辑
|
|
41
|
+
LOCALTEST_APP_VERSION: '9.9.9',
|
|
42
|
+
|
|
43
|
+
// 模拟配置本地测试用的appName,用于模拟加载不同APP的模块,当前支持"爱家宝"、"安电工"
|
|
44
|
+
LOCALTEST_APP_NAME: '禺乐慧家',
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export default config;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
CONTENTTYPE_LIST: [
|
|
3
|
+
{
|
|
4
|
+
id: 1100,
|
|
5
|
+
name: '电视剧',
|
|
6
|
+
},
|
|
7
|
+
{
|
|
8
|
+
id: 1105,
|
|
9
|
+
name: '动漫',
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
id: 1106,
|
|
13
|
+
name: '纪录片',
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
id: 1107,
|
|
17
|
+
name: '教育',
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
id: 1108,
|
|
21
|
+
name: '体育',
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
id: 1109,
|
|
25
|
+
name: '生活',
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
id: 1110,
|
|
29
|
+
name: '游戏',
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
id: 1111,
|
|
33
|
+
name: '广告',
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
id: 1112,
|
|
37
|
+
name: '明显百科',
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
id: 1113,
|
|
41
|
+
name: '应用',
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
id: 1114,
|
|
45
|
+
name: '少儿',
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
id: 1200,
|
|
49
|
+
name: '电商',
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
id: 1300,
|
|
53
|
+
name: '手机直播',
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
AREA: ['内地', '中国香港', '韩国', '美国', '泰国'],
|
|
57
|
+
};
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import storage from '../storage';
|
|
2
|
+
|
|
3
|
+
// 业务自己处理的错误码
|
|
4
|
+
const selfHandleErrCodes = [20511, 20512];
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @param {*} options
|
|
8
|
+
* options.url
|
|
9
|
+
* options.method
|
|
10
|
+
* options.data
|
|
11
|
+
* options.headers
|
|
12
|
+
*/
|
|
13
|
+
async function http(options) {
|
|
14
|
+
let url = options.url;
|
|
15
|
+
const method = options.method.toLowerCase();
|
|
16
|
+
|
|
17
|
+
const config = {
|
|
18
|
+
method: options.method,
|
|
19
|
+
headers: options.headers || {
|
|
20
|
+
// 'Content-Type': 'application/x-www-form-urlencoded'
|
|
21
|
+
'Content-Type': 'application/json',
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
// 设置超时
|
|
26
|
+
if (options.timeout) {
|
|
27
|
+
const controller = new AbortController();
|
|
28
|
+
config.signal = controller.signal;
|
|
29
|
+
setTimeout(() => {
|
|
30
|
+
controller.abort();
|
|
31
|
+
}, options.timeout); // 设置超时时间为5秒
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const TOKEN = await storage.get('accessToken');
|
|
35
|
+
const apartmentToken = await storage.get('apartmentToken');
|
|
36
|
+
const apartmentData = await storage.get('apartmentData');
|
|
37
|
+
|
|
38
|
+
if (method === 'post') {
|
|
39
|
+
if (options.data instanceof FormData || typeof options.data !== 'object') {
|
|
40
|
+
config.body = options.data;
|
|
41
|
+
if (TOKEN) {
|
|
42
|
+
if (url.includes('?')) {
|
|
43
|
+
url += `&access_token=${TOKEN}`;
|
|
44
|
+
} else {
|
|
45
|
+
url += `?access_token=${TOKEN}`;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
} else {
|
|
49
|
+
const data = {...options.data};
|
|
50
|
+
if (TOKEN) {
|
|
51
|
+
data.access_token = TOKEN;
|
|
52
|
+
}
|
|
53
|
+
config.body = JSON.stringify(data);
|
|
54
|
+
}
|
|
55
|
+
} else if (method === 'get') {
|
|
56
|
+
let query = [];
|
|
57
|
+
const data = {...options.data};
|
|
58
|
+
if (url.includes('smartapartment/switch_token')) {
|
|
59
|
+
// config.headers.Authorization =
|
|
60
|
+
// 'Bearer eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6IjAyMDM1NzBkLWRkNzUtNDI5My1iNTZkLTQ1MTlmMjc1ZWJkNiJ9.NU4KR98Ddltz-Wib4J7AIilVxy7EmbCG8P5EPskSGXWcNyim63nTMyDfhKqvQPqzAajNRxghrs2jeG-f3VcbGw';
|
|
61
|
+
data.token = TOKEN;
|
|
62
|
+
} else if (TOKEN) {
|
|
63
|
+
data.access_token = TOKEN;
|
|
64
|
+
}
|
|
65
|
+
Object.keys(data).forEach(key => {
|
|
66
|
+
query.push(`${key}=${data[key]}`);
|
|
67
|
+
});
|
|
68
|
+
if (query.length > 0) {
|
|
69
|
+
url = `${url}?${query.join('&')}`;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (
|
|
73
|
+
url.includes('/smartapartment/proxy') &&
|
|
74
|
+
apartmentToken &&
|
|
75
|
+
apartmentData &&
|
|
76
|
+
apartmentData.role
|
|
77
|
+
) {
|
|
78
|
+
config.headers.Authorization = `Bearer ${apartmentToken}`;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
console.log(url, config);
|
|
82
|
+
|
|
83
|
+
return fetch(url, config)
|
|
84
|
+
.then(response => {
|
|
85
|
+
console.log(response, 'url');
|
|
86
|
+
return response.json();
|
|
87
|
+
})
|
|
88
|
+
.then(json => {
|
|
89
|
+
if (
|
|
90
|
+
typeof json.error_code !== 'undefined' &&
|
|
91
|
+
typeof json.code === 'undefined'
|
|
92
|
+
) {
|
|
93
|
+
json.code = json.error_code;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (typeof json.code !== 'undefined') {
|
|
97
|
+
if (json.code !== 0 && !selfHandleErrCodes.includes(json.code)) {
|
|
98
|
+
// global.toast.showToast(
|
|
99
|
+
// errCodes[json.code] ||
|
|
100
|
+
// `${json.message || '请求失败'}(code:${json.code})`,
|
|
101
|
+
// );
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return json;
|
|
106
|
+
})
|
|
107
|
+
.catch(err => {
|
|
108
|
+
console.log(err);
|
|
109
|
+
throw err;
|
|
110
|
+
// Alert.alert('服务繁忙,请稍候重试');
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export const homedHttp = async options => {
|
|
115
|
+
let url = options.url;
|
|
116
|
+
const method = options.method.toLowerCase();
|
|
117
|
+
|
|
118
|
+
const config = {
|
|
119
|
+
method: options.method,
|
|
120
|
+
headers: options.headers || {
|
|
121
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
//! 注意:APP内获取homed数据时优先取homed正式用户token(即homedAccessToken),
|
|
126
|
+
//! 当homedAccessToken取不到时,才取homedTouristAccessToken(游客token);
|
|
127
|
+
//! homedAccessToken不为空时,表示当前登录的ipanelcloud用户已绑定电视业务(某个homed用户),
|
|
128
|
+
//! 如果homedAccessToken为空时,则表示未绑定电视业务
|
|
129
|
+
const TOKEN = await global.base.getHomedToken();
|
|
130
|
+
|
|
131
|
+
if (method === 'post') {
|
|
132
|
+
if (options.data instanceof FormData || typeof options.data !== 'object') {
|
|
133
|
+
config.body = options.data;
|
|
134
|
+
if (TOKEN) {
|
|
135
|
+
if (url.includes('?')) {
|
|
136
|
+
url += `&access_token=${TOKEN}`;
|
|
137
|
+
} else {
|
|
138
|
+
url += `?access_token=${TOKEN}`;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
} else {
|
|
142
|
+
const data = {...options.data};
|
|
143
|
+
if (TOKEN) {
|
|
144
|
+
data.accesstoken = TOKEN;
|
|
145
|
+
}
|
|
146
|
+
config.body = JSON.stringify(data);
|
|
147
|
+
}
|
|
148
|
+
} else if (method === 'get') {
|
|
149
|
+
let query = [];
|
|
150
|
+
const data = {...options.data};
|
|
151
|
+
if (TOKEN) {
|
|
152
|
+
data.accesstoken = TOKEN;
|
|
153
|
+
}
|
|
154
|
+
Object.keys(data).forEach(key => {
|
|
155
|
+
query.push(`${key}=${data[key]}`);
|
|
156
|
+
});
|
|
157
|
+
if (query.length > 0) {
|
|
158
|
+
url = `${url}?${query.join('&')}`;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
console.log(url, config);
|
|
163
|
+
|
|
164
|
+
return fetch(url, config)
|
|
165
|
+
.then(response => {
|
|
166
|
+
return response.json();
|
|
167
|
+
})
|
|
168
|
+
.then(json => {
|
|
169
|
+
return json;
|
|
170
|
+
})
|
|
171
|
+
.catch(err => {
|
|
172
|
+
console.log(err);
|
|
173
|
+
// Alert.alert('服务繁忙,请稍候重试');
|
|
174
|
+
return Promise.reject(err);
|
|
175
|
+
});
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
export default http;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export const showLoading = (...args) => {
|
|
2
|
+
global.loading?.showLoading(...args);
|
|
3
|
+
};
|
|
4
|
+
|
|
5
|
+
export const hideLoading = (...args) => {
|
|
6
|
+
global.loading?.hideLoading(...args);
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
*
|
|
11
|
+
* @param args (message:sting) || ({message?: string, duration?: number, forbidClick?: boolean})
|
|
12
|
+
*/
|
|
13
|
+
export const showToast = (...args) => {
|
|
14
|
+
global.toast?.showToast(...args);
|
|
15
|
+
};
|