You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
720 B

8 months ago
  1. import http from './http.js'
  2. const config = {
  3. // 微信登录
  4. wxLogin : {url : '/api/wxLogin', method : 'POST', auth : false},
  5. // 2 用户支付
  6. createOrder : {url : '/api/createOrder', method : 'POST', auth : true},
  7. }
  8. export function api(key, data, callback, loadingTitle){
  9. if (!config[key]) {
  10. return console.error('无效key' + key);
  11. }
  12. if (config[key].auth) {
  13. if (!localStorage.getItem('token')) {
  14. uni.navigateTo({
  15. url: '/pages/login/mobile'
  16. })
  17. console.error('需要登录')
  18. return {
  19. then() {}
  20. };
  21. }
  22. }
  23. http.http(config[key].url, data, callback, config[key].method,
  24. loadingTitle || config[key].showLoading, loadingTitle || config[key].loadingTitle)
  25. }
  26. export default api