1. import query from "vendor/utils/getUrlParms";
  2. import LS from "vendor/utils/cz-storage";
  3. import Loading from "vendor/ui/loading";
  4. let scene = query('scene')||localStorage.scene||'';
  5. if( scene ) localStorage.scene = scene;
  6. let appid = query('appid')||LS.get('appid')||'';
  7. let token = query('token')||LS.get('token')||'';
  8. LS.put('appid',appid)
  9. LS.put('token',token)
  10. module.exports = {
  11. //签到
  12. miniSign(data,opt={}){
  13. return request('xx/xx/xx', data,Object.assign({type:'POST',isLoading:true }, opt));
  14. },
  15. }
  16. function request(url, data={}, opt={}) {
  17. var dtd = $.Deferred();
  18. if( opt.isLoading ){
  19. Loading.show();
  20. }
  21. data.scene = data.scene||scene||'';
  22. // 取llb用户信息
  23. if( window.userId&&window.token ){
  24. data.originalToken = window.token||'';
  25. data.userIdStr = window.userId||'';
  26. }
  27. let ajaxHeader = {
  28. headers: {
  29. "Accept": "application/json; charset=utf-8",
  30. "appid": appid,
  31. "authorization": token?'Bearer ' +token:'',
  32. },
  33. url: url.indexOf('http')!=-1?url:vueApp.config.serverPath+url,
  34. type: opt.type||"POST",
  35. data: data,
  36. }
  37. if( opt.isUpload ){
  38. ajaxHeader.contentType = false;
  39. ajaxHeader.processData = false;
  40. }
  41. $.ajax(ajaxHeader).done((res,status,xhr) => {
  42. dtd.resolve(res);
  43. }).fail(res => {
  44. Loading.hide();
  45. dtd.resolve({success:false,msg:'网络错误请重试!'});
  46. }).always((res) => {
  47. if( opt.isLoading ){
  48. Loading.hide();
  49. }
  50. });
  51. return dtd;
  52. }