ShareVideoTools.ts
5.86 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
/*
* 分享与视频工具类;
*/
export default class ShareVideoTools {
/**
* @param key
* @param params
*/
static getType(key: ShareVideoKeys): ShareVideoType {
return PCSDK.shareVideo.getType(key.toString());
}
/**
* 普通分享,不进行处理回调
* @param key
* @param params 分享参数
* @param opts 扩展参数
*/
static share(key: ShareVideoKeys, params: any, opts?: any) {
PCSDK.shareVideo.share(key.toString(), params, opts).then(ret => this.handleSuccess(ShareVideoFrom.Share, ret));
}
/**
* 验证分享:可处理成功、失败
* @param key
* @param params
*/
static dispatch(key: ShareVideoKeys, params?: { type?: number, success?: Function, fail?: Function, context?: any }) {
PCSDK.shareVideo.shareDispatch(key.toString(), this.buildParams(params));
}
/**
* 可自定义类型的验证分享:例如后台配的shareVideoKey是分享,但是这个key临时想要看视频,可传递shareVideoType Video类型强制使用视频
* @param shareVideoType
* @param key
* @param params
*/
static dispatchType(shareType: ShareVideoType, key: ShareVideoKeys, params?: { type?: number, success?: Function, fail?: Function, context?: any }) {
PCSDK.shareVideo.dispatchType(shareType, key.toString(), this.buildParams(params));
}
/**
* 对参数进行处理
* @param params
*/
private static buildParams(params: any = {}) {
let { isOveride } = params;
let { success, fail, context } = params;
// 设置成功处理
params = {
...params,
success: (from: ShareVideoFrom, ret) => {
success && success.call(context, from, ret);
this.handleSuccess(from, ret);
}
};
if (isOveride)
// 覆盖:失败默认处理
return {
...params,
fail: (from: ShareVideoFrom, err) => {
fail && fail.call(context, from, err);
}
};
else
// 不覆盖:失败默认处理
return {
...params,
fail: (from: ShareVideoFrom, err) => {
fail && fail.call(context, from, err);
this.handleError(from, err);
}
};
}
/**
* 成功默认处理:分享和视频统计
* @param from 来源
* @param ret?
*/
private static handleSuccess(from: ShareVideoFrom, ret: any | null) {
switch (from) {
case ShareVideoFrom.Share: // 同步分享
case ShareVideoFrom.ShareAysnc: // 异步分享
break;
case ShareVideoFrom.Video: // 看视频
break;
}
}
/**
* 失败默认设置(可覆盖)
* @param from 来源
* @param error: 失败消息对象
*/
private static handleError(from: ShareVideoFrom, error: { code: number, msg: string } | null) {
if (!error) return;
// 开发者自定义处理 error msg
if (error.code) {
// wx.showToast({
// title: error.msg
// });
// ViewManager.I.showModal(ComTipFull, error.msg);
}
}
}
// 分享视频类型(与后台一一对应)
export enum ShareVideoType {
None = -1, // -1无分享无视频
Share = 0, // 0同步分享
ShareAysnc = 1, // 1异步分享
ShareIntegral = 5, // 5分享积分
Video = 2, // 2看视频
VideoToShare = 3, // 3无视频则分享
VideoAndShare = 4, // 4视频和分享(控制分享和视频两个按钮的显示) ,
}
// 分享或者视频来源
export enum ShareVideoFrom {
None, // 无分享
Share, // 同步分享
ShareAysnc, // 异步分享
Video // 看视频
}
// 分享视频keysKeys
export enum ShareVideoKeys {
Forward = <any>'forward', // 右上角三点转发
CoinTip = <any>'coin_tip', // 金币不足弹出框
DiamondDouble = <any>'diamond_double', // 钻石再来一份
SuccessDouble = <any>'success_double', // 成功界面双倍
LevelUpDiamond = <any>'levelup_diamond', // 升级活动钻石
FailRewardDouble = <any>'fail_reward_double' // 失败获得双倍奖励
}
// 分享和视频错误
export enum ShareVideoError {
VideoQuit = 1000, // { code: 1000, msg: '要看完视频哦!' },
VideoFail = 1001, // { code: 1001, msg: '加载视频广告失败!' },
VideoNotOpen = 1002, // { code: 1002, msg: '微信版本过低,暂不支持看视频!' },
VideoPlaying = 1003, // { code: 1003, msg: '正在观看视频中...' },
VideoInvalid = 999, // { code: 999, msg: '视频UID不存在!' },
ShareFail = 1004, // { code: 1004, msg: '失败,发给其他好友试试!' },
ShareSame = 1005, // { code: 1005, msg: '别总骚扰这个群,换个群分享吧!' },
ShareNotGroup = 1006, // { code: 1006, msg: '请分享到群哦!' }
ShareAsyncNotGroup = 1007 // { code: 1007, msg: '分享到群才能领取更多~' }
}