暂时提交
parent
696bcbd4e5
commit
059554e1b1
|
|
@ -20,6 +20,7 @@
|
|||
class="text uni-flex_control_one uni-view"
|
||||
v-for="item in sensorCards.temp"
|
||||
:key="item.key"
|
||||
@click="openDataModal(item)"
|
||||
>
|
||||
<text class="data" :style="fontStyle">
|
||||
{{ liveData[item.key] }}
|
||||
|
|
@ -61,7 +62,8 @@
|
|||
@click="openTimeModal(card)"
|
||||
>
|
||||
<view class="card-text">
|
||||
<text class="card-main">{{ card.name }}</text>
|
||||
<text class="card-main" v-if="dtu_remark[card.type]">{{ dtu_remark[card.type] }}</text>
|
||||
<text class="card-main" v-else>{{ card.name }}</text>
|
||||
<view class="card-sub-wrapper">
|
||||
<text class="card-sub" v-if="showStatusText">{{ show[card.type] || '未知' }}</text>
|
||||
<text class="limit-time">
|
||||
|
|
@ -83,6 +85,20 @@
|
|||
|
||||
|
||||
|
||||
<uni-popup ref="inputNamelog" mode="center" >
|
||||
<!-- 新增:修改运行时间的弹窗 -->
|
||||
<view class="modal-container">
|
||||
<view class="modal-title">{{ `【${selectedText} - 实时温湿度】别名设置` }}</view>
|
||||
<view class="modal-input-wrap" >
|
||||
<text class="modal-label">别名设置:</text>
|
||||
<uni-easyinput style="width: 100px" v-model="remark" placeholder="不填展示默认备注" />
|
||||
</view>
|
||||
<view class="modal-btn-wrap">
|
||||
<button class="modal-btn cancel" @click="closeModalDataName">取消</button>
|
||||
<button class="modal-btn confirm" @click="confirmModifyName">确定</button>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
|
||||
<uni-popup ref="inputDialog" mode="center" >
|
||||
<!-- 新增:修改运行时间的弹窗 -->
|
||||
|
|
@ -135,7 +151,7 @@ import {addLimit, getAgriByImei, updateLimit} from "../../api/system/assets/limi
|
|||
import {listAgri} from "../../api/system/assets/agri";
|
||||
import {getNewSpecialData} from "../../api/data/specialData";
|
||||
import store from "../../store";
|
||||
import {getRemarkByImei, updateRemark} from "../../api/system/assets/remark";
|
||||
import {addRemark, getRemarkByImei, updateRemark} from "../../api/system/assets/remark";
|
||||
|
||||
export default {
|
||||
dicts: ['sys_data_map'],
|
||||
|
|
@ -191,6 +207,7 @@ export default {
|
|||
{ label: '湿度4', key: 'humi4' }
|
||||
]
|
||||
},
|
||||
sensorCard:{},
|
||||
// 优化:设备卡片配置(固定顺序)
|
||||
deviceCards: [
|
||||
{ type: 'jbk', name: '卷被开' },
|
||||
|
|
@ -611,86 +628,155 @@ export default {
|
|||
this.currentCard = card; // 记录当前卡片信息
|
||||
this.currentCardTime = this.limitTimes[`${card.type}Limit`]; // 记录当前时间
|
||||
this.newLimitTime = this.currentCardTime; // 默认填充当前时间
|
||||
this.remark = this.remark[card.type] || card.name;
|
||||
this.remark = this.dtu_remark[card.type] || card.name;
|
||||
this.$refs.inputDialog.open()
|
||||
},
|
||||
openDataModal(sensorCard) {
|
||||
this.sensorCard = sensorCard;
|
||||
this.remark=this.dtu_remark[sensorCard.key] || sensorCard.label;
|
||||
this.$refs.inputNamelog.open()
|
||||
},
|
||||
confirmModifyName() {
|
||||
let {
|
||||
selectedText, dtu_remark, imei, sensorCard, remark
|
||||
} = this;
|
||||
const isRemarkModified = (remark !== (dtu_remark[sensorCard.key] || sensorCard.label)); // 别名是否修改
|
||||
if (!isRemarkModified) {
|
||||
// 关闭弹窗(无论确认/取消都关闭)
|
||||
this.closeModalDataName();
|
||||
return;
|
||||
}
|
||||
|
||||
// 6. 确认弹窗(async/await处理异步请求)
|
||||
uni.showModal({
|
||||
title: '温馨提示:',
|
||||
content: `确定将${selectedText}-${sensorCard.label}别名设置为:${remark}`,
|
||||
cancelText: '取消',
|
||||
confirmText: '确定',
|
||||
success: (res) => {
|
||||
// 关闭弹窗(无论确认/取消都关闭)
|
||||
this.closeModalDataName();
|
||||
|
||||
if (!res.confirm) return; // 取消操作则直接返回
|
||||
this.$set(dtu_remark, `${sensorCard.key}`, remark);
|
||||
// 补全imei字段
|
||||
if (!dtu_remark.imei) {
|
||||
this.$set(dtu_remark, 'imei', imei);
|
||||
}
|
||||
// 发起请求并等待结果
|
||||
const remarkRes = dtu_remark.id
|
||||
? updateRemark(dtu_remark)
|
||||
: addRemark(dtu_remark);
|
||||
this.$modal[remarkRes.code===200 ? 'msgSuccess' : 'msgError'](
|
||||
remarkRes.code===200 ? '修改成功' : '修改失败'
|
||||
);
|
||||
// 新增后刷新数据
|
||||
this.getRemarkByImei();
|
||||
}
|
||||
});
|
||||
},
|
||||
closeModalDataName() {
|
||||
this.$refs.inputNamelog.close()
|
||||
},
|
||||
close() {
|
||||
this.$refs.inputDialog.close()
|
||||
},
|
||||
// 新增:确认修改运行时间
|
||||
// 确认修改运行时间
|
||||
confirmModifyTime() {
|
||||
// 校验输入:必须是1-60的数字
|
||||
/*if (!this.newLimitTime || this.newLimitTime < 1 || this.newLimitTime > 60) {
|
||||
uni.showToast({
|
||||
title: '请输入1-60的有效数字',
|
||||
icon: 'none'
|
||||
});
|
||||
// 1. 解构赋值:简化频繁的this.xxx调用,提升可读性
|
||||
let {
|
||||
newLimitTime, currentCardTime, selectedText, currentCard,
|
||||
limitTimes, dtu_remark, imei, agriId, remark
|
||||
} = this;
|
||||
|
||||
// 2. 恢复并优化数字校验(如需启用,取消注释即可)
|
||||
/*if (!newLimitTime || newLimitTime < 1 || newLimitTime > 60) {
|
||||
uni.showToast({ title: '请输入1-60的有效数字', icon: 'none' });
|
||||
return;
|
||||
}*/
|
||||
var showText = `确定修改${this.selectedText}-${this.currentCard.name}:\n1. `;
|
||||
// 修改limitTimes(用$set确保响应式)
|
||||
var limitTimeUpdate = this.newLimitTime !== this.currentCardTime;
|
||||
if (limitTimeUpdate) {
|
||||
showText += `运行时间为:${this.newLimitTime} 秒?`
|
||||
}
|
||||
var remarkName = this.remark !== (this.remark[this.currentCard.type] || this.currentCard.name);
|
||||
if (limitTimeUpdate && remarkName) {
|
||||
showText += `\n2. `
|
||||
}
|
||||
if (remarkName) {
|
||||
showText += `别名设置为:${this.remark}?`
|
||||
|
||||
// 3. 定义核心判定变量(语义化命名)
|
||||
const isLimitTimeModified = newLimitTime !== currentCardTime; // 运行时间是否修改
|
||||
const isRemarkModified = (remark !== (dtu_remark[currentCard.type] || currentCard.name)); // 别名是否修改
|
||||
|
||||
// 4. 无修改则直接返回,避免无效弹窗
|
||||
if (!isLimitTimeModified && !isRemarkModified) {
|
||||
// 关闭弹窗(无论确认/取消都关闭)
|
||||
this.$refs?.inputDialog?.close();
|
||||
return;
|
||||
}
|
||||
|
||||
if (limitTimeUpdate || remarkName) {
|
||||
// 提示修改成功
|
||||
// 提示修改成功
|
||||
// 5. 简化提示文案拼接(减少嵌套判断)
|
||||
let confirmContent = `确定修改${selectedText}-${currentCard.name}:`;
|
||||
const tips = [];
|
||||
if (isLimitTimeModified) tips.push(`运行时间为:${newLimitTime} 秒`);
|
||||
if (isRemarkModified) {
|
||||
remark = remark || currentCard.name
|
||||
tips.push(`别名设置为:${remark}`)
|
||||
}
|
||||
confirmContent += `\n${tips.map((tip, idx) => `${idx + 1}. ${tip}?`).join('\n')}`;
|
||||
|
||||
// 6. 确认弹窗(async/await处理异步请求)
|
||||
uni.showModal({
|
||||
title: '温馨提示:',
|
||||
content: `${showText}`,
|
||||
content: confirmContent,
|
||||
cancelText: '取消',
|
||||
confirmText: '确定',
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
var updateFlag = true;
|
||||
if (limitTimeUpdate) {
|
||||
this.$set(this.limitTimes, `${this.currentCard.type}Limit`, this.newLimitTime);
|
||||
if (this.limitTimes.imei) {
|
||||
updateLimit(this.limitTimes).then(response => {
|
||||
if (response.code!==200) updateFlag=false;
|
||||
})
|
||||
} else {
|
||||
this.$set(this.limitTimes, 'imei', this.imei);
|
||||
this.$set(this.limitTimes, 'agriName', this.selectedText);
|
||||
this.$set(this.limitTimes, 'agriId', this.agriId);
|
||||
addLimit(this.limitTimes).then(response => {
|
||||
if (response.code!==200) updateFlag=false;
|
||||
this.getAgriByImei();
|
||||
})
|
||||
success: async (res) => {
|
||||
// 关闭弹窗(无论确认/取消都关闭)
|
||||
this.$refs?.inputDialog?.close();
|
||||
|
||||
if (!res.confirm) return; // 取消操作则直接返回
|
||||
|
||||
let isAllSuccess = true; // 统一判定所有请求是否成功
|
||||
|
||||
try {
|
||||
// 7. 处理运行时间修改
|
||||
if (isLimitTimeModified) {
|
||||
this.$set(limitTimes, `${currentCard.type}Limit`, newLimitTime || 0);
|
||||
// 补全必要字段(合并重复逻辑)
|
||||
if (!limitTimes.imei) {
|
||||
this.$set(limitTimes, 'imei', imei);
|
||||
this.$set(limitTimes, 'agriName', selectedText);
|
||||
this.$set(limitTimes, 'agriId', agriId);
|
||||
}
|
||||
// 发起请求并等待结果(async/await确保顺序执行)
|
||||
const limitRes = limitTimes.id
|
||||
? await updateLimit(limitTimes)
|
||||
: await addLimit(limitTimes);
|
||||
if (limitRes.code !== 200) isAllSuccess = false;
|
||||
// 新增后刷新数据
|
||||
if (!limitTimes.imei) this.getAgriByImei();
|
||||
}
|
||||
|
||||
// 8. 处理别名修改
|
||||
if (isRemarkModified) {
|
||||
this.$set(dtu_remark, `${currentCard.type}`, remark);
|
||||
// 补全imei字段
|
||||
if (!dtu_remark.imei) {
|
||||
this.$set(dtu_remark, 'imei', imei);
|
||||
}
|
||||
// 发起请求并等待结果
|
||||
const remarkRes = dtu_remark.id
|
||||
? await updateRemark(dtu_remark)
|
||||
: await addRemark(dtu_remark);
|
||||
if (remarkRes.code !== 200) isAllSuccess = false;
|
||||
// 新增后刷新数据
|
||||
if (!dtu_remark.imei) this.getRemarkByImei();
|
||||
}
|
||||
|
||||
// 9. 正确的提示逻辑(修复原本文案反写的问题)
|
||||
this.$modal[isAllSuccess ? 'msgSuccess' : 'msgError'](
|
||||
isAllSuccess ? '修改成功' : '修改失败'
|
||||
);
|
||||
} catch (error) {
|
||||
// 捕获网络异常/接口报错,避免页面卡死
|
||||
console.error('修改失败:', error);
|
||||
this.$modal.msgError('修改失败,请重试');
|
||||
}
|
||||
}
|
||||
if (remarkName) {
|
||||
this.$set(this.dtu_remark, `${this.currentCard.type}`, this.remark);
|
||||
if (this.dtu_remark.imei) {
|
||||
updateRemark(this.dtu_remark).then(response => {
|
||||
if (response.code!==200) updateFlag=false;
|
||||
})
|
||||
} else {
|
||||
this.$set(this.dtu_remark, 'imei', this.imei);
|
||||
updateRemark(this.dtu_remark).then(response => {
|
||||
if (response.code!==200) updateFlag=false;
|
||||
this.getRemarkByImei();
|
||||
})
|
||||
}
|
||||
}
|
||||
updateFlag?this.$modal.msgError("修改成功"):this.$modal.msgSuccess("修改失败")
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
// 关闭弹窗
|
||||
this.$refs.inputDialog.close()
|
||||
// (可选)这里可以加接口请求,把新时间同步到后端
|
||||
// this.saveLimitTimeToServer(this.currentCard.type, this.newLimitTime);
|
||||
});
|
||||
}
|
||||
},
|
||||
onHide() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue