Commit b9fc064ccf1e3c593fddc7fdcf69297f1cb2c309
1 parent
fafd085a
Exists in
master
1
Showing
3 changed files
with
0 additions
and
199 deletions
Show diff stats
No preview for this file type
tools/sdk-share-tools-1.0.1/SDKTools.ts
| ... | ... | @@ -1,49 +0,0 @@ |
| 1 | -import ShareVideoTools, { ShareVideoKeys, ShareVideoType } from "./ShareVideoTools"; | |
| 2 | - | |
| 3 | -/* | |
| 4 | -* SDK工具类库; | |
| 5 | -*/ | |
| 6 | -export default class SDKTools { | |
| 7 | - // 判断PCSDK是否支持 | |
| 8 | - static get isSupported() { | |
| 9 | - return typeof PCSDK === 'object'; | |
| 10 | - } | |
| 11 | - | |
| 12 | - /** | |
| 13 | - * 检测普通不是返回值为Promise的 api接口:在浏览器中或其他不支持的平台不至于报错 | |
| 14 | - * @param callback 接口 api函数 | |
| 15 | - * @param defaltVal 返回的默认值 | |
| 16 | - */ | |
| 17 | - private static checkNormal<T>(callback: Function, defaltVal?: T): T { | |
| 18 | - if (!this.isSupported) return defaltVal; | |
| 19 | - return callback(); | |
| 20 | - } | |
| 21 | - | |
| 22 | - /** | |
| 23 | - * 检测普返回值为Promise的 api接口:在浏览器中或其他不支持的平台不至于报错 | |
| 24 | - * @param callback 接口 api函数 | |
| 25 | - * @param defaltVal 返回的默认值 | |
| 26 | - */ | |
| 27 | - private static checkPromise(callback: Function, defaultVal: Promise<any> = Promise.resolve()): Promise<any> { | |
| 28 | - return this.checkNormal<Promise<any>>(callback, defaultVal); | |
| 29 | - } | |
| 30 | - | |
| 31 | - static getType(shareVideoKey: ShareVideoKeys): ShareVideoType { | |
| 32 | - return this.checkNormal(() => ShareVideoTools.getType(shareVideoKey), ShareVideoType.Share); | |
| 33 | - } | |
| 34 | - | |
| 35 | - static share(shareVideoKey: ShareVideoKeys, params?: any, opts?: any): void { | |
| 36 | - return this.checkNormal(() => ShareVideoTools.share(shareVideoKey, params, opts), null); | |
| 37 | - } | |
| 38 | - | |
| 39 | - static dispatch(shareVideoKey: ShareVideoKeys, params?: { type?: number, success?: Function, fail?: Function, context?: any }): void { | |
| 40 | - if (!this.isSupported) | |
| 41 | - return params && params.success && params.success.call(params.context || this); | |
| 42 | - else | |
| 43 | - return this.checkNormal(() => ShareVideoTools.dispatch(shareVideoKey, params), null); | |
| 44 | - } | |
| 45 | - | |
| 46 | - static dispatchType(shareVideoType: ShareVideoType, shareVideoKey: ShareVideoKeys, opts?: { success?: Function, fail?: Function, context?: any }): void { | |
| 47 | - return this.checkNormal(() => ShareVideoTools.dispatchType(shareVideoType, shareVideoKey, opts), null); | |
| 48 | - } | |
| 49 | -} | |
| 50 | 0 | \ No newline at end of file |
tools/sdk-share-tools-1.0.1/ShareVideoTools.ts
| ... | ... | @@ -1,150 +0,0 @@ |
| 1 | -/* | |
| 2 | -* 分享与视频工具类; | |
| 3 | -*/ | |
| 4 | -export default class ShareVideoTools { | |
| 5 | - /** | |
| 6 | - * @param key | |
| 7 | - * @param params | |
| 8 | - */ | |
| 9 | - static getType(key: ShareVideoKeys): ShareVideoType { | |
| 10 | - return PCSDK.shareVideo.getType(key.toString()); | |
| 11 | - } | |
| 12 | - | |
| 13 | - /** | |
| 14 | - * 普通分享,不进行处理回调 | |
| 15 | - * @param key | |
| 16 | - * @param params 分享参数 | |
| 17 | - * @param opts 扩展参数 | |
| 18 | - */ | |
| 19 | - static share(key: ShareVideoKeys, params: any, opts?: any) { | |
| 20 | - PCSDK.shareVideo.share(key.toString(), params, opts).then(ret => this.handleSuccess(ShareVideoFrom.Share, ret)); | |
| 21 | - } | |
| 22 | - | |
| 23 | - /** | |
| 24 | - * 验证分享:可处理成功、失败 | |
| 25 | - * @param key | |
| 26 | - * @param params | |
| 27 | - */ | |
| 28 | - static dispatch(key: ShareVideoKeys, params?: { type?: number, success?: Function, fail?: Function, context?: any }) { | |
| 29 | - PCSDK.shareVideo.shareDispatch(key.toString(), this.buildParams(params)); | |
| 30 | - } | |
| 31 | - | |
| 32 | - /** | |
| 33 | - * 可自定义类型的验证分享:例如后台配的shareVideoKey是分享,但是这个key临时想要看视频,可传递shareVideoType Video类型强制使用视频 | |
| 34 | - * @param shareVideoType | |
| 35 | - * @param key | |
| 36 | - * @param params | |
| 37 | - */ | |
| 38 | - static dispatchType(shareType: ShareVideoType, key: ShareVideoKeys, params?: { type?: number, success?: Function, fail?: Function, context?: any }) { | |
| 39 | - PCSDK.shareVideo.dispatchType(shareType, key.toString(), this.buildParams(params)); | |
| 40 | - } | |
| 41 | - | |
| 42 | - /** | |
| 43 | - * 对参数进行处理 | |
| 44 | - * @param params | |
| 45 | - */ | |
| 46 | - private static buildParams(params: any = {}) { | |
| 47 | - let { isOveride } = params; | |
| 48 | - let { success, fail, context } = params; | |
| 49 | - // 设置成功处理 | |
| 50 | - params = { | |
| 51 | - ...params, | |
| 52 | - success: (from: ShareVideoFrom, ret) => { | |
| 53 | - success && success.call(context, from, ret); | |
| 54 | - this.handleSuccess(from, ret); | |
| 55 | - } | |
| 56 | - }; | |
| 57 | - | |
| 58 | - if (isOveride) | |
| 59 | - // 覆盖:失败默认处理 | |
| 60 | - return { | |
| 61 | - ...params, | |
| 62 | - fail: (from: ShareVideoFrom, err) => { | |
| 63 | - fail && fail.call(context, from, err); | |
| 64 | - } | |
| 65 | - }; | |
| 66 | - else | |
| 67 | - // 不覆盖:失败默认处理 | |
| 68 | - return { | |
| 69 | - ...params, | |
| 70 | - fail: (from: ShareVideoFrom, err) => { | |
| 71 | - fail && fail.call(context, from, err); | |
| 72 | - this.handleError(from, err); | |
| 73 | - } | |
| 74 | - }; | |
| 75 | - } | |
| 76 | - | |
| 77 | - /** | |
| 78 | - * 成功默认处理:分享和视频统计 | |
| 79 | - * @param from 来源 | |
| 80 | - * @param ret? | |
| 81 | - */ | |
| 82 | - private static handleSuccess(from: ShareVideoFrom, ret: any | null) { | |
| 83 | - switch (from) { | |
| 84 | - case ShareVideoFrom.Share: // 同步分享 | |
| 85 | - case ShareVideoFrom.ShareAysnc: // 异步分享 | |
| 86 | - break; | |
| 87 | - | |
| 88 | - case ShareVideoFrom.Video: // 看视频 | |
| 89 | - break; | |
| 90 | - } | |
| 91 | - } | |
| 92 | - | |
| 93 | - /** | |
| 94 | - * 失败默认设置(可覆盖) | |
| 95 | - * @param from 来源 | |
| 96 | - * @param error: 失败消息对象 | |
| 97 | - */ | |
| 98 | - private static handleError(from: ShareVideoFrom, error: { code: number, msg: string } | null) { | |
| 99 | - if (!error) return; | |
| 100 | - // 开发者自定义处理 error msg | |
| 101 | - if (error.code) { | |
| 102 | - // wx.showToast({ | |
| 103 | - // title: error.msg | |
| 104 | - // }); | |
| 105 | - // ViewManager.I.showModal(ComTipFull, error.msg); | |
| 106 | - } | |
| 107 | - } | |
| 108 | -} | |
| 109 | - | |
| 110 | -// 分享视频类型(与后台一一对应) | |
| 111 | -export enum ShareVideoType { | |
| 112 | - None = -1, // -1无分享无视频 | |
| 113 | - Share = 0, // 0同步分享 | |
| 114 | - ShareAysnc = 1, // 1异步分享 | |
| 115 | - ShareIntegral = 5, // 5分享积分 | |
| 116 | - Video = 2, // 2看视频 | |
| 117 | - VideoToShare = 3, // 3无视频则分享 | |
| 118 | - VideoAndShare = 4, // 4视频和分享(控制分享和视频两个按钮的显示) , | |
| 119 | -} | |
| 120 | - | |
| 121 | -// 分享或者视频来源 | |
| 122 | -export enum ShareVideoFrom { | |
| 123 | - None, // 无分享 | |
| 124 | - Share, // 同步分享 | |
| 125 | - ShareAysnc, // 异步分享 | |
| 126 | - Video // 看视频 | |
| 127 | -} | |
| 128 | - | |
| 129 | -// 分享视频keysKeys | |
| 130 | -export enum ShareVideoKeys { | |
| 131 | - Forward = <any>'forward', // 右上角三点转发 | |
| 132 | - CoinTip = <any>'coin_tip', // 金币不足弹出框 | |
| 133 | - DiamondDouble = <any>'diamond_double', // 钻石再来一份 | |
| 134 | - SuccessDouble = <any>'success_double', // 成功界面双倍 | |
| 135 | - LevelUpDiamond = <any>'levelup_diamond', // 升级活动钻石 | |
| 136 | - FailRewardDouble = <any>'fail_reward_double' // 失败获得双倍奖励 | |
| 137 | -} | |
| 138 | - | |
| 139 | -// 分享和视频错误 | |
| 140 | -export enum ShareVideoError { | |
| 141 | - VideoQuit = 1000, // { code: 1000, msg: '要看完视频哦!' }, | |
| 142 | - VideoFail = 1001, // { code: 1001, msg: '加载视频广告失败!' }, | |
| 143 | - VideoNotOpen = 1002, // { code: 1002, msg: '微信版本过低,暂不支持看视频!' }, | |
| 144 | - VideoPlaying = 1003, // { code: 1003, msg: '正在观看视频中...' }, | |
| 145 | - VideoInvalid = 999, // { code: 999, msg: '视频UID不存在!' }, | |
| 146 | - ShareFail = 1004, // { code: 1004, msg: '失败,发给其他好友试试!' }, | |
| 147 | - ShareSame = 1005, // { code: 1005, msg: '别总骚扰这个群,换个群分享吧!' }, | |
| 148 | - ShareNotGroup = 1006, // { code: 1006, msg: '请分享到群哦!' } | |
| 149 | - ShareAsyncNotGroup = 1007 // { code: 1007, msg: '分享到群才能领取更多~' } | |
| 150 | -} | |
| 151 | 0 | \ No newline at end of file |