ipanel-rnapp-ajb-base 1.0.12 → 1.0.14

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.
@@ -50,5 +50,6 @@ export const EVENTS = {
50
50
  RECONNECT: 'shop.message.reconnect', // 触发websocket重连事件
51
51
  ONLINE_LIST: 'shop.message.online', // 商城在线用户
52
52
  CUSTOM_SERVICE_CONNECT_CHANGE: 'shop.message.customServiceConnectChange', // 智能客服转人工的进入和退出事件
53
+ HISTORY_MESSAGE_LIST: 'shop.message.history', // 获取历史消息
53
54
  },
54
55
  };
@@ -12,23 +12,27 @@ let connectStatus = -1; // -1 连接中 0 连接成功 1连接失败
12
12
  let tryConnectTimes = 0;
13
13
  let seq_id = 0;
14
14
 
15
+ // let customer_id = ''; // imchat的user_uid
16
+
17
+ // const ishopcs = 'http://192.168.36.241:9101';
18
+
15
19
  /**
16
20
  * 商城客服中心JS
17
21
  */
18
22
 
19
23
  // 消息记录
20
- storage.get('shopMessageList').then(msgList => {
21
- if (typeof msgList === 'string') {
22
- try {
23
- msgList = JSON.parse(msgList);
24
- } catch (e) {
25
- console.log('msgList error', e, msgList);
26
- msgList = [];
27
- }
28
- }
29
- // console.log(msgList, '商城客服消息列表msgList');
30
- global.base.shopMessageManager.messages = msgList || [];
31
- });
24
+ // storage.get('shopMessageList').then(msgList => {
25
+ // if (typeof msgList === 'string') {
26
+ // try {
27
+ // msgList = JSON.parse(msgList);
28
+ // } catch (e) {
29
+ // console.log('msgList error', e, msgList);
30
+ // msgList = [];
31
+ // }
32
+ // }
33
+ // // console.log(msgList, '商城客服消息列表msgList');
34
+ // global.base.shopMessageManager.messages = msgList || [];
35
+ // });
32
36
 
33
37
  // 当前是否处于智能客服转人工
34
38
  // let isManualCustomServiceActive = false;
@@ -60,6 +64,27 @@ const ShopMessageManager = () => {
60
64
  }
61
65
  }, []);
62
66
 
67
+ // 获取im本人user_id
68
+ const getUserUid = () => {
69
+ let proto = {
70
+ id: seq_id,
71
+ type: 1000, // 1000 request 2000 response
72
+ ecode: 0,
73
+ emessage: '',
74
+ route: 'user_uid',
75
+ data: '',
76
+ };
77
+ sendShopImMessage(proto);
78
+ };
79
+
80
+ // 发送im消息,传参直接发
81
+ const sendShopImMessage = useCallback(params => {
82
+ console.log('发送im消息,传参直接发');
83
+ if (ws.current) {
84
+ ws.current.send(JSON.stringify(params));
85
+ }
86
+ }, []);
87
+
63
88
  // 发送消息
64
89
  const sendMessage = useCallback(msg => {
65
90
  if (ws.current) {
@@ -82,7 +107,7 @@ const ShopMessageManager = () => {
82
107
  `user_id=${accountData?.user?.user_id}`,
83
108
  'platform=web',
84
109
  'api=ipanel_test',
85
- `source=${'dev.ipanelcloud2.ipanel.cn' || config.IPANEL_CLOUD_DOMAIN}`,
110
+ `source=${config.IPANEL_CLOUD_DOMAIN}`,
86
111
  ];
87
112
 
88
113
  // 缓存全局商城客服websocket连接
@@ -96,9 +121,11 @@ const ShopMessageManager = () => {
96
121
  connectCallback && connectCallback(null); // success
97
122
  connectStatus = 0;
98
123
  eventBus.emit(EVENTS.SHOPMESSAGE.CONNECT_STATUS_CHANGE, connectStatus);
124
+ getUserUid();
99
125
  };
100
126
  ws.current.onmessage = ({data}) => {
101
127
  const msgData = JSON.parse(data);
128
+ console.log('msgDatamessage', msgData);
102
129
  // 2000是接收自己发的消息
103
130
  if (msgData.type === 1000) {
104
131
  const msg = JSON.parse(msgData?.data);
@@ -112,6 +139,26 @@ const ShopMessageManager = () => {
112
139
  // 获取在线用户
113
140
  const msg = JSON.parse(msgData?.data);
114
141
  eventBus.emit(EVENTS.SHOPMESSAGE.ONLINE_LIST, msg);
142
+ } else if (msgData.type === 2000 && msgData.route === 'user_uid') {
143
+ // 获取user_id
144
+ // customer_id = msgData?.data;
145
+ if (msgData?.data) {
146
+ storage.set('shopImData', {
147
+ customer_id: msgData?.data,
148
+ });
149
+ }
150
+ } else if (
151
+ msgData.type === 2000 &&
152
+ (msgData.route === 'message_list_history' ||
153
+ msgData.route === 'message_list_new')
154
+ ) {
155
+ if (msgData?.data) {
156
+ const msgList = JSON.parse(msgData?.data);
157
+ global.base.shopMessageManager.messages =
158
+ msgList?.list || msgList || [];
159
+ let list = msgList?.list || msgList || [];
160
+ eventBus.emit(EVENTS.SHOPMESSAGE.HISTORY_MESSAGE_LIST, list);
161
+ }
115
162
  }
116
163
  };
117
164
  ws.current.onerror = err => {
@@ -216,13 +263,13 @@ const ShopMessageManager = () => {
216
263
  msg.CreateTime = new Date().getTime();
217
264
  console.log(msg, '商城客服msg');
218
265
  // console.log(global.base.shopMessageManager.messages, '22');
219
- global.base.shopMessageManager.messages.push(msg);
266
+ // global.base.shopMessageManager.messages.push(msg);
220
267
 
221
268
  // // save to local 存到本地
222
- storage.set(
223
- 'shopMessageList',
224
- global.base.shopMessageManager.messages.slice(-100),
225
- );
269
+ // storage.set(
270
+ // 'shopMessageList',
271
+ // global.base.shopMessageManager.messages.slice(-100),
272
+ // );
226
273
  // storage.remove('shopMessageList');
227
274
 
228
275
  eventBus.emit(EVENTS.SHOPMESSAGE.RENDER, msg);
@@ -293,6 +340,7 @@ const ShopMessageManager = () => {
293
340
 
294
341
  return {
295
342
  sendMessage,
343
+ sendShopImMessage,
296
344
  getOnlineUser,
297
345
  // requestShopManualCustomService,
298
346
  // exitShopManualCustomService,
@@ -167,7 +167,9 @@ function HomeTabScreen({navigation, route}) {
167
167
  });
168
168
  } else {
169
169
  // 单业务包开发调试环境
170
- const component = await global.base.getRemoteComponentByName('__BASE_SINGLETON_MODE_APP__');
170
+ const component = await global.base.getRemoteComponentByName(
171
+ '__BASE_SINGLETON_MODE_APP__',
172
+ );
171
173
  typeof component?.registerStackScreens === 'function' &&
172
174
  component.registerStackScreens();
173
175
  tabs = [
@@ -293,11 +295,16 @@ function HomeTabScreen({navigation, route}) {
293
295
  getManualCustomServiceActiveFlag;
294
296
 
295
297
  // 商城客服
296
- const {handleShopTextSubmit, handleShopMediaSelect, getOnlineUser} =
297
- ShopMessageManager();
298
+ const {
299
+ handleShopTextSubmit,
300
+ handleShopMediaSelect,
301
+ getOnlineUser,
302
+ sendShopImMessage,
303
+ } = ShopMessageManager();
298
304
  global.base.shopMessageManager.handleShopTextSubmit = handleShopTextSubmit;
299
305
  global.base.shopMessageManager.handleShopMediaSelect = handleShopMediaSelect;
300
306
  global.base.shopMessageManager.getOnlineUser = getOnlineUser;
307
+ global.base.shopMessageManager.sendShopImMessage = sendShopImMessage;
301
308
  const renderCustomTabBar = props => {
302
309
  return <CustomTabBar {...props} />;
303
310
  };
@@ -95,7 +95,35 @@ export default class ScanQRCode extends Component {
95
95
  //扫码后的操作
96
96
  if (data) {
97
97
  const routes = getState().routes;
98
- if (routes[routes.length - 2]) {
98
+ if (data.includes('action=redirect')) {
99
+ /**
100
+ * action=redirect 重定向APP页面
101
+ mop=ipanel operatorId(模块运营商,未来有可能废弃)
102
+ m=shop 商城模块
103
+ s=detail screenName
104
+ a/b/c 传给商城模块的参数
105
+ */
106
+ const querys = data.substring(data.indexOf('?') + 1).split('&');
107
+ const params = {};
108
+ for (let i = 0; i < querys.length; i++) {
109
+ const temp = querys[i].split('=');
110
+ if (temp.length < 2) {
111
+ params[temp[0]] = '';
112
+ } else {
113
+ params[temp[0]] = temp[1];
114
+ }
115
+ }
116
+ if (params.s) {
117
+ navigate({
118
+ name: params.s,
119
+ params,
120
+ merge: true,
121
+ });
122
+ this.setState({
123
+ scanDone: true,
124
+ });
125
+ }
126
+ } else if (routes[routes.length - 2]) {
99
127
  navigate({
100
128
  name: sourceRouteName || routes[routes.length - 2].name,
101
129
  params: {
@@ -148,7 +176,35 @@ export default class ScanQRCode extends Component {
148
176
  //扫码后的操作
149
177
  if (data) {
150
178
  const routes = getState().routes;
151
- if (routes[routes.length - 2]) {
179
+ if (data.includes('action=redirect')) {
180
+ /**
181
+ * action=redirect 重定向APP页面
182
+ mop=ipanel operatorId(模块运营商,未来有可能废弃)
183
+ m=shop 商城模块
184
+ s=detail screenName
185
+ a/b/c 传给商城模块的参数
186
+ */
187
+ const querys = data.substring(data.indexOf('?') + 1).split('&');
188
+ const params = {};
189
+ for (let i = 0; i < querys.length; i++) {
190
+ const temp = querys[i].split('=');
191
+ if (temp.length < 2) {
192
+ params[temp[0]] = '';
193
+ } else {
194
+ params[temp[0]] = temp[1];
195
+ }
196
+ }
197
+ if (params.s) {
198
+ navigate({
199
+ name: params.s,
200
+ params,
201
+ merge: true,
202
+ });
203
+ this.setState({
204
+ scanDone: true,
205
+ });
206
+ }
207
+ } else if (routes[routes.length - 2]) {
152
208
  navigate({
153
209
  name: sourceRouteName || routes[routes.length - 2].name,
154
210
  params: {
@@ -262,7 +318,7 @@ export default class ScanQRCode extends Component {
262
318
  }}
263
319
  resizeMode="contain"
264
320
  />
265
-
321
+
266
322
  <Text style={styles.albumText}>相册</Text>
267
323
  </TouchableOpacity>
268
324
  </View>
@@ -6,6 +6,7 @@ import {
6
6
  Text,
7
7
  NativeModules,
8
8
  FlatList,
9
+ Platform,
9
10
  } from 'react-native';
10
11
  import {Divider} from '@rneui/themed';
11
12
  const {px} = global.base;
@@ -29,7 +30,11 @@ export default ({setVisible}) => {
29
30
  global.toast.showToast('设置成功');
30
31
  setVisible(false);
31
32
  } else {
32
- if (res === 1) {
33
+ // ios 值为1或者2为在线日志,安卓值为1为在线日志
34
+ if (
35
+ (Platform.OS === 'ios' && (res === 1 || res === 2)) ||
36
+ res === 1
37
+ ) {
33
38
  onOpen(1);
34
39
  } else {
35
40
  onOpen(2);
@@ -256,7 +256,6 @@ async function shopGenMsg(
256
256
  client_msg_id: client_msg_id,
257
257
  server_msg_id: 0,
258
258
  conversation_id, // 会话
259
- sender_id: accountData?.user?.user_id, // 802eed8f01b14c1d90a9112787ddaf49
260
259
  recver_id, // 接收消息的人
261
260
  nick_name: accountData?.user?.nickname, // 发送方 zhanghaoyy
262
261
  face_url: accountData?.user?.icon_url
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ipanel-rnapp-ajb-base",
3
- "version": "1.0.12",
4
- "ipanelVersion": "1.0.300",
3
+ "version": "1.0.14",
4
+ "ipanelVersion": "1.0.308",
5
5
  "description": "",
6
6
  "main": "index.js",
7
7
  "bin": {