indexHead.sjs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * 获取扩展字段
  3. * */
  4. const getExtInfo = (item) => {
  5. const { componentExtInfo } = item;
  6. return componentExtInfo || {};
  7. };
  8. /*
  9. * 获取消息列表
  10. * */
  11. const getNotifyList = (item) => {
  12. const { serviceList = [] } = item;
  13. return serviceList;
  14. };
  15. const msgClass = (item, showMsg) => {
  16. const { length } = getNotifyList(item);
  17. return !length || !showMsg ? ' no-msg' : '';
  18. };
  19. /*
  20. * 获取样式
  21. * */
  22. const getStyleMode = (item) => {
  23. const {
  24. icon,
  25. styleMode = 'a',
  26. } = getExtInfo(item);
  27. /*
  28. * 三种模式
  29. * */
  30. const modes = {
  31. a: 'head-a',
  32. b: 'head-b',
  33. c: 'head-c',
  34. };
  35. return icon ? 'head-custom' : modes[styleMode];
  36. };
  37. const getImgUrl = (url, prefix) => (
  38. url.length === 32 ? `${prefix}${url}` : url
  39. );
  40. const getBgStyle = (item, imgSrcPrefix) => {
  41. const styles = [];
  42. const { icon } = getExtInfo(item);
  43. if (icon) {
  44. styles.push(`background-image:url(${getImgUrl(icon, imgSrcPrefix)})`);
  45. }
  46. return styles.join(';');
  47. };
  48. /*
  49. * 获取二级标题
  50. * */
  51. const getSubTitle = (item) => {
  52. const { desc } = getExtInfo(item);
  53. return desc || '了解本院特色';
  54. };
  55. const getTitle = (item) => {
  56. const { title } = getExtInfo(item);
  57. return title || '首页';
  58. };
  59. export default {
  60. msgClass,
  61. getTitle,
  62. getBgStyle,
  63. getExtInfo,
  64. getStyleMode,
  65. getNotifyList,
  66. getSubTitle,
  67. };