This commit is contained in:
luoshiwen 2024-03-14 09:15:02 +08:00
commit 15026f7ed5
3 changed files with 405 additions and 151 deletions

78
src/api/lighting.js Normal file
View File

@ -0,0 +1,78 @@
import http from '@/utils/http'
//照明监测
export function getLightingMonitoring() {
return http({
url: '/api/GetLightingMonitoring',
method: 'get',
})
}
//照明回路详情
export function getLightingDetail() {
return http({
url: '/api/GetLightingDetail',
method: 'get',
})
}
//照明负荷
export function getLightingLoad(params) {
return http({
url: '/api/GetLightingLoad',
method: 'get',
params
})
}
//展馆照明
export function getPavilionLighting() {
return http({
url: '/api/GetPavilionLighting',
method: 'get',
})
}
//照明控制
export function getLightingControl() {
return http({
url: '/api/GetLightingControl',
method: 'get',
})
}
//故障情况
export function getFaultCondition() {
return http({
url: '/api/GetFaultCondition',
method: 'get',
})
}
//照明单控
export function getSingleControl(params) {
return http({
url: '/api/GetSingleControl',
method: 'get',
params
})
}
//控制照明
export function setLighting(params) {
return http({
url: '/api/SetLighting',
method: 'get',
params
})
}
//照明单控
export function setSingleSwitch(params) {
return http({
url: '/api/SetSingleSwitch',
method: 'get',
params
})
}
//照明全控
export function setFullSwitch(params) {
return http({
url: '/api/SetFullSwitch',
method: 'get',
params
})
}

View File

@ -1,45 +1,53 @@
<script setup>
import {ref} from 'vue'
const lightControl = ref([
{
name:'照明1',
state:false
},
{
name:'照明1',
state:true
},
{
name:'照明1',
state:false
},
{
name:'照明1',
state:false
},
{
name:'照明1',
state:false
}
])
import { ref, onMounted, watch } from "vue";
import { setLighting, setSingleSwitch } from "@/api/lighting";
const lightControl = ref([]);
//
const controlBtn = ref('')
const controlBtn = ref("");
const toggleControl = (event) => {
controlBtn.value = event.srcElement.className
if (event.srcElement.className === "off") {
lightControl.value.forEach(ele=>{
ele.state = false
controlBtn.value = "off";
let dataMap = {
name: props.name,
value: "全关",
};
lightControl.value.forEach((ele) => {
setSingleSwitch(dataMap)
.then((res) => {
if (res.code == 200) {
ele.State = false;
} else {
return false;
}
})
.catch((err) => {
console.log(err);
});
});
} else if (event.srcElement.className === "on") {
lightControl.value.forEach(ele=>{
ele.state = true
controlBtn.value = "on";
lightControl.value.forEach((ele) => {
let dataMap = {
name: props.name,
value: "全开",
};
lightControl.value.forEach((ele) => {
setSingleSwitch(dataMap)
.then((res) => {
if (res.code == 200) {
ele.State = true;
} else {
return false;
}
})
.catch((err) => {
console.log(err);
});
});
});
}
}
const props = defineProps(
{
};
const props = defineProps({
show: {
type: Boolean,
default: false,
@ -47,15 +55,47 @@ const props = defineProps(
name: {
type: String,
default: "",
}
}
)
const emit = defineEmits(['update'])
},
tableData: {
type: Array,
},
});
const emit = defineEmits(["update"]);
const closeDialog = () => {
//
emit('update',false)
emit("update", false);
};
//
function control(params) {
let dataMap = {
name: params.Id,
value: params.State == true ? "255" : "0",
};
setLighting(dataMap)
.then((res) => {
if (res.code == 200) {
controlBtn.value = "";
emit("closeAll", false);
} else {
return false;
}
})
.catch((err) => {
console.log(err);
});
}
// 使 watch
watch(
() => props.tableData,
(newVal, oldVal) => {
//
newVal.forEach((item) => {
item.State = item.State == "255" ? true : false;
});
lightControl.value = newVal;
controlBtn.value = "";
}
);
</script>
<template>
@ -65,8 +105,19 @@ const closeDialog = () => {
<span>{{ props.name }}</span>
</div>
<div class="control-btn">
<span class="on" :class="controlBtn==='on'?'select':''" @click="toggleControl">全开</span>
<span style="margin-left: .7rem" class="off" :class="controlBtn==='off'?'select':''" @click="toggleControl">全关</span>
<span
class="on"
:class="controlBtn === 'on' ? 'select' : ''"
@click="toggleControl"
>全开</span
>
<span
style="margin-left: 0.7rem"
class="off"
:class="controlBtn === 'off' ? 'select' : ''"
@click="toggleControl"
>全关</span
>
</div>
<div class="dialog-content">
<div class="runningState">
@ -75,14 +126,19 @@ const closeDialog = () => {
<span>操作</span>
</div>
<div class="tableContent">
<div class="tableBoby"
<div
class="tableBoby"
v-for="(item, index) in lightControl"
:key="index"
>
<span class="name">{{ item.name }}</span>
<span><el-switch v-model="item.state" style="left: 8px" /></span>
<span
><el-switch
v-model="item.State"
style="left: 8px"
@change="control(item)"
/></span>
</div>
</div>
</div>
@ -91,7 +147,6 @@ const closeDialog = () => {
</template>
<style lang="scss" scoped>
.dialog-content {
position: relative;
width: 100%;
@ -101,7 +156,7 @@ const closeDialog = () => {
}
.control-btn {
padding-left: 1rem;
padding-top: .8rem;
padding-top: 0.8rem;
box-sizing: border-box;
display: flex;
.select {
@ -118,8 +173,6 @@ const closeDialog = () => {
}
}
:deep(.el-switch__core) {
border-radius: 0;
background: transparent;

View File

@ -3,76 +3,45 @@ import { onMounted, ref } from "vue";
import getPath from "@/utils/getPath.js";
import * as echarts from "echarts";
import dialogBox from "./components/dialog.vue";
import {
getLightingMonitoring,
getLightingDetail,
getLightingLoad,
getPavilionLighting,
getLightingControl,
getFaultCondition,
getSingleControl,
setFullSwitch,
} from "@/api/lighting";
//
const lightingNumList = ref([
{
name: "照明四路数量",
num: 1130,
num: 0,
pic: getPath.lightTotal,
},
{
name: "照明四路灭灯数量",
num: 1130,
num: 0,
pic: getPath.noLightNum,
},
{
name: "照明四路亮灯数量",
num: 1130,
num: 0,
pic: getPath.lightingNum,
},
{
name: "离线数量",
num: 1130,
num: 0,
pic: getPath.offlineNum,
},
]);
//
const lightDetail = ref([
{
name: "照明1",
address: "西大厅",
state: false,
},
{
name: "照明2",
address: "西大厅",
state: false,
},
{
name: "照明3",
address: "西大厅",
state: false,
},
{
name: "照明4",
address: "西大厅",
state: true,
},
{
name: "照明5",
address: "西大厅",
state: true,
},
]);
const lightDetail = ref([]);
//
const lightControl = ref([
{
name: "控制箱名称1",
},
{
name: "控制箱名称2",
},
{
name: "控制箱名称3",
},
{
name: "控制箱名称4",
},
{
name: "控制箱名称5",
},
]);
const lightControl = ref([]);
const tableData = ref([]);
//
const lightLoadDate = ref("day");
@ -110,11 +79,18 @@ const toggleFloor = (item, index) => {
const toggleLightLoad = (event) => {
lightLoadDate.value = event.srcElement.className;
lightingLoad();
};
//
const controlBtn = ref("on");
const controlBtn = ref("");
const toggleControl = (event) => {
controlBtn.value = event.srcElement.className;
if (event.srcElement.className == "on") {
controlBtn.value = "on";
fullControl("全开");
} else if (event.srcElement.className == "off") {
controlBtn.value = "off";
fullControl("全关");
}
};
//
const dialogShow = ref(false);
@ -126,20 +102,26 @@ const openDialog = (name) => {
dialogTitle.value = name;
dialogShow.value = true;
singleControl(name);
};
const closeDialog = (val) => {
dialogShow.value = val;
};
function closeAll(params) {
if (params == false) {
controlBtn.value = "";
}
}
//
const drawFaultConditionsChart = () => {
const drawFaultConditionsChart = (params) => {
let trafficWay = [
{
name: "正常",
value: 1260,
value: params[0].Normality,
},
{
name: "故障",
value: 80,
value: params[0].Malfunction,
},
];
var total = 0;
@ -317,7 +299,9 @@ const drawFaultConditionsChart = () => {
});
};
//
const drawHallLightingChart = () => {
const drawHallLightingChart = (params) => {
// let dataList = [params[0].Indoor,params[0].Outdoor]
const offsetX = 10; //bar
const offsetY = 5; //
//
@ -351,7 +335,7 @@ const drawHallLightingChart = () => {
const xAxisPoint = shape.xAxisPoint;
const c1 = [shape.x + 7, shape.y];
const c2 = [xAxisPoint[0] + 7, xAxisPoint[1]];
const c3 = [xAxisPoint[0] + 7 + 7, xAxisPoint[1] - 10];
const c3 = [xAxisPoint[0] + 7 + 7, xAxisPoint[1] - 5];
const c4 = [shape.x + 7 + 7, shape.y - 5];
ctx
.moveTo(c1[0], c1[1])
@ -387,7 +371,7 @@ const drawHallLightingChart = () => {
echarts.graphic.registerShape("CubeRight", CubeRight);
echarts.graphic.registerShape("CubeTop", CubeTop);
let intAxisData = ["室内", "户外"];
let intSeriesData = [100, 200];
let intSeriesData = [params[0].Indoor, params[0].Outdoor];
// 绿
// let colorArr = [["#12D5AF"], ["#0BC19D", "rgba(13,8,16,0)"], ["#68EFD4", "rgba(14,185,151,0)"]]
let colorArr;
@ -597,9 +581,16 @@ const drawHallLightingChart = () => {
});
};
//
const drawLightLoadChart = () => {
const drawLightLoadChart = (params) => {
let xData = [];
let toDay = [];
let lastDay = [];
params.forEach((item) => {
xData.push(item.time);
toDay.push(item.TP);
lastDay.push(item.YP);
});
let myChart = echarts.init(document.getElementById("lightLoad"));
let option = {
grid: {
top: "18%",
@ -635,7 +626,7 @@ const drawLightLoadChart = () => {
],
xAxis: {
type: "category",
data: ["13:00", "14:00", "15:00", "16:00", "17:00"],
data: xData,
axisLine: {
//线x
show: true,
@ -701,7 +692,7 @@ const drawLightLoadChart = () => {
lineStyle: {
color: "rgba(91, 250, 241, 1)",
},
data: [400, 320, 100, 320, 100],
data: lastDay,
},
{
name: "今日",
@ -719,7 +710,7 @@ const drawLightLoadChart = () => {
lineStyle: {
color: "#91cc75",
},
data: [100, 320, 400, 420, 500],
data: toDay,
},
],
};
@ -729,14 +720,144 @@ const drawLightLoadChart = () => {
myChart.resize(); // resize
});
};
//
function lightingMonitoring() {
getLightingMonitoring()
.then((res) => {
if (res.code == 200) {
lightingNumList.value[0].num = res.data[0].Amount;
lightingNumList.value[1].num = res.data[0].Blackout;
lightingNumList.value[2].num = res.data[0].Connection;
lightingNumList.value[3].num = res.data[0].Offline;
} else {
return false;
}
})
.catch((err) => {
console.log(err);
});
}
//
function lightingCircuit() {
getLightingDetail()
.then((res) => {
if (res.code == 200) {
res.data.forEach((item) => {
item.state = item.state == "0" ? false : true;
});
lightDetail.value = res.data;
} else {
return false;
}
})
.catch((err) => {
console.log(err);
});
}
//
function lightingLoad() {
let date =
lightLoadDate.value == "year"
? "年"
: lightLoadDate.value == "month"
? "月"
: "日";
getLightingLoad({ date })
.then((res) => {
if (res.code == 200) {
drawLightLoadChart(res.data);
} else {
return false;
}
})
.catch((err) => {
console.log(err);
});
}
//
function exhibitionHall() {
getPavilionLighting()
.then((res) => {
if (res.code == 200) {
drawHallLightingChart(res.data);
} else {
return false;
}
})
.catch((err) => {
console.log(err);
});
}
//
function lightingControl() {
getLightingControl()
.then((res) => {
if (res.code == 200) {
lightControl.value = res.data;
} else {
return false;
}
})
.catch((err) => {
console.log(err);
});
}
//
function fault() {
getFaultCondition()
.then((res) => {
if (res.code == 200) {
drawFaultConditionsChart(res.data);
} else {
return false;
}
})
.catch((err) => {
console.log(err);
});
}
//
function singleControl(name) {
getSingleControl({ name })
.then((res) => {
if (res.code == 200) {
tableData.value = res.data;
} else {
return false;
}
})
.catch((err) => {
console.log(err);
});
}
//
function fullControl(params) {
let name = params;
setFullSwitch({ name })
.then((res) => {
if (res.code == 200) {
} else {
return false;
}
})
.catch((err) => {
console.log(err);
});
}
onMounted(() => {
window.openBox = openDialog;
//
drawFaultConditionsChart();
fault();
//
drawHallLightingChart();
exhibitionHall();
//
drawLightLoadChart();
lightingLoad();
//
lightingMonitoring();
//
lightingCircuit();
//
lightingControl();
});
</script>
@ -756,7 +877,9 @@ onMounted(() => {
ref="box"
:name="dialogTitle"
:show="dialogShow"
:tableData="tableData"
@update="closeDialog"
@closeAll="closeAll"
/>
<div class="page-left-box">
<!-- 照明监测-->
@ -783,14 +906,14 @@ onMounted(() => {
<span>位置</span>
<span>状态</span>
</div>
<div class="tableContent">
<div class="tableContent" style="height: 86.5%">
<div
v-for="(item, index) in lightDetail"
:key="index"
class="tableBoby"
>
<span class="name">{{ item.name }}</span>
<span>{{ item.address }}</span>
<span>{{ item.location }}</span>
<span><i :class="item.state ? 'state1' : 'state0'"></i></span>
</div>
</div>
@ -853,15 +976,15 @@ onMounted(() => {
<span>控制箱名称</span>
<span>操作</span>
</div>
<div class="tableContent">
<div class="tableContent" style="height: 86.5%">
<div
v-for="(item, index) in lightControl"
:key="index"
class="tableBoby"
>
<span class="name">{{ item.name }}</span>
<span class="name">{{ item.TypeName }}</span>
<span class="control" @click="openDialog(item.name)"
<span class="control" @click="openDialog(item.TypeName)"
>照明控制</span
>
</div>