index.js 3.0 KB

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