api.js 806 B

1234567891011121314151617181920212223242526272829303132
  1. import request from '@/utils/request'
  2. import md5 from 'js-md5'
  3. import {
  4. getUser
  5. } from '@/utils/auth'
  6. const version = '1.0'
  7. const secret = '017c0743819088468e590246464cc75f';
  8. export function postData(method, data) {
  9. let user = getUser();
  10. let uid = user.uid
  11. let token = user.token
  12. let role = user.roles&&user.roles[0]||''
  13. // 未登入
  14. if (method.split(".")[0] == 'Auth') {
  15. uid = '0'
  16. token = ''
  17. role = ''
  18. }else if( token == ''){
  19. return
  20. }
  21. let body = JSON.stringify(data);
  22. let mtime = parseInt(Date.now() / 1000);
  23. let sigureStr = "rental_" + version + token + body + method + mtime + secret
  24. let sign = md5(sigureStr)
  25. let url = `/rental/${method}?t=${mtime}&u=${uid}&v=${version}&s=${sign}`
  26. return request({
  27. url: url,
  28. method: 'post',
  29. data: body
  30. })
  31. }