28 lines
799 B
JavaScript
28 lines
799 B
JavaScript
import { KEFU_BASE_URL, Authorization } from '@/utils/config.js'
|
|||
|
|
import { getStorageFun, TOKEN_NAME } from '@/utils/auth.js'
|
||
|
|
|
||
|
|
export function getUnreadCount(userId) {
|
||
|
|
const token = getStorageFun(TOKEN_NAME)
|
||
|
|
return new Promise((resolve, reject) => {
|
||
|
|
uni.request({
|
||
|
|
url: `${KEFU_BASE_URL}/kefu/user/unread-count`,
|
||
|
|
method: 'GET',
|
||
|
|
data: { userId },
|
||
|
|
header: {
|
||
|
|
Authorization,
|
||
|
|
'HSM-AUTH': token || '',
|
||
|
|
'content-type': 'application/json'
|
||
|
|
},
|
||
|
|
success: response => {
|
||
|
|
const body = response.data || {}
|
||
|
|
if (response.statusCode >= 200 && response.statusCode < 300 && body.bizcode === 100) {
|
||
|
|
resolve(Number(body.data || 0))
|
||
|
|
return
|
||
|
|
}
|
||
|
|
resolve(0)
|
||
|
|
},
|
||
|
|
fail: () => resolve(0)
|
||
|
|
})
|
||
|
|
})
|
||
|
|
}
|