shareTools.ts
6.84 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
import { UIManager } from "../../framework/core/view/UIManager";
import { AudioManager } from "../../framework/mananger/AudioManager";
import TAMgr from "../../framework/ta/TAMgr";
import WXSDK from "../../framework/wxsdk/WXSDK";
import { EventModels, EventPool } from "../const/EventModels";
import { GameConst } from "../const/GameConst";
import { EActivitySubTaskType, EWindowExitCode, WindowType } from "../const/types";
import { mapController } from "../modules/map/MapController";
import { PayShopManager } from "../modules/server/manager/PayShopManager";
import { shopController } from "../modules/shop/ShopController";
import { Utils } from "../utils/Utils";
import MaskView from "../view/common/MaskView";
import { Analytics } from "./Analytics";
import { Ge } from "./Ge";
import { SDKTools } from "./SDKTools";
import { WxHelper } from "./WxHelper";
/*
* 分享与视频工具类;
*/
export class ShareTools {
/**
* 是否进入分享 onShow有插屏的话用这个判断
*/
public static onShowAd: boolean = false;
public static isTest: boolean = false;
// private static getAdCount() {
// try {
// let adCount = SDKTools.getParamsString("ad_count", '10,10');
// let arr = adCount.split(',').map(Number);
// if (SDKTools.isnew) {
// return +arr[0];
// } else {
// return +arr[1];
// }
// } catch (error) {
// return 10;
// }
// }
/**
* 验证分享:可处理成功、失败
* @param shareKey
* @param params params.fail 有就不处理,没有自动处理
* @param opts 目前支持4个key 1,title自定义分享标题 2,img_url自定义分享图片 3,share_type(不走后台配置写死走视频or分享。1分享2视频3无视频则分享)4,closeSimulate是否关闭模拟分享
*/
static async share(shareKey: string, params?: { success?: Function, fail?: Function, context?: any }, opts?: any) {
const type = this.getShareType(shareKey);
// 免广告卡、体验卡
if ((type == 2 && (!opts || opts.share_type != 1)) || (opts && opts.share_type == 2)) {
if (PayShopManager.I.isExperienceOrNoAd()) {
Analytics.I.dot("video_no_ad", { form: shareKey });
params && params.success && params.success();
return;
} else {
// 非免广告卡、体验卡用户 检查是否买过体验卡
if (PayShopManager.I.checkShowExperience()) {
if (shopController.buyExperienceTips != Utils.getDayTime(0)) {
shopController.buyExperienceTips = Utils.getDayTime(0);;
UIManager.instance.showWindow2(WindowType.ExperienceGiftWindow);
params && params.fail && params.fail();
return;
}
}
}
}
// 广告卡
if (((type == 2 && (!opts || opts.share_type != 1)) || (opts && opts.share_type == 2)) && mapController.getPackageItemNum(GameConst.ITEM_ADCARD_ID) > 0) {
const ret = await UIManager.instance.waitWindow2(WindowType.AdCardWindow);
if (ret == EWindowExitCode.Yes) {
Analytics.I.dot("ad_card", { ad_card: shareKey });
params && params.success && params.success();
return;
}
}
if ((typeof wx == 'undefined'&&typeof my == 'undefined') || this.isTest) {
params && params.success && params.success();
// 分享
const evt = EventPool.get(EventModels.AcitvitySubTaskEvent);
evt.type = EActivitySubTaskType.Share;
evt.centerEmit();
return
}
// // 看广告n次后处理为分享
// let count = this.getAdCount();
// let isClear = false;
// // console.log("改为分享前:", settingsController.videoCount, count);
// if (settingsController.videoCount >= count) {
// if (type != 1 || (opts && opts.share_type == 2)) {// 视频 or // 强制视频
// opts = {
// ...opts,
// share_type: 1,//强制改为分享
// };
// isClear = true;
// // console.log("改为分享了");
// }
// }
this.onShowAd = true;
AudioManager.I.pauseAll();
if (!opts || !opts.closeSimulate) {
MaskView.Show()
}
WXSDK.share.share(shareKey.toString(), params, opts).then(async res => {
this.onShowAd = false;
// if (isClear) {
// settingsController.videoCount = 0;
// }
if (res.type == 2) {
// 视频
// settingsController.videoCount++;
Ge.I.adShowEvent("video", shareKey.toString());
TAMgr.Ins.userAdd({ total_ad_num: 1 });
} else {
// 分享
const evt = EventPool.get(EventModels.AcitvitySubTaskEvent);
evt.type = EActivitySubTaskType.Share;
evt.centerEmit();
TAMgr.Ins.dot('share_source', { from: shareKey });
}
params && params.success && params.success(res);
AudioManager.I.resumeAll();
MaskView.Hide();
}).catch(async err => {
AudioManager.I.resumeAll();
MaskView.Hide();
this.onShowAd = false;
if (!params || !params.fail) {
if (err && err.msg) {
WxHelper.showToast(err.msg)
}
} else {
params && params.fail && params.fail(err);
}
})
}
/**
* 必定视频 不走后台配置
* @param shareKey
* @param params
*/
static video(shareKey: string, params?: { success?: Function, fail?: Function, context?: any }, opts?: any) {
this.share(shareKey, params, { ...opts, share_type: 2 });
}
/**
* 纯净分享 不处理回调
* @param shareKey
*/
static pureShare(shareKey: string, opts = {}) {
this.share(shareKey, {}, { closeSimulate: true, ...opts });
}
/**
* 设置右上角分享key
* @param key
*/
static setForwardKey(key) {
WXSDK.share.setForwardKey(key)
}
/**
* 获取分享还是视频
* @param key
*/
static getShareType(key) {
try {
return WXSDK.share.getType(key)
} catch (err) {
console.log("1")
return 2
}
}
/**
* 分享到朋友圈 bate 只支持安卓
*/
static onShareTimeline(title: string, imageUrl: string, imagePreviewUrl?: string, query?: string) {
WXSDK.share.onShareTimeline(title, imageUrl, imagePreviewUrl, query);
}
}