diff --git a/App.vue b/App.vue index 8e85087..892d0a4 100644 --- a/App.vue +++ b/App.vue @@ -1,11 +1,11 @@ diff --git a/pages/index.vue b/pages/index.vue index 4c65eeb..4040023 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -382,7 +382,7 @@ - + @@ -399,10 +399,16 @@ landList: [1, 2, 3], value: false, sliderValue: 1, + landDataChange: true, } }, onLoad() { - // uni.$emit("mqtt-link"); + // uni.$emit("mqtt-link"); + uni.$off("notify-updates-land"); + uni.$on("notify-updates-land", () => { + console.error("更新数据") + this.landDataChange = true; + }); }, onShow() { // #ifdef APP-PLUS diff --git a/utils/land.js b/utils/indexUtil.js similarity index 75% rename from utils/land.js rename to utils/indexUtil.js index 4934a3d..f0682dd 100644 --- a/utils/land.js +++ b/utils/indexUtil.js @@ -6,37 +6,40 @@ import { getManagerGroundList, } from "@/api/index.js" -class land { +class indexUtil { static isFirst = true //是否第一次加载 - static userId = null; - static list = []; - static selectCId = null; - static selectItem = null; + static userId = null; //用户id + static list = []; //列表 + static showIndex = null; //默认显示的面板索引 + static selectItem = null; //选中的数据 + static isDataChange = false; //数据是否改变 //接收创建来的数据 constructor() { this.isFirst = true; this.userId = null; this.list = []; - this.selectCId = null; + this.showIndex = null; this.selectItem = null; } // 获取列表 getList(userId) { - console.error("isFirst:",this.isFirst); + uni.showLoading(); this.userId = userId; if (this.isFirst) { const lands = uni.getStorageSync(constant.lands); if (lands && lands.userId == userId) { this.list = lands.data; } + this.selectItem = uni.getStorageSync(constant.landItem) || null; + this.showIndex = this.findLandIndex(this.list, this.selectItem); } + uni.hideLoading(); if (this.isFirst) { this.isFirst = false; this.getNewList(userId); } - console.error("list:",this.list); } // 获取最新数据 @@ -56,29 +59,31 @@ class land { // console.error("land:", land); if (land.data.length) { this.handleData(companys, land.data); - // 持久化到本地缓存中 - this.setStorage(1, { - userId: this.userId, - data: this.list, - }); - this.setStorage(2, this.selectItem); } else { commonUtils.toast("无数据"); - // 持久化到本地缓存中 - this.setStorage(1, null); - this.setStorage(2, null); + this.list = null; + this.selectItem = null; } } else { commonUtils.toast("无数据"); - this.setStorage(1, null); - this.setStorage(2, null); + this.list = null; + this.selectItem = null; } + // 持久化到本地缓存中 + if (this.list) { + this.setStorage(1, { + userId: this.userId, + data: this.list, + }); + } else { + this.setStorage(1, null); + } + this.setStorage(2, this.selectItem); } // 组织数据 handleData(companys, lands) { let id = null; - let selectCId = null; let selectItem = null; const landItem = uni.getStorageSync(constant.landItem); if (landItem) { @@ -125,15 +130,27 @@ class land { let index = 0; while (!selectItem) { if (companys[index].children.length) { - companys[index].isLoad = true; companys[index].children[0].isSelect = true; selectItem = companys[index].children[0]; } } - - this.selectCId = selectItem.companyId; this.list = companys; this.selectItem = selectItem; + this.showIndex = this.findLandIndex(this.list, this.selectItem); + } + + //寻找默认显示的行 + findLandIndex(list, item) { + let showIndex = null + if (list.length && item) { + for (var i = 0; i < list.length; i++) { + if (list[i].id == item.companyId) { + showIndex = i; + break; + } + } + } + return showIndex; } // 缓存数据 @@ -145,7 +162,6 @@ class land { } else { commonUtils.toast("数据持久化异常"); } - } } -export default land \ No newline at end of file +export default indexUtil \ No newline at end of file