DCHandler.ts 827 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import { CocosHandler } from "./CocosHandler";
  2. //数据上报
  3. export class DCHandler {
  4. private static _inst: DCHandler;
  5. public static get inst(): DCHandler {
  6. if (!this._inst) {
  7. this._inst = new DCHandler();
  8. }
  9. return this._inst;
  10. }
  11. //数据上报
  12. async reportData(eventId: number, id?: number) {
  13. let param = {
  14. eventId: eventId,
  15. props: {}
  16. }
  17. if (id) {
  18. param.props = {
  19. id: id
  20. }
  21. }
  22. const data = {
  23. method: 'analytics.event',
  24. param: JSON.stringify(param)
  25. };
  26. const result = await CocosHandler.inst.sendMessageToAndroid(data, '获取数据上报状态');
  27. return JSON.parse(result);
  28. }
  29. }
  30. window["DCHandler"] = DCHandler;