Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
NJ_BookTable
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
NJ_BookTable
Commits
412543e3
Commit
412543e3
authored
Jun 10, 2022
by
liujiangnan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 界面
parent
d5c494f9
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
552 additions
and
167 deletions
+552
-167
NJ_BookTable.fire
assets/NJ_BookTable/scene/NJ_BookTable.fire
+306
-38
NJ_BookTable.ts
assets/NJ_BookTable/scene/NJ_BookTable.ts
+52
-7
MyCocosSceneComponent.ts
assets/NJ_BookTable/script/MyCocosSceneComponent.ts
+2
-2
defaultData.ts
assets/NJ_BookTable/script/defaultData.ts
+7
-4
util.ts
assets/NJ_BookTable/script/util.ts
+185
-116
No files found.
assets/NJ_BookTable/scene/NJ_BookTable.fire
View file @
412543e3
...
...
@@ -78,13 +78,13 @@
"_active": true,
"_components": [
{
"__id__":
29
"__id__":
34
},
{
"__id__": 3
0
"__id__": 3
5
},
{
"__id__": 3
1
"__id__": 3
6
}
],
"_prefab": null,
...
...
@@ -245,16 +245,16 @@
"__id__": 6
},
{
"__id__": 2
5
"__id__": 2
6
}
],
"_active": true,
"_components": [
{
"__id__":
27
"__id__":
32
},
{
"__id__":
28
"__id__":
33
}
],
"_prefab": null,
...
...
@@ -317,19 +317,19 @@
"__id__": 7
},
{
"__id__": 1
2
"__id__": 1
3
},
{
"__id__": 1
6
"__id__": 1
7
},
{
"__id__": 2
0
"__id__": 2
1
}
],
"_active":
tru
e,
"_active":
fals
e,
"_components": [
{
"__id__": 2
4
"__id__": 2
5
}
],
"_prefab": null,
...
...
@@ -399,6 +399,9 @@
},
{
"__id__": 11
},
{
"__id__": 12
}
],
"_prefab": null,
...
...
@@ -603,6 +606,74 @@
"_originalHeight": 0,
"_id": "85UeamOldJ3LdQv6cbs3Hu"
},
{
"__type__": "cc.Button",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 7
},
"_enabled": true,
"_normalMaterial": null,
"_grayMaterial": null,
"duration": 0.1,
"zoomScale": 1.2,
"clickEvents": [],
"_N$interactable": true,
"_N$enableAutoGrayEffect": false,
"_N$transition": 0,
"transition": 0,
"_N$normalColor": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_N$pressedColor": {
"__type__": "cc.Color",
"r": 211,
"g": 211,
"b": 211,
"a": 255
},
"pressedColor": {
"__type__": "cc.Color",
"r": 211,
"g": 211,
"b": 211,
"a": 255
},
"_N$hoverColor": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"hoverColor": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_N$disabledColor": {
"__type__": "cc.Color",
"r": 124,
"g": 124,
"b": 124,
"a": 255
},
"_N$normalSprite": null,
"_N$pressedSprite": null,
"pressedSprite": null,
"_N$hoverSprite": null,
"hoverSprite": null,
"_N$disabledSprite": null,
"_N$target": null,
"_id": "d04RQHZHxPybDpAuSOHyVz"
},
{
"__type__": "cc.Node",
"_name": "kdh",
...
...
@@ -613,14 +684,14 @@
"_children": [],
"_active": true,
"_components": [
{
"__id__": 13
},
{
"__id__": 14
},
{
"__id__": 15
},
{
"__id__": 16
}
],
"_prefab": null,
...
...
@@ -676,7 +747,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 1
2
"__id__": 1
3
},
"_enabled": true,
"_materials": [
...
...
@@ -708,7 +779,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 1
2
"__id__": 1
3
},
"_enabled": true,
"alignMode": 1,
...
...
@@ -735,7 +806,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 1
2
"__id__": 1
3
},
"_enabled": true,
"_normalMaterial": null,
...
...
@@ -796,7 +867,7 @@
"hoverSprite": null,
"_N$disabledSprite": null,
"_N$target": {
"__id__": 1
2
"__id__": 1
3
},
"_id": "3cl54y78pGh7GzyRwC6XUa"
},
...
...
@@ -810,14 +881,14 @@
"_children": [],
"_active": true,
"_components": [
{
"__id__": 17
},
{
"__id__": 18
},
{
"__id__": 19
},
{
"__id__": 20
}
],
"_prefab": null,
...
...
@@ -873,7 +944,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 1
6
"__id__": 1
7
},
"_enabled": true,
"_materials": [
...
...
@@ -905,7 +976,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 1
6
"__id__": 1
7
},
"_enabled": true,
"alignMode": 1,
...
...
@@ -932,7 +1003,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 1
6
"__id__": 1
7
},
"_enabled": true,
"_normalMaterial": null,
...
...
@@ -993,7 +1064,7 @@
"hoverSprite": null,
"_N$disabledSprite": null,
"_N$target": {
"__id__": 1
6
"__id__": 1
7
},
"_id": "6acK64wVhOAbLiZEmUtwWJ"
},
...
...
@@ -1007,14 +1078,14 @@
"_children": [],
"_active": true,
"_components": [
{
"__id__": 21
},
{
"__id__": 22
},
{
"__id__": 23
},
{
"__id__": 24
}
],
"_prefab": null,
...
...
@@ -1070,7 +1141,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 2
0
"__id__": 2
1
},
"_enabled": true,
"_materials": [
...
...
@@ -1102,7 +1173,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 2
0
"__id__": 2
1
},
"_enabled": true,
"alignMode": 1,
...
...
@@ -1129,7 +1200,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 2
0
"__id__": 2
1
},
"_enabled": true,
"_normalMaterial": null,
...
...
@@ -1190,7 +1261,7 @@
"hoverSprite": null,
"_N$disabledSprite": null,
"_N$target": {
"__id__": 2
0
"__id__": 2
1
},
"_id": "29RvRx27JGjoTI88DWu+TZ"
},
...
...
@@ -1228,11 +1299,18 @@
"_parent": {
"__id__": 5
},
"_children": [],
"_children": [
{
"__id__": 27
}
],
"_active": true,
"_components": [
{
"__id__": 26
"__id__": 30
},
{
"__id__": 31
}
],
"_prefab": null,
...
...
@@ -1259,7 +1337,7 @@
"ctor": "Float64Array",
"array": [
-352.121,
0
,
-22.620000000000005
,
0,
0,
0,
...
...
@@ -1283,12 +1361,134 @@
"groupIndex": 0,
"_id": "fcQ83I201BUYpiHw346tT3"
},
{
"__type__": "cc.Node",
"_name": "img",
"_objFlags": 0,
"_parent": {
"__id__": 26
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 28
},
{
"__id__": 29
}
],
"_prefab": null,
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 450,
"height": 600
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_trs": {
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
0,
0,
0,
0,
0,
0,
1,
1,
1,
1
]
},
"_eulerAngles": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_skewX": 0,
"_skewY": 0,
"_is3DNode": false,
"_groupIndex": 0,
"groupIndex": 0,
"_id": "e5h0lC/1BGkJL1Gf3DHZYT"
},
{
"__type__": "cc.Sprite",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 27
},
"_enabled": true,
"_materials": [
{
"__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432"
}
],
"_srcBlendFactor": 770,
"_dstBlendFactor": 771,
"_spriteFrame": null,
"_type": 0,
"_sizeMode": 0,
"_fillType": 0,
"_fillCenter": {
"__type__": "cc.Vec2",
"x": 0,
"y": 0
},
"_fillStart": 0,
"_fillRange": 0,
"_isTrimmedMode": true,
"_atlas": null,
"_id": "0eG74YtohBhZ1H/s1qWRry"
},
{
"__type__": "cc.Widget",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 25
"__id__": 27
},
"_enabled": true,
"alignMode": 1,
"_target": null,
"_alignFlags": 4,
"_left": 0,
"_right": 0,
"_top": 0,
"_bottom": 0,
"_verticalCenter": 0,
"_horizontalCenter": 0,
"_isAbsLeft": true,
"_isAbsRight": true,
"_isAbsTop": true,
"_isAbsBottom": true,
"_isAbsHorizontalCenter": true,
"_isAbsVerticalCenter": true,
"_originalWidth": 0,
"_originalHeight": 600,
"_id": "c2dWn0ot1HfKzkaAnWRszt"
},
{
"__type__": "cc.Widget",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 26
},
"_enabled": true,
"alignMode": 1,
...
...
@@ -1296,8 +1496,8 @@
"_alignFlags": 13,
"_left": 62.87900000000002,
"_right": 0,
"_top":
60
,
"_bottom":
60
,
"_top":
82.62000000000003
,
"_bottom":
37.37999999999998
,
"_verticalCenter": 0,
"_horizontalCenter": 0,
"_isAbsLeft": true,
...
...
@@ -1310,6 +1510,74 @@
"_originalHeight": 600,
"_id": "f95qipqS9MPYtPkUAMbgiy"
},
{
"__type__": "cc.Button",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 26
},
"_enabled": true,
"_normalMaterial": null,
"_grayMaterial": null,
"duration": 0.1,
"zoomScale": 1.2,
"clickEvents": [],
"_N$interactable": true,
"_N$enableAutoGrayEffect": false,
"_N$transition": 0,
"transition": 0,
"_N$normalColor": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_N$pressedColor": {
"__type__": "cc.Color",
"r": 211,
"g": 211,
"b": 211,
"a": 255
},
"pressedColor": {
"__type__": "cc.Color",
"r": 211,
"g": 211,
"b": 211,
"a": 255
},
"_N$hoverColor": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"hoverColor": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_N$disabledColor": {
"__type__": "cc.Color",
"r": 124,
"g": 124,
"b": 124,
"a": 255
},
"_N$normalSprite": null,
"_N$pressedSprite": null,
"pressedSprite": null,
"_N$hoverSprite": null,
"hoverSprite": null,
"_N$disabledSprite": null,
"_N$target": null,
"_id": "35Ie+Ps3JKGYyMtZ//QWPt"
},
{
"__type__": "cc.Sprite",
"_name": "",
...
...
assets/NJ_BookTable/scene/NJ_BookTable.ts
View file @
412543e3
import
{
asyncDelay
,
onHomeworkFinish
}
from
"
../script/util
"
;
import
{
asyncDelay
,
playAudioByUrl
,
asyncGetSpriteFrimeByUrl
,
buttonOnClick
}
from
"
../script/util
"
;
import
{
MyCocosSceneComponent
}
from
"
../script/MyCocosSceneComponent
"
;
const
{
ccclass
,
property
}
=
cc
.
_decorator
;
...
...
@@ -7,14 +7,12 @@ const { ccclass, property } = cc._decorator;
export
default
class
SceneComponent
extends
MyCocosSceneComponent
{
addPreloadImage
()
{
// TODO 根据自己的配置预加载图片资源
// this._imageResList.push({ url: this.data.pic_url });
// this._imageResList.push({ url: this.data.pic_url_2 });
this
.
_imageResList
.
push
({
url
:
this
.
data
.
bookImg
});
}
addPreloadAudio
()
{
// TODO 根据自己的配置预加载音频资源
// this._audioResList.push({ url: this.data.audio_url
});
this
.
_audioResList
.
push
({
url
:
this
.
data
.
questionTextAudio
});
this
.
_audioResList
.
push
({
url
:
this
.
data
.
bookAudio
});
}
addPreloadAnima
()
{
...
...
@@ -22,12 +20,59 @@ export default class SceneComponent extends MyCocosSceneComponent {
}
async
onLoadEnd
()
{
// TODO 加载完成后的逻辑写在这里, 下面的代码仅供参考
await
this
.
initView
();
this
.
initListener
();
}
async
initView
()
{
const
levelNode
=
cc
.
find
(
`Canvas/bg/L
${
this
.
data
.
choseLevel
}
`
);
if
(
!
levelNode
)
{
return
;
}
levelNode
.
active
=
true
;
cc
.
find
(
`box/title`
,
levelNode
).
getComponent
(
cc
.
Label
).
string
=
this
.
data
.
title
;
try
{
const
bookImgFrame
:
any
=
await
asyncGetSpriteFrimeByUrl
(
this
.
data
.
bookImg
);
cc
.
find
(
`Canvas/bg/bookImg/img`
).
getComponent
(
cc
.
Sprite
).
spriteFrame
=
bookImgFrame
;
}
catch
(
error
)
{
console
.
error
(
error
);
}
}
initListener
()
{
const
bgButton
=
cc
.
find
(
`Canvas/bg/bookImg`
);
bgButton
.
on
(
'
click
'
,
()
=>
{
playAudioByUrl
(
this
.
data
.
bookAudio
);
});
const
levelNode
=
cc
.
find
(
`Canvas/bg/L
${
this
.
data
.
choseLevel
}
`
);
if
(
!
levelNode
)
{
return
;
}
const
levelButton
=
cc
.
find
(
`box`
,
levelNode
);
levelButton
.
on
(
'
click
'
,
()
=>
{
if
(
levelButton
[
'
cantClick
'
])
{
return
;
}
levelButton
[
'
cantClick
'
]
=
true
;
// TODO 播放骨骼动画
playAudioByUrl
(
this
.
data
.
questionTextAudio
,
()
=>
{
// TODO 更新骨骼动画状态
levelButton
[
'
cantClick
'
]
=
false
;
});
})
buttonOnClick
(
cc
.
find
(
`kdh`
,
levelNode
),
()
=>
{
// TODO 跳转到看动画(第一个课件)
});
buttonOnClick
(
cc
.
find
(
`dgs`
,
levelNode
),
()
=>
{
// TODO 跳转到读故事(第二个课件)
});
buttonOnClick
(
cc
.
find
(
`qpy`
,
levelNode
),
()
=>
{
// TODO 跳转到趣配音(第三个课件)
});
}
...
...
assets/NJ_BookTable/script/MyCocosSceneComponent.ts
View file @
412543e3
...
...
@@ -87,7 +87,7 @@ export class MyCocosSceneComponent extends cc.Component {
preload
()
{
const
preloadArr
=
this
.
_imageResList
.
concat
(
this
.
_audioResList
).
concat
(
this
.
_animaResList
);
cc
.
assetManager
.
loadAny
(
preloadArr
,
null
,
null
,
(
err
,
data
)
=>
{
cc
.
assetManager
.
loadAny
(
preloadArr
,
null
,
null
,
async
(
err
,
data
)
=>
{
if
(
window
&&
window
[
"
air
"
])
{
// window["air"].onCourseInScreen = (next) => {
...
...
@@ -95,7 +95,7 @@ export class MyCocosSceneComponent extends cc.Component {
// this.onLoadEnd();
// next();
// };
this
.
onLoadEnd
();
await
this
.
onLoadEnd
();
window
[
"
air
"
].
hideAirClassLoading
();
}
else
{
this
.
onLoadEnd
();
...
...
assets/NJ_BookTable/script/defaultData.ts
View file @
412543e3
export
const
defaultData
=
{
"
pic_url
"
:
"
http://staging-teach.cdn.ireadabc.com/ed94332a503c31e0908bd4c6923a2665.png
"
,
"
pic_url_2
"
:
"
http://staging-teach.cdn.ireadabc.com/5fb60317ade0195d35ad8034d5370a7f.png
"
,
"
text
"
:
"
This is a test label.
"
,
"
audio_url
"
:
"
http://staging-teach.cdn.ireadabc.com/f47f1d7b5c160fe1c59500d180346240.mp3
"
"
title
"
:
"
猩猩有个苹果。
\n
他想要什么?
"
,
"
questionTextAudio
"
:
"
http://staging-teach.cdn.ireadabc.com/69a71b1cfb979a5e0b32d72c21c55423_l.mp3
"
,
"
audioFileName
"
:
"
胜利音效1.mp3
"
,
"
choseLevel
"
:
"
1
"
,
"
bookImg
"
:
"
http://staging-teach.cdn.ireadabc.com/601b7713313df8ee51c3533ed2e8e63d.png
"
,
"
bookAudio
"
:
"
http://staging-teach.cdn.ireadabc.com/1c923d9ad42a500edceba37a985b49d5_l.mp3
"
,
"
bookAudioFileName
"
:
"
占位音频.mp3
"
}
\ No newline at end of file
assets/NJ_BookTable/script/util.ts
View file @
412543e3
...
...
@@ -94,13 +94,13 @@ export function getScaleRateBy2Node(baseNode, targetNode, maxFlag = true) {
}
}
export
function
getDistance
(
start
,
end
)
{
export
function
getDistance
(
start
,
end
)
{
var
pos
=
cc
.
v2
(
start
.
x
-
end
.
x
,
start
.
y
-
end
.
y
);
var
dis
=
Math
.
sqrt
(
pos
.
x
*
pos
.
x
+
pos
.
y
*
pos
.
y
);
var
dis
=
Math
.
sqrt
(
pos
.
x
*
pos
.
x
+
pos
.
y
*
pos
.
y
);
return
dis
;
}
export
function
playAudioByUrl
(
audio_url
,
cb
=
null
)
{
export
function
playAudioByUrl
(
audio_url
,
cb
=
null
)
{
if
(
audio_url
)
{
cc
.
assetManager
.
loadRemote
(
audio_url
,
(
err
,
audioClip
)
=>
{
const
audioId
=
cc
.
audioEngine
.
play
(
audioClip
,
false
,
0.8
);
...
...
@@ -114,21 +114,21 @@ export function playAudioByUrl(audio_url, cb=null) {
}
export
function
btnClickAnima
(
btn
,
time
=
0.15
,
rate
=
1.05
)
{
export
function
btnClickAnima
(
btn
,
time
=
0.15
,
rate
=
1.05
)
{
btn
.
tmpScale
=
btn
.
scale
;
btn
.
on
(
cc
.
Node
.
EventType
.
TOUCH_START
,
()
=>
{
cc
.
tween
(
btn
)
.
to
(
time
/
2
,
{
scale
:
btn
.
scale
*
rate
})
.
to
(
time
/
2
,
{
scale
:
btn
.
scale
*
rate
})
.
start
()
})
btn
.
on
(
cc
.
Node
.
EventType
.
TOUCH_CANCEL
,
()
=>
{
cc
.
tween
(
btn
)
.
to
(
time
/
2
,
{
scale
:
btn
.
tmpScale
})
.
to
(
time
/
2
,
{
scale
:
btn
.
tmpScale
})
.
start
()
})
btn
.
on
(
cc
.
Node
.
EventType
.
TOUCH_END
,
()
=>
{
cc
.
tween
(
btn
)
.
to
(
time
/
2
,
{
scale
:
btn
.
tmpScale
})
.
to
(
time
/
2
,
{
scale
:
btn
.
tmpScale
})
.
start
()
})
}
...
...
@@ -143,6 +143,19 @@ export function getSpriteFrimeByUrl(url, cb) {
})
}
export
function
asyncGetSpriteFrimeByUrl
(
url
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
cc
.
loader
.
load
({
url
},
(
err
,
img
)
=>
{
if
(
err
){
reject
(
err
);
return
;
}
const
spriteFrame
=
new
cc
.
SpriteFrame
(
img
);
resolve
(
spriteFrame
);
})
});
}
export
function
getSprNode
(
resName
)
{
const
sf
=
cc
.
find
(
'
Canvas/res/img/
'
+
resName
).
getComponent
(
cc
.
Sprite
).
spriteFrame
;
const
node
=
new
cc
.
Node
();
...
...
@@ -179,7 +192,7 @@ export async function asyncDelay(time) {
try
{
cc
.
tween
(
cc
.
find
(
'
Canvas
'
))
.
delay
(
time
)
.
call
(()
=>
{
.
call
(()
=>
{
resolve
(
null
);
})
.
start
();
...
...
@@ -236,7 +249,7 @@ export async function asyncLoadDragonBoneAnime(node, { skeJsonData: { url: skeJs
});
Promise
.
all
([
loadTexture
,
loadTexJsonData
,
loadSkeJsonData
]).
then
(([
texture
,
atlasJson
,
dragonBonesJson
])
=>
{
const
atlas
=
new
dragonBones
.
DragonBonesAtlasAsset
();
const
atlas
:
any
=
new
dragonBones
.
DragonBonesAtlasAsset
();
atlas
.
atlasJson
=
JSON
.
stringify
(
atlasJson
);
atlas
.
texture
=
texture
;
...
...
@@ -246,7 +259,7 @@ export async function asyncLoadDragonBoneAnime(node, { skeJsonData: { url: skeJs
dragonDisplay
.
dragonAtlasAsset
=
atlas
;
dragonDisplay
.
dragonAsset
=
asset
;
let
armatureNames
=
dragonBonesJson
.
armature
.
map
(
data
=>
data
.
name
);
let
armatureNames
=
(
<
any
>
dragonBonesJson
)
.
armature
.
map
(
data
=>
data
.
name
);
if
(
armatureNames
.
length
>
0
)
{
dragonDisplay
.
armatureName
=
armatureNames
[
0
];
...
...
@@ -411,56 +424,112 @@ export function showTrebleFirework(baseNode, rabbonList) {
showFireworks
(
right
);
}
export
function
httpHeadCall
(
requsetUrl
:
string
,
callback
)
{
let
xhr
=
new
XMLHttpRequest
();
console
.
log
(
"
Status: Send Post Request to
"
+
requsetUrl
);
try
{
export
function
onHomeworkFinish
()
{
const
middleLayer
=
cc
.
find
(
'
middleLayer
'
);
if
(
middleLayer
)
{
const
middleLayerComponent
=
middleLayer
.
getComponent
(
'
middleLayer
'
);
if
(
middleLayerComponent
.
role
==
'
student
'
)
{
middleLayerComponent
.
onHomeworkFinish
(()
=>
{
});
}
}
else
{
console
.
log
(
'
onHomeworkFinish
'
);
}
}
export
function
asyncCallNetworkApiGet
(
apiName
,
data
):
Promise
<
any
>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
callNetworkApiGet
(
apiName
,
data
,
(
res
=>
{
resolve
(
res
);
}));
});
}
export
function
asyncCallNetworkApiPost
(
uri
,
data
):
Promise
<
any
>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
callNetworkApiPost
(
uri
,
data
,
(
res
)
=>
{
resolve
(
res
);
});
});
}
export
function
callNetworkApiPost
(
uri
,
data
,
callBack
)
{
const
middleLayer
=
cc
.
find
(
'
middleLayer
'
)?.
getComponent
(
'
middleLayer
'
);
if
(
middleLayer
)
{
middleLayer
.
callNetworkApiPost
(
uri
,
data
,
callBack
);
return
;
}
const
baseUrl
=
'
http://staging-openapi.iteachabc.com
'
;
const
xhr
=
new
XMLHttpRequest
();
const
url
=
`
${
baseUrl
}${
uri
}
`
;
xhr
.
open
(
"
POST
"
,
url
,
true
);
xhr
.
setRequestHeader
(
'
content-type
'
,
'
application/json
'
);
xhr
.
onreadystatechange
=
()
=>
{
try
{
console
.
log
(
'
xhr.readyState:
'
,
xhr
.
readyState
);
if
(
xhr
.
readyState
==
4
)
{
if
((
xhr
.
status
>=
200
&&
xhr
.
status
<
400
))
{
callback
(
true
);
}
else
{
callback
(
false
);
callBack
(
JSON
.
parse
(
xhr
.
responseText
));
}
}
xhr
.
send
(
JSON
.
stringify
(
data
));
}
}
catch
(
e
)
{
console
.
log
(
e
)
export
function
callNetworkApiGet
(
uri
,
data
,
callBack
)
{
const
middleLayer
=
cc
.
find
(
'
middleLayer
'
)?.
getComponent
(
'
middleLayer
'
);
if
(
middleLayer
)
{
middleLayer
.
callNetworkApiGet
(
uri
,
data
,
callBack
);
return
;
}
const
baseUrl
=
'
http://staging-openapi.iteachabc.com
'
;
let
queryStr
=
'
?
'
;
const
params
=
[];
for
(
const
key
in
data
)
{
if
(
Object
.
hasOwnProperty
.
call
(
data
,
key
))
{
params
.
push
(
`
${
key
}
=
${
data
[
key
]}
`
);
}
}
queryStr
+=
params
.
join
(
"
&
"
);
const
xhr
=
new
XMLHttpRequest
();
xhr
.
onreadystatechange
=
()
=>
{
if
(
xhr
.
readyState
==
4
&&
(
xhr
.
status
>=
200
&&
xhr
.
status
<
400
))
{
callBack
(
xhr
.
responseText
);
}
};
xhr
.
open
(
"
HEAD
"
,
requsetUrl
,
true
);
const
url
=
`
${
baseUrl
}${
uri
}${
queryStr
}
`
;
console
.
log
(
'
url =
'
+
url
);
xhr
.
open
(
'
GET
'
,
url
,
true
);
xhr
.
send
();
xhr
.
timeout
=
15000
;
xhr
.
onerror
=
(
e
)
=>
{
callback
(
false
);
};
xhr
.
ontimeout
=
(
e
)
=>
{
callback
(
false
);
};
}
catch
(
e
)
{
console
.
log
(
"
Send Get Request error:
"
,
e
);
}
}
export
function
onHomeworkFinish
(
data
=
""
,
callback
=
()
=>
{}
)
{
export
function
jumpToBundle
(
bundleName
:
string
)
{
const
middleLayer
=
cc
.
find
(
'
middleLayer
'
);
if
(
middleLayer
)
{
const
middleLayerComponent
=
middleLayer
.
getComponent
(
'
middleLayer
'
);
middleLayerComponent
.
onHomeworkFinish
(
callback
,
data
);
middleLayerComponent
.
loadOnlineBundle
(
bundleName
);
}
else
{
console
.
log
(
'
onHomeworkFinish
'
,
JSON
.
stringify
(
data
)
);
console
.
log
(
'
jump to bundle:
'
+
bundleName
);
}
}
export
function
callMiddleLayerFunction
(
apiName
:
string
,
data
:
any
,
callback
:
Function
)
{
export
function
jumpToCourseWare
(
courseWareId
:
number
)
{
const
middleLayer
=
cc
.
find
(
'
middleLayer
'
);
if
(
middleLayer
)
{
const
middleLayerComponent
=
middleLayer
.
getComponent
(
'
middleLayer
'
);
middleLayerComponent
.
callMiddleLayerFunction
(
apiName
,
data
,
callback
);
middleLayerComponent
.
loadOnlineCourseWare
(
courseWareId
);
}
else
{
console
.
log
(
'
callMiddleLayerFunction:
'
+
apiName
);
console
.
log
(
'
jump to CourseWare:
'
+
courseWareId
);
}
}
export
function
buttonOnClick
(
button
:
cc
.
Node
,
callback
:
Function
,
scale
=
1.0
)
{
button
.
on
(
'
click
'
,
()
=>
{
if
(
button
[
'
cantClick
'
])
{
return
;
}
button
[
'
cantClick
'
]
=
true
;
cc
.
tween
(
button
)
.
to
(
0.1
,
{
scale
:
scale
*
1.1
})
.
to
(
0.1
,
{
scale
:
scale
})
.
call
(()
=>
{
button
[
'
cantClick
'
]
=
false
;
callback
&&
callback
();
})
.
start
();
});
}
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