fix: 太阳能网控,代码提交,待优化。

This commit is contained in:
tianyongbao
2026-04-02 22:57:19 +08:00
parent 59709f1821
commit 3835b910ee
4 changed files with 2267 additions and 0 deletions

View File

@@ -1089,6 +1089,11 @@ function setParams(id: number, name: string, type: number) {
Taro.navigateTo({
url: `/home/wqm?id=${id}&name=${name}&page=home`,
});
} else if (type == 3) {
// 太阳能网控
Taro.navigateTo({
url: `/home/solar?id=${id}&name=${name}&page=home`,
});
} else {
Taro.navigateTo({
url: `/home/ctr?id=${id}&name=${name}&page=home`,

1563
src/home/solar.vue Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -27,6 +27,15 @@
<IconFont :name="check_a" />
</template>
</nut-radio>
<nut-radio label="3" icon-size="25">
太阳能网控
<template #icon>
<IconFont :name="check" />
</template>
<template #checkedIcon>
<IconFont :name="check_a" />
</template>
</nut-radio>
</nut-radio-group>
</nut-col>
<nut-col :span="24">
@@ -138,6 +147,11 @@ function submit() {
Taro.navigateTo({
url: "/my/addDetector?params=" + encodeURIComponent(JSON.stringify(paramsToSend)) + "&page=" + page,
});
} else if (params.devType == 3) {
isLoading.value = false
Taro.navigateTo({
url: "/my/addSolarDetector?params=" + encodeURIComponent(JSON.stringify(paramsToSend)) + "&page=" + page,
});
} else {
isLoading.value = false
Taro.navigateTo({

685
src/my/addSolarDetector.vue Normal file
View File

@@ -0,0 +1,685 @@
<template>
<view class="detector_home">
<view class="body">
<nut-cell>
<nut-row>
<nut-col :span="24">
<nut-steps :current="current">
<nut-step title="第一步" />
<nut-step title="第二步" />
<nut-step title="第三步" />
<nut-step title="第四步" />
</nut-steps>
</nut-col>
</nut-row>
</nut-cell>
<nut-cell>
<nut-row v-if="current === 1">
<nut-col :span="24">
<nut-col :span="2"
><img
:src="dc_1"
:style="{
width: '48rpx',
height: '48rpx',
marginRight: '20rpx',
}"
/></nut-col>
<nut-col :span="22" class="font_36 f_weight c_222"
>检查设备</nut-col
>
</nut-col>
<nut-col :span="24">
<nut-col :span="2">&nbsp;</nut-col>
<nut-col :span="22" class="font_32 c_666"
>请检查设备是否上电网络指示灯处于常亮状态</nut-col
>
</nut-col>
<nut-col :span="24" class="m_t_20">
<nut-col :span="2"
><img
:src="dc_2"
:style="{
width: '48rpx',
height: '48rpx',
marginRight: '20rpx',
}"
/></nut-col>
<nut-col :span="22" class="font_36 f_weight c_222"
>检测设备</nut-col
>
</nut-col>
<nut-col :span="24">
<nut-col :span="2">&nbsp;</nut-col>
<nut-col :span="22" class="font_32 c_666"
>正式使用前将设备提前上电并将探头浸泡在水中24小时以上使用最佳</nut-col
>
</nut-col>
</nut-row>
<nut-row v-else-if="current === 2 && status == 1">
<nut-col :span="24" class="m_t_10">
<nut-radio-group v-model="waterType" direction="horizontal">
<nut-radio :label="1" icon-size="25">
淡水
<template #icon>
<IconFont :name="check" />
</template>
<template #checkedIcon>
<IconFont :name="check_a" />
</template>
</nut-radio>
<nut-radio :label="2" icon-size="25">
海水
<template #icon>
<IconFont :name="check" />
</template>
<template #checkedIcon>
<IconFont :name="check_a" />
</template>
</nut-radio>
</nut-radio-group>
</nut-col>
<nut-col :span="24" v-if="waterType == 2">
<nut-config-provider :theme-vars="themeVars">
<nut-cell
title="请设置您的盐度"
is-link
:desc="salt + '‰'"
@click="setSalt"
></nut-cell>
</nut-config-provider>
</nut-col>
<nut-col :span="24" class="c_888 font_28">
<view>淡水养殖无需设置海水根据实际盐度设置</view>
</nut-col>
</nut-row>
<nut-row v-else-if="current === 3 && status == 1">
<nut-col :span="24">
<nut-config-provider :theme-vars="themeVars">
<nut-cell
title="溶解氧告警值设置"
is-link
:desc="String(alarm) + 'Mg/L'"
@click="setAlarm"
></nut-cell>
</nut-config-provider>
</nut-col>
<nut-col :span="24" class="c_888 font_28">
<view>当溶解氧低于设定数值时会电话告警</view>
<view>(数值默认为3Mg/L可设定最低值不能低于1.5Mg/L) </view>
</nut-col>
</nut-row>
<nut-row v-else-if="current === 4 && status == 1">
<nut-col :span="24">
<nut-config-provider :theme-vars="themeVars">
<nut-cell title="电量电话告警开关">
<template #desc>
<nut-switch
v-model="batteryWarnCallOpen"
active-color="#04D98A"
/>
</template>
</nut-cell>
<nut-cell
v-if="batteryWarnCallOpen"
title="电量电话告警下限"
is-link
:desc="String(batteryWarnLower) + '%'"
@click="setBatteryWarnLower"
></nut-cell>
<nut-cell title="电量告警免打扰" v-if="batteryWarnCallOpen">
<template #desc>
<nut-switch
v-model="batteryWarnCallNoDis"
active-color="#04D98A"
/>
</template>
</nut-cell>
</nut-config-provider>
</nut-col>
<nut-col :span="24" class="c_888 font_28">
<view>当电量低于设定数值时会电话告警</view>
<view>(数值默认为2可设定范围1-7)</view>
</nut-col>
</nut-row>
</nut-cell>
<view>
<nut-button
block
shape="square"
size="large"
:loading="isLoading"
:style="{
fontWeight: 'bold',
fontSize: '14px !important',
borderRadius: '10px',
marginBottom: '15px',
}"
@click="prev"
v-if="current != 1"
>
上一步
</nut-button>
<nut-button
block
shape="square"
type="primary"
size="large"
:loading="isLoading"
:style="{
fontWeight: 'bold',
fontSize: '14px !important',
borderRadius: '10px',
}"
@click="next"
>{{ current == 4 ? "添加" : "下一步" }}</nut-button
>
</view>
<nut-config-provider :theme-vars="themeVars">
<nut-dialog v-model:visible="saltShow" text-align="left" no-footer>
<view :style="{ height: '100%' }">
<view class="d_body">
<nut-row>
<nut-col :span="24">
<view class="d_title">请设置您的盐度</view>
</nut-col>
<nut-col :span="24">
<nut-divider class="divider" />
</nut-col>
<nut-col :span="24" class="view_f">
<view :style="{ width: '20%' }" class="font_32 c_444"
>盐度</view
>
<view :style="{ width: '80%' }">
<nut-input
type="digit"
@blur="upValue"
v-model="salt"
placeholder="(盐度输入数值0-40‰)"
:border="false"
input-align="right"
clearable
max-length="5"
:cursor="String(salt).length"
>
<template #right>
<text class="c_222"></text>
</template>
</nut-input>
</view>
</nut-col>
<nut-col :span="24">
<nut-divider class="divider" />
</nut-col>
</nut-row>
</view>
<view class="d_btn">
<nut-row>
<nut-col
:span="12"
:style="{ border: '1px solid #eee', color: '#222' }"
@click="saltShow = false"
>
取消
</nut-col>
<nut-col
:span="12"
:style="{ border: '1px solid #eee', color: '#15BBC5' }"
@click="saltShow = false"
>
确定
</nut-col>
</nut-row>
</view>
</view>
</nut-dialog>
<nut-dialog v-model:visible="alarmShow" text-align="left" no-footer>
<view :style="{ height: '100%' }">
<view class="d_body">
<nut-row>
<nut-col :span="24">
<view class="d_title">溶解氧告警值设置</view>
</nut-col>
<nut-col :span="24">
<nut-divider class="divider" />
</nut-col>
<nut-col :span="24" class="view_f">
<view :style="{ width: '20%' }" class="font_32 c_444"
>告警值</view
>
<view :style="{ width: '80%' }">
<nut-input
type="digit"
@blur="upAlarmValue"
v-model="alarm"
placeholder="1.5~20"
:border="false"
input-align="right"
clearable
max-length="5"
:cursor="String(alarm).length"
>
<template #right>
<text class="c_222">Mg/L</text>
</template>
</nut-input>
</view>
</nut-col>
<nut-col :span="24">
<nut-divider class="divider" />
</nut-col>
</nut-row>
</view>
<view class="d_btn">
<nut-row>
<nut-col
:span="12"
:style="{ border: '1px solid #eee', color: '#222' }"
@click="alarmShow = false"
>
取消
</nut-col>
<nut-col
:span="12"
:style="{ border: '1px solid #eee', color: '#15BBC5' }"
@click="alarmShow = false"
>
确定
</nut-col>
</nut-row>
</view>
</view>
</nut-dialog>
<nut-dialog v-model:visible="batteryWarnLowerShow" text-align="left" no-footer>
<view :style="{ height: '100%' }">
<view class="d_body">
<nut-row>
<nut-col :span="24">
<view class="d_title">电量电话告警下限设置</view>
</nut-col>
<nut-col :span="24">
<nut-divider class="divider" />
</nut-col>
<nut-col :span="24" class="view_f">
<view :style="{ width: '30%' }" class="font_32 c_444"
>告警下限</view
>
<view :style="{ width: '70%' }">
<nut-input
type="digit"
@blur="upBatteryWarnLowerValue"
v-model="batteryWarnLower"
placeholder="1~7"
:border="false"
input-align="right"
clearable
max-length="5"
:cursor="String(batteryWarnLower).length"
>
<template #right>
<text class="c_222">%</text>
</template>
</nut-input>
</view>
</nut-col>
<nut-col :span="24">
<nut-divider class="divider" />
</nut-col>
</nut-row>
</view>
<view class="d_btn">
<nut-row>
<nut-col
:span="12"
:style="{ border: '1px solid #eee', color: '#222' }"
@click="batteryWarnLowerShow = false"
>
取消
</nut-col>
<nut-col
:span="12"
:style="{ border: '1px solid #eee', color: '#15BBC5' }"
@click="batteryWarnLowerShow = false"
>
确定
</nut-col>
</nut-row>
</view>
</view>
</nut-dialog>
</nut-config-provider>
</view>
<!-- 弹出层提示 -->
<nut-toast
:msg="state.msg"
v-model:visible="state.show"
:type="state.type"
/>
</view>
</template>
<script lang="ts" setup>
import Taro from "@tarojs/taro";
import { stateType } from "@/utils/types";
import { addDeviceSolarDetector, checkDeviceStatus } from "@/api/device";
import { imgUrl } from "@/utils/imgUrl";
import { IconFont } from "@nutui/icons-vue-taro";
definePageConfig({
navigationBarTitleText: "添加太阳能网控",
});
const dc_1 = imgUrl + "dc_1.png";
const dc_2 = imgUrl + "dc_2.png";
const check = `https://www.yuceyun.cn/wechat/check.png`;
const check_a = `https://www.yuceyun.cn/wechat/check_a.png`;
const instance = Taro.getCurrentInstance();
const r = instance.router.params.params;
const page = instance.router.params.page;
console.log('URL参数原始值', r);
let params: any = undefined;
try {
if (r) {
// URL解码后再解析JSON
const decodedParams = decodeURIComponent(r);
console.log('URL解码后', decodedParams);
params = JSON.parse(decodedParams);
console.log('解析后的参数', params);
} else {
console.error('未获取到params参数');
}
} catch (e) {
console.error('参数解析失败', e, '原始参数:', r);
// 参数解析失败,显示提示后返回
Taro.showModal({
title: '提示',
content: '参数错误,请重新进入',
showCancel: false,
success: () => {
Taro.navigateBack();
}
});
}
// 步骤
const current = ref<number>(1);
const themeVars = ref({
cellBoxShadow: "0px 0px 0px 0px",
cellPadding: "0",
cellColor: "#666666",
cellTitleFont: "32rpx",
cellTitleDescFont: "30rpx",
cellDescFont: "30rpx",
cellDescColor: "#222222",
popupBorderRadius: "10rpx",
});
// 盐度
const salt = ref<number>(30);
const waterType = ref<number>(1);
const saltShow = ref<boolean>(false);
const alarm = ref<number>(3);
const alarmShow = ref<boolean>(false);
// 电量相关
const batteryWarnCallOpen = ref<boolean>(false);
const batteryWarnCallNoDis = ref<boolean>(false);
const batteryWarnLower = ref<number>(2);
const batteryWarnLowerShow = ref<boolean>(false);
const state: stateType = reactive({
msg: "",
type: "text",
center: true,
show: false,
});
const status = ref(0);
const isLoading = ref<boolean>(false);
/** ----------------metod start------------------ */
// 监测设备在线状态
function getCheckDevice() {
if (!params) {
console.error('params参数为空');
state.show = true;
state.msg = '参数错误';
return;
}
const data = {
devicetype: params.devType,
serialnum: params.devNum,
};
console.log('检查设备状态', data);
isLoading.value = true;
checkDeviceStatus(data)
.then((res: any) => {
if (res.code == 200) {
status.value = res.data;
if (status.value == 0) {
state.show = true;
state.msg = "设备未激活";
} else if (status.value == 1) {
current.value = 2;
} else if (status.value == 3) {
state.show = true;
state.msg = "设备离线";
} else if (status.value == 8) {
state.show = true;
state.msg = "设备禁用";
} else {
state.show = true;
state.msg = "设备异常";
}
} else {
// 显示错误提示
state.show = true;
state.msg = res.msg || "检查设备失败,请重试";
state.type = "fail";
}
})
.catch((error) => {
// 处理网络错误等异常情况
state.show = true;
state.msg = "网络错误,请重试";
state.type = "fail";
})
.finally(() => {
isLoading.value = false;
});
}
function next() {
if (!params) {
state.show = true;
state.msg = '参数错误';
return;
}
const num = current.value;
if (num == 4) {
isLoading.value = true;
// 验证参数,发起添加设备请求
if (salt.value) {
if (Number(salt.value) < 0 || Number(salt.value) > 40) {
state.show = true;
state.msg = "盐度范围为0-40";
return;
}
} else {
state.show = true;
state.msg = "请录入盐度";
return;
}
if (alarm.value) {
if (Number(alarm.value) < 1.5 || Number(alarm.value) > 20) {
state.show = true;
state.msg = "告警值范围为1.5-20";
return;
}
} else {
state.show = true;
state.msg = "请录入告警值";
return;
}
// 验证电量告警下限
if (batteryWarnCallOpen.value) {
if (batteryWarnLower.value) {
if (Number(batteryWarnLower.value) < 1 || Number(batteryWarnLower.value) > 7) {
state.show = true;
state.msg = "电量告警下限范围为1-7";
return;
}
} else {
state.show = true;
state.msg = "请录入电量告警下限";
return;
}
}
// 发起添加设备请求
const data = {
serialNum: Number(params.devNum),
pondId: String(params.pondId[0]), // 转为字符串保持精度
salinityCompensation: waterType.value == 1 ? 0 : Number(salt.value),
oxyWarnLower: Number(alarm.value),
batteryWarnCallOpen: batteryWarnCallOpen.value ? 1 : 0,
batteryWarnCallNoDis: batteryWarnCallNoDis.value ? 1 : 0,
batteryWarnLower: Number(batteryWarnLower.value),
};
console.log('添加设备数据', data);
addDeviceSolarDetector(data)
.then((res) => {
if (res.code == 200) {
Taro.redirectTo({
url: "/my/addDevSuccess?name=添加太阳能网控&page=" + page,
});
} else {
// 显示错误提示
state.show = true;
state.msg = res.msg || "添加失败,请重试";
state.type = "fail";
}
})
.catch((error) => {
// 处理网络错误等异常情况
state.show = true;
state.msg = "网络错误,请重试";
state.type = "fail";
})
.finally(() => {
isLoading.value = false;
});
} else {
if (num != 1 && status.value == 1) {
current.value = num + 1;
}
if (num == 1) {
// 检查设备状态
getCheckDevice();
} else {
}
}
}
// 上一步
function prev() {
const num = current.value;
current.value = num - 1;
}
// 设置盐度弹框
function setSalt() {
saltShow.value = true;
}
// 验证输入框内容
function upValue() {
const val = salt.value;
if (Number(val) < 0 || Number(val) > 40) {
salt.value = 40;
}
}
// 设置溶解氧告警弹框
function setAlarm() {
alarmShow.value = true;
}
// 验证输入框内容
function upAlarmValue() {
const val = alarm.value;
if (Number(val) < 1.5 || Number(val) > 20) {
alarm.value = 20;
}
}
// 设置电量告警下限弹框
function setBatteryWarnLower() {
batteryWarnLowerShow.value = true;
}
// 验证电量告警下限输入
function upBatteryWarnLowerValue() {
const val = batteryWarnLower.value;
if (Number(val) < 1 || Number(val) > 7) {
batteryWarnLower.value = 2;
}
}
/** ----------------metod end-------------------- */
</script>
<style lang="scss">
.detector_home {
width: 100%;
height: 100%;
background-image: url("https://www.yuceyun.cn/wechat/bg.jpg");
background-color: #e5ebed;
background-repeat: no-repeat;
background-size: 100% 100%;
position: fixed;
margin: 0;
font-size: 32px;
font-family: "PingFang SC";
font-weight: 400;
.body {
padding: 15px;
.title {
font-size: 32px;
color: #222;
font-weight: bold;
}
.time {
font-size: 24px;
color: #666666;
}
.mt {
margin-top: 10px;
}
.content {
margin-top: 10px;
font-size: 28px;
color: #444;
}
.tag {
background: RGB(21, 137, 233, 0.1);
border-radius: 4px;
color: #1589e9;
font-size: 28rpx;
margin-left: 10px;
}
.price {
font-size: 48px;
color: #444444;
font-weight: bold;
text-align: right;
}
.nut-dialog {
padding: 0;
}
.nut-dialog__content {
margin: 0;
}
.nut-input {
padding: 20rpx 0;
}
}
}
</style>