@@ -86,25 +86,27 @@ function loginSuccess(dispatch, getState) {
86
86
} , 0 ) ;
87
87
}
88
88
89
- export const login = function ( username : string , password : string ) : TRPGAction {
90
- return function ( dispatch , getState ) {
89
+ export const login = function ( username : string , password : string ) : TRPGAction {
90
+ return function ( dispatch , getState ) {
91
91
password = md5 ( password ) ;
92
92
const isApp = config . platform === 'app' ;
93
93
dispatch ( { type : LOGIN_REQUEST } ) ;
94
94
return api . emit (
95
95
'player::login' ,
96
96
{ username, password, platform : config . platform , isApp } ,
97
- function ( data ) {
97
+ function ( data ) {
98
98
dispatch ( hideLoading ( ) ) ;
99
99
100
100
if ( data . result ) {
101
101
// 登录成功
102
102
const { uuid, token, app_token } = data . info ;
103
103
if ( isApp ) {
104
104
// 如果是app的话,则永久储存
105
- rnStorage . save ( { uuid, token : app_token } ) ;
105
+ rnStorage . save ( 'uuid' , uuid ) ;
106
+ rnStorage . save ( 'token' , app_token ) ;
106
107
} else {
107
- rnStorage . set ( { uuid, token } ) ;
108
+ rnStorage . set ( 'uuid' , uuid ) ;
109
+ rnStorage . set ( 'token' , token ) ;
108
110
}
109
111
console . log ( 'set user token, user:' , uuid ) ;
110
112
data . info . avatar = config . file . getAbsolutePath ! ( data . info . avatar ) ;
@@ -127,18 +129,18 @@ export const login = function(username: string, password: string): TRPGAction {
127
129
} ;
128
130
} ;
129
131
130
- export const loginWithToken = function (
132
+ export const loginWithToken = function (
131
133
uuid : string ,
132
134
token : string ,
133
135
channel : any = null
134
136
) : TRPGAction {
135
- return function ( dispatch , getState ) {
137
+ return function ( dispatch , getState ) {
136
138
const isApp = config . platform === 'app' ;
137
139
dispatch ( { type : LOGIN_REQUEST } ) ;
138
140
return api . emit (
139
141
'player::loginWithToken' ,
140
142
{ uuid, token, platform : config . platform , isApp, channel } ,
141
- function ( data ) {
143
+ function ( data ) {
142
144
if ( data . result ) {
143
145
data . info . avatar = config . file . getAbsolutePath ! ( data . info . avatar ) ;
144
146
dispatch ( { type : LOGIN_TOKEN_SUCCESS , payload : data . info , isApp } ) ;
@@ -164,23 +166,23 @@ export const loginWithToken = function(
164
166
} ;
165
167
166
168
// 重新获取一次用户登录后的数据
167
- export const updateAllInfo = function ( ) : TRPGAction {
168
- return function ( dispatch , getState ) {
169
+ export const updateAllInfo = function ( ) : TRPGAction {
170
+ return function ( dispatch , getState ) {
169
171
if ( getState ( ) . user . isLogin === true ) {
170
172
loginSuccess ( dispatch , getState ) ;
171
173
}
172
174
} ;
173
175
} ;
174
176
175
- export const logout = function ( ) : TRPGAction {
177
+ export const logout = function ( ) : TRPGAction {
176
178
const isApp = config . platform === 'app' ;
177
- return function ( dispatch , getState ) {
179
+ return function ( dispatch , getState ) {
178
180
const info = getState ( ) . user . info ;
179
181
const uuid = info . uuid ;
180
182
const token = isApp ? info . app_token : info . token ;
181
183
dispatch ( showLoading ( ) ) ;
182
184
dispatch ( { type : LOGOUT } ) ;
183
- api . emit ( 'player::logout' , { uuid, token, isApp } , function ( data ) {
185
+ api . emit ( 'player::logout' , { uuid, token, isApp } , function ( data ) {
184
186
dispatch ( hideLoading ( ) ) ;
185
187
if ( data . result ) {
186
188
rnStorage . remove ( 'uuid' ) ;
@@ -196,15 +198,17 @@ export const logout = function(): TRPGAction {
196
198
} ;
197
199
} ;
198
200
199
- export const register = function (
201
+ export const register = function (
200
202
username : string ,
201
203
password : string ,
202
204
onSuccess : ( ) => void
203
205
) : TRPGAction {
204
206
password = md5 ( password ) ;
205
- return function ( dispatch , getState ) {
207
+ return function ( dispatch , getState ) {
206
208
dispatch ( { type : REGISTER_REQUEST } ) ;
207
- return api . emit ( 'player::register' , { username, password } , function ( data ) {
209
+ return api . emit ( 'player::register' , { username, password } , function (
210
+ data
211
+ ) {
208
212
dispatch ( hideLoading ( ) ) ;
209
213
console . log ( data ) ;
210
214
if ( data . result ) {
@@ -227,8 +231,8 @@ export const register = function(
227
231
/**
228
232
* 获取用于web鉴权的jwt
229
233
*/
230
- export const fetchWebToken = function ( ) : TRPGAction {
231
- return function ( dispatch , getState ) {
234
+ export const fetchWebToken = function ( ) : TRPGAction {
235
+ return function ( dispatch , getState ) {
232
236
return api . emit ( 'player::getWebToken' , null , ( data ) => {
233
237
const token = data . jwt ?? null ;
234
238
if ( _isNil ( token ) ) {
@@ -250,7 +254,7 @@ export const fetchWebToken = function(): TRPGAction {
250
254
*/
251
255
function getUserInitData ( ) : TRPGAction {
252
256
return ( dispatch , getState ) => {
253
- return api . emit ( 'player::getUserInitData' , { } , function ( data ) {
257
+ return api . emit ( 'player::getUserInitData' , { } , function ( data ) {
254
258
if ( ! data . result ) {
255
259
console . error ( data . msg ) ;
256
260
return ;
@@ -293,12 +297,12 @@ function getUserInitData(): TRPGAction {
293
297
} ;
294
298
}
295
299
296
- export const findUser = function ( text : string , type : string ) : TRPGAction {
297
- return function ( dispatch , getState ) {
300
+ export const findUser = function ( text : string , type : string ) : TRPGAction {
301
+ return function ( dispatch , getState ) {
298
302
dispatch ( { type : FIND_USER_REQUEST } ) ;
299
303
300
304
console . log ( { text, type } ) ;
301
- return api . emit ( 'player::findUser' , { text, type } , function ( data ) {
305
+ return api . emit ( 'player::findUser' , { text, type } , function ( data ) {
302
306
console . log ( 'findUser' , data ) ;
303
307
if ( data . result ) {
304
308
const list = data . results ;
@@ -319,12 +323,12 @@ export const findUser = function(text: string, type: string): TRPGAction {
319
323
} ;
320
324
} ;
321
325
322
- export const updateInfo = function (
326
+ export const updateInfo = function (
323
327
updatedData : { } ,
324
328
onSuccess ?: ( ) => void
325
329
) : TRPGAction {
326
- return function ( dispatch , getState ) {
327
- return api . emit ( 'player::updateInfo' , updatedData , function ( data ) {
330
+ return function ( dispatch , getState ) {
331
+ return api . emit ( 'player::updateInfo' , updatedData , function ( data ) {
328
332
if ( data . result ) {
329
333
data . user . avatar = config . file . getAbsolutePath ! ( data . user . avatar ) ;
330
334
dispatch ( { type : UPDATE_INFO_SUCCESS , payload : data . user } ) ;
@@ -336,19 +340,19 @@ export const updateInfo = function(
336
340
} ;
337
341
} ;
338
342
339
- export const changePassword = function (
343
+ export const changePassword = function (
340
344
oldPassword : string ,
341
345
newPassword : string ,
342
346
onSuccess ?: ( ) => void ,
343
347
onError ?: ( msg : string ) => void
344
348
) : TRPGAction {
345
349
oldPassword = md5 ( oldPassword ) ;
346
350
newPassword = md5 ( newPassword ) ;
347
- return function ( dispatch , getState ) {
351
+ return function ( dispatch , getState ) {
348
352
return api . emit (
349
353
'player::changePassword' ,
350
354
{ oldPassword, newPassword } ,
351
- function ( data ) {
355
+ function ( data ) {
352
356
if ( data . result ) {
353
357
console . log ( '密码修改成功' ) ;
354
358
onSuccess && onSuccess ( ) ;
@@ -365,9 +369,9 @@ export const changePassword = function(
365
369
* 发送好友请求
366
370
* @param uuid 目标用户UUID
367
371
*/
368
- export const sendFriendRequest = function ( uuid : string ) : TRPGAction {
369
- return function ( dispatch , getState ) {
370
- return api . emit ( 'player::sendFriendInvite' , { to : uuid } , function ( data ) {
372
+ export const sendFriendRequest = function ( uuid : string ) : TRPGAction {
373
+ return function ( dispatch , getState ) {
374
+ return api . emit ( 'player::sendFriendInvite' , { to : uuid } , function ( data ) {
371
375
if ( data . result ) {
372
376
dispatch ( showToast ( '请求已发送' ) ) ;
373
377
dispatch ( {
@@ -383,29 +387,31 @@ export const sendFriendRequest = function(uuid: string): TRPGAction {
383
387
} ;
384
388
export const sendFriendInvite = sendFriendRequest ; // 兼容旧名字
385
389
386
- export const agreeFriendInvite = function ( inviteUUID : string ) : TRPGAction {
387
- return function ( dispatch , getState ) {
388
- return api . emit ( 'player::agreeFriendInvite' , { uuid : inviteUUID } , function (
389
- data
390
- ) {
391
- if ( data . result ) {
392
- checkUser ( data . invite . from_uuid ) ;
393
- dispatch ( { type : AGREE_FRIEND_INVITE_SUCCESS , payload : data . invite } ) ;
394
- getFriendInviteInfoCache . refresh ( inviteUUID ) ; // 操作成功后重新获取邀请信息缓存
395
- } else {
396
- console . error ( data . msg ) ;
397
- dispatch ( showAlert ( data . msg ) ) ;
390
+ export const agreeFriendInvite = function ( inviteUUID : string ) : TRPGAction {
391
+ return function ( dispatch , getState ) {
392
+ return api . emit (
393
+ 'player::agreeFriendInvite' ,
394
+ { uuid : inviteUUID } ,
395
+ function ( data ) {
396
+ if ( data . result ) {
397
+ checkUser ( data . invite . from_uuid ) ;
398
+ dispatch ( { type : AGREE_FRIEND_INVITE_SUCCESS , payload : data . invite } ) ;
399
+ getFriendInviteInfoCache . refresh ( inviteUUID ) ; // 操作成功后重新获取邀请信息缓存
400
+ } else {
401
+ console . error ( data . msg ) ;
402
+ dispatch ( showAlert ( data . msg ) ) ;
403
+ }
398
404
}
399
- } ) ;
405
+ ) ;
400
406
} ;
401
407
} ;
402
408
403
- export const refuseFriendInvite = function ( inviteUUID : string ) : TRPGAction {
404
- return function ( dispatch , getState ) {
409
+ export const refuseFriendInvite = function ( inviteUUID : string ) : TRPGAction {
410
+ return function ( dispatch , getState ) {
405
411
return api . emit (
406
412
'player::refuseFriendInvite' ,
407
413
{ uuid : inviteUUID } ,
408
- function ( data ) {
414
+ function ( data ) {
409
415
if ( data . result ) {
410
416
dispatch ( { type : REFUSE_FRIEND_INVITE_SUCCESS , payload : data . res } ) ;
411
417
getFriendInviteInfoCache . refresh ( inviteUUID ) ; // 操作成功后重新获取邀请信息缓存
@@ -417,7 +423,7 @@ export const refuseFriendInvite = function(inviteUUID: string): TRPGAction {
417
423
} ;
418
424
} ;
419
425
420
- export const addFriendInvite = function ( invite : any ) : TRPGAction {
426
+ export const addFriendInvite = function ( invite : any ) : TRPGAction {
421
427
return { type : ADD_FRIEND_INVITE , payload : invite } ;
422
428
} ;
423
429
@@ -445,16 +451,16 @@ export const requestRemoveFriendInvite = createAsyncThunk<
445
451
}
446
452
} ) ;
447
453
448
- export const saveSettings = function ( ) : TRPGAction {
449
- return function ( dispatch , getState ) {
454
+ export const saveSettings = function ( ) : TRPGAction {
455
+ return function ( dispatch , getState ) {
450
456
const settings = getState ( ) . settings ;
451
457
return api . emit (
452
458
'player::saveSettings' ,
453
459
{
454
460
userSettings : settings . user ,
455
461
systemSettings : settings . system ,
456
462
} ,
457
- function ( data ) {
463
+ function ( data ) {
458
464
if ( ! data . result ) {
459
465
console . error ( data ) ;
460
466
}
0 commit comments