BaseAppSdk.ts
4.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
import AddGoldData from "./sdkData/AddGoldData";
import MyCoinData from "./sdkData/MyCoinData";
import { GoldConfigData } from "./sdkData/GoldConfigData";
/** 返回参数类型 */
interface IAppResult<T> {
/** 错误码 */
code?: number;
/** 返回数据 */
data?: T;
}
export default class BaseAppSdk {
protected _bridge: any;
private netOnArr: Array<Function> = [];
private netOffArr: Array<Function> = [];
private _width: number;
private _height: number;
private _channel: string;
private _version: string;
private _level: number;
public pangolinId: string;
public adnetId: string;
init() {
let conch = window['conch'];
if (conch) {
conch.setNetworkEvtFunction(this.networkEvtFunc.bind(this));
}
this.callApp('setAppCallback', 1, 'AppSdk.onShow()');
this.callApp('setAppCallback', 2, 'AppSdk.onHide()');
this.getSystemInfo();
}
private getSystemInfo() {
this.callAppWithBack(ret => {
console.log('---------------getSystemInfo-------' + JSON.stringify(ret))
let { w, h, versionName, channel, pangolin, adnet, level } = JSON.parse(ret);
this._width = w;
this._height = h;
this._version = versionName;
this._channel = channel;
this.pangolinId = pangolin;
this.adnetId = adnet;
this._level = level;
}, 'getSystemInfo', 0);
}
private onShow() {
// EventCenter.emit(EventEnum.APP_SHOW);
}
private onHide() {
// EventCenter.emit(EventEnum.APP_HIDE);
}
vibrate() {
this.callApp('openSystemFun', 0);
}
hideSplash() {
this.callApp('hideSplash');
}
/**弹出提现 */
withDrawal() {
this.callApp('withDrawal');
}
/**意见反馈 */
feedback() {
this.callApp('feedback');
}
/**
* key 默认0 ,签到 1
*/
personal(key = 0) {
this.callApp('personal', key);
}
/**邀请好友*/
invitation() {
this.callApp('invitation');
}
currentShut(value: number) {
this.callApp('currentShut', value);
}
/**
* 获取金币配表
* @param key 1红包 2 摇一摇红包
*/
async getGameConfig(key: number = 1) {
let result = await this.onCallBack('getGameConfig', key)
GoldConfigData.I.initData(result);
return result;
}
/**
* 要求发放金币
* @param key 1红包
*/
async addGold(key: number = 1) {
let result = await this.onCallBack('addGold', key);
AddGoldData.initData(result);
return result;
}
async myCoin() {
let result = await this.onCallBack('myCoin')
MyCoinData.initData(result);
return result;
}
/**获取当前提现的档位 */
async minWithDrawal() {
let result = await this.onCallBack('minWithDrawal');
if (!Boolean(parseInt(result.code + ''))) {
return parseInt(result.data['money']) * 100;
}
return 0;
}
onCallBack(cmd: string, ...params) {
return new Promise<IAppResult<any[]>>(async (resolve, reject) => {
await this.callAppWithBack(res => {
res = JSON.parse(res)
// res = { code: 1000 }
if (!res.code) {
resolve({ code: res.code, data: res.data });
} else {
resolve({ code: res.code })
}
}, cmd, ...params);
})
}
callApp(cmd: string, ...params) {
}
callAppWithBack(callBack: Function, cmd: string, ...params) {
}
private networkEvtFunc(type: number) {
let funcArr;
if (type == 0) {
funcArr = this.netOffArr;
} else if (type == 5) {
funcArr = this.netOnArr;
}
if (funcArr) {
for (let i = 0; i < funcArr.length; i++) {
funcArr[i]();
}
}
}
onNetOn(func: Function) {
this.netOnArr.push(func);
}
onNetOff(func: Function) {
this.netOffArr.push(func);
}
get level() {
return this._level;
}
get width() {
return this._width;
}
get height() {
return this._height;
}
get version() {
return this._version;
}
get channel() {
return this._channel;
}
protected get bridge() {
return null;
}
protected createClass(name: string) {
return window['PlatformClass'].createClass(name);
}
}