From db83067025f79abe33c151eda0ab9aaf72d844d4 Mon Sep 17 00:00:00 2001 From: Luk Date: Mon, 5 Feb 2024 09:49:51 +0800 Subject: [PATCH] console.log({_at, ...}) --- unitool.js | 49 +++++++++++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/unitool.js b/unitool.js index c9b94d9..ab0ca4c 100644 --- a/unitool.js +++ b/unitool.js @@ -171,10 +171,10 @@ export default { }) { const thisRoute = getCurrentPages()?.pop?.()?.route || 'VueApp' // 立刻保存 route,因为在调用后台后,可能已切换到了其他页面。 const startTime = new Date().toJSON() - let url = undefined + let apiurl = undefined apiWhat._clientInfo = globalThis.wo?.envar?.clientInfo // #ifdef WEB - Object.assign(apiWhat._clientInfo, { url: globalThis.location?.href, lang: globalThis.wo?.ss?.i18n?.mylang }) + Object.assign(apiWhat._clientInfo, { requrl: globalThis.location?.href, lang: globalThis.wo?.ss?.i18n?.mylang }) // #endif apiWhat._passtoken = uni.getStorageSync('_passtoken') let result = {} @@ -213,10 +213,10 @@ export default { apiWhat[key] = JSON.stringify(apiWhat[key]) } } - url = this.make_server_url(`${apiVersion}/${apiWho}/${apiTodo}`) + apiurl = this.make_server_url(`${apiVersion}/${apiWho}/${apiTodo}`) let [error, { statusCode, header, errMsg, data: resultServer = {} } = {}] = await uni.request({ method: httpMethod, - url, + url: apiurl, data: apiWhat, timeout, }) @@ -240,22 +240,35 @@ export default { // 注意1,resultServer 和 resultCloud 推荐遵循同样的格式 { _state, error | data },这样方便前端做统一判断。 // 注意2,虽然预设了 resultServer 和 resultCloud = {},但如果后台返回了 null,那么 resultServer/resultCloud 也是 null。 if (process.env.NODE_ENV !== 'production') { - console.log( - `%c ${startTime} (IN) ${thisRoute} :: ${apiTodo}`, - 'background: #87cefa; border-radius: 0.5em;color: white; font-weight: bold; padding: 2px 0.5em;', - { - baseType, - apiWho, - apiTodo, - apiWhat, - timeout, - url, - } + console.log({ + _at: startTime, + _type: 'REQ', + _path: `${thisRoute} => ${apiWho}/${apiTodo}`, + apiurl, + baseType, + apiWhat, + timeout, + } + // `%c ${startTime} (IN) ${thisRoute} :: ${apiTodo}`, + // 'background: #87cefa; border-radius: 0.5em;color: white; font-weight: bold; padding: 2px 0.5em;', + // { + // baseType, + // apiWho, + // apiTodo, + // apiWhat, + // timeout, + // apiurl, + // } ) - console.log( - `%c ${new Date().toJSON()} (OUT) ${thisRoute} :: ${apiTodo}`, - 'background: #4169e1; border-radius: 0.5em;color: white; font-weight: bold; padding: 2px 0.5em;', + console.log({ + _at: new Date().toJSON(), + _type: 'RES', + _path: `${thisRoute} => ${apiWho}/${apiTodo}`, result + } + // `%c ${new Date().toJSON()} (OUT) ${thisRoute} :: ${apiTodo}`, + // 'background: #4169e1; border-radius: 0.5em;color: white; font-weight: bold; padding: 2px 0.5em;', + // result ) } return result