handler.wxs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // +----------------------------------------------------------------------
  2. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  3. // +----------------------------------------------------------------------
  4. // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
  5. // +----------------------------------------------------------------------
  6. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  7. // +----------------------------------------------------------------------
  8. // | Author: CRMEB Team <admin@crmeb.com>
  9. // +----------------------------------------------------------------------
  10. var inlineTags = {
  11. abbr: 1,
  12. b: 1,
  13. big: 1,
  14. code: 1,
  15. del: 1,
  16. em: 1,
  17. i: 1,
  18. ins: 1,
  19. label: 1,
  20. q: 1,
  21. small: 1,
  22. span: 1,
  23. strong: 1
  24. }
  25. module.exports = {
  26. // 从顶层标签的样式中取出一些给 rich-text
  27. getStyle: function(style) {
  28. if (style) {
  29. var i, j, res = '';
  30. if ((i = style.indexOf('display')) != -1)
  31. res = style.substring(i, (j = style.indexOf(';', i)) == -1 ? style.length : j);
  32. if ((i = style.indexOf('float')) != -1)
  33. res += ';' + style.substring(i, (j = style.indexOf(';', i)) == -1 ? style.length : j);
  34. return res;
  35. }
  36. },
  37. // 处理懒加载
  38. getNode: function(item, imgLoad) {
  39. if (!imgLoad && item.attrs.i != '0') {
  40. var img = {
  41. name: 'img',
  42. attrs: JSON.parse(JSON.stringify(item.attrs))
  43. }
  44. delete img.attrs.src;
  45. img.attrs.style += ';width:20px;height:20px';
  46. return [img];
  47. } else return [item];
  48. },
  49. // 是否通过 rich-text 显示
  50. useRichText: function(item) {
  51. return !item.c && !inlineTags[item.name] && (item.attrs.style || '').indexOf('display:inline') == -1;
  52. }
  53. }