Skip to content

Commit

Permalink
Merge pull request #174 from xixiIBN5100/fix/electricity
Browse files Browse the repository at this point in the history
perf(electricity): sync campus state
  • Loading branch information
xixiIBN5100 authored Jan 4, 2025
2 parents 0f6cbf9 + fa5f524 commit 1b32058
Showing 1 changed file with 9 additions and 23 deletions.
32 changes: 9 additions & 23 deletions src/pages/electricity/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -96,39 +96,26 @@ import {
} from "@/components";
import { useRequest } from "@/hooks";
import { YxyService } from "@/services";
import { computed, ref, watch } from "vue";
import { computed, ref } from "vue";
import store, { serviceStore } from "@/store";
import Taro from "@tarojs/taro";
const options = ref(["朝晖/屏峰", "莫干山"]);
const selectedIndex = ref(serviceStore.electricity.selectIndex);
const selectedIndex = computed(() => serviceStore.electricity.selectIndex);
const selectedOption = computed(() => options.value[selectedIndex.value]);
const valueMap = {
"朝晖/屏峰": "zhpf",
"莫干山": "mgs"
};
// eslint-disable-next-line no-warning-comments
// TODO: 优化双向同步操作
// 双向同步 selectedIndex 和 serviceStore.electricity.selectedIndex
watch(
selectedIndex,
(newValue) => {
serviceStore.electricity.selectIndex = newValue;
}
);
watch(
() => serviceStore.electricity.selectIndex,
(newValue) => {
selectedIndex.value = newValue;
}
);
const selectedOption = computed(() => options.value[selectedIndex.value]);
const onPickerChange = (event: { detail: { value: number } }) => {
selectedIndex.value = event.detail.value;
const selectedValue = valueMap[selectedOption.value];
const selectedValue = valueMap[options.value[event.detail.value]];
serviceStore.electricity.electricityCampus = selectedValue;
serviceStore.electricity.selectIndex = event.detail.value;
// 调用查询接口
getQueryBalance({ campus: selectedValue });
getQueryConsumption({ campus: selectedValue });
};
Expand Down Expand Up @@ -177,8 +164,7 @@ const {
if (response.data.code === 1) {
store.commit("setConsumption", response.data.data[0].used);
} else if (response.data.code === 200525) {
selectedIndex.value = 0;
serviceStore.electricity.selectedIndex = 0;
serviceStore.electricity.selectIndex = 0;
serviceStore.electricity.electricityCampus = "zhpf";
} else {
throw new Error(response.data.msg);
Expand Down

0 comments on commit 1b32058

Please sign in to comment.