全部打开/关闭
This commit is contained in:
parent
07459ccd39
commit
8cf6372b6e
|
|
@ -128,6 +128,33 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// 统一构建网关命令负载
|
||||||
|
buildGatewayPayload(command, reason) {
|
||||||
|
// 使用子组件提供的 getCurrentSelection 获取最新的楼层信息
|
||||||
|
let selection = this.currentSelection;
|
||||||
|
if (
|
||||||
|
this.$refs.floorSelector &&
|
||||||
|
typeof this.$refs.floorSelector.getCurrentSelection === "function"
|
||||||
|
) {
|
||||||
|
selection = this.$refs.floorSelector.getCurrentSelection();
|
||||||
|
}
|
||||||
|
const floorId = selection?.floor?.label;
|
||||||
|
if (!floorId) {
|
||||||
|
uni.showToast({ title: "请先选择楼层", icon: "none" });
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
console.log("floodr", floorId);
|
||||||
|
return {
|
||||||
|
// 兼容字段:同时传 floorId 与后端现用的 regionId
|
||||||
|
|
||||||
|
regionId: String(floorId),
|
||||||
|
command, // open | close
|
||||||
|
mac: "FFFFFFFFFFFF",
|
||||||
|
timeout: "11",
|
||||||
|
reason,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
// 选择单位并输入时长
|
// 选择单位并输入时长
|
||||||
async promptDurationAndUnit() {
|
async promptDurationAndUnit() {
|
||||||
// 1:天 2:小时 3:分钟 4:秒
|
// 1:天 2:小时 3:分钟 4:秒
|
||||||
|
|
@ -173,11 +200,20 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
async handleAllOpen() {
|
async handleAllOpen() {
|
||||||
if (!this.ensureUnitSelected()) return;
|
const payload = this.buildGatewayPayload("open", "全开");
|
||||||
await this.performPut(
|
await this.performPut(
|
||||||
`/app/memorial/sendCommandGateway`,
|
`/app/memorial/sendCommandGateway`,
|
||||||
null,
|
payload,
|
||||||
"handleForceOpen",
|
"handleAllOpen",
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
|
async handleAllClose() {
|
||||||
|
const payload = this.buildGatewayPayload("close", "全关");
|
||||||
|
await this.performPut(
|
||||||
|
`/app/memorial/sendCommandGateway`,
|
||||||
|
payload,
|
||||||
|
"handleAllClose",
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,8 @@
|
||||||
<view
|
<view
|
||||||
v-for="floor in floors"
|
v-for="floor in floors"
|
||||||
:key="floor.id"
|
:key="floor.id"
|
||||||
class="floor-btn"
|
|
||||||
:class="{ active: selectedFloor && selectedFloor.id === floor.id }"
|
:class="{ active: selectedFloor && selectedFloor.id === floor.id }"
|
||||||
|
class="floor-btn"
|
||||||
@click="selectFloor(floor)"
|
@click="selectFloor(floor)"
|
||||||
>
|
>
|
||||||
{{ floor.label }}
|
{{ floor.label }}
|
||||||
|
|
@ -25,8 +25,8 @@
|
||||||
<view
|
<view
|
||||||
v-for="area in areas"
|
v-for="area in areas"
|
||||||
:key="area.id"
|
:key="area.id"
|
||||||
class="area-btn"
|
|
||||||
:class="{ active: selectedArea && selectedArea.id === area.id }"
|
:class="{ active: selectedArea && selectedArea.id === area.id }"
|
||||||
|
class="area-btn"
|
||||||
@click="selectArea(area)"
|
@click="selectArea(area)"
|
||||||
>
|
>
|
||||||
{{ area.label }}
|
{{ area.label }}
|
||||||
|
|
@ -42,8 +42,8 @@
|
||||||
<view
|
<view
|
||||||
v-for="unit in units"
|
v-for="unit in units"
|
||||||
:key="unit.id"
|
:key="unit.id"
|
||||||
class="unit-btn"
|
|
||||||
:class="{ active: selectedUnit && selectedUnit.id === unit.id }"
|
:class="{ active: selectedUnit && selectedUnit.id === unit.id }"
|
||||||
|
class="unit-btn"
|
||||||
@click="selectUnit(unit)"
|
@click="selectUnit(unit)"
|
||||||
>
|
>
|
||||||
{{ unit.label }}
|
{{ unit.label }}
|
||||||
|
|
@ -55,25 +55,25 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { getMemorialTree } from '@/api/memorial/index.js'
|
import { getMemorialTree } from "@/api/memorial/index.js";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'FloorSelector',
|
name: "FloorSelector",
|
||||||
props: {
|
props: {
|
||||||
// 默认选中的楼层ID
|
// 默认选中的楼层ID
|
||||||
defaultFloorId: {
|
defaultFloorId: {
|
||||||
type: String,
|
type: String,
|
||||||
default: '',
|
default: "",
|
||||||
},
|
},
|
||||||
// 默认选中的区域ID
|
// 默认选中的区域ID
|
||||||
defaultAreaId: {
|
defaultAreaId: {
|
||||||
type: String,
|
type: String,
|
||||||
default: '',
|
default: "",
|
||||||
},
|
},
|
||||||
// 默认选中的单元ID
|
// 默认选中的单元ID
|
||||||
defaultUnitId: {
|
defaultUnitId: {
|
||||||
type: String,
|
type: String,
|
||||||
default: '',
|
default: "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
|
|
@ -83,70 +83,70 @@
|
||||||
selectedArea: null,
|
selectedArea: null,
|
||||||
selectedUnit: null,
|
selectedUnit: null,
|
||||||
loading: false,
|
loading: false,
|
||||||
}
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
// 楼层列表
|
// 楼层列表
|
||||||
floors() {
|
floors() {
|
||||||
if (!this.treeData.length) return []
|
if (!this.treeData.length) return [];
|
||||||
const memorial = this.treeData[0]
|
const memorial = this.treeData[0];
|
||||||
return memorial && memorial.children ? memorial.children : []
|
return memorial && memorial.children ? memorial.children : [];
|
||||||
},
|
},
|
||||||
// 当前选中楼层的区域列表
|
// 当前选中楼层的区域列表
|
||||||
areas() {
|
areas() {
|
||||||
if (!this.selectedFloor) return []
|
if (!this.selectedFloor) return [];
|
||||||
return this.selectedFloor.children ? this.selectedFloor.children : []
|
return this.selectedFloor.children ? this.selectedFloor.children : [];
|
||||||
},
|
},
|
||||||
// 当前选中区域的单元列表
|
// 当前选中区域的单元列表
|
||||||
units() {
|
units() {
|
||||||
if (!this.selectedArea) return []
|
if (!this.selectedArea) return [];
|
||||||
return this.selectedArea.children ? this.selectedArea.children : []
|
return this.selectedArea.children ? this.selectedArea.children : [];
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
// 监听选中变化,向父组件发送事件
|
// 监听选中变化,向父组件发送事件
|
||||||
selectedUnit: {
|
selectedUnit: {
|
||||||
handler(newUnit) {
|
handler(newUnit) {
|
||||||
this.$emit('selection-change', {
|
this.$emit("selection-change", {
|
||||||
floor: this.selectedFloor,
|
floor: this.selectedFloor,
|
||||||
area: this.selectedArea,
|
area: this.selectedArea,
|
||||||
unit: newUnit,
|
unit: newUnit,
|
||||||
})
|
});
|
||||||
},
|
},
|
||||||
deep: true,
|
deep: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.loadTreeData()
|
this.loadTreeData();
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
// 加载树形数据
|
// 加载树形数据
|
||||||
async loadTreeData() {
|
async loadTreeData() {
|
||||||
this.loading = true
|
this.loading = true;
|
||||||
try {
|
try {
|
||||||
const response = await getMemorialTree()
|
const response = await getMemorialTree();
|
||||||
console.log('楼层树形数据:', response)
|
console.log("楼层树形数据:", response);
|
||||||
|
|
||||||
if (response && response.code === 200) {
|
if (response && response.code === 200) {
|
||||||
this.treeData = response.data || []
|
this.treeData = response.data || [];
|
||||||
|
|
||||||
// 设置默认选中项
|
// 设置默认选中项
|
||||||
this.setDefaultSelection()
|
this.setDefaultSelection();
|
||||||
} else {
|
} else {
|
||||||
console.error('获取楼层数据失败:', response)
|
console.error("获取楼层数据失败:", response);
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: '获取楼层数据失败',
|
title: "获取楼层数据失败",
|
||||||
icon: 'none',
|
icon: "none",
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('加载楼层数据失败:', error)
|
console.error("加载楼层数据失败:", error);
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: '网络异常,请稍后重试',
|
title: "网络异常,请稍后重试",
|
||||||
icon: 'none',
|
icon: "none",
|
||||||
})
|
});
|
||||||
} finally {
|
} finally {
|
||||||
this.loading = false
|
this.loading = false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
@ -154,64 +154,64 @@
|
||||||
setDefaultSelection() {
|
setDefaultSelection() {
|
||||||
// 设置默认楼层
|
// 设置默认楼层
|
||||||
if (this.defaultFloorId) {
|
if (this.defaultFloorId) {
|
||||||
const floor = this.floors.find(f => f.id === this.defaultFloorId)
|
const floor = this.floors.find((f) => f.id === this.defaultFloorId);
|
||||||
if (floor) {
|
if (floor) {
|
||||||
this.selectFloor(floor)
|
this.selectFloor(floor);
|
||||||
}
|
}
|
||||||
} else if (this.floors.length > 0) {
|
} else if (this.floors.length > 0) {
|
||||||
// 默认选中第一个楼层
|
// 默认选中第一个楼层
|
||||||
this.selectFloor(this.floors[0])
|
this.selectFloor(this.floors[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 设置默认区域
|
// 设置默认区域
|
||||||
if (this.defaultAreaId && this.selectedFloor) {
|
if (this.defaultAreaId && this.selectedFloor) {
|
||||||
const area = this.areas.find(a => a.id === this.defaultAreaId)
|
const area = this.areas.find((a) => a.id === this.defaultAreaId);
|
||||||
if (area) {
|
if (area) {
|
||||||
this.selectArea(area)
|
this.selectArea(area);
|
||||||
}
|
}
|
||||||
} else if (this.areas.length > 0) {
|
} else if (this.areas.length > 0) {
|
||||||
// 默认选中第一个区域
|
// 默认选中第一个区域
|
||||||
this.selectArea(this.areas[0])
|
this.selectArea(this.areas[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 设置默认单元
|
// 设置默认单元
|
||||||
if (this.defaultUnitId && this.selectedArea) {
|
if (this.defaultUnitId && this.selectedArea) {
|
||||||
const unit = this.units.find(u => u.id === this.defaultUnitId)
|
const unit = this.units.find((u) => u.id === this.defaultUnitId);
|
||||||
if (unit) {
|
if (unit) {
|
||||||
this.selectUnit(unit)
|
this.selectUnit(unit);
|
||||||
}
|
}
|
||||||
} else if (this.units.length > 0) {
|
} else if (this.units.length > 0) {
|
||||||
// 默认选中第一个单元
|
// 默认选中第一个单元
|
||||||
this.selectUnit(this.units[0])
|
this.selectUnit(this.units[0]);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// 选择楼层
|
// 选择楼层
|
||||||
selectFloor(floor) {
|
selectFloor(floor) {
|
||||||
this.selectedFloor = floor
|
this.selectedFloor = floor;
|
||||||
this.selectedArea = null
|
this.selectedArea = null;
|
||||||
this.selectedUnit = null
|
this.selectedUnit = null;
|
||||||
|
|
||||||
// 自动选中第一个区域
|
// 自动选中第一个区域
|
||||||
if (this.areas.length > 0) {
|
if (this.areas.length > 0) {
|
||||||
this.selectArea(this.areas[0])
|
this.selectArea(this.areas[0]);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// 选择区域
|
// 选择区域
|
||||||
selectArea(area) {
|
selectArea(area) {
|
||||||
this.selectedArea = area
|
this.selectedArea = area;
|
||||||
this.selectedUnit = null
|
this.selectedUnit = null;
|
||||||
|
|
||||||
// 自动选中第一个单元
|
// 自动选中第一个单元
|
||||||
if (this.units.length > 0) {
|
if (this.units.length > 0) {
|
||||||
this.selectUnit(this.units[0])
|
this.selectUnit(this.units[0]);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// 选择单元
|
// 选择单元
|
||||||
selectUnit(unit) {
|
selectUnit(unit) {
|
||||||
this.selectedUnit = unit
|
this.selectedUnit = unit;
|
||||||
},
|
},
|
||||||
|
|
||||||
// 获取当前选中信息
|
// 获取当前选中信息
|
||||||
|
|
@ -220,18 +220,18 @@
|
||||||
floor: this.selectedFloor,
|
floor: this.selectedFloor,
|
||||||
area: this.selectedArea,
|
area: this.selectedArea,
|
||||||
unit: this.selectedUnit,
|
unit: this.selectedUnit,
|
||||||
}
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
// 重置选择
|
// 重置选择
|
||||||
resetSelection() {
|
resetSelection() {
|
||||||
this.selectedFloor = null
|
this.selectedFloor = null;
|
||||||
this.selectedArea = null
|
this.selectedArea = null;
|
||||||
this.selectedUnit = null
|
this.selectedUnit = null;
|
||||||
this.setDefaultSelection()
|
this.setDefaultSelection();
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user