Commit 8d5544ffa3b8675ddc03587ebfd3872e638e6a9e

Authored by 宋庆平
1 parent cfd1e4db
Exists in zfb_waibu_linshi

去掉平台代码

sdk/WxHelper.ts
@@ -14,7 +14,7 @@ export class WxHelper { @@ -14,7 +14,7 @@ export class WxHelper {
14 /** 微信用户信息 */ 14 /** 微信用户信息 */
15 public static userInfo: WxUserInfo; 15 public static userInfo: WxUserInfo;
16 public static get isOperable() { 16 public static get isOperable() {
17 - return (cc.sys.platform === cc.sys.WECHAT_GAME || cc.sys.platform === cc.sys.ALIPAY_GAME) 17 + return (typeof wx !== 'undefined' || typeof my != 'undefined')
18 } 18 }
19 19
20 /** 获取设备信息 */ 20 /** 获取设备信息 */
@@ -191,13 +191,13 @@ export class WxHelper { @@ -191,13 +191,13 @@ export class WxHelper {
191 * @param time 关闭时间 191 * @param time 关闭时间
192 */ 192 */
193 public static showToast(msg: string, time: number = 1500) { 193 public static showToast(msg: string, time: number = 1500) {
194 - if (cc.sys.platform === cc.sys.WECHAT_GAME) 194 + if (typeof wx !== 'undefined')
195 wx.showToast({ 195 wx.showToast({
196 title: msg, 196 title: msg,
197 icon: 'none', 197 icon: 'none',
198 duration: time 198 duration: time
199 }) 199 })
200 - else if (cc.sys.platform === cc.sys.ALIPAY_GAME) { 200 + else if (typeof my != 'undefined') {
201 my.showToast({ 201 my.showToast({
202 type: 'none', 202 type: 'none',
203 content: msg, 203 content: msg,
@@ -397,7 +397,7 @@ export class WxHelper { @@ -397,7 +397,7 @@ export class WxHelper {
397 } 397 }
398 398
399 public static setUserWxCloudStorage(data: object) { 399 public static setUserWxCloudStorage(data: object) {
400 - if (cc.sys.platform != cc.sys.WECHAT_GAME || !DataService.I.Authorize) return null; 400 + if (typeof wx == 'undefined' || !DataService.I.Authorize) return null;
401 wx.setUserCloudStorage({ 401 wx.setUserCloudStorage({
402 KVDataList: [{ key: 'data', value: JSON.stringify(data) }], 402 KVDataList: [{ key: 'data', value: JSON.stringify(data) }],
403 success: res => { 403 success: res => {
@@ -413,7 +413,7 @@ export class WxHelper { @@ -413,7 +413,7 @@ export class WxHelper {
413 return WxHelper.isOperable && AlipayApi.I.canUseRank() 413 return WxHelper.isOperable && AlipayApi.I.canUseRank()
414 } 414 }
415 public static getRank(key: string) { 415 public static getRank(key: string) {
416 - if (cc.sys.platform === cc.sys.ALIPAY_GAME) { 416 + if (typeof my != 'undefined') {
417 AlipayApi.I.getRankList(key).then(() => { 417 AlipayApi.I.getRankList(key).then(() => {
418 console.log('success 关闭banner') 418 console.log('success 关闭banner')
419 // BannerManager.I.hideAll(); 419 // BannerManager.I.hideAll();
@@ -425,7 +425,7 @@ export class WxHelper { @@ -425,7 +425,7 @@ export class WxHelper {
425 425
426 } 426 }
427 public static setRankScore(key: string, score: number, updateType?: number) { 427 public static setRankScore(key: string, score: number, updateType?: number) {
428 - if (cc.sys.platform === cc.sys.ALIPAY_GAME) 428 + if (typeof my != 'undefined')
429 AlipayApi.I.setRankScoreData(key, score, updateType); 429 AlipayApi.I.setRankScoreData(key, score, updateType);
430 } 430 }
431 public static async loginWx(isAuthorize: boolean, failFunction?: Function, count?: number, success?: Function): Promise<any> { 431 public static async loginWx(isAuthorize: boolean, failFunction?: Function, count?: number, success?: Function): Promise<any> {
@@ -452,7 +452,7 @@ export class WxHelper { @@ -452,7 +452,7 @@ export class WxHelper {
452 public static goToGameCenter(success: Function, fail: Function) { 452 public static goToGameCenter(success: Function, fail: Function) {
453 //每个游戏跳转游戏中心的url 不一样 453 //每个游戏跳转游戏中心的url 不一样
454 let url = "alipays://platformapi/startapp?appId=2021003125685383&url=https%3A%2F%2Frender.alipay.com%2Fp%2Fyuyan%2F180020010001206617%2Findex.html%3FcaprMode%3Dsync&chInfo=gamesetlattice&sms=YES&appClearTop=false"; 454 let url = "alipays://platformapi/startapp?appId=2021003125685383&url=https%3A%2F%2Frender.alipay.com%2Fp%2Fyuyan%2F180020010001206617%2Findex.html%3FcaprMode%3Dsync&chInfo=gamesetlattice&sms=YES&appClearTop=false";
455 - if (cc.sys.platform === cc.sys.ALIPAY_GAME) { 455 + if (typeof my != 'undefined') {
456 AlipayApi.I.navigateToMiniProgramByScheme(url, success, fail) 456 AlipayApi.I.navigateToMiniProgramByScheme(url, success, fail)
457 } 457 }
458 } 458 }
wxsdk/alipay/AlipayApi.ts
@@ -378,7 +378,7 @@ export default class AlipayApi { @@ -378,7 +378,7 @@ export default class AlipayApi {
378 navigateToMiniProgramByScheme(scheme, success, fail) { 378 navigateToMiniProgramByScheme(scheme, success, fail) {
379 let { params, message } = this.schemeToParams(scheme); 379 let { params, message } = this.schemeToParams(scheme);
380 console.log('params--', { ...params }); 380 console.log('params--', { ...params });
381 - if (cc.sys.platform != cc.sys.ALIPAY_GAME) return 381 + if (typeof my == 'undefined') return
382 if (params) { 382 if (params) {
383 my.navigateToMiniProgram({ ...params, success, fail,}); 383 my.navigateToMiniProgram({ ...params, success, fail,});
384 } else { 384 } else {
@@ -585,7 +585,7 @@ export default class AlipayApi { @@ -585,7 +585,7 @@ export default class AlipayApi {
585 //段位 585 //段位
586 setRankSegmentData(rankKey: string, segment: number, segmentName: string) { 586 setRankSegmentData(rankKey: string, segment: number, segmentName: string) {
587 return new Promise((resolve, reject) => { 587 return new Promise((resolve, reject) => {
588 - if (cc.sys.platform != cc.sys.ALIPAY_GAME) return reject({ errMsg: `无环境`, errCode: -1 }) 588 + if (typeof my == 'undefined') return reject({ errMsg: `无环境`, errCode: -1 })
589 if (!this.canIUse('10.5.6')) return reject(this.getVersionError('10.5.6')); 589 if (!this.canIUse('10.5.6')) return reject(this.getVersionError('10.5.6'));
590 my.setImRankData({ 590 my.setImRankData({
591 rankId: rankKey, 591 rankId: rankKey,
@@ -611,7 +611,7 @@ export default class AlipayApi { @@ -611,7 +611,7 @@ export default class AlipayApi {
611 setRankScoreData(rankKey: string, score: number, updateType: number = 1) { 611 setRankScoreData(rankKey: string, score: number, updateType: number = 1) {
612 612
613 return new Promise((resolve, reject) => { 613 return new Promise((resolve, reject) => {
614 - if (cc.sys.platform != cc.sys.ALIPAY_GAME) return reject({ errMsg: `无环境`, errCode: -1 }) 614 + if (typeof my == 'undefined') return reject({ errMsg: `无环境`, errCode: -1 })
615 if (!this.canIUse(this._requirementVersion.rank)) return reject(this.getVersionError(this._requirementVersion.rank)); 615 if (!this.canIUse(this._requirementVersion.rank)) return reject(this.getVersionError(this._requirementVersion.rank));
616 my.setImRankData({ 616 my.setImRankData({
617 rankId: rankKey, 617 rankId: rankKey,
@@ -645,7 +645,7 @@ export default class AlipayApi { @@ -645,7 +645,7 @@ export default class AlipayApi {
645 */ 645 */
646 getRankList(rankKey: string, scorePrefix?: string, scoreSuffix?: string) { 646 getRankList(rankKey: string, scorePrefix?: string, scoreSuffix?: string) {
647 return new Promise((resolve, reject) => { 647 return new Promise((resolve, reject) => {
648 - if (cc.sys.platform != cc.sys.ALIPAY_GAME) return reject({ errMsg: `无环境`, errCode: -1 }) 648 + if (typeof my == 'undefined') return reject({ errMsg: `无环境`, errCode: -1 })
649 if (!this.canIUse(this._requirementVersion.rank)) return reject(this.getVersionError(this._requirementVersion.rank)); 649 if (!this.canIUse(this._requirementVersion.rank)) return reject(this.getVersionError(this._requirementVersion.rank));
650 my.getImRankList({ 650 my.getImRankList({
651 rankId: rankKey, 651 rankId: rankKey,
wxsdk/base/wx.d.ts
@@ -2,3 +2,4 @@ @@ -2,3 +2,4 @@
2 declare const wx; 2 declare const wx;
3 declare const qq; 3 declare const qq;
4 declare const my; 4 declare const my;
  5 +declare const tt;
wxsdk/service/AdService.ts
@@ -20,11 +20,11 @@ export default class AdService { @@ -20,11 +20,11 @@ export default class AdService {
20 */ 20 */
21 createBanner(adUnitId: string, opts?: { type?: number; bannerWidth?: number, offsetY?: number; adIntervals?: number, isOff?: boolean }) { 21 createBanner(adUnitId: string, opts?: { type?: number; bannerWidth?: number, offsetY?: number; adIntervals?: number, isOff?: boolean }) {
22 22
23 - if (cc.sys.platform === cc.sys.BYTEDANCE_GAME) { 23 + if (typeof tt != 'undefined') {
24 return null 24 return null
25 - } else if (cc.sys.platform === cc.sys.ALIPAY_GAME) { 25 + } else if (typeof my != 'undefined') {
26 return AlipayBanner.I.create(adUnitId) 26 return AlipayBanner.I.create(adUnitId)
27 - } else if (cc.sys.platform === cc.sys.WECHAT_GAME) { 27 + } else if (typeof wx !== 'undefined') {
28 return WxBanner.I.create(adUnitId, opts); 28 return WxBanner.I.create(adUnitId, opts);
29 } 29 }
30 } 30 }
@@ -32,11 +32,11 @@ export default class AdService { @@ -32,11 +32,11 @@ export default class AdService {
32 * banner 显示 ps:创建默认显示 32 * banner 显示 ps:创建默认显示
33 */ 33 */
34 showBanner() { 34 showBanner() {
35 - if (cc.sys.platform === cc.sys.BYTEDANCE_GAME) { 35 + if (typeof tt != 'undefined') {
36 36
37 - } else if (cc.sys.platform === cc.sys.ALIPAY_GAME) { 37 + } else if (typeof my != 'undefined') {
38 AlipayBanner.I.show(); 38 AlipayBanner.I.show();
39 - } else if (cc.sys.platform === cc.sys.WECHAT_GAME) { 39 + } else if (typeof wx !== 'undefined') {
40 WxBanner.I.show(); 40 WxBanner.I.show();
41 } 41 }
42 42
@@ -45,11 +45,11 @@ export default class AdService { @@ -45,11 +45,11 @@ export default class AdService {
45 * banner 隐藏 45 * banner 隐藏
46 */ 46 */
47 hideBanner() { 47 hideBanner() {
48 - if (cc.sys.platform === cc.sys.BYTEDANCE_GAME) { 48 + if (typeof tt != 'undefined') {
49 49
50 - } else if (cc.sys.platform === cc.sys.ALIPAY_GAME) { 50 + } else if (typeof my != 'undefined') {
51 AlipayBanner.I.hide(); 51 AlipayBanner.I.hide();
52 - } else if (cc.sys.platform === cc.sys.WECHAT_GAME) { 52 + } else if (typeof wx !== 'undefined') {
53 WxBanner.I.hide(); 53 WxBanner.I.hide();
54 } 54 }
55 } 55 }
@@ -58,11 +58,11 @@ export default class AdService { @@ -58,11 +58,11 @@ export default class AdService {
58 */ 58 */
59 destoryBanner() { 59 destoryBanner() {
60 60
61 - if (cc.sys.platform === cc.sys.BYTEDANCE_GAME) { 61 + if (typeof tt != 'undefined') {
62 62
63 - } else if (cc.sys.platform === cc.sys.ALIPAY_GAME) { 63 + } else if (typeof my != 'undefined') {
64 AlipayBanner.I.destory(); 64 AlipayBanner.I.destory();
65 - } else if (cc.sys.platform === cc.sys.WECHAT_GAME) { 65 + } else if (typeof wx !== 'undefined') {
66 WxBanner.I.destory(); 66 WxBanner.I.destory();
67 } 67 }
68 } 68 }
@@ -72,11 +72,11 @@ export default class AdService { @@ -72,11 +72,11 @@ export default class AdService {
72 * @param adUnitId 72 * @param adUnitId
73 */ 73 */
74 initInterstitialAd(adUnitId?: string) { 74 initInterstitialAd(adUnitId?: string) {
75 - if (cc.sys.platform === cc.sys.BYTEDANCE_GAME) { 75 + if (typeof tt != 'undefined') {
76 // return DouyinInterstitial.initInterstitialAd(adUnitId); 76 // return DouyinInterstitial.initInterstitialAd(adUnitId);
77 - } else if (cc.sys.platform === cc.sys.ALIPAY_GAME) { 77 + } else if (typeof my != 'undefined') {
78 AlipayInterstitial.initInterstitialAd(adUnitId) 78 AlipayInterstitial.initInterstitialAd(adUnitId)
79 - } else if (cc.sys.platform === cc.sys.WECHAT_GAME) { 79 + } else if (typeof wx !== 'undefined') {
80 return WxInterstitial.initInterstitialAd(adUnitId) 80 return WxInterstitial.initInterstitialAd(adUnitId)
81 } 81 }
82 } 82 }
@@ -87,11 +87,11 @@ export default class AdService { @@ -87,11 +87,11 @@ export default class AdService {
87 createInterstitialAd(adUnitId: string) { 87 createInterstitialAd(adUnitId: string) {
88 console.log('~~~~~~~~~~~插屏'); 88 console.log('~~~~~~~~~~~插屏');
89 // return WxInterstitial.showInterstitialAd(adUnitId) 89 // return WxInterstitial.showInterstitialAd(adUnitId)
90 - if (cc.sys.platform === cc.sys.BYTEDANCE_GAME) { 90 + if (typeof tt != 'undefined') {
91 // return DouyinInterstitial.initInterstitialAd(adUnitId); 91 // return DouyinInterstitial.initInterstitialAd(adUnitId);
92 - } else if (cc.sys.platform === cc.sys.ALIPAY_GAME) { 92 + } else if (typeof my != 'undefined') {
93 AlipayInterstitial.showInterstitialAd(adUnitId) 93 AlipayInterstitial.showInterstitialAd(adUnitId)
94 - } else if (cc.sys.platform === cc.sys.WECHAT_GAME) { 94 + } else if (typeof wx !== 'undefined') {
95 return WxInterstitial.showInterstitialAd(adUnitId) 95 return WxInterstitial.showInterstitialAd(adUnitId)
96 } 96 }
97 } 97 }
@@ -130,10 +130,10 @@ export default class AdService { @@ -130,10 +130,10 @@ export default class AdService {
130 let { id, appid, path, game } = data; 130 let { id, appid, path, game } = data;
131 LogService.I.jumps(id, type); 131 LogService.I.jumps(id, type);
132 if (!path) path = `?channel_id=${GAMEDATA.channel_id}`; 132 if (!path) path = `?channel_id=${GAMEDATA.channel_id}`;
133 - if (cc.sys.platform === cc.sys.BYTEDANCE_GAME) {  
134 - } else if (cc.sys.platform === cc.sys.ALIPAY_GAME) { 133 + if (typeof tt != 'undefined') {
  134 + } else if (typeof my != 'undefined') {
135 return AlipayApi.I.navigateToMiniProgram(appid, path, opts) 135 return AlipayApi.I.navigateToMiniProgram(appid, path, opts)
136 - } else if (cc.sys.platform === cc.sys.WECHAT_GAME) { 136 + } else if (typeof wx !== 'undefined') {
137 return WxApi.I.navigateToMiniProgram(appid, path, opts) 137 return WxApi.I.navigateToMiniProgram(appid, path, opts)
138 } 138 }
139 139
wxsdk/share/SDKShare.ts
@@ -55,10 +55,10 @@ export default class SDKShare { @@ -55,10 +55,10 @@ export default class SDKShare {
55 LogService.I.share(shareKey, share_id, DOT_SHARE_TYPE.share) 55 LogService.I.share(shareKey, share_id, DOT_SHARE_TYPE.share)
56 } 56 }
57 // 主动拉起转发 57 // 主动拉起转发
58 - if (cc.sys.platform === cc.sys.ALIPAY_GAME) { 58 + if (typeof my != 'undefined') {
59 //模拟分享支付宝上面会失败 59 //模拟分享支付宝上面会失败
60 return AlipayApi.I.shareAppMessage(commonObj, callbackObj) 60 return AlipayApi.I.shareAppMessage(commonObj, callbackObj)
61 - } else if (cc.sys.platform === cc.sys.WECHAT_GAME) { 61 + } else if (typeof wx !== 'undefined') {
62 return wx.shareAppMessage(commonObj); 62 return wx.shareAppMessage(commonObj);
63 } else { 63 } else {
64 return callbackObj.success(); 64 return callbackObj.success();
@@ -83,7 +83,7 @@ export default class SDKShare { @@ -83,7 +83,7 @@ export default class SDKShare {
83 forward(params: any, opts: any = {}) { 83 forward(params: any, opts: any = {}) {
84 let me = this; 84 let me = this;
85 let { title, imageUrl, query, imageUrlId } = params; 85 let { title, imageUrl, query, imageUrlId } = params;
86 - if (cc.sys.platform === cc.sys.ALIPAY_GAME) { 86 + if (typeof my != 'undefined') {
87 my.onShareAppMessage = function () { 87 my.onShareAppMessage = function () {
88 return { 88 return {
89 title: title, 89 title: title,
wxsdk/share/SDKVideo.ts
@@ -179,7 +179,7 @@ export default class SDKVideo { @@ -179,7 +179,7 @@ export default class SDKVideo {
179 try { 179 try {
180 __LOG__ && console.warn("handleLoaded2"); 180 __LOG__ && console.warn("handleLoaded2");
181 LogService.I.adStat(this.videoKey, this.adUnitId, DOT_AD_TYPE.video, DOT_AD_STATUS.show) 181 LogService.I.adStat(this.videoKey, this.adUnitId, DOT_AD_TYPE.video, DOT_AD_STATUS.show)
182 - if (cc.sys.platform === cc.sys.WECHAT_GAME && typeof qq == 'undefined') { 182 + if (typeof wx !== 'undefined' && typeof qq == 'undefined') {
183 if (that.videoAd.isReady()) {//抖音、qq 没有 isReady 183 if (that.videoAd.isReady()) {//抖音、qq 没有 isReady
184 that.show_time = Date.now(); 184 that.show_time = Date.now();
185 await that.videoAd.show(); 185 await that.videoAd.show();
wxsdk/wx/WxLogin.ts
@@ -6,7 +6,6 @@ import WxSystem from &quot;./WxSystem&quot;; @@ -6,7 +6,6 @@ import WxSystem from &quot;./WxSystem&quot;;
6 import DateUtils from "../utils/DateUtils"; 6 import DateUtils from "../utils/DateUtils";
7 import LogService from "../service/LogService"; 7 import LogService from "../service/LogService";
8 import { DOT_SHARE_TYPE } from "../base/SDKEnum"; 8 import { DOT_SHARE_TYPE } from "../base/SDKEnum";
9 -import ShareVideoService from "../service/ShareVideoService";  
10 import OnlineService from "../service/OnlineService"; 9 import OnlineService from "../service/OnlineService";
11 import AlipayApi from '../alipay/AlipayApi'; 10 import AlipayApi from '../alipay/AlipayApi';
12 11
@@ -19,9 +18,7 @@ export default class WxLogin { @@ -19,9 +18,7 @@ export default class WxLogin {
19 */ 18 */
20 async login(isAuthorize: boolean): Promise<any> { 19 async login(isAuthorize: boolean): Promise<any> {
21 20
22 - if (cc.sys.platform === cc.sys.BYTEDANCE_GAME) {  
23 - return  
24 - } else if (cc.sys.platform === cc.sys.ALIPAY_GAME) { 21 + if (typeof my !== 'undefined') {
25 let self = this; 22 let self = this;
26 return new Promise(async (resolve, reject) => { 23 return new Promise(async (resolve, reject) => {
27 if (isAuthorize) { 24 if (isAuthorize) {
@@ -36,7 +33,7 @@ export default class WxLogin { @@ -36,7 +33,7 @@ export default class WxLogin {
36 self.weakLogin({ errCode: 1, msg: '默认未授权登录' }, code, resolve, reject) 33 self.weakLogin({ errCode: 1, msg: '默认未授权登录' }, code, resolve, reject)
37 } 34 }
38 }); 35 });
39 - } else if (cc.sys.platform === cc.sys.WECHAT_GAME) { 36 + } else if (typeof wx !== 'undefined') {
40 return new Promise(async (resolve, reject) => { 37 return new Promise(async (resolve, reject) => {
41 let code = await WxApi.I.login(); 38 let code = await WxApi.I.login();
42 if (isAuthorize) { 39 if (isAuthorize) {