requestConfig.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import store from "@/store";
  2. var doubleClickList = []; //防连击的数组对象
  3. // 请求地址对象
  4. const endpoints = {
  5. upload: 'elab-marketing-system/behavior/brandMiniWeb/upload', //埋点接口
  6. login: 'elab-marketing-analyse/cockpit/login', //用户登录
  7. uploadBase64: 'elab-marketing-file/upload/uploadBase64', //uploadBase64
  8. // // webGL接口
  9. getHouseTypeSpaceDetailsV2: 'elab-marketing-file/space_generation_background/getHouseTypeSpaceDetails/v2', //V1.1.0-城市首页
  10. getHouseTypeSpaceDetails: 'elab-marketing-file/space_generation_background/getHouseTypeSpaceDetails', //V1.1.0-城市首页
  11. // // 柔性定制接口
  12. getHouseTypeSpaceWalls: '/elab-marketing-file/space_generation_background/getHouseTypeSpaceWalls', // 批量获取墙面信息
  13. houseDetail: 'elab-marketing-user/house/detail',
  14. findHouseTypeSpaceList: 'elab-marketing-file/space_generation_background/findHouseTypeSpaceList',
  15. layoutList: 'elab-marketing-content/aiDreamHouse/V3.0/layoutList',
  16. labelList: 'elab-marketing-content/aiDreamHouse/V3.0/labelList',
  17. findOverallArrangementList: 'elab-marketing-file/space_generation_background/findOverallArrangementList',
  18. getOverallArrangementDetailsList: 'elab-marketing-file/space_generation_background/getOverallArrangementDetailsList',
  19. choiceList: "elab-marketing-content/aiDreamHouse/V3.0/choiceList",
  20. getHardboundEffects: "elab-marketing-file/space_vary/getHardboundEffects",
  21. uploadImgControlNet: "elab-marketing-content/aiBeautyFamily/uploadImgControlNet",
  22. // generateProcess: "elab-marketing-content/aiBeautyFamily/generateProcess",
  23. getUploadToken: "elab-marketing-file/upload/getUploadToken",
  24. findSpatialInfoList: "elab-marketing-file/flexible_customization/findSpatialInfoList",
  25. // AI生成界面
  26. AIuploadImgControlNet: 'elab-marketing-content/aiGenerateImg/uploadImgControlNet', //ControlNet图片上传
  27. saveCustomizedRecord: 'elab-marketing-file/space_vary/saveCustomizedRecord', //用户AI信息上传
  28. getCustomizedRecord: 'elab-marketing-file/space_vary/getCustomizedRecord', //获取用户定制记录
  29. deleteCustomizedRecord: 'elab-marketing-file/space_vary/deleteCustomizedRecord', //删除用户定制记录
  30. chineseToPinyin: 'elab-marketing-file/tools/chineseToPinyin', //汉字转拼音
  31. generateTaskImgToImgForAliyun: 'elab-marketing-content/aiGenerateImg/img2Img', // 生成识别任务-阿里云(图生图)
  32. generateTaskWordToImgForAliyun: 'elab-marketing-content/aiGenerateImg/addTaskWithWord2Img', // 生成识别任务-阿里云(文生图)
  33. generateProcess: 'elab-marketing-content/aiGenerateImg/getResult', // 获取任务进度-阿里云
  34. shareDetail: '/elab-marketing-content/aiDreamHouse/V3.0/shareDetail', // 分享查看
  35. // predictions: "https://api.replicate.com/v1/deployments/feathers-wing/spacely-realistic-style-softedge-a100/predictions", // 分享查看
  36. };
  37. window.requestConfig = async(endpoint, options, isHideLoading = false, preventDoubleClick = false, method = 'post') => {
  38. if (!endpoints.hasOwnProperty(endpoint)) {
  39. console.error(`no such endpoint: ${endpoint}`);
  40. return {
  41. message: "不存在该接口"
  42. };
  43. }
  44. const requestOptions = {
  45. path: endpoints[endpoint],
  46. data: options,
  47. };
  48. if (preventDoubleClick) {
  49. //说明该接口需要防止连击
  50. if (doubleClickList[requestOptions.path] && doubleClickList[requestOptions.path].isRunning) {
  51. console.log(`${requestOptions.path}触发连击,屏蔽该请求`)
  52. return
  53. } else {
  54. console.log(`${requestOptions.path}触发连击,通过`)
  55. doubleClickList[requestOptions.path] = {
  56. isRunning: true
  57. }
  58. }
  59. }
  60. console.log(`获取${requestOptions.path}请求的参数:`, requestOptions.data)
  61. requestOptions.url = requestOptions.path;
  62. // var t = Math.round(new Date());
  63. // requestOptions.time = t;
  64. if (!requestOptions.url.includes('/elab-marketing-user/aysn/task/byone') &&
  65. !requestOptions.url.includes('elab-marketing-analyse/heavenlyEye/saleTarget/add') &&
  66. !requestOptions.url.includes('elab-marketing-analyse/heavenlyEye/customer/coverPopulation') &&
  67. !requestOptions.url.includes('elab-marketing-analyse/heavenlyEye/customer/intention') &&
  68. !requestOptions.url.includes('elab-marketing-analyse/urbanCockpit/sky_eye_marketing/getAdCreativeDraftCheckResult') &&
  69. !requestOptions.url.includes('elab-marketing-analyse/heavenlyEye/getCompareMapTotalPopulation') &&
  70. !requestOptions.url.includes('aiGenerateImg/uploadImgControlNet') &&
  71. !requestOptions.url.includes('aiGenerateImg/img2Img') &&
  72. !requestOptions.url.includes('aiGenerateImg/getResult')
  73. ) {
  74. store.state.loading = true; //显示loading态
  75. }
  76. if (isHideLoading) {
  77. store.state.loading = false; //显示loading态
  78. }
  79. if (requestOptions.url.includes('elab-marketing-analyse/heavenlyEye/importLocations') ||
  80. requestOptions.url.includes('elab-marketing-sms/aliyun/openapi/uploadOss')) {
  81. requestOptions.ContentType = 'multipart/form-data'
  82. }
  83. if (requestOptions) {
  84. let platform = (window.userInfo && window.userInfo['userAccount'] && window.userInfo['userAccount'].platform) ? window.userInfo['userAccount'].platform : ''; //TODO 要还原成‘’的
  85. let currentProject = store.state.currentProject ? store.state.currentProject : null;
  86. let landId = currentProject ? currentProject.id : '';
  87. requestOptions.data = requestOptions.data ? requestOptions.data : {};
  88. let userTypeId = window.userInfo && window.userInfo.userType ? window.userInfo.userType.id : ''; //1客户端 ,2投手端
  89. if (userTypeId == 2) {
  90. if (!requestOptions.data.hasOwnProperty('platform') || !requestOptions.data.platform) {
  91. requestOptions.data.platform = platform
  92. }
  93. }
  94. if (!requestOptions.data.hasOwnProperty('landId') || !requestOptions.data.landId) {
  95. requestOptions.data.landId = landId
  96. }
  97. }
  98. var response;
  99. if (requestOptions.url.includes('http') || method == 'get') {
  100. let params = requestOptions.data;
  101. response = await axios.get(requestOptions.url, { params });
  102. } else {
  103. response = await axios.post(requestOptions.url, requestOptions.data);
  104. }
  105. //说明该接口需要防止连击
  106. if (preventDoubleClick && doubleClickList[requestOptions.path] && doubleClickList[requestOptions.path]
  107. .isRunning) {
  108. console.log(`${requestOptions.path}连击接口已返回,清空连击数组`)
  109. doubleClickList[requestOptions.path].isRunning = false
  110. }
  111. // console.log('返回' + requestOptions.path + '请求的结果:', response)
  112. return response;
  113. }