Преглед на файлове

fix: 环境控制页面bug修改

chenzhen2 преди 2 години
родител
ревизия
0b134e34a8
променени са 5 файла, в които са добавени 88 реда и са изтрити 10 реда
  1. 6 6
      src/apis/envmonitor.ts
  2. 5 1
      src/router/index.ts
  3. 2 1
      src/store/modules/user/action-types.ts
  4. 24 0
      src/store/modules/user/actions.ts
  5. 51 2
      src/views/home/index.vue

+ 6 - 6
src/apis/envmonitor.ts

@@ -2,11 +2,11 @@ import { RootObject, RootWeatherObject } from '@/model/rootObject'
 import { CompanyModel, OutherWeather, SpaceModel } from '@/model/userModel'
 import { https, post } from '@/utils/https'
 import { ContentType, Method, RequestParams } from 'axios-mapper'
-import { getUserInfo, setQueryConfig } from '@/utils'
+import { setQueryConfig } from '@/utils'
 import { duoduoenvService, objectService, setupService, testApi, weachatService } from '@/config'
 
-const comInfo = getUserInfo()
-const comParams: string = ""
+// const comInfo = getUserInfo()
+// const comParams: string = ""
 
 // https://sagacare-h5.tenants.link/api/company/config/245e7060643811eb934c0237aedb39a6
 export const getCompanyInfo = (companyInfo: RequestParams) => {
@@ -47,7 +47,7 @@ export const getLampHttp = (params: any) => {
 
 // 批量操作 灯
 export const setallLampHttp = (data: any) => {
-  return post(`${duoduoenvService}light/onoff/set?${comParams}`, data)
+  return post(`${duoduoenvService}light/onoff/set`, data)
 }
 // 设置窗帘
 export const setEquipeHttp = (data: any) => {
@@ -214,7 +214,7 @@ export const insertWorkSpace = (params: any) => {
  * 删除工作空间
  * @param params 
  */
- export const deleteWorkSpace = (params: any) => {
+export const deleteWorkSpace = (params: any) => {
   return https().request<any>(`${setupService}padSpace/deleteWorkSpace`, Method.POST, params, ContentType.json)
 }
 
@@ -231,7 +231,7 @@ export let queryWorkSpace = (params: any) => {
 /**
  * 查询平板下面的办公空间
  */
- export let checkWorkSpace = (params: any) => {
+export let checkWorkSpace = (params: any) => {
   return https().request<any>(`${setupService}padSpace/queryWorkSpace`, Method.POST, params, ContentType.json)
 }
 

+ 5 - 1
src/router/index.ts

@@ -16,7 +16,11 @@ const SetMainSpace: any = () => import('@/views/choiceSpace/setMainSpace.vue')
 export const constantRoutes: Array<RouteRecordRaw> = [
   {
     path: '/',
-    redirect: '/home'
+    redirect: '/home',
+    meta: {
+      title: '首页',
+      hideHeader: true
+    }
   },
   {
     path: '/home',

+ 2 - 1
src/store/modules/user/action-types.ts

@@ -5,5 +5,6 @@ export enum UserActionTypes {
   ACTION_GET_USER_INFO = 'ACTION_GET_USER_INFO',
   ACTION_CHANGE_ROLES = 'ACTION_CHANGE_ROLES',
   ACTION_LOGIN_OUT = 'ACTION_LOGIN_OUT',
-  SET_USER_MAC='SET_USER_MAC'
+  SET_USER_MAC = 'SET_USER_MAC',
+  ACTION_GET_WORKSPACE = "ACTION_GET_WORKSPACE"
 }

+ 24 - 0
src/store/modules/user/actions.ts

@@ -12,6 +12,7 @@ import { RouteRecordRaw } from 'vue-router'
 import { getUsersInfo } from '@/apis/user'
 import { clearAllLocalData, getLocalProjectId, setLocalProjectId } from '@/utils'
 import { Toast } from 'vant'
+import { queryWorkSpace } from '@/apis/envmonitor'
 
 type AugmentedActionContext = {
   commit<K extends keyof Mutations>(
@@ -34,6 +35,10 @@ export interface Actions {
     { commit }: AugmentedActionContext
   ): void
 
+  [UserActionTypes.ACTION_GET_WORKSPACE](
+    { commit }: AugmentedActionContext
+  ): void
+
   [UserActionTypes.ACTION_CHANGE_ROLES](
     { commit }: AugmentedActionContext, role: string
   ): void
@@ -84,6 +89,25 @@ export const actions: ActionTree<UserState, RootState> & Actions = {
     commit(UserMutationTypes.SET_USER_MAC, macAdr)
     // store.commit(UserMutationTypes.SET_PROJECT_ID, nowProjectId)
   },
+  async [UserActionTypes.ACTION_GET_WORKSPACE]({ commit }: AugmentedActionContext) {
+    let params: any = {
+      "criteria": {
+        "macAddress": "DA:BF:E8:7A:61:97"
+      },
+      "orders": [
+        {
+          "column": "createTime",
+          "asc": false
+        }
+      ],
+      "page": 1,
+      "size": 1
+    }
+    queryWorkSpace(params).then((res) => {
+      console.log("===")
+      console.log(res)
+    })
+  },
   async [UserActionTypes.ACTION_CHANGE_ROLES](
     { commit }: AugmentedActionContext,
     role: string

+ 51 - 2
src/views/home/index.vue

@@ -83,13 +83,14 @@ import {
   setQueryConfig,
 } from "@/utils";
 import { UserActionTypes } from "@/store/modules/user/action-types";
-import { useStore } from "@/store";
+import { store, useStore } from "@/store";
 import { login } from "@/apis/user";
 import { Form, Field, CellGroup, Button, Toast } from "vant";
 import { setToken } from "@/utils/cookies";
-import { getPadQrCodeStatus } from "@/apis/envmonitor";
+import { getPadQrCodeStatus, queryWorkSpace } from "@/apis/envmonitor";
 import { getUrlParams } from "@/utils/https";
 import { UserMutationTypes } from "@/store/modules/user/mutation-types";
+import router from "@/router";
 
 export default defineComponent({
   components: {
@@ -99,6 +100,24 @@ export default defineComponent({
     CellGroup,
     vanButton: Button,
   },
+  beforeRouteEnter(to, from, next) {
+    // 不能获取组件实例
+    // 因为当守卫执行前,组件实例还没被创建
+    console.log("路由导航首位---");
+    console.log(to);
+    console.log(from);
+    // next()
+    if (from.name !== "choiceProject") {
+      next((e: any) => {
+        console.log(e);
+        e.queryWorkSpace();
+      });
+    } else {
+      next((e: any) => {
+        router.push({ name: "home", query: { mac: e.userInfo.mac } });
+      });
+    }
+  },
   setup(props) {
     let router: any = useRouter();
     const userInfo: any = getUserInfo();
@@ -142,6 +161,36 @@ export default defineComponent({
           }
         });
       },
+      // 查询工作空间
+      queryWorkSpace() {
+        let params: any = {
+          criteria: {
+            macAddress: proxyData.userInfo.mac,
+          },
+          orders: [
+            {
+              column: "createTime",
+              asc: false,
+            },
+          ],
+          page: 1,
+          size: 1,
+        };
+        queryWorkSpace(params).then((res: any) => {
+          let resData: any = res;
+          if (resData.result === "success") {
+            let content: any = resData?.content ?? [];
+            if (content && content.length) {
+              let projectId: any = content[0].projectId;
+              store.commit(UserMutationTypes.SET_PROJECT_ID, projectId);
+              router.push({
+                name: "envmonitor",
+                query: { spaceId: content[0].spaceId },
+              });
+            }
+          }
+        });
+      },
       /**
        * 获取mac地址
        */