添加四个按钮控制牌位-代码优化
This commit is contained in:
parent
0827eb2da7
commit
d859e98230
|
|
@ -94,100 +94,62 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
// 底部按钮:强制开启
|
// 校验是否已选择单元
|
||||||
async handleForceOpen() {
|
ensureUnitSelected() {
|
||||||
|
if (!this.selectedUnitId) {
|
||||||
|
uni.showToast({ title: "请先选择单元", icon: "none" });
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
|
||||||
|
// 通用 PUT 请求封装:包含 Loading 与结果提示
|
||||||
|
async performPut(url, data, logTag = "performPut") {
|
||||||
uni.showLoading({ title: "处理中...", mask: true });
|
uni.showLoading({ title: "处理中...", mask: true });
|
||||||
try {
|
try {
|
||||||
const res = await this.$request.put(
|
const res = await this.$request.put(url, data);
|
||||||
`/bst/memorial/open/${this.selectedUnitId}`,
|
|
||||||
);
|
|
||||||
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({
|
uni.showToast({ title: (res && res.msg) || "操作失败", icon: "none" });
|
||||||
title: (res && res.msg) || "操作失败",
|
|
||||||
icon: "none",
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
return res;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
uni.showToast({ title: "请求失败", icon: "none" });
|
uni.showToast({ title: "请求失败", icon: "none" });
|
||||||
console.error("handleForceOpen error", error);
|
console.error(`${logTag} error`, error);
|
||||||
|
throw error;
|
||||||
} finally {
|
} finally {
|
||||||
uni.hideLoading();
|
uni.hideLoading();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// 底部按钮:强制开启
|
||||||
|
async handleForceOpen() {
|
||||||
|
if (!this.ensureUnitSelected()) return;
|
||||||
|
await this.performPut(`/bst/memorial/open/${this.selectedUnitId}`, null, "handleForceOpen");
|
||||||
|
},
|
||||||
|
|
||||||
// 底部按钮:强制关闭
|
// 底部按钮:强制关闭
|
||||||
async handleForceClose() {
|
async handleForceClose() {
|
||||||
uni.showLoading({ title: "处理中...", mask: true });
|
if (!this.ensureUnitSelected()) return;
|
||||||
try {
|
await this.performPut(`/bst/memorial/close/${this.selectedUnitId}`, null, "handleForceClose");
|
||||||
const res = await this.$request.put(
|
|
||||||
`/bst/memorial/close/${this.selectedUnitId}`,
|
|
||||||
);
|
|
||||||
if (res && (res.code === 200 || res.status === 200)) {
|
|
||||||
uni.showToast({ title: res.msg || "操作成功", icon: "success" });
|
|
||||||
} else {
|
|
||||||
uni.showToast({
|
|
||||||
title: (res && res.msg) || "操作失败",
|
|
||||||
icon: "none",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
uni.showToast({ title: "请求失败", icon: "none" });
|
|
||||||
console.error("handleForceClose error", error);
|
|
||||||
} finally {
|
|
||||||
uni.hideLoading();
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// 底部按钮:时长归零
|
// 底部按钮:时长归零
|
||||||
async handleResetDuration() {
|
async handleResetDuration() {
|
||||||
uni.showLoading({ title: "处理中...", mask: true });
|
if (!this.ensureUnitSelected()) return;
|
||||||
try {
|
await this.performPut(`/bst/memorial/reset/${this.selectedUnitId}`, null, "handleResetDuration");
|
||||||
const res = await this.$request.put(
|
|
||||||
`/bst/memorial/reset/${this.selectedUnitId}`,
|
|
||||||
);
|
|
||||||
if (res && (res.code === 200 || res.status === 200)) {
|
|
||||||
uni.showToast({ title: res.msg || "操作成功", icon: "success" });
|
|
||||||
} else {
|
|
||||||
uni.showToast({
|
|
||||||
title: (res && res.msg) || "操作失败",
|
|
||||||
icon: "none",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
uni.showToast({ title: "请求失败", icon: "none" });
|
|
||||||
console.error("handleResetDuration error", error);
|
|
||||||
} finally {
|
|
||||||
uni.hideLoading();
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// 底部按钮:增加时长
|
// 底部按钮:增加时长
|
||||||
async handleIncreaseDuration() {
|
async handleIncreaseDuration() {
|
||||||
uni.showLoading({ title: "处理中...", mask: true });
|
if (!this.ensureUnitSelected()) return;
|
||||||
try {
|
const payload = {
|
||||||
// 默认增加 20 秒;unit: 4 表示“秒”
|
memorialId: String(this.selectedUnitId),
|
||||||
const payload = {
|
seconds: "20",
|
||||||
memorialId: String(this.selectedUnitId),
|
unit: "1",
|
||||||
seconds: "20",
|
};
|
||||||
unit: "1",
|
await this.performPut(`/bst/memorial/addTime`, payload, "handleIncreaseDuration");
|
||||||
};
|
|
||||||
const res = await this.$request.put(`/bst/memorial/addTime`, payload);
|
|
||||||
if (res && (res.code === 200 || res.status === 200)) {
|
|
||||||
uni.showToast({ title: res.msg || "操作成功", icon: "success" });
|
|
||||||
} else {
|
|
||||||
uni.showToast({
|
|
||||||
title: (res && res.msg) || "操作失败",
|
|
||||||
icon: "none",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
uni.showToast({ title: "请求失败", icon: "none" });
|
|
||||||
console.error("handleIncreaseDuration error", error);
|
|
||||||
} finally {
|
|
||||||
uni.hideLoading();
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// 初始化页面
|
// 初始化页面
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user