Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
scilla-components
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
劳工
scilla-components
Commits
d0ed027f
Commit
d0ed027f
authored
Apr 18, 2019
by
Stepheno
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(data center)
parent
09c0d0e2
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
67 additions
and
18 deletions
+67
-18
index.ts
src/index.ts
+0
-1
SampleApi.ts
src/net/SampleApi.ts
+4
-3
SamplePollingApi.ts
src/net/SamplePollingApi.ts
+2
-2
index.ts
src/net/index.ts
+0
-1
webService.ts
src/net/webService.ts
+15
-9
registerAllComponents.ts
src/registerAllComponents.ts
+46
-2
No files found.
src/index.ts
View file @
d0ed027f
...
...
@@ -7,6 +7,5 @@ export * from './base';
export
*
from
'./other'
;
export
*
from
'./renderer'
;
export
*
from
'./ui'
;
export
*
from
'./net'
;
export
*
from
'./registerAllComponents'
\ No newline at end of file
src/net/SampleApi.ts
View file @
d0ed027f
...
...
@@ -9,11 +9,11 @@ import ApiComponent from "./ApiComponent";
import
{
callApi
}
from
"./webService"
;
export
default
class
SampleApi
extends
ApiComponent
{
ignoreSuccessField
:
boolean
=
false
;
name
:
string
;
uri
:
string
;
method
:
string
=
'POST'
;
params
:
any
=
{};
ignoreSuccessField
:
boolean
=
false
;
async
callApi
(
name
,
paramsInput
,
...
args
){
if
(
this
.
name
==
name
){
...
...
@@ -36,11 +36,11 @@ export default class SampleApi extends ApiComponent {
utils
.
injectProp
(
params
,
paramsInput
);
}
const
{
uri
,
method
}
=
this
;
const
{
uri
,
method
,
name
}
=
this
;
try
{
const
response
=
await
callApi
(
uri
,
params
,
method
,
'json'
,
this
.
ignoreSuccessField
);
const
response
=
await
callApi
(
name
,
uri
,
params
,
method
,
'json'
,
this
.
ignoreSuccessField
);
this
.
onGotResponse
(
response
);
...
...
@@ -50,3 +50,4 @@ export default class SampleApi extends ApiComponent {
}
}
}
src/net/SamplePollingApi.ts
View file @
d0ed027f
...
...
@@ -39,10 +39,10 @@ export default class SamplePollingApi extends ApiComponent {
utils
.
injectProp
(
params
,
paramsInput
);
}
const
{
uri
,
method
}
=
this
;
const
{
uri
,
method
,
name
}
=
this
;
try
{
const
response
=
await
polling
(
this
.
successFunc
,
uri
,
params
,
this
.
maxTimes
,
this
.
delay
,
method
);
const
response
=
await
polling
(
name
,
this
.
successFunc
,
uri
,
params
,
this
.
maxTimes
,
this
.
delay
,
method
);
this
.
onGotResponse
(
response
);
...
...
src/net/index.ts
View file @
d0ed027f
export
{
default
as
SampleApi
}
from
'./SampleApi'
\ No newline at end of file
src/net/webService.ts
View file @
d0ed027f
...
...
@@ -3,8 +3,7 @@
* 网络组件
*/
import
{
utils
,
customConfig
}
from
"scilla"
;
import
{
utils
,
customConfig
,
dataCenter
,
dataCenterConfig
}
from
"scilla"
;
/**
* 调用接口
* @param uri
...
...
@@ -12,8 +11,9 @@ import {utils, customConfig} from "scilla";
* @param method
* @param responseType
* @param ignoreSuccessField
* @param name
*/
export
function
callApi
(
uri
:
string
,
params
:
any
=
null
,
method
:
string
=
'post'
,
responseType
=
'json'
,
ignoreSuccessField
=
false
):
Promise
<
any
>
{
export
function
callApi
(
name
:
string
,
uri
:
string
,
params
:
any
=
null
,
method
:
string
=
'post'
,
responseType
=
'json'
,
ignoreSuccessField
=
false
):
Promise
<
any
>
{
let
ts
=
Date
.
now
()
+
Math
.
floor
(
Math
.
random
()
*
9999999
);
let
url
=
uri
.
indexOf
(
'//'
)
===
0
?
uri
:
`
${
uri
}
?_=
${
ts
}
`
;
...
...
@@ -48,7 +48,6 @@ export function callApi(uri: string, params: any = null, method: string = 'post'
const
fetchMethod
=
responseType
==
'jsonp'
?
window
[
'fetchJsonp'
]
:
fetch
;
url
=
baseUrl
?
baseUrl
+
url
:
url
return
fetchMethod
(
url
,
options
)
.
then
((
response
)
=>
{
if
(
response
.
type
===
'opaque'
)
{
...
...
@@ -90,10 +89,16 @@ export function callApi(uri: string, params: any = null, method: string = 'post'
return
Promise
.
reject
();
})
.
then
(
response
=>
{
dataCenter
.
set
(
dataCenterConfig
.
ajax
,
name
,
response
.
origin
)
return
response
})
.
then
(
console
.
log
)
}
/**
* 轮训请求
* @param name
* @param successFunc
* @param maxTimes
* @param delay
...
...
@@ -102,7 +107,7 @@ export function callApi(uri: string, params: any = null, method: string = 'post'
* @param method
* @param responseType
*/
export
function
polling
(
successFunc
,
uri
,
params
,
maxTimes
=
10
,
delay
=
500
,
method
=
'POST'
,
responseType
=
'json'
):
Promise
<
any
>
{
export
function
polling
(
name
,
successFunc
,
uri
,
params
,
maxTimes
=
10
,
delay
=
500
,
method
=
'POST'
,
responseType
=
'json'
):
Promise
<
any
>
{
let
p
=
Promise
.
resolve
();
for
(
let
i
=
0
;
i
<
maxTimes
;
i
++
)
{
...
...
@@ -128,7 +133,7 @@ export function polling(successFunc, uri, params, maxTimes = 10, delay = 500, me
);
function
func
()
{
return
callApi
(
uri
,
params
,
method
,
responseType
).
then
(
return
callApi
(
name
,
uri
,
params
,
method
,
responseType
).
then
(
(
data
)
=>
{
if
(
successFunc
(
data
))
{
lastData
=
data
;
...
...
@@ -144,20 +149,21 @@ export function polling(successFunc, uri, params, maxTimes = 10, delay = 500, me
/**
* 获取token并发送
* @param name
* @param uri
* @param params
* @param method
* @param responseType
*/
export
async
function
getToken
(
uri
:
string
,
params
:
any
,
method
:
string
=
'POST'
,
responseType
:
string
=
'json'
)
{
export
async
function
getToken
(
name
:
string
,
uri
:
string
,
params
:
any
,
method
:
string
=
'POST'
,
responseType
:
string
=
'json'
)
{
if
(
window
[
'getDuibaToken'
])
{
window
[
'getDuibaToken'
](
async
(
tokenObj
:
any
)
=>
{
params
.
token
=
tokenObj
.
token
;
await
this
.
send
(
uri
,
params
,
method
,
responseType
);
await
callApi
(
name
,
uri
,
params
,
method
,
responseType
);
},
()
=>
{
});
}
else
{
await
this
.
send
(
uri
,
params
,
method
,
responseType
);
await
callApi
(
name
,
uri
,
params
,
method
,
responseType
);
}
}
...
...
src/registerAllComponents.ts
View file @
d0ed027f
...
...
@@ -9,12 +9,34 @@ import TouchZoom from './animation/TouchZoom';
import
Wave
from
'./animation/Wave'
;
import
ZoomLoop
from
'./animation/ZoomLoop'
;
import
InteractComponent
from
'./base/InteractComponent'
;
import
ScillaComponent
from
'./base/ScillaComponent'
;
import
TouchInterrupt
from
'./base/TouchInterrupt'
;
import
Transform
from
'./base/Transform'
;
import
AjaxElementComponent
from
'./net/api/hdtool/base/AjaxElementComponent'
;
import
DoJoinComponent
from
'./net/api/hdtool/base/DoJoinComponent'
;
import
GetOrderStatusComponent
from
'./net/api/hdtool/base/GetOrderStatusComponent'
;
import
PrizeDetailComponent
from
'./net/api/hdtool/base/PrizeDetailComponent'
;
import
SubCreditsStatusComponent
from
'./net/api/hdtool/base/SubCreditsStatusComponent'
;
import
DatapashComponent
from
'./net/api/hdtool/game/DatapashComponent'
;
import
GetNgameStartStatusComponent
from
'./net/api/hdtool/game/GetNgameStartStatusComponent'
;
import
NgameManySubmitComponent
from
'./net/api/hdtool/game/NgameManySubmitComponent'
;
import
NgameSubmitComponent
from
'./net/api/hdtool/game/NgameSubmitComponent'
;
import
ResurrectionComponent
from
'./net/api/hdtool/game/ResurrectionComponent'
;
import
ResurrectionStatusComponent
from
'./net/api/hdtool/game/ResurrectionStatusComponent'
;
import
GetGameOrderInfoComponent
from
'./net/api/hdtool/preLottery/GetGameOrderInfoComponent'
;
import
GetGameSubmitComponent
from
'./net/api/hdtool/preLottery/GetGameSubmitComponent'
;
import
CheckOutAnswerComponent
from
'./net/api/hdtool/question/CheckOutAnswerComponent'
;
import
GetQuestionComponent
from
'./net/api/hdtool/question/GetQuestionComponent'
;
import
QuestionSubmitComponent
from
'./net/api/hdtool/question/QuestionSubmitComponent'
;
import
AjaxThroughInfoComponent
from
'./net/api/hdtool/throughGame/AjaxThroughInfoComponent'
;
import
ThroughSubmitComponent
from
'./net/api/hdtool/throughGame/ThroughSubmitComponent'
;
import
ApiComponent
from
'./net/ApiComponent'
;
import
SampleApi
from
'./net/SampleApi'
;
import
SamplePollingApi
from
'./net/SamplePollingApi'
;
import
CameraController
from
'./other/CameraController'
;
import
ContentSizeFitter
from
'./other/ContentSizeFitter'
;
import
RelativeLayout
from
'./other/RelativeLayout'
;
import
FullStageSize
from
'./other/FullStageSize'
;
import
RelativeLayout
from
'./other/RelativeLayout'
;
import
CircleRenderer
from
'./renderer/CircleRenderer'
;
import
FrameAnimationRenderer
from
'./renderer/FrameAnimationRenderer'
;
import
GraphicRenderer
from
'./renderer/GraphicRenderer'
;
...
...
@@ -37,12 +59,34 @@ export function registerAllComponents(){
registerDef
(
'components/animation/Wave'
,
Wave
);
registerDef
(
'components/animation/ZoomLoop'
,
ZoomLoop
);
registerDef
(
'components/base/InteractComponent'
,
InteractComponent
);
registerDef
(
'components/base/ScillaComponent'
,
ScillaComponent
);
registerDef
(
'components/base/TouchInterrupt'
,
TouchInterrupt
);
registerDef
(
'components/base/Transform'
,
Transform
);
registerDef
(
'components/net/api/hdtool/base/AjaxElementComponent'
,
AjaxElementComponent
);
registerDef
(
'components/net/api/hdtool/base/DoJoinComponent'
,
DoJoinComponent
);
registerDef
(
'components/net/api/hdtool/base/GetOrderStatusComponent'
,
GetOrderStatusComponent
);
registerDef
(
'components/net/api/hdtool/base/PrizeDetailComponent'
,
PrizeDetailComponent
);
registerDef
(
'components/net/api/hdtool/base/SubCreditsStatusComponent'
,
SubCreditsStatusComponent
);
registerDef
(
'components/net/api/hdtool/game/DatapashComponent'
,
DatapashComponent
);
registerDef
(
'components/net/api/hdtool/game/GetNgameStartStatusComponent'
,
GetNgameStartStatusComponent
);
registerDef
(
'components/net/api/hdtool/game/NgameManySubmitComponent'
,
NgameManySubmitComponent
);
registerDef
(
'components/net/api/hdtool/game/NgameSubmitComponent'
,
NgameSubmitComponent
);
registerDef
(
'components/net/api/hdtool/game/ResurrectionComponent'
,
ResurrectionComponent
);
registerDef
(
'components/net/api/hdtool/game/ResurrectionStatusComponent'
,
ResurrectionStatusComponent
);
registerDef
(
'components/net/api/hdtool/preLottery/GetGameOrderInfoComponent'
,
GetGameOrderInfoComponent
);
registerDef
(
'components/net/api/hdtool/preLottery/GetGameSubmitComponent'
,
GetGameSubmitComponent
);
registerDef
(
'components/net/api/hdtool/question/CheckOutAnswerComponent'
,
CheckOutAnswerComponent
);
registerDef
(
'components/net/api/hdtool/question/GetQuestionComponent'
,
GetQuestionComponent
);
registerDef
(
'components/net/api/hdtool/question/QuestionSubmitComponent'
,
QuestionSubmitComponent
);
registerDef
(
'components/net/api/hdtool/throughGame/AjaxThroughInfoComponent'
,
AjaxThroughInfoComponent
);
registerDef
(
'components/net/api/hdtool/throughGame/ThroughSubmitComponent'
,
ThroughSubmitComponent
);
registerDef
(
'components/net/ApiComponent'
,
ApiComponent
);
registerDef
(
'components/net/SampleApi'
,
SampleApi
);
registerDef
(
'components/net/SamplePollingApi'
,
SamplePollingApi
);
registerDef
(
'components/other/CameraController'
,
CameraController
);
registerDef
(
'components/other/ContentSizeFitter'
,
ContentSizeFitter
);
registerDef
(
'components/other/RelativeLayout'
,
RelativeLayout
);
registerDef
(
'components/other/FullStageSize'
,
FullStageSize
);
registerDef
(
'components/other/RelativeLayout'
,
RelativeLayout
);
registerDef
(
'components/renderer/CircleRenderer'
,
CircleRenderer
);
registerDef
(
'components/renderer/FrameAnimationRenderer'
,
FrameAnimationRenderer
);
registerDef
(
'components/renderer/GraphicRenderer'
,
GraphicRenderer
);
...
...
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