Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
middleLayer_for_DG
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_DG
Commits
a50b58ce
Commit
a50b58ce
authored
Oct 21, 2022
by
liujiangnan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 接口
parent
f2032c4e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
16 deletions
+50
-16
middleLayer.ts
assets/middleLayer_for_DG/script/middleLayer.ts
+50
-16
No files found.
assets/middleLayer_for_DG/script/middleLayer.ts
View file @
a50b58ce
...
...
@@ -7,6 +7,7 @@ const { ccclass, property } = cc._decorator;
export
default
class
NewClass
extends
middleLayerBase
{
role
;
token
;
// 统一释放异步资源的方法
async
onLoad
()
{
initAir
(
this
);
...
...
@@ -21,14 +22,26 @@ export default class NewClass extends middleLayerBase {
cc
.
game
.
addPersistRootNode
(
this
.
node
);
global
.
middleLayer
=
cc
.
find
(
'
middleLayer
'
).
getComponent
(
'
middleLayer
'
);
// 预加载
cc
.
find
(
`middleLayer/preload`
).
active
=
false
;
this
.
loadOnlineCourseWare
(
23751
);
}
onHomeworkFinish
(
callBack
,
data
=
null
)
{
// TODO 上报总成绩
if
(
!
this
.
token
)
{
return
;
}
if
(
typeof
(
callBack
)
==
'
object
'
)
{
data
=
callBack
;
}
this
.
callNetworkApiPost
(
`/api/dige/v1/user/report`
,
{
token
:
this
.
token
,
syllabus_id
:
this
.
courseItem
.
course_id
,
courseware_id
:
this
.
courseItem
.
id
,
template_name
:
this
.
courseItem
.
template_name
,
study_duration
:
Date
.
now
()
-
this
.
courseOpenTimeStamp
,
result
:
JSON
.
stringify
(
data
),
},
res
=>
{
callBack
&&
callBack
(
res
);
});
}
initListener
()
{
...
...
@@ -44,20 +57,27 @@ export default class NewClass extends middleLayerBase {
this
.
log
(
"
===成功调用getData===
"
+
JSON
.
stringify
(
data
));
callback
&&
callback
(
data
);
}
(
<
any
>
window
).
courseware
.
sendAnswer
=
(
answerObj
)
=>
{
this
.
log
(
"
===成功调用sendAnswer===
"
+
JSON
.
stringify
(
answerObj
));
this
.
callNetworkApiPost
(
`/api/dige/courseware/v1/
${
this
.
courseItem
.
id
}
/saveanswer`
,
answerObj
,
(
data
)
=>
{
answerObj
.
callback
&&
answerObj
.
callback
(
JSON
.
stringify
(
data
.
row
));
});
}
(
<
any
>
window
).
courseware
.
getAnswer
=
(
queryObj
,
callback
)
=>
{
this
.
log
(
"
===成功调用getAnswer===
"
+
JSON
.
stringify
(
queryObj
));
this
.
callNetworkApiGet
(
`/api/dige/courseware/v1/
${
this
.
courseItem
.
id
}
/getanswer`
,
queryObj
,
(
datastr
)
=>
{
const
data
=
JSON
.
parse
(
datastr
);
callback
&&
callback
(
JSON
.
stringify
(
data
.
rows
));
});
(
<
any
>
window
).
courseware
.
stopTest
=
(
callback
)
=>
{
(
<
any
>
window
).
courseware
.
hasCalledStartTest
=
false
;
console
.
log
(
`===成功调用stopTest===`
);
if
(
!
callback
)
{
// 不传回调函数就表示取消评测
console
.
log
(
`===成功取消录音评测===`
);
(
<
any
>
window
).
courseware
.
callOcMethod
(
"
stopTest
"
,
{
isBreak
:
1
});
return
;
}
// 结束录音
(
<
any
>
window
).
air
.
testCallBack
=
(
res
)
=>
{
res
=
typeof
(
res
)
==
'
string
'
?
res
:
JSON
.
stringify
(
res
);
console
.
log
(
`===成功调用testCallBack=== res ==
${
res
}
`
);
this
.
saveRecordResult
(
res
);
callback
&&
callback
(
res
);
(
<
any
>
window
).
air
.
testCallBack
=
null
;
};
(
<
any
>
window
).
courseware
.
callOcMethod
(
"
stopTest
"
,
{});
}
if
(
!
(
<
any
>
window
).
air
)
{
(
<
any
>
window
).
air
=
{};
}
...
...
@@ -70,6 +90,20 @@ export default class NewClass extends middleLayerBase {
}
}
saveRecordResult
(
recordResult
)
{
if
(
!
this
.
token
)
{
return
;
}
const
result
=
JSON
.
parse
(
recordResult
);
this
.
callNetworkApiPost
(
`/api/dige/v1/record/save`
,
{
token
:
this
.
token
,
syllabus_id
:
this
.
courseItem
.
course_id
,
courseware_id
:
this
.
courseItem
.
id
,
record_url
:
result
.
audioUrl
,
test_result
:
recordResult
},
()
=>
{
});
}
onMiddleLayerLoadingFinish
()
{
if
(
cc
.
sys
.
isNative
&&
cc
.
sys
.
os
==
cc
.
sys
.
OS_IOS
)
{
jsb
.
reflection
.
callStaticMethod
(
...
...
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