Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
middleLayer_for_NJ_lite
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_NJ_lite
Commits
41e0b978
Commit
41e0b978
authored
Sep 19, 2023
by
liujiangnan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 日志功能
parent
565d78b5
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
240 additions
and
38 deletions
+240
-38
air.js
assets/middleLayer_for_NJ_lite/script/air.js
+127
-2
middleLayer.ts
assets/middleLayer_for_NJ_lite/script/middleLayer.ts
+43
-2
middleLayerBase.ts
assets/middleLayer_for_NJ_lite/script/middleLayerBase.ts
+70
-34
No files found.
assets/middleLayer_for_NJ_lite/script/air.js
View file @
41e0b978
...
...
@@ -13,6 +13,12 @@ export function initAir(_this) {
_this
.
log
(
"
***成功调用onCourseInScreen***
"
);
});
},
recordRealtimeCallBack
:
function
(
res
)
{
_this
.
log
(
`***成功调用recordRealtimeCallBack***参数==
${
res
}
`
);
},
recordWordSpellCallBack
:
function
(
res
)
{
_this
.
log
(
`***成功调用recordWordSpellCallBack***参数==
${
res
}
`
);
},
osmoCallback
:
function
(
res
)
{
_this
.
log
(
`***成功调用osmoCallback***参数==
${
res
}
`
);
},
...
...
@@ -31,12 +37,16 @@ export function initAir(_this) {
startScanCodeCallback
:
null
,
needUpdateCallback
:
null
,
getEngineInfoCallback
:
null
,
logFileUploadCallback
:
null
,
takePictureCallBack
:
null
,
configurationPortraitCallback
:
null
,
configurationLandscapeCallback
:
null
,
openPhotoAlbumCallback
:
null
,
startBuyToAppStoreCallBack
:
null
,
fileSaveCallback
:
null
,
recognitionCameraCallBack
:
null
,
testCallBack
:
null
,
testConvertCallBack
:
null
,
recordCallBack
:
null
,
onCourseInScreen
:
null
,
};
...
...
@@ -44,7 +54,7 @@ export function initAir(_this) {
window
.
air
=
new
Proxy
(
realAir
,
{
set
:
function
(
target
,
key
,
value
,
receiver
)
{
let
newValue
=
value
;
if
(
key
==
"
osmoCallback
"
||
key
==
"
osmoHandwritingCallback
"
||
key
==
"
osmoHandwritingMlkitCallback
"
||
key
==
"
osmoFingerReadCallback
"
)
{
if
(
key
==
"
osmoCallback
"
||
key
==
"
osmoHandwritingCallback
"
||
key
==
"
osmoHandwritingMlkitCallback
"
||
key
==
"
osmoFingerReadCallback
"
||
key
==
"
recordWordSpellCallBack
"
||
key
==
"
recordRealtimeCallBack
"
)
{
newValue
=
function
(
res
)
{
_this
.
log
(
`||==成功调用
${
key
}
==||参数==
${
JSON
.
stringify
(
res
)}
`
);
if
(
typeof
(
res
)
==
'
string
'
)
{
...
...
@@ -166,6 +176,76 @@ export function initAir(_this) {
};
window
.
courseware
.
callOcMethod
(
"
stopTest
"
,
{});
},
startTestConvert
(
testText
,
option
)
{
window
.
courseware
.
hasCalledStartTestConvert
=
true
;
_this
.
log
(
`===成功调用startTestConvert=== testText ==
${
testText
}
`
);
window
.
courseware
.
callOcMethod
(
"
startTestConvert
"
,
{
...
option
,
"
params
"
:
testText
});
},
stopTestConvert
(
testCallback
,
convertCallback
)
{
window
.
courseware
.
hasCalledStartTestConvert
=
false
;
_this
.
log
(
`===成功调用stopTestConvert===`
);
if
(
!
testCallback
)
{
// 不传回调函数就表示取消评测
_this
.
log
(
`===成功取消录音评测===`
);
window
.
courseware
.
callOcMethod
(
"
stopTestConvert
"
,
{
isBreak
:
1
});
return
;
}
// 结束录音
window
.
air
.
testCallBack
=
(
res
)
=>
{
res
=
typeof
(
res
)
==
'
string
'
?
res
:
JSON
.
stringify
(
res
);
_this
.
log
(
`===成功调用testCallBack=== res ==
${
res
}
`
);
// 录音异常兼容处理
const
resObj
=
JSON
.
parse
(
res
);
if
(
resObj
.
errCode
)
{
resObj
.
result
=
{
overall
:
0
};
resObj
.
audioUrl
=
""
;
res
=
JSON
.
stringify
(
resObj
);
_this
.
showTips
(
`评测服务信号弱,可能会造成评分不准确,请稍后再来录音评测吧~`
);
}
testCallback
&&
testCallback
(
res
);
window
.
air
.
testCallBack
=
null
;
};
// 结束变声
window
.
air
.
testConvertCallBack
=
(
res
)
=>
{
res
=
typeof
(
res
)
==
'
string
'
?
res
:
JSON
.
stringify
(
res
);
_this
.
log
(
`===成功调用testConvertCallBack=== res ==
${
res
}
`
);
// 录音异常兼容处理
const
resObj
=
JSON
.
parse
(
res
);
if
(
resObj
.
errCode
)
{
resObj
.
convertUrl
=
""
;
res
=
JSON
.
stringify
(
resObj
);
_this
.
showTips
(
`变声失败,请稍后再来尝试吧~`
);
}
convertCallback
&&
convertCallback
(
res
);
window
.
air
.
testConvertCallBack
=
null
;
};
window
.
courseware
.
callOcMethod
(
"
stopTestConvert
"
,
{});
},
startRealtimeRecord
(
params
=
{})
{
window
.
courseware
.
hasCalledRealtimeRecord
=
true
;
_this
.
log
(
`===成功调用startRealtimeRecord===
${
JSON
.
stringify
(
params
)}
`
);
window
.
courseware
.
callOcMethod
(
"
startRealtimeRecord
"
,
params
);
},
stopRealtimeRecord
(
params
=
{})
{
window
.
courseware
.
hasCalledRealtimeRecord
=
false
;
_this
.
log
(
`===成功调用stopRealtimeRecord===`
);
window
.
courseware
.
callOcMethod
(
"
stopRealtimeRecord
"
,
params
);
},
startWordSpell
(
params
=
{})
{
window
.
courseware
.
hasWordSpelling
=
true
;
_this
.
log
(
`===成功调用startWordSpell===
${
JSON
.
stringify
(
params
)}
`
);
window
.
courseware
.
callOcMethod
(
"
startWordSpell
"
,
params
);
},
stopWordSpell
(
params
=
{})
{
window
.
courseware
.
hasWordSpelling
=
false
;
_this
.
log
(
`===成功调用stopWordSpell===`
);
window
.
courseware
.
callOcMethod
(
"
stopWordSpell
"
,
params
);
},
// 拍照
takePicture
(
callback
)
{
_this
.
log
(
`===成功调用takePicture===`
);
...
...
@@ -209,6 +289,19 @@ export function initAir(_this) {
};
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
=
""
)
{
// 埋点所需接口 levelPayForSuccess userRegistrationEvent
window
.
courseware
.
callOcMethod
(
"
behaviorToCollectWithParam
"
,
{
event
,
type
});
...
...
@@ -299,6 +392,16 @@ export function initAir(_this) {
};
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
)
{
// 苹果支付
_this
.
log
(
`===成功调用startBuyToAppStore===`
);
...
...
@@ -307,6 +410,17 @@ export function initAir(_this) {
};
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
)
{
const
paramStr
=
JSON
.
stringify
(
param
);
_this
.
log
(
`===成功调用原生方法
${
method
}
===参数==
${
paramStr
}
`
);
...
...
@@ -319,7 +433,9 @@ export function initAir(_this) {
}
else
{
console
.
error
(
`非源生环境,网页版不支持
${
method
}
方法,将返回此方法的Mock数据以便于网页版调试使用`
);
if
(
method
==
'
getEngineInfo
'
){
window
.
air
.
getEngineInfoCallback
({
isDev
:
1
,
uuid
:
'
debug-xxxxxx-xxxxxx
'
});
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
==
'
stopTest
'
)
{
window
.
air
.
testCallBack
(
testMockData
);
...
...
@@ -340,6 +456,15 @@ export function initAir(_this) {
if
(
window
.
courseware
.
hasCalledStartTest
)
{
window
.
courseware
.
stopTest
();
}
if
(
window
.
courseware
.
hasCalledStartTestConvert
)
{
window
.
courseware
.
stopTestConvert
();
}
if
(
window
.
courseware
.
hasCalledRealtimeRecord
)
{
window
.
courseware
.
stopRealtimeRecord
();
}
if
(
window
.
courseware
.
hasWordSpelling
)
{
window
.
courseware
.
stopWordSpell
();
}
if
(
window
.
courseware
.
hasCalledOpenRecognitionCamera
)
{
window
.
courseware
.
closeRecognitionCamera
();
}
...
...
assets/middleLayer_for_NJ_lite/script/middleLayer.ts
View file @
41e0b978
import
{
delayCall
}
from
"
../../../form_angular/src/app/play/Unit
"
;
import
{
initAir
}
from
"
./air
"
;
import
{
middleLayerBase
}
from
"
./middleLayerBase
"
;
import
{
asyncDelay
,
getSpriteFrimeByUrl
,
buttonOnceClick
,
buttonOnClick
,
guid
}
from
"
./util
"
;
import
{
buttonOnceClick
,
buttonOnClick
,
guid
}
from
"
./util
"
;
const
{
ccclass
,
property
}
=
cc
.
_decorator
;
...
...
@@ -909,6 +908,39 @@ export default class NewClass extends middleLayerBase {
this
.
data
=
_data
;
}
async
navLogCaller
()
{
const
res
=
await
this
.
asyncCallNetworkApiGet
(
"
/api/application/v1/engine/report
"
,
{
engineid
:
this
.
ENGINE_INFO
.
uuid
,
packagename
:
'
com.iplayabc.oxford.lite
'
});
const
data
=
JSON
.
parse
(
res
).
data
;
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.oxford.lite
'
,
file_name
:
fileUrl
});
}
});
}
this
.
scheduleOnce
(()
=>
{
this
.
navLogCaller
();
},
5
);
}
doHeart
()
{
const
token
=
cc
.
sys
.
localStorage
.
getItem
(
'
token
'
);
this
.
callNetworkApiGet
(
`/api/oxford/v1/heart`
,
{
token
,
engine_uuid
:
this
.
ENGINE_INFO
.
uuid
},
()
=>
{
// 心跳结果,暂时不做任何处理
});
this
.
scheduleOnce
(()
=>
{
this
.
doHeart
();
},
5
);
}
activeLevels
=
null
;
isLogin
=
false
;
async
start
()
{
...
...
@@ -927,6 +959,12 @@ export default class NewClass extends middleLayerBase {
cc
.
find
(
'
middleLayer/cross
'
).
active
=
false
;
cc
.
find
(
'
middleLayer/free
'
).
active
=
false
;
this
.
doHeart
();
this
.
scheduleOnce
(()
=>
{
// 启动日志召回监听服务
this
.
navLogCaller
();
},
5
);
if
(
this
.
type
==
"
aixuebao
"
)
{
await
this
.
asyncCallNetworkApiGet
(
`/api/aixuebao/v1/engine/active`
,
{
engineid
:
this
.
engine_uuid
,
...
...
@@ -1445,6 +1483,9 @@ export default class NewClass extends middleLayerBase {
this
.
gameModel
=
cc
.
sys
.
localStorage
.
getItem
(
'
gameModel
'
)
||
'
cross
'
;
initAir
(
this
);
this
.
reWriteAir
();
(
<
any
>
window
).
courseware
.
getEngineInfo
();
this
.
reportErrorLog
();
}
}
assets/middleLayer_for_NJ_lite/script/middleLayerBase.ts
View file @
41e0b978
...
...
@@ -29,27 +29,28 @@ export abstract class middleLayerBase extends cc.Component {
}
}
callNetworkApiPost
(
uri
,
_data
,
callBack
)
{
const
data
=
{...
_data
,
org_id
:
this
.
ORG_ID
};
callNetworkApiPost
(
uri
,
data
,
callback
)
{
uri
=
uri
.
replace
(
"
/oxford/
"
,
"
/oxfordlite/
"
);
this
.
getBaseUrl
((
baseUrl
)
=>
{
this
.
getEngineInfo
().
then
(()
=>
{
data
=
{...
data
,
org_id
:
this
.
ORG_ID
};
const
xhr
=
new
XMLHttpRequest
();
const
url
=
`
${
baseUrl
}${
uri
}
`
;
const
url
=
`
${
this
.
ENGINE_INFO
[
"
apiBase
"
]
}${
uri
}
`
;
xhr
.
open
(
"
POST
"
,
url
,
true
);
xhr
.
setRequestHeader
(
'
content-type
'
,
'
application/json
'
);
xhr
.
onreadystatechange
=
()
=>
{
if
(
xhr
.
readyState
==
4
)
{
call
B
ack
(
JSON
.
parse
(
xhr
.
responseText
));
call
b
ack
(
JSON
.
parse
(
xhr
.
responseText
));
}
}
xhr
.
send
(
JSON
.
stringify
(
data
));
});
}
callNetworkApiGet
(
uri
,
_data
,
callBack
)
{
const
data
=
{...
_data
,
org_id
:
this
.
ORG_ID
};
callNetworkApiGet
(
uri
,
data
,
callback
)
{
uri
=
uri
.
replace
(
"
/oxford/
"
,
"
/oxfordlite/
"
);
this
.
getBaseUrl
((
baseUrl
)
=>
{
this
.
getEngineInfo
().
then
(()
=>
{
data
=
{...
data
,
org_id
:
this
.
ORG_ID
};
let
queryStr
=
'
?
'
;
const
params
=
[];
for
(
const
key
in
data
)
{
...
...
@@ -59,58 +60,93 @@ export abstract class middleLayerBase extends cc.Component {
}
queryStr
+=
params
.
join
(
"
&
"
);
const
xhr
=
new
XMLHttpRequest
();
let
flag
=
false
;
xhr
.
onreadystatechange
=
()
=>
{
if
(
xhr
.
readyState
==
4
&&
(
xhr
.
status
>=
200
&&
xhr
.
status
<
400
))
{
callBack
(
xhr
.
responseText
);
flag
=
true
;
callback
(
xhr
.
responseText
);
}
};
const
url
=
`
${
baseUrl
}${
uri
}${
queryStr
}
`
;
console
.
warn
(
'
url =
'
+
url
);
const
url
=
`
${
this
.
ENGINE_INFO
[
"
apiBase
"
]}${
uri
}${
queryStr
}
`
;
xhr
.
open
(
'
GET
'
,
url
,
true
);
xhr
.
send
();
// 五秒超时重试一次
this
.
scheduleOnce
(()
=>
{
if
(
flag
)
{
return
;
}
xhr
.
abort
();
this
.
callNetworkApiGet
(
uri
,
data
,
callback
);
},
5
);
});
}
getConfigInfo
(
url
,
callback
)
{
const
xhr
=
new
XMLHttpRequest
();
let
flag
=
false
;
xhr
.
onreadystatechange
=
()
=>
{
if
(
xhr
.
readyState
==
4
&&
(
xhr
.
status
>=
200
&&
xhr
.
status
<
400
))
{
flag
=
true
;
callback
(
JSON
.
parse
(
xhr
.
responseText
));
}
};
console
.
warn
(
'
url =
'
+
`
${
url
}
/config.json`
);
xhr
.
open
(
'
GET
'
,
`
${
url
}
/config.json`
,
true
);
xhr
.
send
();
// 五秒超时重试一次
this
.
scheduleOnce
(()
=>
{
if
(
flag
)
{
return
;
}
xhr
.
abort
();
this
.
getConfigInfo
(
url
,
callback
);
},
5
);
}
ORG_ID
;
DOMAIN
;
async
getBaseUrl
(
callback
=
null
)
{
const
engineInfo
=
await
this
.
getEngineInfo
();
const
{
isDev
}
=
JSON
.
parse
(
engineInfo
);
if
(
isDev
==
1
)
{
this
.
ORG_ID
=
513
;
this
.
DOMAIN
=
"
http://staging-teach.cdn.ireadabc.com/
"
;
callback
&&
callback
(
'
http://staging-openapi.iteachabc.com
'
);
return
'
http://staging-openapi.iteachabc.com
'
;
}
else
{
this
.
ORG_ID
=
512
;
this
.
DOMAIN
=
"
http://teach.cdn.ireadabc.com/
"
;
callback
&&
callback
(
'
http://openapi.iteachabc.com
'
);
return
'
http://openapi.iteachabc.com
'
;
}
await
this
.
getEngineInfo
();
callback
&&
callback
(
this
.
ENGINE_INFO
[
`apiBase`
]);
return
this
.
ENGINE_INFO
[
`apiBase`
];
}
ENGINE_INFO
;
getEngineInfo
()
{
if
((
<
any
>
window
).
air
.
engineInfo
)
{
return
(
<
any
>
window
).
air
.
engineInfo
;
}
else
{
return
new
Promise
((
resolve
,
reject
)
=>
{
(
<
any
>
window
).
courseware
.
getEngineInfo
(()
=>
{
resolve
((
<
any
>
window
).
air
.
engineInfo
);
});
});
}
return
new
Promise
((
resolve
,
reject
)
=>
{
if
(
this
.
ENGINE_INFO
)
{
resolve
(
JSON
.
stringify
(
this
.
ENGINE_INFO
));
return
;
}
const
loopEngineInfo
=
()
=>
{
this
.
scheduleOnce
(()
=>
{
if
(
!
(
<
any
>
window
).
air
.
engineInfo
)
{
loopEngineInfo
();
return
;
}
if
(
this
.
ENGINE_INFO
)
{
resolve
(
JSON
.
stringify
(
this
.
ENGINE_INFO
));
return
;
}
const
engineInfo
=
JSON
.
parse
((
<
any
>
window
).
air
.
engineInfo
);
if
(
engineInfo
.
isDev
==
1
)
{
engineInfo
.
domain
=
"
http://staging-teach.cdn.ireadabc.com/
"
;
engineInfo
.
apiBase
=
'
http://staging-openapi.iteachabc.com
'
;
engineInfo
.
orgId
=
513
;
}
else
{
engineInfo
.
domain
=
"
http://teach.cdn.ireadabc.com/
"
;
engineInfo
.
apiBase
=
'
http://openapi.iteachabc.com
'
;
engineInfo
.
orgId
=
512
;
}
this
.
ORG_ID
=
engineInfo
[
`orgId`
];
this
.
DOMAIN
=
engineInfo
[
`domain`
];
this
.
ENGINE_INFO
=
engineInfo
;
resolve
(
JSON
.
stringify
(
engineInfo
));
},
0.05
);
};
loopEngineInfo
();
});
}
asyncCallNetworkApiGet
(
apiName
,
data
):
Promise
<
any
>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
...
...
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