rankUI.ts 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // Learn TypeScript:
  2. // - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
  3. // Learn Attribute:
  4. // - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
  5. // Learn life-cycle callbacks:
  6. // - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html
  7. import LocalData from "../manager/LocalData";
  8. import Plat from "../utils/Palt";
  9. import UIbase from "../utils/UIbase";
  10. import PrefabUtil from "../utils/manager/PrefabUtil";
  11. const { ccclass, property } = cc._decorator;
  12. @ccclass
  13. export default class rankUI extends UIbase {
  14. private static _inst: rankUI;
  15. public static get inst() {
  16. if (this._inst == null) {
  17. let v = cc.instantiate(PrefabUtil.get("rankUI"));
  18. this._inst = v.getComponent(rankUI);
  19. }
  20. return this._inst;
  21. }
  22. @property(cc.SubContextView)
  23. view: cc.SubContextView = null;
  24. public showUI(data?: any): void {
  25. super.showUI(data)
  26. Plat.setRank(LocalData.lv)
  27. Plat.updateRank()
  28. }
  29. // update (dt) {}
  30. protected onShow(): void {
  31. wx.getSetting({
  32. success(res) {
  33. if (!res.authSetting['scope.userInfo']) {
  34. wx.authorize({
  35. scope: 'scope.userInfo',
  36. success() {
  37. console.error('用户已经同意授权,可以调用 getUserCloudStorage 方法');
  38. // // 用户已经同意授权,可以调用 getUserCloudStorage 方法
  39. // wx.getUserCloudStorage({
  40. // keyList: ['score'],
  41. // success: (kvData) => {
  42. // if (kvData.KVDataList && kvData.KVDataList.length > 0) {
  43. // let level = Number(kvData.KVDataList[0].value)
  44. // if (level < data.level) {
  45. // wx.setUserCloudStorage({
  46. // KVDataList: [{
  47. // key: 'score',
  48. // value: String(data.level)
  49. // }],
  50. // success: () => {
  51. // console.log('设置分数完成' + data.level)
  52. // }
  53. // })
  54. // } else {
  55. // console.log('设置的分数比最高分数低', level, data.level)
  56. // }
  57. // } else {
  58. // // 处理没有找到 score 数据的情况
  59. // }
  60. // }
  61. // })
  62. },
  63. fail() {
  64. // 用户拒绝授权,你可以提示用户授权的重要性或提供其他操作选项
  65. console.error('用户拒绝授权');
  66. }
  67. })
  68. } else {
  69. // 用户已经授权,可以直接调用 getUserCloudStorage 方法
  70. console.error('222用户已经授权,可以调用 getUserCloudStorage 方法');
  71. }
  72. }
  73. })
  74. }
  75. }