index.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import common from '../../utils/util';
  2. import server from '../../utils/main';
  3. const innerAudioContext1 = wx.createInnerAudioContext();
  4. const app = getApp()
  5. Page({
  6. data: {
  7. version: app.globalData.version,
  8. FileUrl: app.globalData.fileUrl,
  9. },
  10. onLoad: function () {
  11. var that = this;
  12. server.getLocalHost(function () {
  13. that.getEnumerationData(function () {
  14. that.getQuestionTypesList(function () {
  15. var data = wx.getStorageSync('QuestionTypeList');
  16. that.setData({
  17. QuestionCategory: data,
  18. Containnerheight: common.getSystemHeight(),
  19. });
  20. });
  21. });
  22. });
  23. var url = app.globalData.audioUrlBaidu;
  24. url = url.replace("[token]", "24.6dbece3e76e486120456e6f6fc5dee15.2592000.1531286017.282335-10850912");
  25. url = url.replace("[word]", "答案:45,159,55,197,781,1456,745,159,55,197,781,1456,7");
  26. url = encodeURI(url);
  27. innerAudioContext1.src=url;
  28. innerAudioContext1.play();
  29. },
  30. gotoList: function (e) {
  31. var questionTypeID = e.currentTarget.dataset.id;
  32. wx.navigateTo({
  33. url: './list?id=' + questionTypeID
  34. });
  35. },
  36. //得到题型数据列表
  37. getQuestionTypesList: function (callback) {
  38. server.getData('GetQuestionTypes', function (data) {
  39. var QuestionTypeList = data;
  40. QuestionTypeList[QuestionTypeList.length - 1].List[QuestionTypeList[QuestionTypeList.length - 1].List.length - 1].NextID = QuestionTypeList[0].List[0].ID
  41. for (var i = 0; i < QuestionTypeList.length; i++) {
  42. if (i > 0)
  43. QuestionTypeList[i - 1].List[QuestionTypeList[i - 1].List.length - 1].NextID = QuestionTypeList[i].List[0].ID
  44. for (var j = 1; j < QuestionTypeList[i].List.length; j++) {
  45. QuestionTypeList[i].List[j - 1].NextID = QuestionTypeList[i].List[j].ID;
  46. }
  47. }
  48. //格式化或补充数据
  49. for (var i = 0; i < QuestionTypeList.length; i++) {
  50. for (var j = 0; j < QuestionTypeList[i].List.length; j++) {
  51. var item = QuestionTypeList[i].List[j];
  52. item.DifficultyName = common.getEnumerationName(item.Difficulty, app.globalData.Enumeration);
  53. }
  54. }
  55. wx.setStorage({
  56. key: "QuestionTypeList",
  57. data: data
  58. });
  59. callback();
  60. });
  61. },
  62. //得到枚举数据
  63. getEnumerationData: function (callback) {
  64. server.getData('GetEnumerationList', function (data) {
  65. app.globalData.Enumeration = data;
  66. wx.setStorage({
  67. key: "Enumeration",
  68. data: data
  69. });
  70. callback();
  71. });
  72. },
  73. updateProgram: function () {
  74. if (wx.canIUse("getUpdateManager")) {
  75. const updateManager = wx.getUpdateManager();
  76. updateManager.onCheckForUpdate(function (res) {
  77. // 请求完新版本信息的回调
  78. console.log(res.hasUpdate)
  79. });
  80. updateManager.onUpdateReady(function () {
  81. wx.showModal({
  82. title: '更新提示',
  83. content: '新版本已经准备好,是否重启应用?',
  84. success: function (res) {
  85. if (res.confirm) {
  86. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  87. updateManager.applyUpdate()
  88. }
  89. }
  90. });
  91. });
  92. }
  93. },
  94. onShareAppMessage: function () {
  95. return {
  96. title: '',
  97. path: 'pages/index/index',
  98. success: function (res) {
  99. },
  100. fail: function (err) {
  101. console.log(err);
  102. },
  103. complete: function (res) {
  104. console.log(res);
  105. },
  106. }
  107. },
  108. })