Files
mes-ui-d2/src/libs/util.log.js
liyang 5549c4a92c $log demo page
Former-commit-id: de3c73e90d997405748430bd9e1bfd7be741c398 [formerly de3c73e90d997405748430bd9e1bfd7be741c398 [formerly de3c73e90d997405748430bd9e1bfd7be741c398 [formerly de3c73e90d997405748430bd9e1bfd7be741c398 [formerly 65a43317c2eb9ecb43a1a9f08031c476e3b8b55c [formerly c90c9ba1e15cd4d19e7579afb866820428ce12c6]]]]]
Former-commit-id: aecd29e0e5f95a2ede8d8f58eafe1e1529a58baf
Former-commit-id: b7af51daa09b0c08fc592d559296164ce8b65a00
Former-commit-id: c392aa3faf901c26d6a76338195a51f21466860c [formerly 483132831864e8d14da69aa223e992ad6e9b43fb]
Former-commit-id: 301d0c78028061fb53e72d36f455cb27020f3d09
Former-commit-id: b68eff94b50f328b309a249b63025c4c0ff291f7
Former-commit-id: ace41752e14fb73b30b3ff49bdf64a1dd516572a
Former-commit-id: b3ac4fecd5bd71719215e299da1856c7e82e8fba
Former-commit-id: e3bac2ec8ab2687f61ce9708a416eb556ea2283f
2018-08-12 09:25:10 +08:00

81 lines
1.8 KiB
JavaScript

const log = {}
/**
* @description 返回这个样式的颜色值
* @param {String} type 样式名称 [ primary | success | warning | danger | text ]
*/
function typeColor (type = 'default') {
let color = ''
switch (type) {
case 'default': color = '#35495E'; break
case 'primary': color = '#3488ff'; break
case 'success': color = '#43B883'; break
case 'warning': color = '#e6a23c'; break
case 'danger': color = '#f56c6c'; break
default:; break
}
return color
}
/**
* @description 打印一个 [ title | text ] 样式的信息
* @param {String} title title text
* @param {String} info info text
* @param {String} type style
*/
log.capsule = function (title, info, type = 'primary') {
console.log(
`%c ${title} %c ${info} %c`,
'background:#35495E; padding: 1px; border-radius: 3px 0 0 3px; color: #fff;',
`background:${typeColor(type)}; padding: 1px; border-radius: 0 3px 3px 0; color: #fff;`,
'background:transparent'
)
}
/**
* @description 打印彩色文字
*/
log.colorful = function (textArr) {
console.log(
`%c${textArr.map(t => t.text || '').join('%c')}`,
...textArr.map(t => `color: ${typeColor(t.type)};`)
)
}
/**
* @description 打印 default 样式的文字
*/
log.default = function (text) {
log.colorful([{ text }])
}
/**
* @description 打印 primary 样式的文字
*/
log.primary = function (text) {
log.colorful([{ text, type: 'primary' }])
}
/**
* @description 打印 success 样式的文字
*/
log.success = function (text) {
log.colorful([{ text, type: 'success' }])
}
/**
* @description 打印 warning 样式的文字
*/
log.warning = function (text) {
log.colorful([{ text, type: 'warning' }])
}
/**
* @description 打印 danger 样式的文字
*/
log.danger = function (text) {
log.colorful([{ text, type: 'danger' }])
}
export default log