util拆分

Former-commit-id: 822c86f85a1268c28513cf97b7107dd697eb6d43 [formerly 822c86f85a1268c28513cf97b7107dd697eb6d43 [formerly 822c86f85a1268c28513cf97b7107dd697eb6d43 [formerly 822c86f85a1268c28513cf97b7107dd697eb6d43 [formerly 68c12439e9dd03521d919105efcbc06cb6da2126 [formerly 1d5c6a4b53da991761dd4a9399eefb27e70e96ca]]]]]
Former-commit-id: fbe49d601541d01db7f4c36658c71a6e3b014733
Former-commit-id: e2e4e2958c7f63990339e1d06b4b3aaf463dab31
Former-commit-id: 20c693d8bcc308b276d15d7cbc7288c74c709dbf [formerly fc2f99d56d410c349d5bff5e42176a6fc97325da]
Former-commit-id: 004230c8e00651d1793fd4ee68bb34299d4049f5
Former-commit-id: 94a29c7f87d6d3b6f200d9bdc9033fb25641cf3f
Former-commit-id: b5d93d8b5c1b5e85b62c01ca815c87dc943a694f
Former-commit-id: d787061bbfae4ea01a3aabf6f92cd1620377b572
Former-commit-id: 2fc8371e6d340382cca7539a5dc1aa09881fecb2
This commit is contained in:
liyang
2018-08-09 09:52:52 +08:00
parent 84da66a5ab
commit dde7b07c8b
4 changed files with 122 additions and 114 deletions

73
src/libs/util.log.js Normal file
View File

@@ -0,0 +1,73 @@
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 打印 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