微信小程序学习用demo:考证通,在线题库类小程序

这类小程序比较少,而这个比较完善,包含

1:选择证书
2:题库
3:错题库

 

代码示例:错题库

[AppleScript] 纯文本查看 复制代码

?

01

02

03

04

05

06

07

08

09

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

var wrongs = [];

var app = getApp();

exports.getNext = function(index) {

  var category = app.getCategory();

  for (var i = index; i < 1000; ++i) {

    var problem = wx.getStorageSync("wrong_prob_" + category._id + '_' + i);

    if (problem) {

      problem = JSON.parse(problem);

      if (!problem._id) continue;

      return { index: i, problem: problem };

    } else {

      return null;

    }

  }

}

exports.getPrev = function(index) {

  var category = app.getCategory();

  for (var i = index; i > 0; --i) {

    var problem = wx.getStorageSync("wrong_prob_"+ category._id + '_' + i);

    if (problem) {

      problem = JSON.parse(problem);

      if (!problem._id) continue;

      return { index: i, problem: problem };

    } else {

      return null;

    }

  }

}

exports.save = function() {

}

exports.add = function(problem) {

  var category = app.getCategory();

  wx.getStorage({

    key: 'wrong_cnt_' + category._id,

    success: function(res) {

      var cnt = parseInt(res.data) + 1;

      wx.setStorage({

        key: "wrong_prob_"+ category._id + '_' + cnt,

        data: JSON.stringify(problem)

      });

      wx.setStorage({

        key: "wrong_cnt_"+ category._id,

        data: cnt.toString()

      });

    },

    fail: function() {

      wx.setStorage({

        key: "wrong_prob_"+ category._id + '_1',

        data: JSON.stringify(problem)

      });

      wx.setStorage({

        key: "wrong_cnt_"+ category._id,

        data: '1'

      });

    }

  });

}

exports.del = function(index) {

  var category = app.getCategory();

  wx.setStorage({

    key: "wrong_prob_"+ category._id + '_' + index,

    data: '{}'

  })

  wx.showToast({

    title: '移除题目成功',

    icon: 'success',

    duration: 700

  })

}


项目地址及下载:
https://github.com/xughv/certificate-minapp
 certificate-minapp-master.zip (51.27 KB, 下载次数: 538) 

猜你喜欢

转载自blog.csdn.net/weixin_41722928/article/details/84987471
今日推荐