|
@@ -48,14 +48,14 @@
|
|
|
</template>
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
-import { ref, reactive, toRefs, onBeforeUnmount, onMounted } from "vue";
|
|
|
import lampCloseIcon from "@/assets/taiguv1/svg/lamp_close_icon.svg";
|
|
|
import lampOpenIcon from "@/assets/taiguv1/svg/lamp_open_p_icon.svg";
|
|
|
-import { parseImgUrl } from "@/utils";
|
|
|
-import { Dialog, Loading,Switch } from "vant";
|
|
|
+import { Switch } from "vant";
|
|
|
+import { onBeforeUnmount, onMounted, ref, watch } from "vue";
|
|
|
|
|
|
import any = jasmine.any;
|
|
|
|
|
|
+const emit = defineEmits(['statusChange']);
|
|
|
const LampsStatus = ref("全部关闭");
|
|
|
const childLights = ref([
|
|
|
{
|
|
@@ -75,12 +75,29 @@ const childLights = ref([
|
|
|
},
|
|
|
]);
|
|
|
|
|
|
+// 接收父组件传递的初始状态
|
|
|
+const props = defineProps({
|
|
|
+ initialStatus: {
|
|
|
+ type: Boolean,
|
|
|
+ default: false
|
|
|
+ }
|
|
|
+});
|
|
|
+
|
|
|
const checkLampsStatus = () => {
|
|
|
const allOpen = childLights.value.every((item) => item.isOpen);
|
|
|
const allClose = childLights.value.every((item) => !item.isOpen);
|
|
|
- if (allOpen) return "全部开启";
|
|
|
- if (allClose) return "全部关闭";
|
|
|
- return "部分开启";
|
|
|
+ if (allOpen) {
|
|
|
+ LampsStatus.value = "全部开启";
|
|
|
+ emit('statusChange', true);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (allClose) {
|
|
|
+ LampsStatus.value = "全部关闭";
|
|
|
+ emit('statusChange', false);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ LampsStatus.value = "部分开启";
|
|
|
+ emit('statusChange', true);
|
|
|
};
|
|
|
|
|
|
const handleSwitch = (type) => {
|
|
@@ -93,7 +110,7 @@ const handleSwitch = (type) => {
|
|
|
item.isOpen = false;
|
|
|
});
|
|
|
}
|
|
|
- LampsStatus.value = checkLampsStatus();
|
|
|
+ checkLampsStatus();
|
|
|
};
|
|
|
|
|
|
const handleChildLight = (itemCurrent: any) => {
|
|
@@ -102,8 +119,25 @@ const handleChildLight = (itemCurrent: any) => {
|
|
|
item.isOpen = itemCurrent.isOpen;
|
|
|
}
|
|
|
});
|
|
|
- LampsStatus.value = checkLampsStatus();
|
|
|
+ checkLampsStatus();
|
|
|
};
|
|
|
+
|
|
|
+// 修改 watch,添加 immediate 属性以确保初始状态同步
|
|
|
+watch(
|
|
|
+ () => props.initialStatus,
|
|
|
+ (newVal) => {
|
|
|
+ if ( LampsStatus.value === '部分开启' ) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (newVal) {
|
|
|
+ handleSwitch('allOpen');
|
|
|
+ } else {
|
|
|
+ handleSwitch('allClose');
|
|
|
+ }
|
|
|
+ },
|
|
|
+ { immediate: true }
|
|
|
+);
|
|
|
+
|
|
|
onBeforeUnmount(() => {});
|
|
|
onMounted(() => {});
|
|
|
</script>
|