Files
mes-ui-d2/src/libs/util.log.js
liyang eb5c89ff53 log
Former-commit-id: bab2bb15589539f4140f4582da09eb0069b873b9 [formerly bab2bb15589539f4140f4582da09eb0069b873b9 [formerly bab2bb15589539f4140f4582da09eb0069b873b9 [formerly bab2bb15589539f4140f4582da09eb0069b873b9 [formerly 8974b2fc64f21f240a768ff8657e83556de421d9 [formerly 7b4e1a2a70627488f945eba98d288a79a0a243cb]]]]]
Former-commit-id: 7620f9c9ddad400fbe6fc9042ca9690ad159093f
Former-commit-id: 4d857c13ead50fb0bd6869544b1c3dcdebd18874
Former-commit-id: aa6de588166ddb8fb649b072122f8b4ff2f7b6fa [formerly e2fbfc36ab2f2c86f6e12778c00c381d7f38db33]
Former-commit-id: 07cf29d93eba7745d9c8736c72582f1771b537a8
Former-commit-id: 09fa896073d1b3ebf06ef568f995f6a25e689974
Former-commit-id: 9823ce618d492cb49fb9bf35e4e35733b5580de7
Former-commit-id: b67e2c71b4b7d29f3a40c11f893db0df1a456642
Former-commit-id: 305b824f25acf280a145e9250ac376c17bb2589c
2018-08-09 11:50:45 +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