inviteInfo.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // Learn cc.Class:
  2. // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/class.html
  3. // - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/class.html
  4. // Learn Attribute:
  5. // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
  6. // - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/reference/attributes.html
  7. // Learn life-cycle callbacks:
  8. // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
  9. // - [English] https://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html
  10. cc.Class({
  11. extends: cc.Component,
  12. properties: {
  13. myInviteValue: {
  14. default: null,
  15. type: cc.Label // optional, default is typeof default
  16. },
  17. parentInviteValue: {
  18. default: null,
  19. type: cc.Label // optional, default is typeof default
  20. },
  21. inputInviteValue:'',
  22. },
  23. // LIFE-CYCLE CALLBACKS:
  24. // onLoad () {},
  25. start() {
  26. this.myInviteValue.string = GlobalD.Dapp.UserInfo.invite_code;
  27. if (GlobalD.Dapp.UserInfo.parent) {
  28. this.parentInviteValue.string = GlobalD.Dapp.UserInfo.parent;
  29. }
  30. },
  31. inputInvite(value,e){
  32. console.log(value);
  33. this.inputInviteValue = value;
  34. },
  35. onBindInviteInfo() {
  36. console.log('绑定的inputInviteValue:'+ this.inputInviteValue);
  37. GlobalD.dapp.bindParent(this.inputInviteValue).then(( err, res)=>{
  38. if (err === null) {
  39. // 返回成功,见下面消息体
  40. console.log(res)
  41. } else {
  42. //TODO 服务错误
  43. console.log(err)
  44. }
  45. })
  46. },
  47. onClose(){
  48. this.node.active = false;
  49. },
  50. webCopyString(){
  51. console.log('复制');
  52. var input = GlobalD.Dapp.UserInfo.invite_code + '';
  53. const el = document.createElement('textarea');
  54. el.value = input;
  55. el.setAttribute('readonly', '');
  56. el.style.contain = 'strict';
  57. el.style.position = 'absolute';
  58. el.style.left = '-9999px';
  59. el.style.fontSize = '12pt'; // Prevent zooming on iOS
  60. const selection = getSelection();
  61. var originalRange = false;
  62. if (selection.rangeCount > 0) {
  63. originalRange = selection.getRangeAt(0);
  64. }
  65. document.body.appendChild(el);
  66. el.select();
  67. el.selectionStart = 0;
  68. el.selectionEnd = input.length;
  69. var success = false;
  70. try {
  71. success = document.execCommand('copy');
  72. } catch (err) {}
  73. document.body.removeChild(el);
  74. if (originalRange) {
  75. selection.removeAllRanges();
  76. selection.addRange(originalRange);
  77. }
  78. return success;
  79. },
  80. // update (dt) {},
  81. });