Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
middleLayer_for_kyxq
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
template admin
middleLayer_for_kyxq
Commits
9c385b37
Commit
9c385b37
authored
Sep 18, 2023
by
liujiangnan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 日志采集和请求重试
parent
90cee03c
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
100 additions
and
5 deletions
+100
-5
air.js
assets/middleLayer_for_kyxq/script/air.js
+39
-0
middleLayer.ts
assets/middleLayer_for_kyxq/script/middleLayer.ts
+29
-1
middleLayerBase.ts
assets/middleLayer_for_kyxq/script/middleLayerBase.ts
+32
-4
No files found.
assets/middleLayer_for_kyxq/script/air.js
View file @
9c385b37
...
@@ -37,10 +37,13 @@ export function initAir(_this) {
...
@@ -37,10 +37,13 @@ export function initAir(_this) {
startScanCodeCallback
:
null
,
startScanCodeCallback
:
null
,
needUpdateCallback
:
null
,
needUpdateCallback
:
null
,
getEngineInfoCallback
:
null
,
getEngineInfoCallback
:
null
,
logFileUploadCallback
:
null
,
takePictureCallBack
:
null
,
takePictureCallBack
:
null
,
configurationPortraitCallback
:
null
,
configurationPortraitCallback
:
null
,
configurationLandscapeCallback
:
null
,
configurationLandscapeCallback
:
null
,
openPhotoAlbumCallback
:
null
,
startBuyToAppStoreCallBack
:
null
,
startBuyToAppStoreCallBack
:
null
,
fileSaveCallback
:
null
,
recognitionCameraCallBack
:
null
,
recognitionCameraCallBack
:
null
,
testCallBack
:
null
,
testCallBack
:
null
,
testConvertCallBack
:
null
,
testConvertCallBack
:
null
,
...
@@ -286,6 +289,19 @@ export function initAir(_this) {
...
@@ -286,6 +289,19 @@ export function initAir(_this) {
};
};
window
.
courseware
.
callOcMethod
(
"
getEngineInfo
"
,
{});
window
.
courseware
.
callOcMethod
(
"
getEngineInfo
"
,
{});
},
},
logUpload
(
callback
)
{
_this
.
log
(
`===成功调用logUpload===`
);
// 调用原生获取机器信息
window
.
air
.
logFileUploadCallback
=
(
res
)
=>
{
if
(
typeof
(
res
)
==
'
string
'
)
{
callback
&&
callback
(
res
);
}
else
{
callback
&&
callback
(
JSON
.
stringify
(
res
));
}
window
.
air
.
logFileUploadCallback
=
null
;
};
window
.
courseware
.
callOcMethod
(
"
logUpload
"
,
{});
},
behaviorToCollectWithParam
(
event
,
type
=
""
)
{
behaviorToCollectWithParam
(
event
,
type
=
""
)
{
// 埋点所需接口 levelPayForSuccess userRegistrationEvent
// 埋点所需接口 levelPayForSuccess userRegistrationEvent
window
.
courseware
.
callOcMethod
(
"
behaviorToCollectWithParam
"
,
{
event
,
type
});
window
.
courseware
.
callOcMethod
(
"
behaviorToCollectWithParam
"
,
{
event
,
type
});
...
@@ -376,6 +392,16 @@ export function initAir(_this) {
...
@@ -376,6 +392,16 @@ export function initAir(_this) {
};
};
window
.
courseware
.
callOcMethod
(
"
onConfigurationLandscape
"
,
params
);
window
.
courseware
.
callOcMethod
(
"
onConfigurationLandscape
"
,
params
);
},
},
openPhotoAlbum
(
params
=
{},
callback
)
{
_this
.
log
(
`===成功调用openPhotoAlbum===
${
JSON
.
stringify
(
params
)}
`
);
window
.
air
.
openPhotoAlbumCallback
=
(
res
)
=>
{
res
=
typeof
(
res
)
==
'
string
'
?
res
:
JSON
.
stringify
(
res
);
_this
.
log
(
`===成功调用openPhotoAlbumCallback=== res ==
${
res
}
`
);
callback
&&
callback
(
res
);
window
.
air
.
openPhotoAlbumCallback
=
null
;
};
window
.
courseware
.
callOcMethod
(
"
openPhotoAlbum
"
,
params
);
},
startBuyToAppStore
(
params
=
{},
callback
)
{
startBuyToAppStore
(
params
=
{},
callback
)
{
// 苹果支付
// 苹果支付
_this
.
log
(
`===成功调用startBuyToAppStore===`
);
_this
.
log
(
`===成功调用startBuyToAppStore===`
);
...
@@ -384,6 +410,17 @@ export function initAir(_this) {
...
@@ -384,6 +410,17 @@ export function initAir(_this) {
};
};
window
.
courseware
.
callOcMethod
(
"
startBuyToAppStore
"
,
params
);
window
.
courseware
.
callOcMethod
(
"
startBuyToAppStore
"
,
params
);
},
},
downloadFileAndSave
(
params
=
{},
callback
)
{
// 苹果支付
_this
.
log
(
`===成功调用downloadFileAndSave===`
);
window
.
air
.
fileSaveCallback
=
(
res
)
=>
{
res
=
typeof
(
res
)
==
'
string
'
?
res
:
JSON
.
stringify
(
res
);
_this
.
log
(
`===成功调用fileSaveCallback=== res ==
${
res
}
`
);
callback
&&
callback
(
res
);
window
.
air
.
fileSaveCallback
=
null
;
};
window
.
courseware
.
callOcMethod
(
"
downloadFileAndSave
"
,
params
);
},
callOcMethod
(
method
,
param
)
{
callOcMethod
(
method
,
param
)
{
const
paramStr
=
JSON
.
stringify
(
param
);
const
paramStr
=
JSON
.
stringify
(
param
);
_this
.
log
(
`===成功调用原生方法
${
method
}
===参数==
${
paramStr
}
`
);
_this
.
log
(
`===成功调用原生方法
${
method
}
===参数==
${
paramStr
}
`
);
...
@@ -397,6 +434,8 @@ export function initAir(_this) {
...
@@ -397,6 +434,8 @@ export function initAir(_this) {
console
.
error
(
`非源生环境,网页版不支持
${
method
}
方法,将返回此方法的Mock数据以便于网页版调试使用`
);
console
.
error
(
`非源生环境,网页版不支持
${
method
}
方法,将返回此方法的Mock数据以便于网页版调试使用`
);
if
(
method
==
'
getEngineInfo
'
){
if
(
method
==
'
getEngineInfo
'
){
window
.
air
.
getEngineInfoCallback
({
isDev
:
1
,
uuid
:
'
debug-xxxxxx-xxxxxx
'
,
version
:
'
1.0.2
'
});
window
.
air
.
getEngineInfoCallback
({
isDev
:
1
,
uuid
:
'
debug-xxxxxx-xxxxxx
'
,
version
:
'
1.0.2
'
});
}
else
if
(
method
==
'
logUpload
'
){
window
.
air
.
logFileUploadCallback
({
"
fileUrl
"
:
"
abcedfgh
"
,
"
error
"
:
""
});
}
else
if
(
method
==
'
startTest
'
)
{
}
else
if
(
method
==
'
startTest
'
)
{
}
else
if
(
method
==
'
stopTest
'
)
{
}
else
if
(
method
==
'
stopTest
'
)
{
window
.
air
.
testCallBack
(
testMockData
);
window
.
air
.
testCallBack
(
testMockData
);
...
...
assets/middleLayer_for_kyxq/script/middleLayer.ts
View file @
9c385b37
...
@@ -23,6 +23,7 @@ export default class NewClass extends middleLayerBase {
...
@@ -23,6 +23,7 @@ export default class NewClass extends middleLayerBase {
initAir
(
this
);
initAir
(
this
);
this
.
reWriteAir
();
this
.
reWriteAir
();
(
<
any
>
window
).
courseware
.
getEngineInfo
();
this
.
role
=
'
student
'
;
// 上古遗留问题
this
.
role
=
'
student
'
;
// 上古遗留问题
...
@@ -35,7 +36,7 @@ export default class NewClass extends middleLayerBase {
...
@@ -35,7 +36,7 @@ export default class NewClass extends middleLayerBase {
return
;
return
;
}
}
const
token
=
cc
.
sys
.
localStorage
.
getItem
(
'
token
'
);
const
token
=
cc
.
sys
.
localStorage
.
getItem
(
'
token
'
);
const
{
code
}
=
await
this
.
asyncCallNetworkApiGet
(
"
/api/
jj
/v1/heart
"
,
{
token
});
const
{
code
}
=
await
this
.
asyncCallNetworkApiGet
(
"
/api/
kyxq
/v1/heart
"
,
{
token
});
if
(
code
!=
200
)
{
if
(
code
!=
200
)
{
global
.
middleLayer
.
showTips
(
"
登录过期,请重新登录
"
);
global
.
middleLayer
.
showTips
(
"
登录过期,请重新登录
"
);
this
.
loginPage
.
active
=
true
;
this
.
loginPage
.
active
=
true
;
...
@@ -48,11 +49,38 @@ export default class NewClass extends middleLayerBase {
...
@@ -48,11 +49,38 @@ export default class NewClass extends middleLayerBase {
}
}
async
navLogCaller
()
{
const
{
data
}
=
await
this
.
asyncCallNetworkApiGet
(
"
/api/application/v1/engine/report
"
,
{
engineid
:
this
.
ENGINE_INFO
.
uuid
,
packagename
:
'
com.iplayabc.kyxq
'
});
if
(
data
&&
data
==
true
)
{
(
<
any
>
window
).
courseware
.
logUpload
(
async
(
res
)
=>
{
const
{
fileUrl
,
error
}
=
JSON
.
parse
(
res
);
if
(
fileUrl
)
{
await
this
.
asyncCallNetworkApiPost
(
"
/api/application/v1/engine/report
"
,
{
engineid
:
this
.
ENGINE_INFO
.
uuid
,
packagename
:
'
com.iplayabc.kyxq
'
,
file_name
:
fileUrl
});
}
});
}
this
.
scheduleOnce
(()
=>
{
this
.
navLogCaller
();
},
5
);
}
async
start
()
{
async
start
()
{
this
.
node
.
zIndex
=
9999
;
this
.
node
.
zIndex
=
9999
;
cc
.
game
.
addPersistRootNode
(
this
.
node
);
cc
.
game
.
addPersistRootNode
(
this
.
node
);
this
.
initListener
();
this
.
initListener
();
this
.
scheduleOnce
(()
=>
{
// 启动日志召回监听服务
this
.
navLogCaller
();
},
5
);
const
token
=
cc
.
sys
.
localStorage
.
getItem
(
'
token
'
);
const
token
=
cc
.
sys
.
localStorage
.
getItem
(
'
token
'
);
if
(
!
token
)
{
if
(
!
token
)
{
// this.loginPage.active = true;
// this.loginPage.active = true;
...
...
assets/middleLayer_for_kyxq/script/middleLayerBase.ts
View file @
9c385b37
...
@@ -45,10 +45,11 @@ export abstract class middleLayerBase extends cc.Component {
...
@@ -45,10 +45,11 @@ export abstract class middleLayerBase extends cc.Component {
}
}
}
}
callNetworkApiPost
(
uri
,
data
,
callBack
)
{
callNetworkApiPost
(
uri
,
data
,
callBack
,
sendHook
=
null
)
{
const
token
=
cc
.
sys
.
localStorage
.
getItem
(
'
token
'
);
const
token
=
cc
.
sys
.
localStorage
.
getItem
(
'
token
'
);
data
=
{...
data
,
token
};
data
=
{...
data
,
token
};
this
.
getEngineInfo
().
then
((
engineInfo
)
=>
{
this
.
getEngineInfo
().
then
((
engineInfo
)
=>
{
data
.
engine_uuid
=
engineInfo
[
'
uuid
'
];
const
xhr
=
new
XMLHttpRequest
();
const
xhr
=
new
XMLHttpRequest
();
const
url
=
`
${
engineInfo
[
"
apiBase
"
]}${
uri
}
`
;
const
url
=
`
${
engineInfo
[
"
apiBase
"
]}${
uri
}
`
;
xhr
.
open
(
"
POST
"
,
url
,
true
);
xhr
.
open
(
"
POST
"
,
url
,
true
);
...
@@ -59,10 +60,11 @@ export abstract class middleLayerBase extends cc.Component {
...
@@ -59,10 +60,11 @@ export abstract class middleLayerBase extends cc.Component {
}
}
}
}
xhr
.
send
(
JSON
.
stringify
(
data
));
xhr
.
send
(
JSON
.
stringify
(
data
));
sendHook
&&
sendHook
(
xhr
);
});
});
}
}
callNetworkApiGet
(
uri
,
data
,
call
Back
)
{
callNetworkApiGet
(
uri
,
data
,
call
back
,
sendHook
=
null
)
{
const
token
=
cc
.
sys
.
localStorage
.
getItem
(
'
token
'
);
const
token
=
cc
.
sys
.
localStorage
.
getItem
(
'
token
'
);
data
=
{...
data
,
token
};
data
=
{...
data
,
token
};
this
.
getEngineInfo
().
then
((
engineInfo
)
=>
{
this
.
getEngineInfo
().
then
((
engineInfo
)
=>
{
...
@@ -75,28 +77,54 @@ export abstract class middleLayerBase extends cc.Component {
...
@@ -75,28 +77,54 @@ export abstract class middleLayerBase extends cc.Component {
}
}
queryStr
+=
params
.
join
(
"
&
"
);
queryStr
+=
params
.
join
(
"
&
"
);
const
xhr
=
new
XMLHttpRequest
();
const
xhr
=
new
XMLHttpRequest
();
let
flag
=
false
;
xhr
.
onreadystatechange
=
()
=>
{
xhr
.
onreadystatechange
=
()
=>
{
if
(
xhr
.
readyState
==
4
&&
(
xhr
.
status
>=
200
&&
xhr
.
status
<
400
))
{
if
(
xhr
.
readyState
==
4
&&
(
xhr
.
status
>=
200
&&
xhr
.
status
<
400
))
{
callBack
(
JSON
.
parse
(
xhr
.
responseText
));
flag
=
true
;
callback
(
JSON
.
parse
(
xhr
.
responseText
));
}
}
};
};
const
url
=
`
${
engineInfo
[
"
apiBase
"
]}${
uri
}${
queryStr
}
`
;
const
url
=
`
${
engineInfo
[
"
apiBase
"
]}${
uri
}${
queryStr
}
`
;
console
.
log
(
'
url =
'
+
url
);
console
.
log
(
'
url =
'
+
url
);
sendHook
&&
sendHook
(
xhr
);
xhr
.
open
(
'
GET
'
,
url
,
true
);
xhr
.
open
(
'
GET
'
,
url
,
true
);
xhr
.
send
();
xhr
.
send
();
// 五秒超时重试一次
if
(
sendHook
)
{
// 有hook的无法重试请求
return
;
}
this
.
scheduleOnce
(()
=>
{
if
(
flag
)
{
return
;
}
xhr
.
abort
();
this
.
callNetworkApiGet
(
uri
,
data
,
callback
);
},
5
);
});
});
}
}
getConfigInfo
(
url
,
callback
)
{
getConfigInfo
(
url
,
callback
)
{
const
xhr
=
new
XMLHttpRequest
();
const
xhr
=
new
XMLHttpRequest
();
let
flag
=
false
;
xhr
.
onreadystatechange
=
()
=>
{
xhr
.
onreadystatechange
=
()
=>
{
if
(
xhr
.
readyState
==
4
&&
(
xhr
.
status
>=
200
&&
xhr
.
status
<
400
))
{
if
(
xhr
.
readyState
==
4
&&
(
xhr
.
status
>=
200
&&
xhr
.
status
<
400
))
{
flag
=
true
;
callback
(
JSON
.
parse
(
xhr
.
responseText
));
callback
(
JSON
.
parse
(
xhr
.
responseText
));
}
}
};
};
console
.
log
(
'
url =
'
+
`
${
url
}
/config.json`
);
xhr
.
open
(
'
GET
'
,
`
${
url
}
/config.json`
,
true
);
xhr
.
open
(
'
GET
'
,
`
${
url
}
/config.json`
,
true
);
xhr
.
send
();
xhr
.
send
();
// 五秒超时重试一次
this
.
scheduleOnce
(()
=>
{
if
(
flag
)
{
return
;
}
xhr
.
abort
();
this
.
getConfigInfo
(
url
,
callback
);
},
5
);
}
}
ENGINE_INFO
;
ENGINE_INFO
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment