index.obj.js 622 B

1234567891011121314151617181920212223242526272829
  1. const uniStat = require('uni-stat')
  2. const uniID = require('uni-id')
  3. module.exports = {
  4. report: async function (params = {}) {
  5. //客户端信息
  6. const clientInfo = this.getClientInfo()
  7. //云服务信息
  8. const cloudInfo = this.getCloudInfo()
  9. //token信息
  10. const token = this.getUniIdToken()
  11. //当前登录用户id
  12. let uid
  13. if(token) {
  14. const tokenRes = await uniID.createInstance({
  15. clientInfo
  16. }).checkToken(token)
  17. if(tokenRes.uid) {
  18. uid = tokenRes.uid
  19. }
  20. }
  21. //数据上报
  22. return await uniStat.initReceiver().report(params, {
  23. ...clientInfo,
  24. ...cloudInfo,
  25. uid
  26. })
  27. }
  28. }