From b5fec921d2cb82836feaa617ea962892aad75683 Mon Sep 17 00:00:00 2001 From: Luk Lu Date: Thu, 17 Mar 2022 10:33:10 +0800 Subject: [PATCH] u --- index.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 7650890..5b6f905 100644 --- a/index.js +++ b/index.js @@ -166,8 +166,8 @@ export default { * - CLINET_BACKEND_EXCEPTION: 前端发现后台异常 **/ async callBackend({ backend = this.BACKEND, httpMethod = 'POST', apiVersion = 'api', apiWho, apiTodo, apiWhat = {} }) { - process.env.NODE_ENV === 'production' - || console.log('%c '+JSON.stringify({time:new Date().toJSON(), page:this.thisPage()?.route || 'VueApp'}) + ' %c '+ JSON.stringify({ backend, apiWho, apiTodo, apiWhat }), 'color:blue', 'background:skyblue') + const thisRoute = this.thisPage()?.route || 'VueApp' // 立刻保存 thisPage().route,因为在调用后台后,可能已切换到了其他页面。 + const startTime = new Date().toJSON() let result = {} if (backend === 'UNICLOUD') { let { /* success, header, requestedId, */ result: resultCloud = {} } = await uniCloud @@ -220,8 +220,14 @@ export default { } // 注意1,resultServer 和 resultCloud 推荐遵循同样的格式 { _state, error | data },这样方便前端做统一判断。 // 注意2,虽然预设了 resultServer 和 resultCloud = {},但如果后台返回了 null,那么 resultServer/resultCloud 也是 null。 - process.env.NODE_ENV === 'production' - || console.info(' %c '+JSON.stringify({time:new Date().toJSON(), page:this.thisPage()?.route || 'VueApp'}) + '%c '+ JSON.stringify(result), 'color:magenta', 'background:magenta') // 不知为何,直接用 result 会输出一个奇怪的对象,要主动添加 JSON.stringify 才按照期望输出。 + if (process.env.NODE_ENV === 'development') { + console.log( + '%c '+JSON.stringify({startTime:startTime, page:thisRoute}) + + ' %c '+ JSON.stringify({ backend, apiWho, apiTodo, apiWhat }) + + ' %c '+ JSON.stringify(result) + + ' %c '+ JSON.stringify({endTime:new Date().toJSON()}), + 'color:blue', 'background:skyblue', 'background:magenta', 'color:magenta') // 不知为何,直接用 result 会输出一个奇怪的对象,要主动添加 JSON.stringify 才按照期望输出。 + } return result },