浏览代码

fix: 全局搜索bug

yunxing 4 年之前
父节点
当前提交
909a409717
共有 3 个文件被更改,包括 36 次插入17 次删除
  1. 17 0
      src/store/index.ts
  2. 8 14
      src/views/GlobalSearch.vue
  3. 11 3
      src/views/equipmentFacilities/ElectricWell.vue

+ 17 - 0
src/store/index.ts

@@ -22,6 +22,9 @@ export default new Vuex.Store({
         floorsArr: [], //楼层数组
         categoryId: '', //系统类型
         smsxt: '', //设备设施系统编码
+        oldCategoryId: '', //保存旧的categoryId(全局搜索使用)
+        oldSmsxt: '', //保存旧的smsxt(全局搜索使用)
+        isGlobal: false, //是否是全局搜索
         // 事件类型字典
         objtypeDict: {
             1: '重要维保',
@@ -43,6 +46,9 @@ export default new Vuex.Store({
         floorsArr: (state) => state.floorsArr,
         categoryId: (state) => state.categoryId,
         smsxt: (state) => state.smsxt,
+        oldCategoryId: (state) => state.oldCategoryId,
+        oldSmsxt: (state) => state.oldSmsxt,
+        isGlobal: (state) => state.isGlobal,
         scanAssetid: (state) => state.scanAssetid,
     },
     mutations: {
@@ -75,10 +81,21 @@ export default new Vuex.Store({
         SETCATEGORYID(state, data) {
             state.categoryId = data
         },
+        // 设置系统类型--全局搜索使用
+        SETOLDCATEGORYID(state, data) {
+            state.oldCategoryId = data
+        },
         // 设置设备设施系统编码
         SETSMSXT(state, data) {
             state.smsxt = data
         },
+        // 设置设备设施系统编码--全局搜索使用
+        SETOLDSMSXT(state, data) {
+            state.oldSmsxt = data
+        },
+        SETISGLOBAL(state, data) {
+            state.isGlobal = data
+        },
         // 设置扫一扫返回的assetid
         SCANASSETID(state, data) {
             state.scanAssetid = data

+ 8 - 14
src/views/GlobalSearch.vue

@@ -40,7 +40,7 @@ export default {
   props: {},
   components: {},
   computed: {
-    ...mapGetters(['plazaId', 'smsxt', 'categoryId']),
+    ...mapGetters(['plazaId', 'smsxt', 'categoryId','oldSmsxt', 'oldCategoryId']),
   },
   data() {
     return {
@@ -52,18 +52,19 @@ export default {
       equipList: [], //设备列表
       page: 1, //当前页码
       size: 10, //每页条数
-      oldSmsxt: '', //保存进入页面时的smsxt(点击电井间商铺控制范围,会更改此值)
-      oldCategoryId:'', //保存进入页面时的categoryId(点击电井间商铺控制范围,会更改此值)
+    
     }
   },
   props: {},
   beforeMount() { },
   mounted() {
-    this.oldSmsxt = this.smsxt
-    this.oldCategoryId = this.categoryId
+    //  保存之前的categoryId,smsxt
+    this.SETOLDCATEGORYID(this.categoryId)
+    this.SETOLDSMSXT(this.smsxt)
+    this.SETISGLOBAL(true)
   },
   methods: {
-    ...mapMutations(['SETCATEGORYID','SETSMSXT']),
+    ...mapMutations(['SETCATEGORYID', 'SETSMSXT', 'SETOLDCATEGORYID', 'SETOLDSMSXT', 'SETISGLOBAL']),
     // 跳转机房平面布置图
     handleClickEngineRoomPicture() {
       this.$router.push({ name: 'EngineRoomPicture', params: {type: "all"} })
@@ -123,14 +124,7 @@ export default {
     },
     // 取消搜索
     onCancel() {
-      // 修改smsxt为初始值
-      if(this.smsxt !== this.oldSmsxt){
-        this.SETSMSXT(this.oldSmsxt)
-      }
-      // 修改categoryId为初始值
-      if(this.oldCategoryId !== this.categoryId){
-        this.SETCATEGORYID(this.oldCategoryId)
-      }
+      this.SETISGLOBAL(false)
       this.$router.go(-1)
     },
     onLoad() {

+ 11 - 3
src/views/equipmentFacilities/ElectricWell.vue

@@ -107,7 +107,7 @@
 import Vue from 'vue'
 import { NavBar, Search, List, Cell, Icon, Popup, Button, Empty } from 'vant'
 Vue.use(NavBar).use(Search).use(List).use(Cell).use(Icon).use(Popup).use(Button).use(Empty)
-import { mapGetters } from 'vuex'
+import { mapGetters, mapMutations } from 'vuex'
 
 import { queryShops } from '@/api/equipmentList'
 import { sleep } from '@/utils/util'
@@ -146,7 +146,7 @@ export default {
         }
     },
     computed: {
-        ...mapGetters(['plazaId', 'smsxt', 'categoryId', 'floorsArr']),
+        ...mapGetters(['plazaId', 'smsxt', 'categoryId', 'floorsArr', 'oldSmsxt', 'oldCategoryId','isGlobal']),
     },
     components: {},
     created() {
@@ -155,7 +155,6 @@ export default {
         // gcode:"6F"
         // gname:"f6"
         // seq:600
-
         let floorList = [{ code: '全部', gcname: '全部', gcode: '全部', gname: '全部', seq: null, active: 'active' }]
         this.floorsArr.map(({ code, gcname, gcode, gname, seq }) => {
             floorList.push({ code, gcname, gcode, gname, seq, active: '' })
@@ -167,7 +166,16 @@ export default {
     beforeMount() {},
     mounted() {},
     methods: {
+        ...mapMutations(['SETCATEGORYID', 'SETSMSXT', 'SETOLDCATEGORYID', 'SETOLDSMSXT']),
         backPage() {
+            // 如果是全局搜索进入时,修改smsxt,categoryId为进入全局搜索之前的,
+            // 并将oldSmsxt, oldCategoryId设置为''
+            if(this.isGlobal){
+                this.SETSMSXT(this.oldSmsxt)
+                this.SETCATEGORYID(this.oldCategoryId)
+                this.SETOLDCATEGORYID('')
+                this.SETOLDSMSXT('')
+            }
             this.$router.go(-1)
         },
         /**