ResultMgr.ts 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. import {_decorator, Color, Component, Label, Node, Sprite, tween, Vec3} from 'cc';
  2. import {UserInfo} from '../../script/UserInfo';
  3. import {HttpUtils} from '../../script/utils/HttpUtils';
  4. const {ccclass, property} = _decorator;
  5. @ccclass('ResultMgr')
  6. export class ResultMgr extends Component {
  7. protected onLoad(): void {
  8. this.node.getChildByName("halo").getChildByName("halo").getComponent(Sprite).fillRange = 0
  9. this.node.getChildByName("Label3").getComponent(Label).string = ""
  10. this.node.getChildByName("Label5").getComponent(Label).string = ""
  11. this.node.getChildByName("Label6").getComponent(Label).string = ""
  12. }
  13. start() {
  14. this.sendData()
  15. if (UserInfo.score <= 0) {
  16. this.node.getChildByName("Label3").getComponent(Label).string = "0"
  17. this.setLabels2()
  18. } else {
  19. this.node.getChildByName("halo").getChildByName("halo").getComponent(Sprite).color = Color.RED
  20. const tw = tween(this.node.getChildByName("halo").getChildByName("halo").getComponent(Sprite)).to(2, {fillRange: 1}, {
  21. onUpdate: (target: Vec3, ratio: number) => {
  22. // console.log("000000= "+ratio);
  23. this.node.getChildByName("Label3").getComponent(Label).string = Math.floor(ratio * 100) + "%"
  24. if (ratio < 0.3) {
  25. this.node.getChildByName("halo").getChildByName("halo").getComponent(Sprite).color = new Color(206, 37, 37, 255)
  26. } else if (ratio > 0.7) {
  27. this.node.getChildByName("halo").getChildByName("halo").getComponent(Sprite).color = new Color(151, 206, 37, 255)
  28. } else {
  29. this.node.getChildByName("halo").getChildByName("halo").getComponent(Sprite).color = new Color(206, 129, 37, 255)
  30. }
  31. if (ratio > UserInfo.totalRight / UserInfo.totalQuestion) {
  32. tw.stop()
  33. this.setLabels2()
  34. }
  35. }
  36. })
  37. .call(() => {
  38. this.setLabels2()
  39. })
  40. .start()
  41. }
  42. }
  43. /**
  44. * 上一个版本的结算数据,现在已经不用了
  45. */
  46. private setLabels() {
  47. this.node.getChildByName("Label5").getComponent(Label).string = UserInfo.aveTime.toFixed(3) + "秒"
  48. // if (UserInfo.score < 20) {
  49. // if (UserInfo.aveTime < 2.5) {
  50. // // this.node.getChildByName("Label6").getComponent(Label).string = "您回答的速度太快了,请在保持速度的同时提高准确率!"
  51. // this.node.getChildByName("Label6").getComponent(Label).string = "您回答的速度太快了,并且准确率太低。建议您找专业医护人员进行检查!"
  52. // } else if (UserInfo.aveTime > 10) {
  53. // this.node.getChildByName("Label6").getComponent(Label).string = "您回答的速度太慢了,您的准确率和速度都不太理想,建议您找专业医护人员进行检查!"
  54. // // this.node.getChildByName("Label6").getComponent(Label).string = "您答题的速度都有待提高哦!加油!"
  55. // } else {
  56. // this.node.getChildByName("Label6").getComponent(Label).string = "您的答题速度还不错,但准确率太低了,建议您找专业医护人员进行检查!"
  57. // // this.node.getChildByName("Label6").getComponent(Label).string = "您答题的速度和正确率都有待提高哦!加油!"
  58. // }
  59. // } else if (UserInfo.score > 50) {
  60. // if (UserInfo.aveTime < 2.5) {
  61. // // this.node.getChildByName("Label6").getComponent(Label).string = "您的准确率表现很好,但您回答的速度太快了,请仔细思考后作答!"
  62. // this.node.getChildByName("Label6").getComponent(Label).string = "太棒了!您的准确率和答题速度都非常棒!请继续保持!"
  63. // } else if (UserInfo.aveTime > 10) {
  64. // // this.node.getChildByName("Label6").getComponent(Label).string = "您的准确率表现很好,但您回答的速度太慢了,请在保持准确的同时提高速度!"
  65. // this.node.getChildByName("Label6").getComponent(Label).string = "您的准确率很棒哦,但是您答题的速度太慢。请多加练习,提高速度。加油!"
  66. // } else {
  67. // // this.node.getChildByName("Label6").getComponent(Label).string = "您的准确率和反应速度表现得很稳定,不错!"
  68. // this.node.getChildByName("Label6").getComponent(Label).string = "您的准确率很棒哦,答题速度也不错。请继续加油哦!"
  69. // }
  70. // } else {
  71. // if (UserInfo.aveTime < 2.5) {
  72. // // this.node.getChildByName("Label6").getComponent(Label).string = "虽然您的准确率表现一般,但您的回答速度太快了,请仔细思考后作答!"
  73. // this.node.getChildByName("Label6").getComponent(Label).string = "您的答题准确率一般哦,但是您的回答速度很快。请您多加练习,提高准确率!"
  74. // } else if (UserInfo.aveTime > 10) {
  75. // // this.node.getChildByName("Label6").getComponent(Label).string = "您的准确性表现一般,但您的回答速度有待提高,继续加油哦!"
  76. // this.node.getChildByName("Label6").getComponent(Label).string = "您的答题准确率一般哦,而且您的回答速度太慢。请您多加练习,加油哦!"
  77. // } else {
  78. // // this.node.getChildByName("Label6").getComponent(Label).string = "您的准确性和反应速度表现一般,继续加油哦!"
  79. // this.node.getChildByName("Label6").getComponent(Label).string = "您的准确率和反应速度都一般哦,请您多加练习,加油哦!"
  80. // }
  81. // }
  82. // 20分-50分,2.5s以下:虽然您的准确率表现一般,但您的回答速度太快了,请仔细思考后作答!
  83. // 20分-50分,2.5-15s:您的准确性和反应速度表现一般,继续加油哦!
  84. // 20分-50分,15s以上:您的准确性表现一般,但您的回答速度有待提高,继续加油哦!
  85. // 20分以下,2.5s以下:您回答的速度太快了,请在保持速度的同时提高准确率!
  86. // 20分以下,2.5-15s:您的准确性和反应速度都有待提高哦!
  87. // 20分以下,15s以上:您回答的速度太慢了,您的准确率和速度都有待提高哦!
  88. // 50分以上,2.5s以下:您的准确率表现很好,但您回答的速度太快了,请仔细思考后作答!
  89. // 50分以上,2.5-15s:您的准确率和反应速度表现得很稳定,不错!
  90. // 50分以上,15s以上:您的准确率表现很好,但您回答的速度太慢了,请在保持准确的同时提高速度!
  91. }
  92. private setLabels2() {
  93. this.node.getChildByName("Label4").getComponent(Label).string = "您答对了" + UserInfo.totalRight + "道题"
  94. this.node.getChildByName("Label5").getComponent(Label).string = "您答错了" + UserInfo.totalWrong + "道题"
  95. this.node.getChildByName("Label6").getComponent(Label).string = "您超时了" + UserInfo.totalTimeout + "道题"
  96. const t = UserInfo.totalRight / UserInfo.totalQuestion
  97. if (t < 0.3) {
  98. this.node.getChildByName("Label7").getComponent(Label).string = "您属于高风险人群"
  99. this.node.getChildByName("Label7").getComponent(Label).color = new Color(206, 37, 37, 255)
  100. } else if (t > 0.7) {
  101. this.node.getChildByName("Label7").getComponent(Label).string = "您属于低风险人群"
  102. this.node.getChildByName("Label7").getComponent(Label).color = new Color(151, 206, 37, 255)
  103. } else {
  104. this.node.getChildByName("Label7").getComponent(Label).string = "您属于中风险人群"
  105. this.node.getChildByName("Label7").getComponent(Label).color = new Color(206, 129, 37, 255)
  106. }
  107. }
  108. private async sendData() {
  109. // console.log("00000000000000= " + Math.floor(UserInfo.totalRight / UserInfo.totalQuestion*100) + " " + UserInfo.score);
  110. const data: any = {
  111. "phone": UserInfo.phone,
  112. "sourceCode": UserInfo.sourceCode,
  113. "score": Math.floor(UserInfo.totalRight / UserInfo.totalQuestion * 100),
  114. "aveTime": UserInfo.aveTime,
  115. "hospitalId": UserInfo.hospitalId,
  116. "hospitalName": UserInfo.hospitalName,
  117. "totalRight": UserInfo.totalRight,
  118. "totalWrong": UserInfo.totalWrong,
  119. "totalTimeout": UserInfo.totalTimeout,
  120. "totalQuestion": UserInfo.totalQuestion,
  121. "details": UserInfo.details
  122. }
  123. // console.log("111111111111= "+JSON.stringify(data));
  124. const ret = await HttpUtils.sendPost(HttpUtils.ip + "/detect/add", data)
  125. console.log("...receive data: " + JSON.stringify(ret));
  126. }
  127. update(deltaTime: number) {
  128. }
  129. }