u
This commit is contained in:
parent
37710e887a
commit
663cfd0a1f
27
index.js
27
index.js
@ -48,7 +48,8 @@ module.exports = {
|
|||||||
console.log('👇 < BackendRequest > ', { apiWho, apiHow, apiWhat }, ' < /BackendRequest > 👇')
|
console.log('👇 < BackendRequest > ', { apiWho, apiHow, apiWhat }, ' < /BackendRequest > 👇')
|
||||||
let result = {}
|
let result = {}
|
||||||
if (backend === 'CLOUD') {
|
if (backend === 'CLOUD') {
|
||||||
let { success, header, requestedId, result: resultCloud = {} } = await uniCloud.callFunction({
|
let { /* success, header, requestedId, */ result: resultCloud = {} } = await uniCloud
|
||||||
|
.callFunction({
|
||||||
name: apiWho,
|
name: apiWho,
|
||||||
data: {
|
data: {
|
||||||
apiHow,
|
apiHow,
|
||||||
@ -57,6 +58,14 @@ module.exports = {
|
|||||||
// uniIdToken // uniCloud自动getStorageSync('uni_id_token')并传递为 uniIdToken;也可自行传入 uniIdToken
|
// uniIdToken // uniCloud自动getStorageSync('uni_id_token')并传递为 uniIdToken;也可自行传入 uniIdToken
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
.catch((exp) => {
|
||||||
|
// 断网或云端返回异常 {errMsg, stack} = error
|
||||||
|
if (/request:fail/.test(exp.errMsg)) {
|
||||||
|
return { result: { _state: 'CLIENT_BACKEND_BROKEN' } }
|
||||||
|
}else {
|
||||||
|
return { result: { _state: 'CLIENT_BACKEND_EXCEPTION' }}
|
||||||
|
}
|
||||||
|
})
|
||||||
result = resultCloud
|
result = resultCloud
|
||||||
} else {
|
} else {
|
||||||
if (method === 'GET') {
|
if (method === 'GET') {
|
||||||
@ -71,8 +80,20 @@ module.exports = {
|
|||||||
header: { _passtoken: uni.getStorageSync('_passtoken') },
|
header: { _passtoken: uni.getStorageSync('_passtoken') },
|
||||||
data: apiWhat,
|
data: apiWhat,
|
||||||
})
|
})
|
||||||
|
if (error) {
|
||||||
|
if (error.errMsg === 'request:fail') {
|
||||||
|
// 后台断线
|
||||||
|
result = { _state: 'CLIENT_BACKEND_BROKEN' }
|
||||||
|
} else (error.errMsg==='request:fail timeout') {
|
||||||
|
// 后台异常而超时返回
|
||||||
|
result = { _state: 'CLIENT_BACKEND_TIMEOUT' }
|
||||||
|
}else{
|
||||||
|
result = { _state: 'CLIENT_BACKEND_EXCEPTION' }
|
||||||
|
}
|
||||||
|
} else {
|
||||||
result = resultServer
|
result = resultServer
|
||||||
}
|
}
|
||||||
|
}
|
||||||
console.log('👆 < BackendResult > ️', result, '< /BackendResult > 👆')
|
console.log('👆 < BackendResult > ️', result, '< /BackendResult > 👆')
|
||||||
return result
|
return result
|
||||||
},
|
},
|
||||||
@ -290,11 +311,11 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
formatMoney(value, decimal) {
|
formatMoney(value, decimal) {
|
||||||
return Number(value).toFixed(decimal || 2)
|
return Number(value || 0).toFixed(decimal || 2) // Number(undefined)===NaN
|
||||||
},
|
},
|
||||||
|
|
||||||
formatPercent(value, decimal) {
|
formatPercent(value, decimal) {
|
||||||
return `${Number(value * 100).toFixed(decimal || 2)}`
|
return Number(value * 100 || 0).toFixed(decimal || 2)
|
||||||
},
|
},
|
||||||
|
|
||||||
formatDate(date, format) {
|
formatDate(date, format) {
|
||||||
|
Loading…
Reference in New Issue
Block a user