console.log({_at, ...})

This commit is contained in:
Luk 2024-02-05 09:49:51 +08:00
parent 07ad96602e
commit db83067025

View File

@ -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 {
// 注意1resultServer 和 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