From 07459ccd3945326c2ee2b89d1f7fafc40bd01fbf Mon Sep 17 00:00:00 2001 From: WindowBird <13870814+windows-bird@user.noreply.gitee.com> Date: Tue, 14 Oct 2025 16:43:15 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=97=B6=E9=95=BF=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/memorial/adminMemorial.vue | 112 +++++++++++++++++++++++++++---- 1 file changed, 99 insertions(+), 13 deletions(-) diff --git a/pages/memorial/adminMemorial.vue b/pages/memorial/adminMemorial.vue index 79242f6..25032da 100644 --- a/pages/memorial/adminMemorial.vue +++ b/pages/memorial/adminMemorial.vue @@ -29,6 +29,8 @@ + 全部开启 + 全部关闭 强制开启 强制关闭 时长归零 @@ -111,7 +113,10 @@ export default { if (res && (res.code === 200 || res.status === 200)) { uni.showToast({ title: res.msg || "操作成功", icon: "success" }); } else { - uni.showToast({ title: (res && res.msg) || "操作失败", icon: "none" }); + uni.showToast({ + title: (res && res.msg) || "操作失败", + icon: "none", + }); } return res; } 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() { 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() { 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() { 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() { if (!this.ensureUnitSelected()) return; - const payload = { - memorialId: String(this.selectedUnitId), - seconds: "20", - unit: "1", - }; - await this.performPut(`/bst/memorial/addTime`, payload, "handleIncreaseDuration"); + try { + const { amount, unit } = await this.promptDurationAndUnit(); + const payload = { + memorialId: String(this.selectedUnitId), + seconds: amount, + unit, + }; + 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 { position: fixed; left: 0; - bottom: 0; + bottom: 10rpx; width: 100%; background: #fffbf5; - height: 180rpx; + height: 200rpx; } .btn-grid { display: grid; - grid-template-columns: 1fr 1fr; + grid-template-columns: 1fr 1fr 1fr; grid-template-rows: 1fr 1fr; gap: 20rpx; padding: 20rpx 32rpx;