indexHead.sjs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 { icon, styleMode = "a" } = getExtInfo(item);
  24. /*
  25. * 三种模式
  26. * */
  27. const modes = {
  28. a: "head-a",
  29. b: "head-b",
  30. c: "head-c",
  31. };
  32. return icon ? "head-custom" : modes[styleMode];
  33. };
  34. const getImgUrl = (url, prefix) =>
  35. url.length === 32 ? `${prefix}${url}` : url;
  36. const getBgStyle = (item, imgSrcPrefix) => {
  37. const styles = [];
  38. const { icon } = getExtInfo(item);
  39. if (icon) {
  40. styles.push(`background-image:url(${getImgUrl(icon, imgSrcPrefix)})`);
  41. }
  42. return styles.join(";");
  43. };
  44. /*
  45. * 获取二级标题
  46. * */
  47. const getSubTitle = (item) => {
  48. const { desc } = getExtInfo(item);
  49. return desc || "了解本院特色";
  50. };
  51. const getTitle = (item) => {
  52. const { title } = getExtInfo(item);
  53. return title || "首页";
  54. };
  55. export default {
  56. msgClass,
  57. getTitle,
  58. getBgStyle,
  59. getExtInfo,
  60. getStyleMode,
  61. getNotifyList,
  62. getSubTitle,
  63. };