123456789101112131415161718192021222324252627282930313233343536373839 |
- import { v4 as uuid } from 'uuid'
- const isDev = process.env.NODE_ENV === 'development'
- class CConsole {
- constructor (effective) {
- this.effective = effective
- this.requestHistory = {}
- }
- open (info) {
- if (this.effective) {
- const uid = uuid()
- const data = { uid, info: { method: info, startTime: Date.now() } }
- this.requestHistory[uid] = data
- return uid
- }
- }
- append (uid, type, info) {
- if (this.effective) {
- const currentReq = this.requestHistory[uid]
- if (currentReq) {
- currentReq.info[type] = info
- }
- }
- }
- end (uid) {
- if (this.effective) {
- const endTime = Date.now()
- const times = endTime - this.requestHistory[uid].info.startTime
- Reflect.deleteProperty(this.requestHistory[uid].info, 'startTime')
- this.requestHistory[uid].info.times = times
- console.log('%c【cConsole】', 'color: #67c23a;', this.requestHistory[uid].info)
- this.requestHistory[uid] = null
- }
- }
- }
- export const cConsole = new CConsole(isDev)
|