提交 | 用户 | 时间
|
759b1c
|
1 |
class Log { |
H |
2 |
static type = ["primary", "success", "warn", "error", "info"]; |
|
3 |
|
|
4 |
static typeColor(type = "default") { |
|
5 |
let color = ""; |
|
6 |
switch (type) { |
|
7 |
case "primary": |
|
8 |
color = "#2d8cf0"; |
|
9 |
break; |
|
10 |
case "success": |
|
11 |
color = "#19be6b"; |
|
12 |
break; |
|
13 |
case "info": |
|
14 |
color = "#909399"; |
|
15 |
break; |
|
16 |
case "warn": |
|
17 |
color = "#ff9900"; |
|
18 |
break; |
|
19 |
case "error": |
|
20 |
color = "#f03f14"; |
|
21 |
break; |
|
22 |
case "default": |
|
23 |
color = "#35495E"; |
|
24 |
break; |
|
25 |
default: |
|
26 |
color = type; |
|
27 |
break; |
|
28 |
} |
|
29 |
return color; |
|
30 |
} |
|
31 |
|
|
32 |
static print(text, type = "default", back = false) { |
|
33 |
if (typeof text === "object") { |
|
34 |
// 如果是對象則調用打印對象方式 |
|
35 |
console.dir(text); |
|
36 |
return; |
|
37 |
} |
|
38 |
if (back) { |
|
39 |
// 如果是打印帶背景圖的 |
|
40 |
console.log(`%c ${text} `, `background:${this.typeColor(type)}; padding: 2px; border-radius: 4px;color: #fff;`); |
|
41 |
} else { |
|
42 |
console.log(`%c ${text} `, `color: ${this.typeColor(type)};`); |
|
43 |
} |
|
44 |
} |
|
45 |
|
|
46 |
static pretty(title, text, type = "primary") { |
|
47 |
if (typeof text === "object") { |
|
48 |
console.log( |
|
49 |
`%c ${title} %c`, |
|
50 |
`background:${this.typeColor(type)};border:1px solid ${this.typeColor(type)}; padding: 1px; border-radius: 4px 0 0 4px; color: #fff;` |
|
51 |
); |
|
52 |
console.dir(text); |
|
53 |
return; |
|
54 |
} |
|
55 |
console.log( |
|
56 |
`%c ${title} %c ${text} %c`, |
|
57 |
`background:${this.typeColor(type)};border:1px solid ${this.typeColor(type)}; padding: 1px; border-radius: 4px 0 0 4px; color: #fff;`, |
|
58 |
`border:1px solid ${this.typeColor(type)}; padding: 1px; border-radius: 0 4px 4px 0; color: ${this.typeColor(type)};`, |
|
59 |
"background:transparent" |
|
60 |
); |
|
61 |
} |
|
62 |
} |
|
63 |
export default Log; |