exam-fun.wxs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // 支持es4语法
  2. var filter = {
  3. numberToFixed: function(value) {
  4. return value.toFixed(2);
  5. },
  6. phoneFormat: function(value) {
  7. if( !value ) return "";
  8. if( value.length < 11){
  9. return '';
  10. }
  11. return value.substring(0, 4) +"****"+ value.substring(7,11)
  12. },
  13. cardIdFormat: function(value) {
  14. if( !value ) return "";
  15. if( value.length < 18){
  16. return '';
  17. }
  18. return value.substring(0, 4) +"****"+ value.substring(14,18)
  19. },
  20. trueFalseFormatter: function(question) {
  21. for (var i = 0; i < question.items.length; i++) {
  22. if (question.items[i].prefix === question.correct) {
  23. return question.items[i].content;
  24. }
  25. }
  26. return '';
  27. },
  28. indexOf: function(arg1, arg2) {
  29. return arg1.toString().indexOf(arg2.toString()) > -1 ? true : false;
  30. },
  31. numberToArray: function(number) {
  32. var array = [];
  33. for (var i = 0; i < number; i++) {
  34. array.push(i);
  35. }
  36. return array;
  37. },
  38. getMultResult:function( select ){
  39. var prevList = ["", "A","B","C", "D", "E","F"]
  40. var res = []
  41. select=''+select
  42. for( var i=0; i< select.length;i++){
  43. var index= +select[i]
  44. res.push( prevList[index])
  45. }
  46. return res.join(",")
  47. },
  48. isSelect: function( index, select ){
  49. console.log( "select", select )
  50. if( index == select) return true;
  51. select = ""+select
  52. return select.indexOf( index )>-1;
  53. },
  54. isExamSelect: function( index, info ){
  55. if( !info.answers ) return '';
  56. if( index >= info.answers.length ) return '';
  57. var select = ""
  58. if( index == info.index ) select += 'cur-select';
  59. if( info.answers[index].select>0 ) select += ' is-select';
  60. return select||'un-select'
  61. }
  62. }
  63. // 导出对外暴露的属性
  64. module.exports = {
  65. numberToFixed: filter.numberToFixed,
  66. trueFalseFormatter: filter.trueFalseFormatter,
  67. indexOf: filter.indexOf,
  68. isSelect: filter.isSelect,
  69. phoneFormat: filter.phoneFormat,
  70. getMultResult:filter.getMultResult,
  71. cardIdFormat:filter.cardIdFormat,
  72. isExamSelect: filter.isExamSelect,
  73. numberToArray: filter.numberToArray,
  74. }