1. /**
    2. * @description 打印一个 [ title | text ] 样式的信息
    3. * @param {String} title title text
    4. * @param {String} info info text
    5. * @param {String} type style
    6. */
    7. log.capsule = function(title, info, type = 'primary') {
    8. console.log(
    9. `%c ${title} %c ${info} %c`,
    10. 'background:#35495E; padding: 1px; border-radius: 3px 0 0 3px; color: #fff;',
    11. `background:${typeColor(
    12. type
    13. )}; padding: 1px; border-radius: 0 3px 3px 0; color: #fff;`,
    14. 'background:transparent'
    15. );
    16. };
    17. /**
    18. * @description 打印彩色文字
    19. */
    20. log.colorful = function(textArr) {
    21. console.log(
    22. `%c${textArr.map(t => t.text || '').join('%c')}`,
    23. ...textArr.map(t => `color: ${typeColor(t.type)};`)
    24. );
    25. };
    26. /**
    27. * @description 打印 default 样式的文字
    28. */
    29. log.default = function(text) {
    30. log.colorful([{ text }]);
    31. };
    32. /**
    33. * @description 打印 primary 样式的文字
    34. */
    35. log.primary = function(text) {
    36. log.colorful([{ text, type: 'primary' }]);
    37. };
    38. /**
    39. * @description 打印 success 样式的文字
    40. */
    41. log.success = function(text) {
    42. log.colorful([{ text, type: 'success' }]);
    43. };
    44. /**
    45. * @description 打印 warning 样式的文字
    46. */
    47. log.warning = function(text) {
    48. log.colorful([{ text, type: 'warning' }]);
    49. };
    50. /**
    51. * @description 打印 danger 样式的文字
    52. */
    53. log.danger = function(text) {
    54. log.colorful([{ text, type: 'danger' }]);
    55. };
    56. window.$Log = log;
    57. export default log;