优化页面展示
This commit is contained in:
1 parent
cbcd6b4c7f
commit
1ed38c6648
67 files changed
+4484
-370
No files matched your search
@@ -0,0 +1,64 @@
|
||||
# 今日照护操作防重与接口响应置灰机制方案
|
||||
|
||||
## 1. 背景与目标
|
||||
|
||||
- **问题背景**:
|
||||
在【今日】(`TodayPage.vue`)照护首页进行亲喂计时、一键亲喂、瓶喂、配方奶、混合喂养、睡眠、小便、大便等高频操作时,若用户在网络偶发延迟或弱网环境下连续快速点击,容易造成重复请求与多次入库,甚至导致状态混乱。
|
||||
- **优化目标**:
|
||||
在任何照护操作触发后,全局锁定操作状态(`operating = true`),将操作按钮立即置灰并禁用(`disabled`)以及展示 loading 加载态,直至接口响应完成才恢复可操作,彻底杜绝重复提交。
|
||||
|
||||
---
|
||||
|
||||
## 2. 方案设计
|
||||
|
||||
### 2.1 状态管理与防重拦截
|
||||
在 `TodayPage.vue` 中收敛并强化 `runWithTip` 执行器:
|
||||
```ts
|
||||
const operating = ref(false)
|
||||
|
||||
async function runWithTip(action: () => Promise<void>, message?: string) {
|
||||
if (operating.value) return // 1. 拦截并发与防抖防重
|
||||
operating.value = true // 2. 锁定操作状态
|
||||
try {
|
||||
await action()
|
||||
if (message) {
|
||||
showToast({ message, type: 'success', duration: 1400 })
|
||||
}
|
||||
} catch (err: any) {
|
||||
showToast(err.message || '操作失败')
|
||||
} finally {
|
||||
operating.value = false // 3. 接口返回后解锁
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 2.2 视图层(UI)禁用置灰与 Loading 态绑定
|
||||
1. **喂养面板各操作**:
|
||||
- 开始亲喂:`<van-button :disabled="operating" :loading="operating">`;
|
||||
- 一键记录亲喂:`<van-button :disabled="operating" :loading="operating">`;
|
||||
- 切换侧别:`<van-button :disabled="operating">`;
|
||||
- 结束亲喂:`<van-button :disabled="operating" :loading="operating">`;
|
||||
- 记录瓶喂:`<van-button :disabled="operating" :loading="operating">`;
|
||||
- 记录配方奶:`<van-button :disabled="operating" :loading="operating">`;
|
||||
- 记录混合喂养:`<van-button :disabled="operating" :loading="operating">`。
|
||||
2. **快速记录面板(睡眠、小便、大便)**:
|
||||
- `<button class="primary-action sleep" :disabled="operating">`
|
||||
- `<button class="primary-action pee" :disabled="operating">`
|
||||
- `<button class="primary-action poop" :disabled="operating">`
|
||||
3. **视觉反馈样式**:
|
||||
在 `style.css` 中增加 `.primary-action:disabled` 视觉表现:
|
||||
```css
|
||||
.primary-action:disabled {
|
||||
opacity: 0.55;
|
||||
cursor: not-allowed;
|
||||
filter: grayscale(0.2);
|
||||
pointer-events: none;
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 3. 验收标准
|
||||
1. 点击任何喂养或快速记录按钮后,按钮立即进入 loading 或置灰状态,连续多次点击不会发出多次网络请求;
|
||||
2. 接口返回后(无论成功还是异常),按钮解除置灰并恢复正常交互;
|
||||
3. `npm run build` 前端校验与编译成功。
|
||||
Reference in new issue
Block a user