exam-fun.wxs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. if( index == select) return true;
  50. select = ""+select
  51. return select.indexOf( index )>-1;
  52. },
  53. isExamSelect: function( index, info ){
  54. if( !info.answers ) return '';
  55. if( index >= info.answers.length ) return '';
  56. var select = ""
  57. if( index == info.index ) select += 'cur-select';
  58. if( info.answers[index].select>0 ) select += ' is-select';
  59. return select||'un-select'
  60. }
  61. }
  62. // 导出对外暴露的属性
  63. module.exports = {
  64. numberToFixed: filter.numberToFixed,
  65. trueFalseFormatter: filter.trueFalseFormatter,
  66. indexOf: filter.indexOf,
  67. isSelect: filter.isSelect,
  68. phoneFormat: filter.phoneFormat,
  69. getMultResult:filter.getMultResult,
  70. cardIdFormat:filter.cardIdFormat,
  71. isExamSelect: filter.isExamSelect,
  72. numberToArray: filter.numberToArray,
  73. }