Commit d0ed027f authored by Stepheno's avatar Stepheno

feat(data center)

parent 09c0d0e2
...@@ -7,6 +7,5 @@ export * from './base'; ...@@ -7,6 +7,5 @@ export * from './base';
export * from './other'; export * from './other';
export * from './renderer'; export * from './renderer';
export * from './ui'; export * from './ui';
export * from './net';
export * from './registerAllComponents' export * from './registerAllComponents'
\ No newline at end of file
...@@ -9,11 +9,11 @@ import ApiComponent from "./ApiComponent"; ...@@ -9,11 +9,11 @@ import ApiComponent from "./ApiComponent";
import {callApi} from "./webService"; import {callApi} from "./webService";
export default class SampleApi extends ApiComponent { export default class SampleApi extends ApiComponent {
ignoreSuccessField: boolean = false;
name: string; name: string;
uri: string; uri: string;
method: string = 'POST'; method: string = 'POST';
params: any = {}; params: any = {};
ignoreSuccessField: boolean = false;
async callApi(name, paramsInput, ...args){ async callApi(name, paramsInput, ...args){
if(this.name == name){ if(this.name == name){
...@@ -36,11 +36,11 @@ export default class SampleApi extends ApiComponent { ...@@ -36,11 +36,11 @@ export default class SampleApi extends ApiComponent {
utils.injectProp(params, paramsInput); utils.injectProp(params, paramsInput);
} }
const {uri, method} = this; const {uri, method, name} = this;
try { 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); this.onGotResponse(response);
...@@ -50,3 +50,4 @@ export default class SampleApi extends ApiComponent { ...@@ -50,3 +50,4 @@ export default class SampleApi extends ApiComponent {
} }
} }
} }
...@@ -39,10 +39,10 @@ export default class SamplePollingApi extends ApiComponent { ...@@ -39,10 +39,10 @@ export default class SamplePollingApi extends ApiComponent {
utils.injectProp(params, paramsInput); utils.injectProp(params, paramsInput);
} }
const {uri, method} = this; const {uri, method, name} = this;
try { 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); this.onGotResponse(response);
......
export { default as SampleApi } from './SampleApi'
\ No newline at end of file
...@@ -3,8 +3,7 @@ ...@@ -3,8 +3,7 @@
* 网络组件 * 网络组件
*/ */
import {utils, customConfig} from "scilla"; import {utils, customConfig, dataCenter, dataCenterConfig} from "scilla";
/** /**
* 调用接口 * 调用接口
* @param uri * @param uri
...@@ -12,8 +11,9 @@ import {utils, customConfig} from "scilla"; ...@@ -12,8 +11,9 @@ import {utils, customConfig} from "scilla";
* @param method * @param method
* @param responseType * @param responseType
* @param ignoreSuccessField * @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 ts = Date.now() + Math.floor(Math.random() * 9999999);
let url = uri.indexOf('//') === 0 ? uri : `${uri}?_=${ts}`; let url = uri.indexOf('//') === 0 ? uri : `${uri}?_=${ts}`;
...@@ -48,7 +48,6 @@ export function callApi(uri: string, params: any = null, method: string = 'post' ...@@ -48,7 +48,6 @@ export function callApi(uri: string, params: any = null, method: string = 'post'
const fetchMethod = responseType == 'jsonp' ? window['fetchJsonp'] : fetch; const fetchMethod = responseType == 'jsonp' ? window['fetchJsonp'] : fetch;
url = baseUrl ? baseUrl + url : url url = baseUrl ? baseUrl + url : url
return fetchMethod(url, options) return fetchMethod(url, options)
.then((response) => { .then((response) => {
if (response.type === 'opaque') { if (response.type === 'opaque') {
...@@ -90,10 +89,16 @@ export function callApi(uri: string, params: any = null, method: string = 'post' ...@@ -90,10 +89,16 @@ export function callApi(uri: string, params: any = null, method: string = 'post'
return Promise.reject(); return Promise.reject();
}) })
.then(response => {
dataCenter.set(dataCenterConfig.ajax, name, response.origin)
return response
})
.then(console.log)
} }
/** /**
* 轮训请求 * 轮训请求
* @param name
* @param successFunc * @param successFunc
* @param maxTimes * @param maxTimes
* @param delay * @param delay
...@@ -102,7 +107,7 @@ export function callApi(uri: string, params: any = null, method: string = 'post' ...@@ -102,7 +107,7 @@ export function callApi(uri: string, params: any = null, method: string = 'post'
* @param method * @param method
* @param responseType * @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(); let p = Promise.resolve();
for (let i = 0; i < maxTimes; i++) { for (let i = 0; i < maxTimes; i++) {
...@@ -128,7 +133,7 @@ export function polling(successFunc, uri, params, maxTimes = 10, delay = 500, me ...@@ -128,7 +133,7 @@ export function polling(successFunc, uri, params, maxTimes = 10, delay = 500, me
); );
function func() { function func() {
return callApi(uri, params, method, responseType).then( return callApi(name, uri, params, method, responseType).then(
(data) => { (data) => {
if (successFunc(data)) { if (successFunc(data)) {
lastData = data; lastData = data;
...@@ -144,20 +149,21 @@ export function polling(successFunc, uri, params, maxTimes = 10, delay = 500, me ...@@ -144,20 +149,21 @@ export function polling(successFunc, uri, params, maxTimes = 10, delay = 500, me
/** /**
* 获取token并发送 * 获取token并发送
* @param name
* @param uri * @param uri
* @param params * @param params
* @param method * @param method
* @param responseType * @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']) { if (window['getDuibaToken']) {
window['getDuibaToken'](async (tokenObj: any) => { window['getDuibaToken'](async (tokenObj: any) => {
params.token = tokenObj.token; params.token = tokenObj.token;
await this.send(uri, params, method, responseType); await callApi(name, uri, params, method, responseType);
}, () => { }, () => {
}); });
} else { } else {
await this.send(uri, params, method, responseType); await callApi(name, uri, params, method, responseType);
} }
} }
......
...@@ -9,12 +9,34 @@ import TouchZoom from './animation/TouchZoom'; ...@@ -9,12 +9,34 @@ import TouchZoom from './animation/TouchZoom';
import Wave from './animation/Wave'; import Wave from './animation/Wave';
import ZoomLoop from './animation/ZoomLoop'; import ZoomLoop from './animation/ZoomLoop';
import InteractComponent from './base/InteractComponent'; import InteractComponent from './base/InteractComponent';
import ScillaComponent from './base/ScillaComponent';
import TouchInterrupt from './base/TouchInterrupt'; import TouchInterrupt from './base/TouchInterrupt';
import Transform from './base/Transform'; 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 CameraController from './other/CameraController';
import ContentSizeFitter from './other/ContentSizeFitter'; import ContentSizeFitter from './other/ContentSizeFitter';
import RelativeLayout from './other/RelativeLayout';
import FullStageSize from './other/FullStageSize'; import FullStageSize from './other/FullStageSize';
import RelativeLayout from './other/RelativeLayout';
import CircleRenderer from './renderer/CircleRenderer'; import CircleRenderer from './renderer/CircleRenderer';
import FrameAnimationRenderer from './renderer/FrameAnimationRenderer'; import FrameAnimationRenderer from './renderer/FrameAnimationRenderer';
import GraphicRenderer from './renderer/GraphicRenderer'; import GraphicRenderer from './renderer/GraphicRenderer';
...@@ -37,12 +59,34 @@ export function registerAllComponents(){ ...@@ -37,12 +59,34 @@ export function registerAllComponents(){
registerDef('components/animation/Wave', Wave); registerDef('components/animation/Wave', Wave);
registerDef('components/animation/ZoomLoop', ZoomLoop); registerDef('components/animation/ZoomLoop', ZoomLoop);
registerDef('components/base/InteractComponent', InteractComponent); registerDef('components/base/InteractComponent', InteractComponent);
registerDef('components/base/ScillaComponent', ScillaComponent);
registerDef('components/base/TouchInterrupt', TouchInterrupt); registerDef('components/base/TouchInterrupt', TouchInterrupt);
registerDef('components/base/Transform', Transform); 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/CameraController', CameraController);
registerDef('components/other/ContentSizeFitter', ContentSizeFitter); registerDef('components/other/ContentSizeFitter', ContentSizeFitter);
registerDef('components/other/RelativeLayout', RelativeLayout);
registerDef('components/other/FullStageSize', FullStageSize); registerDef('components/other/FullStageSize', FullStageSize);
registerDef('components/other/RelativeLayout', RelativeLayout);
registerDef('components/renderer/CircleRenderer', CircleRenderer); registerDef('components/renderer/CircleRenderer', CircleRenderer);
registerDef('components/renderer/FrameAnimationRenderer', FrameAnimationRenderer); registerDef('components/renderer/FrameAnimationRenderer', FrameAnimationRenderer);
registerDef('components/renderer/GraphicRenderer', GraphicRenderer); registerDef('components/renderer/GraphicRenderer', GraphicRenderer);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment