test.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. import common from '../../utils/util';
  2. import server from '../../utils/main';
  3. import pinyin from '../../utils/pinyin';
  4. const app = getApp();
  5. var currentIndex=0;
  6. var isRight=false;
  7. Page({
  8. data: {
  9. List:[
  10. {
  11. Name:"程",
  12. Pinyin:"cheng2",
  13. AnswerList: [
  14. {
  15. pinyin: "cen2",
  16. }, {
  17. pinyin: "chen2",
  18. }, {
  19. pinyin: "ceng2",
  20. }, {
  21. pinyin: "cheng2",
  22. },
  23. ]
  24. },
  25. {
  26. Name: "杰",
  27. Pinyin: "jie2",
  28. AnswerList: [
  29. {
  30. pinyin: "ji2",
  31. }, {
  32. pinyin: "jie2",
  33. }, {
  34. pinyin: "xie2",
  35. }, {
  36. pinyin: "qie2",
  37. },
  38. ]
  39. }
  40. ]
  41. },
  42. onLoad: function (options) {
  43. this.setData({
  44. Height: common.getSystemHeight(),
  45. });
  46. this.getList();
  47. this.audioCtx = wx.createAudioContext('myAudio');
  48. },
  49. getList: function () {
  50. isRight=false;
  51. var pinyinList = pinyin.getPinyinArray();
  52. var item = this.data.List[currentIndex];
  53. var list = item.AnswerList;
  54. for (var i = 0; i < list.length; i++) {
  55. for (var j = 0; j < pinyinList.length; j++) {
  56. if (list[i].pinyin == pinyinList[j][0]) {
  57. list[i].Pinyin = pinyinList[j][1];
  58. list[i].Name = pinyinList[j][2][0];
  59. break;
  60. }
  61. }
  62. if (item.Pinyin==list[i].pinyin)
  63. list[i].IsResult=true;
  64. else
  65. list[i].IsResult=false;
  66. }
  67. this.setData({
  68. CurrentItem: item,
  69. });
  70. },
  71. selectedHanzi: function (e) {
  72. var id = e.currentTarget.dataset.id;
  73. var list = this.data.CurrentItem.AnswerList;
  74. for (var i = 0; i < list.length; i++) {
  75. list[i].IsSelected = false;
  76. }
  77. list[id].IsSelected = true;
  78. if (list[id].IsResult)
  79. isRight=true;
  80. this.data.CurrentItem.AnswerList=list;
  81. this.playAudio(list[id].Pinyin, list[id].Name);
  82. this.setData({
  83. CurrentItem: this.data.CurrentItem,
  84. });
  85. },
  86. playAudio: function (pinyin,name) {
  87. var url = app.globalData.audioUrlBaidu;
  88. url = url.replace("[token]", app.globalData.BaiduToken);
  89. url = url.replace("[word]", name+"("+pinyin+")");
  90. url = encodeURI(url);
  91. this.audioCtx.setSrc(url);
  92. this.audioCtx.play();
  93. },
  94. gotoOK:function(){
  95. var that=this;
  96. var title="错误";
  97. var icon="none";
  98. if (isRight){
  99. title="正确";
  100. icon ="success";
  101. }
  102. wx.showToast({
  103. title: title,
  104. icon: icon,
  105. duration:1000,
  106. complete:function(){
  107. currentIndex++;
  108. if (currentIndex >= that.data.List.length)
  109. currentIndex = 0;
  110. that.getList();
  111. }
  112. })
  113. },
  114. onShareAppMessage: function () {
  115. return {
  116. title: app.globalData.ShareTitle,
  117. path: 'pages/index/index?UserID=' + app.globalData.userInfo.UserID,
  118. imageUrl: '../../images/07001.png',
  119. }
  120. },
  121. });