Ver código fonte

fix:通用工具栏request.js修改

chenzhen2 1 ano atrás
pai
commit
1a394a959c

+ 45 - 0
src/common/request.js

@@ -2,12 +2,57 @@
 import config from '@/config';
 import store from '@/store';
 import errorRequest from './errorRequest.js';
+// get参数反序列化
+const setQueryConfig = function (queryConfig) {
+  let _str = ''
+  for (const o in queryConfig) {
+    if (queryConfig[o] !== -1) {
+      _str += o + '=' + queryConfig[o] + '&'
+    }
+  }
+  _str = _str.substring(0, _str.length - 1) // 末尾是&
+  return _str
+}
+
+function storeUser() {
+  return store.state.user.userInfo;
+}
+
+function getProjectId() {
+  return (
+    store.state.company.companyConfig &&
+    store.state.company.companyConfig.sagacareProjectId
+  );
+}
+
+// 通用参数携带
+function commonParams() {
+  return `openid=${storeUser().userId}&pubname=${config.brsgServer.pubname
+    }&projectId=${getProjectId()}&userName=${storeUser().userName}&userPhone=${storeUser().phone
+    }&userId=${storeUser().userId}`;
+}
 
 export default function (info) {
   if (info.url.startsWith('/')) {
     const serverSp = info.serverSp ? info.serverSp : config.serverUrl
     info.url = serverSp + info.url
   }
+  // get参数格式化(新增通用参数处理)
+  if (info.params && (info.method == 'GET' || info.method == 'get')) {
+    if (info.url.indexOf("?") != -1) { // 携带有参数
+      info.url = `${info.url}&${setQueryConfig(info.params)}`
+    } else {
+      info.url = `${info.url}?${setQueryConfig(info.params)}`
+    }
+  }
+  if (info.isComParams) {
+    if (info.url.indexOf("?") != -1) { // 携带有参数
+      info.url = `${info.url}&${commonParams()}`
+    } else {
+      info.url = `${info.url}?${commonParams()}`
+    }
+
+  }
 
   const token = store.state.user.token;
   if (token) {

+ 1 - 1
src/config/dev.js

@@ -3,7 +3,7 @@
 // let appKey = '6166782f14e22b6a4f1ef5a0'; // um 蓝色图标小程序
 // const websoketUrl = 'wss://dev.tenants.link';
 
-const serverUrl = '';
+const serverUrl = 'https://duoduoenv.sagacloud.cn';
 let h5Origin = '';
 let appKey = ''; // um 蓝色图标小程序
 const websoketUrl = '';

+ 7 - 0
src/config/index.js

@@ -21,6 +21,10 @@ if (env === 'prod') {
 }
 
 
+ const setupService = '/duoduo-service/setup-service/'
+ const objectService = '/duoduo-service/object-service/'
+ const duoduoenvService = '/duoduo-service/duoduoenv-service/'
+
 config = Object.assign(base, config, {
   // h5PagePath: config.h5Origin + '/#',
   h5PagePath: "http://localhost:8081/" + '/#',
@@ -28,6 +32,9 @@ config = Object.assign(base, config, {
   // h5StaticPath: config.h5Origin + '/static/WeChat',
   featuresVersion,
   projectName,
+  setupService,
+  objectService,
+  duoduoenvService,
   env
 });
 

+ 2 - 2
src/config/prod.js

@@ -14,7 +14,7 @@ if (featuresVersion === 'enterprise') {
   // appKey = '61663db014e22b6a4f1e66b6'; // um 黄色图标小程序
   // websoketUrl = 'wss://sagacare-h5.tenants.link';
 
-  const serverUrl = '';
+  // const serverUrl = 'https://duoduoenv.sagacloud.cn';
   let h5Origin = '';
   let appKey = ''; // um 蓝色图标小程序
   const websoketUrl = '';
@@ -44,7 +44,7 @@ if (featuresVersion === 'enterprise') {
     projectDomain = ProjectNameDomainMap[projectName];
   }
 
-  serverUrl = `https://${projectDomain}/api`;
+  serverUrl = `https://duoduoenv.sagacloud.cn`;
   // h5Origin = `https://${projectDomain}`;
   h5Origin = 'http://localhost:8081/';
   websoketUrl = `wss://${projectDomain}`

+ 15 - 15
src/packagesEnv/api/intelligentControl.js

@@ -21,15 +21,15 @@ function getSpaceLightsHttp(spaceId, companyId) {
         let testResult = {
             'result': 'success',
             'content': JSON.stringify([{
-                    runStatus: 1,
-                    lampType: '顶灯',
-                    id: 1
-                },
-                {
-                    runStatus: 1,
-                    lampType: '射灯',
-                    id: 2
-                }
+                runStatus: 1,
+                lampType: '顶灯',
+                id: 1
+            },
+            {
+                runStatus: 1,
+                lampType: '射灯',
+                id: 2
+            }
             ])
         };
         return Promise.resolve({
@@ -84,11 +84,11 @@ function changeAirconditionHttp(spaceId, status, companyId) {
 }
 
 function getSpaceBytoothHttp(devices, companyId) {
-  return $http({
-      url: `/persagy/space/device2?companyId=${companyId}`,
-      method: 'POST',
-      data: JSON.stringify(devices)
-  })
+    return $http({
+        url: `/persagy/space/device2?companyId=${companyId}`,
+        method: 'POST',
+        data: JSON.stringify(devices)
+    })
 }
 
 function checkChangeLightStatusSuccessHttp(params, companyId) {
@@ -123,7 +123,7 @@ function saveCustomServerTimeHttp(params) {
         serverSp: config.brsgServer.duoduoUrl,
         url: `/tenantslink/customScene/save?projectId=${projectId}`,
         method: 'POST',
-        data: JSON.stringify({...params, projectId: projectId })
+        data: JSON.stringify({ ...params, projectId: projectId })
     })
 }
 

+ 26 - 0
src/packagesEnv/api/mapApi.js

@@ -0,0 +1,26 @@
+import $http from '@/common/request.js';
+import config from '@/config';
+
+// 获取楼层数据
+function getFloorList(params) {
+    return $http({
+        url: `${config.objectService}object/floor/query`,
+        method: 'POST',
+        data: JSON.stringify(params),
+        isComParams: false   // 是否携带通用的参数
+    })
+}
+
+// 获取地图数据
+function getMapInfo(params) {
+    return $http({
+        url: `${config.setupService}map/queryMapInfo`,
+        method: 'POST',
+        data: JSON.stringify(params),
+        isComParams: false    // 是否携带通用的参数
+    })
+}
+
+export {
+    getFloorList
+}

+ 27 - 27
src/packagesEnv/pages/intelligentControl/home2.wpy

@@ -394,7 +394,7 @@ wepy.component({
       this.foldStatus = 'fold';
       this.canSlideExpanel = false;
     }
-   
+
     checkHasUserInfo()
       .then(userInfo => {
         // let companyId =
@@ -412,9 +412,9 @@ wepy.component({
         return this.getHistorySelectedArea();
       })
       .then(historyArea => {
-        let historyAreaInfo = CompanyMapData.mapInfo.find(
-          e => e.id == historyArea.spaceId
-        );
+        // let historyAreaInfo = CompanyMapData.mapInfo.find(
+        //   e => e.id == historyArea.spaceId
+        // );
         return getMapInfoHttp(this.companyId).then(res => {
           const result = JSON.parse(res.data);
           const httpDdata = (result && result.content) || [];
@@ -483,30 +483,30 @@ wepy.component({
       }
     }
   },
-  //   onShow() {
-  //     const lastSearchedSpace = wx.getStorageSync('lastSearchedSpace');
-  //     // 从搜索页面返回且搜索有效
-  //     if (lastSearchedSpace) {
-  //       let area = this.mapAreasInfo.find(item => {
-  //         return item.id == lastSearchedSpace.spaceId;
-  //       });
-  //       this.foldPanelFun();
-  //       this.doSelectArea(area);
-  //       // 清空,以免每次onshow时都执行(只需在从搜索页面返回时执行)
-  //       wx.removeStorageSync('lastSearchedSpace');
-  //     }
-  //     if (this.pageHide) {
-  //       this.pageHide = false;
-  //     }
-  //   },
-
-  //   onHide() {
-  //     this.pageHide = true;
-  //   },
-  //   onUnload() {
-  //     this.pageHide = true;
-  //   },
   methods: {
+    /**
+     * 查询楼层信息
+     */
+    getFloorList(flag) {
+      let params = {
+        criteria: {
+          projectId: projectId
+        }
+      };
+      getFloorList(params).then(res => {});
+    },
+    /**
+     * 获取地图信息
+     */
+    getMapInfo() {
+      let params = {
+        projectId: 'props.projectId',
+        floorId: 'proxyData.floorItem.id'
+      };
+      getMapInfo(params)
+        .then(res => {})
+        .catch(() => {});
+    },
     getMapSize() {
       getScreenInfo().then(res => {
         this.screenScale = res.screenScale;

+ 7 - 2
src/store/company.js

@@ -1,13 +1,18 @@
 export default {
   state: {
-    companyConfig: null
+    companyConfig: {
+      projectId: 'Pj1101080255'  // 测试阶段先给一个默认值
+    }
   },
   mutations: {
     setCompanyConfig(state, configInfo) {
       state.companyConfig = configInfo;
     },
     clearCompanyConfig(state) {
-      state.companyConfig = null;
+      // state.companyConfig = null;
+      state.companyConfig = {
+        projectId: 'Pj1101080255'  // 测试阶段先给一个默认值
+      }
     }
   },
   actions: {