MiniGameApiBase.ts 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. import { Vec2, Node } from "cc";
  2. export interface toastParams {
  3. //属性 类型 默认值 必填 说明
  4. title: string;// 是 提示的内容
  5. icon?: string;// 'success' 否 图标
  6. image?: string;// 否 自定义图标的本地路径,image 的优先级高于 icon 1.1.0
  7. duration?: number;// 1500 否 提示的延迟时间
  8. mask?: boolean;// false 否 是否显示透明蒙层,防止触摸穿透
  9. success?: () => void;// 否 接口调用成功的回调函数
  10. fail?: () => void;// 否 接口调用失败的回调函数
  11. complete?: () => void;// 否 接口调用结束的回调函数(调用成功、失败都会执行
  12. }
  13. export interface loadParams {
  14. //属性 类型 默认值 必填 说明
  15. title: string;// 是 提示的内容
  16. mask?: boolean;// false 否 是否显示透明蒙层,防止触摸穿透
  17. success?: () => void;// 否 接口调用成功的回调函数
  18. fail?: () => void;// 否 接口调用失败的回调函数
  19. complete?: () => void;// 否 接口调用结束的回调函数(调用成功、失败都会执行)
  20. }
  21. export interface ModalParams {
  22. title?: string;// 否 标题 1.0.0
  23. content?: string;// 否 内容 1.0.0
  24. confirmText?: string;// 确定 否 确定按钮的文案,最多 4 个字符 1.0.0
  25. showCancel?: boolean;// true 否 是否显示取消按钮 1.0.0
  26. cancelText?: string;// 取消 否 取消按钮的文案,最多 4 个字符 1.0.0
  27. success?: (result: { errMsg: string, confirm: boolean, cancel: boolean }) => void;// 否 接口调用成功后的回调函数 1.0.0
  28. fail?: (err: { errMsg: string }) => void;// 否 接口调用失败后的回调函数 1.0.0
  29. complete?: () => void;// 否 接口调用结束后的回调函数(调用成功、失败都会执行) 1.0.0
  30. }
  31. export interface authorizeParams {
  32. // 属性 类型 默认值 必填 说明 最低版本
  33. scope?: string; //是 需要获取权限的 scope,详见 scope 列表
  34. success?: () => void; // 否 接口调用成功的回调函数
  35. fail?: () => void; //否 接口调用失败的回调函数
  36. complete?: () => void; //否 接口调用结束的回调函数(调用成功、失败都会执行)
  37. }
  38. export interface loginParams {
  39. // 属性 类型 默认值 必填 说明 最低版本
  40. timeout?: number; // 否 超时时间,单位ms 1.9.90
  41. success?: (res: { code: string }) => void; // 否 接口调用成功的回调函数
  42. fail?: () => void; //否 接口调用失败的回调函数
  43. complete?: () => void; //否 接口调用结束的回调函数(调用成功、失败都会执行)
  44. force?: boolean;
  45. }
  46. export interface UserInfo {
  47. nickName: string; //用户昵称
  48. avatarUrl: string; //用户头像图片的 URL。URL 最后一个数值代表正方形头像大小(有 0、46、64、96、132 数值可选,0 代表 640x640 的正方形头像,46 表示 46x46 的正方形头像,剩余数值以此类推。默认132),用户没有头像时该项为空。若用户更换头像,原有头像 URL 将失效。
  49. gender: number; //gender 的合法值 0 未知 1 男性 2 女性
  50. country: string; //用户所在国家
  51. province: string; //用户所在省份
  52. city: string; //用户所在城市
  53. language: string //显示country,province,city所用的语言 en 英文 zh_CN 简体中文 zh_TW 繁体中文
  54. }
  55. export interface getUserInfoParams {
  56. //属性 类型 默认值 必填 说明
  57. withCredentials?: boolean; // 否 是否带上登录态信息。当 withCredentials 为 true 时,要求此前有调用过 wx.login 且登录态尚未过期,此时返回的数据会包含 encryptedData, iv 等敏感信息;当 withCredentials 为 false 时,不要求有登录态,返回的数据不包含 encryptedData, iv 等敏感信息。
  58. lang?: string; // en 否 显示用户信息的语言
  59. success?: (res: { userInfo: UserInfo }) => void;// 否 接口调用成功的回调函数
  60. fail?: () => void;// 否 接口调用失败的回调函数
  61. complete?: () => void;// 否 接口调用结束的回调函数(调用成功、失败都会执行)
  62. }
  63. export interface recordedGameScreenParams {
  64. //属性 类型 默认值 是否必填 说明 最低版本
  65. duration: number; // 10 否 录屏的时长,单位 s,必须大于 3s,最大值 300s(5 分钟)。
  66. isMarkOpen?: boolean; // true 否 是否添加水印,会在录制出来的视频上添加默认水印,目前不支持自定义水印图案。 1.69.0+
  67. locTop?: number; // 0 否 水印距离屏幕左边界的位置,单位为 dp。 1.69.0+
  68. locLeft?: number; // 0 否 水印距离屏幕上边界的位置,单位为 dp。
  69. frameRate?: number; // 30 否 设置录屏帧率,对于性能较差的手机可以调低参数以降低录屏性能消耗。 1.80.0+
  70. }
  71. export abstract class MiniGameApiBase {
  72. /** 应用ID */
  73. protected abstract m_AppId: string;
  74. /** 密匙 */
  75. protected abstract m_Secret: string;
  76. /** 视频广告索引 */
  77. protected abstract m_VideoAdIdIndex: number;
  78. /** 视频广告列表 */
  79. protected abstract m_VideoAdIdList: string[];
  80. /** banner广告索引 */
  81. protected abstract m_BannerAdIdIndex: number;
  82. /** banner广告ID列表 */
  83. protected abstract m_BannerAdId: string[];
  84. /** 插屏广告索引 */
  85. protected abstract m_InsertAdIdIndex: number;
  86. /** 插屏广告ID列表 */
  87. protected abstract m_InsertAdId: string[];
  88. /** 视频广告组件 */
  89. protected abstract m_videoAd: unknown;
  90. /** banner广告组件 */
  91. protected abstract m_BannerAd: unknown;
  92. /** 判断是否合法APP-ID */
  93. abstract validAppId(): void;
  94. /** api准备 */
  95. abstract ready(): void;
  96. /** 获取用户数据 */
  97. abstract getUserInfo(params: getUserInfoParams): void;
  98. /** 显示提示框 */
  99. abstract showToast(params: toastParams): void;
  100. /** 显示进度框 */
  101. abstract showLoading(params: loadParams): void;
  102. /** 隐藏进度框 */
  103. abstract hideLoading(): void;
  104. /** 显示对话框 */
  105. abstract showModal(params: ModalParams): void;
  106. /** 授权 */
  107. abstract authorize(params: authorizeParams): void;
  108. /** 登录 */
  109. abstract login(params: loginParams): void;
  110. /**
  111. * 加载并显示视频广告
  112. * @param successCB 成功回调
  113. * @param errorCB 失败回调
  114. * @param completeCB 完成回调
  115. * @param reportAnalyticsExplain 成功上报描述
  116. */
  117. abstract loadAndShowVideoAd(successCB: () => void, errorCB?: (error: any) => void,
  118. completeCB?: () => void, reportAnalyticsExplain?: string): void;
  119. /**
  120. * 显示插屏
  121. * @param onAdClose
  122. * @param onFailed
  123. */
  124. abstract showInsertAd(onAdClose: () => void, onFailed: () => void): void;
  125. /** 显示banner广告 */
  126. abstract showBannerAD(node: Node, successCB?: () => void, errorCB?: (error: any) => void, onCloseCB?: () => void, setBannerPos?: ({
  127. screenWidth,
  128. screenHeight
  129. }) => Vec2): void;
  130. /** 隐藏banner广告 */
  131. abstract hideBanner(): void;
  132. /** 录屏开始 */
  133. abstract recordedGameScreenStart(params: recordedGameScreenParams, onStart?: (res) => void): void;
  134. /** 录屏停止 */
  135. abstract recordedGameScreenStop(): boolean;
  136. /** 分享录屏 */
  137. abstract shareRecordedGameScreen(successCb?: () => void, failCb?: (e?) => void): void;
  138. /** 是否有分享录屏 */
  139. abstract isHaveRecordedGameScreen(): boolean;
  140. /** 获取本地数据 */
  141. abstract getStorageSync(key?: string): any;
  142. /** 移除本地数据 */
  143. abstract removeStorage(key?: string): any;
  144. /** 获取设备信息 */
  145. abstract getDeviceInfo(): any;
  146. abstract setUnlockAllTime(time: number): any;
  147. abstract getUnlockAllTime(call: Function): any;
  148. abstract setUnitState(state?: string);
  149. /**
  150. * 打点
  151. * @param eventName 事件名,注意不能超过 110 字符
  152. * @param data 上报的数据 可选 {}
  153. */
  154. abstract reportAnalytics(eventName: string, data?: { [key: string]: number | string | boolean }): any;
  155. abstract setSoundInfo(sound?: boolean, music?: boolean): any;
  156. abstract checkScene(successCB?: Function, errorCB?: Function): any;
  157. abstract navigateToScene(successCB?: Function, errorCB?: Function): any;
  158. abstract getLaunchOptionsSync(): any;
  159. }