简化 req/res 的输出格式

This commit is contained in:
陆柯 2021-10-02 20:41:04 +08:00
parent 2f24358bb8
commit db048bc98c

View File

@ -24,9 +24,10 @@ module.exports = {
// 快速输出详尽提示,可用来取代 console.log // 快速输出详尽提示,可用来取代 console.log
clog(...message) { clog(...message) {
process.env.NODE_ENV === 'production' ||
console.log( console.log(
'【', '【',
getCurrentPages().length > 0 ? getCurrentPages().pop().route : 'pages/Welcome', // 在首页时getApp() 或 getCurrentPages() 有可能获取不到。 getCurrentPages().length > 0 ? getCurrentPages().pop().route : 'App', // 在首页时getApp() 或 getCurrentPages() 有可能获取不到。
'【', '【',
...message, ...message,
'】】' '】】'
@ -117,9 +118,9 @@ module.exports = {
} }
} }
console.log('👇 👇 👇 👇 < Request > 👇 👇 👇 👇 ', { method, url, header, data }, '👆 👆 👆 👆 < /Request > 👆 👆 👆 👆') console.log('👇 Request 👇 ', { method, url, header, data }, ' 👆 👆')
let [error, response] = await uni.request({ method, url, header, data }) let [error, response] = await uni.request({ method, url, header, data })
console.log('⬇️ ⬇️ ⬇️ ⬇️ < Response > ⬇️ ⬇️ ⬇️ ⬇️ ', response, '⬆️ ⬆️ ⬆️ ⬆️ < /Response > ⬆️ ⬆️ ⬆️ ⬆️') console.log('⬇️ Response ⬇️ ', response, ' ⬆️ ⬆️')
return [error, response] return [error, response]
}, },
@ -130,7 +131,7 @@ module.exports = {
* - CLINET_BACKEND_EXCEPTION: 前端发现后台异常 * - CLINET_BACKEND_EXCEPTION: 前端发现后台异常
**/ **/
async callBackend({ backend = this.BACKEND, httpMethod = 'POST', apiVersion = 'api', apiWho, apiTodo, apiWhat = {} }) { async callBackend({ backend = this.BACKEND, httpMethod = 'POST', apiVersion = 'api', apiWho, apiTodo, apiWhat = {} }) {
console.log('👇 < BackendRequest > ', { apiWho, apiTodo, apiWhat }, ' < /BackendRequest > 👇') console.log('👇 BackendRequest 👇 ', { apiWho, apiTodo, apiWhat }, ' 👆 👆')
let result = {} let result = {}
if (backend === 'UNICLOUD') { if (backend === 'UNICLOUD') {
let { /* success, header, requestedId, */ result: resultCloud = {} } = await uniCloud let { /* success, header, requestedId, */ result: resultCloud = {} } = await uniCloud
@ -181,7 +182,7 @@ module.exports = {
result = resultServer result = resultServer
} }
} }
console.log('👆 < BackendResult > ', JSON.stringify(result), '< /BackendResult > 👆') // 不知为何,直接用 result 会输出一个奇怪的对象,要主动添加 JSON.stringify 才按照期望输出。 console.log('⬇️ BackendResult ⬇️ ', JSON.stringify(result), ' ⬆️ ⬆️') // 不知为何,直接用 result 会输出一个奇怪的对象,要主动添加 JSON.stringify 才按照期望输出。
return result return result
}, },