filters.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. export function quTypeFilter(value) {
  2. const map = {
  3. '1': '单选题',
  4. '2': '多选题',
  5. '3': '判断题',
  6. '4': '简答题'
  7. }
  8. return map[value]
  9. }
  10. export function examResultFilter(value) {
  11. const map = {
  12. '1': '合格',
  13. '0': '不合格'
  14. }
  15. return map[value]
  16. }
  17. export function paperStateFilter(value) {
  18. const map = {
  19. '0': '考试中',
  20. '1': '待阅卷',
  21. '2': '已考完',
  22. '3': '!已弃考'
  23. }
  24. return map[value]
  25. }
  26. export function examOpenType(value) {
  27. const map = {
  28. '1': '完全公开',
  29. '2': '指定部门',
  30. '3': '需要密码'
  31. }
  32. return map[value]
  33. }
  34. export function examStateFilter(value) {
  35. const map = {
  36. '0': '进行中',
  37. '1': '已禁用',
  38. '2': '待开始',
  39. '3': '已结束'
  40. }
  41. return map[value]
  42. }
  43. export function quLevelFilter(value) {
  44. const map = {
  45. '1': '普通',
  46. '2': '较难'
  47. }
  48. return map[value]
  49. }
  50. /**
  51. * 处理富文本里的图片宽度自适应
  52. * 1.去掉img标签里的style、width、height属性
  53. * 2.img标签添加style属性:max-width:100%;height:auto
  54. * 3.修改所有style里的width属性为max-width:100%
  55. * 4.去掉<br/>标签
  56. * @param html
  57. * @returns {void|string|*}
  58. */
  59. export function formatRichText (html) { //控制小程序中图片大小
  60. if(!html){
  61. return ''
  62. }
  63. let newContent= html.replace(/<img[^>]*>/gi,function(match,capture){
  64. match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '');
  65. match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
  66. match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');
  67. return match;
  68. });
  69. newContent = newContent.replace(/style="[^"]+"/gi,function(match,capture){
  70. match = match.replace(/width:[^;]+;/gi, 'max-width:100%;').replace(/width:[^;]+;/gi, 'max-width:100%;');
  71. return match;
  72. });
  73. // newContent = newContent.replace(/<br[^>]*\/>/gi, '');
  74. newContent = newContent.replace(/\<img/gi, '<img style="max-width:100%;height:auto;display:inline-block;margin:10rpx auto;"');
  75. return newContent;
  76. }