增加时长功能完善
This commit is contained in:
parent
d859e98230
commit
07459ccd39
|
|
@ -29,6 +29,8 @@
|
||||||
|
|
||||||
<view class="bottom">
|
<view class="bottom">
|
||||||
<view class="btn-grid">
|
<view class="btn-grid">
|
||||||
|
<view class="grid-btn" @click="handleAllOpen">全部开启</view>
|
||||||
|
<view class="grid-btn" @click="handleAllClose">全部关闭</view>
|
||||||
<view class="grid-btn" @click="handleForceOpen">强制开启</view>
|
<view class="grid-btn" @click="handleForceOpen">强制开启</view>
|
||||||
<view class="grid-btn" @click="handleForceClose">强制关闭</view>
|
<view class="grid-btn" @click="handleForceClose">强制关闭</view>
|
||||||
<view class="grid-btn" @click="handleResetDuration">时长归零</view>
|
<view class="grid-btn" @click="handleResetDuration">时长归零</view>
|
||||||
|
|
@ -111,7 +113,10 @@ export default {
|
||||||
if (res && (res.code === 200 || res.status === 200)) {
|
if (res && (res.code === 200 || res.status === 200)) {
|
||||||
uni.showToast({ title: res.msg || "操作成功", icon: "success" });
|
uni.showToast({ title: res.msg || "操作成功", icon: "success" });
|
||||||
} else {
|
} else {
|
||||||
uni.showToast({ title: (res && res.msg) || "操作失败", icon: "none" });
|
uni.showToast({
|
||||||
|
title: (res && res.msg) || "操作失败",
|
||||||
|
icon: "none",
|
||||||
|
});
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
@ -123,33 +128,114 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// 选择单位并输入时长
|
||||||
|
async promptDurationAndUnit() {
|
||||||
|
// 1:天 2:小时 3:分钟 4:秒
|
||||||
|
const unitOptions = [
|
||||||
|
{ name: "天", value: "1" },
|
||||||
|
{ name: "小时", value: "2" },
|
||||||
|
{ name: "分钟", value: "3" },
|
||||||
|
{ name: "秒", value: "4" },
|
||||||
|
];
|
||||||
|
|
||||||
|
// 先选择单位
|
||||||
|
const unitRes = await new Promise((resolve, reject) => {
|
||||||
|
uni.showActionSheet({
|
||||||
|
itemList: unitOptions.map((o) => o.name),
|
||||||
|
success: (res) => resolve(res),
|
||||||
|
fail: (err) => reject(err),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
const chosen = unitOptions[unitRes.tapIndex];
|
||||||
|
|
||||||
|
// 再输入时长数值(支持小数)
|
||||||
|
const inputRes = await new Promise((resolve) => {
|
||||||
|
uni.showModal({
|
||||||
|
title: `输入时长(单位:${chosen.name})`,
|
||||||
|
editable: true,
|
||||||
|
placeholderText: "请输入时长数值:",
|
||||||
|
success: (res) => resolve(res),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!inputRes || !inputRes.confirm) {
|
||||||
|
throw new Error("UserCancelled");
|
||||||
|
}
|
||||||
|
|
||||||
|
const value = String((inputRes.content || "").trim());
|
||||||
|
// 基础校验:数字与小数
|
||||||
|
if (!/^\d+(\.\d+)?$/.test(value)) {
|
||||||
|
uni.showToast({ title: "请输入有效的数字", icon: "none" });
|
||||||
|
throw new Error("InvalidNumber");
|
||||||
|
}
|
||||||
|
|
||||||
|
return { amount: value, unit: chosen.value };
|
||||||
|
},
|
||||||
|
|
||||||
|
async handleAllOpen() {
|
||||||
|
if (!this.ensureUnitSelected()) return;
|
||||||
|
await this.performPut(
|
||||||
|
`/app/memorial/sendCommandGateway`,
|
||||||
|
null,
|
||||||
|
"handleForceOpen",
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
// 底部按钮:强制开启
|
// 底部按钮:强制开启
|
||||||
async handleForceOpen() {
|
async handleForceOpen() {
|
||||||
if (!this.ensureUnitSelected()) return;
|
if (!this.ensureUnitSelected()) return;
|
||||||
await this.performPut(`/bst/memorial/open/${this.selectedUnitId}`, null, "handleForceOpen");
|
await this.performPut(
|
||||||
|
`/bst/memorial/open/${this.selectedUnitId}`,
|
||||||
|
null,
|
||||||
|
"handleForceOpen",
|
||||||
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
// 底部按钮:强制关闭
|
// 底部按钮:强制关闭
|
||||||
async handleForceClose() {
|
async handleForceClose() {
|
||||||
if (!this.ensureUnitSelected()) return;
|
if (!this.ensureUnitSelected()) return;
|
||||||
await this.performPut(`/bst/memorial/close/${this.selectedUnitId}`, null, "handleForceClose");
|
await this.performPut(
|
||||||
|
`/bst/memorial/close/${this.selectedUnitId}`,
|
||||||
|
null,
|
||||||
|
"handleForceClose",
|
||||||
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
// 底部按钮:时长归零
|
// 底部按钮:时长归零
|
||||||
async handleResetDuration() {
|
async handleResetDuration() {
|
||||||
if (!this.ensureUnitSelected()) return;
|
if (!this.ensureUnitSelected()) return;
|
||||||
await this.performPut(`/bst/memorial/reset/${this.selectedUnitId}`, null, "handleResetDuration");
|
await this.performPut(
|
||||||
|
`/bst/memorial/reset/${this.selectedUnitId}`,
|
||||||
|
null,
|
||||||
|
"handleResetDuration",
|
||||||
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
// 底部按钮:增加时长
|
// 底部按钮:增加时长
|
||||||
async handleIncreaseDuration() {
|
async handleIncreaseDuration() {
|
||||||
if (!this.ensureUnitSelected()) return;
|
if (!this.ensureUnitSelected()) return;
|
||||||
|
try {
|
||||||
|
const { amount, unit } = await this.promptDurationAndUnit();
|
||||||
const payload = {
|
const payload = {
|
||||||
memorialId: String(this.selectedUnitId),
|
memorialId: String(this.selectedUnitId),
|
||||||
seconds: "20",
|
seconds: amount,
|
||||||
unit: "1",
|
unit,
|
||||||
};
|
};
|
||||||
await this.performPut(`/bst/memorial/addTime`, payload, "handleIncreaseDuration");
|
await this.performPut(
|
||||||
|
`/bst/memorial/addTime`,
|
||||||
|
payload,
|
||||||
|
"handleIncreaseDuration",
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
// 用户取消或输入无效时,不再抛出
|
||||||
|
if (
|
||||||
|
e &&
|
||||||
|
e.message !== "UserCancelled" &&
|
||||||
|
e.message !== "InvalidNumber"
|
||||||
|
) {
|
||||||
|
console.error("handleIncreaseDuration prompt error", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// 初始化页面
|
// 初始化页面
|
||||||
|
|
@ -285,15 +371,15 @@ export default {
|
||||||
.bottom {
|
.bottom {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
left: 0;
|
left: 0;
|
||||||
bottom: 0;
|
bottom: 10rpx;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
background: #fffbf5;
|
background: #fffbf5;
|
||||||
height: 180rpx;
|
height: 200rpx;
|
||||||
}
|
}
|
||||||
|
|
||||||
.btn-grid {
|
.btn-grid {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: 1fr 1fr;
|
grid-template-columns: 1fr 1fr 1fr;
|
||||||
grid-template-rows: 1fr 1fr;
|
grid-template-rows: 1fr 1fr;
|
||||||
gap: 20rpx;
|
gap: 20rpx;
|
||||||
padding: 20rpx 32rpx;
|
padding: 20rpx 32rpx;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user