Parcourir la source

feat(inspection): 添加PC端巡检整改选项的草稿持久化

- 新增 isWap 判断区分 PC 端与移动端存储策略
- PC 端使用 localStorage 按用户、巡检单和轮次持久化草稿选择
- 移动端沿用 sessionStorage 一次性暂存逻辑
- 启动巡检和只读模式下自动清除 PC 端草稿缓存
- 保存整改选项时 PC 端即时写入草稿
- 关闭巡检按钮样式改为 btn-danger,文案精简为"关闭"
caipin il y a 2 semaines
Parent
commit
ecdff8c658

+ 16 - 5
app/public/js/quality_inspection_information.js

@@ -754,6 +754,7 @@ function postQualityInspection(url, data, success, failure) {
 function bindQualityInspectionFlow() {
     const $flow = $('.quality-inspection-flow');
     const $radios = $('[name="quality-need-rectification"]');
+    const isWap = window.location.pathname.indexOf('/wap/') === 0;
     let needRectification = qualityInspectionNeedDraft();
     showQualityInspectionNeed(needRectification);
     let pending = null;
@@ -765,6 +766,7 @@ function bindQualityInspectionFlow() {
         postQualityInspection(preUrl + '/save', data, function () {
             busy = false;
             $button.prop('disabled', false);
+            if (!isWap && data.type === 'start-inspection') qualityInspectionNeedDraft(null);
             if (reload) {
                 if (!inspection.readOnly && ['flow-add-audit', 'flow-del-audit'].includes(data.type)) qualityInspectionNeedDraft(needRectification);
                 window.location.reload();
@@ -828,6 +830,7 @@ function bindQualityInspectionFlow() {
             return;
         }
         needRectification = value;
+        if (!isWap) qualityInspectionNeedDraft(needRectification);
         showQualityInspectionNeed(needRectification);
     });
     $('.flow-save-rectification').on('click', function () {
@@ -892,21 +895,29 @@ function bindQualityInspectionFlow() {
     });
 }
 
-// 仅在添加、移除审批人引起的刷新之间暂存选择,读取后即清除。
+// 电脑版按用户、巡检单和轮次保留草稿选择;手机端沿用一次性暂存。
 function qualityInspectionNeedDraft(value) {
     const current = inspection.need_rectification === 0 ? 0 : 1;
     const key = 'quality-inspection-need:' + cur_uid + ':' + inspection.id + ':' + inspection.times + ':' + inspection.stage_round;
+    const isWap = window.location.pathname.indexOf('/wap/') === 0;
     try {
+        if (!isWap && (value === null || inspection.readOnly)) {
+            removeLocalCache(key);
+            return current;
+        }
         if (value !== undefined) {
-            sessionStorage.setItem(key, JSON.stringify({ value, savedValue: current }));
+            const saved = JSON.stringify({ value, savedValue: current });
+            if (isWap) sessionStorage.setItem(key, saved);
+            else setLocalCache(key, saved);
         } else {
-            const saved = sessionStorage.getItem(key);
-            sessionStorage.removeItem(key);
+            const saved = isWap ? sessionStorage.getItem(key) : getLocalCache(key);
+            if (isWap) sessionStorage.removeItem(key);
             const draft = saved ? JSON.parse(saved) : null;
             if (!inspection.readOnly && draft && draft.savedValue === current && [0, 1].includes(draft.value)) return draft.value;
+            if (!isWap && saved) removeLocalCache(key);
         }
     } catch (error) {
-        console.warn('无法暂存是否整改选项', error);
+        console.warn('无法保存或读取是否整改选项', error);
     }
     return current;
 }

+ 16 - 5
app/public/js/safe_inspection_information.js

@@ -754,6 +754,7 @@ function postSafeInspection(url, data, success, failure) {
 function bindSafeInspectionFlow() {
     const $flow = $('.safe-inspection-flow');
     const $radios = $('[name="safe-need-rectification"]');
+    const isWap = window.location.pathname.indexOf('/wap/') === 0;
     let needRectification = safeInspectionNeedDraft();
     showSafeInspectionNeed(needRectification);
     let pending = null;
@@ -765,6 +766,7 @@ function bindSafeInspectionFlow() {
         postSafeInspection(preUrl + '/save', data, function () {
             busy = false;
             $button.prop('disabled', false);
+            if (!isWap && data.type === 'start-inspection') safeInspectionNeedDraft(null);
             if (reload) {
                 if (!inspection.readOnly && ['flow-add-audit', 'flow-del-audit'].includes(data.type)) safeInspectionNeedDraft(needRectification);
                 window.location.reload();
@@ -828,6 +830,7 @@ function bindSafeInspectionFlow() {
             return;
         }
         needRectification = value;
+        if (!isWap) safeInspectionNeedDraft(needRectification);
         showSafeInspectionNeed(needRectification);
     });
     $('.flow-save-rectification').on('click', function () {
@@ -892,21 +895,29 @@ function bindSafeInspectionFlow() {
     });
 }
 
-// 仅在添加、移除审批人引起的刷新之间暂存选择,读取后即清除。
+// 电脑版按用户、巡检单和轮次保留草稿选择;手机端沿用一次性暂存。
 function safeInspectionNeedDraft(value) {
     const current = inspection.need_rectification === 0 ? 0 : 1;
     const key = 'safe-inspection-need:' + cur_uid + ':' + inspection.id + ':' + inspection.times + ':' + inspection.stage_round;
+    const isWap = window.location.pathname.indexOf('/wap/') === 0;
     try {
+        if (!isWap && (value === null || inspection.readOnly)) {
+            removeLocalCache(key);
+            return current;
+        }
         if (value !== undefined) {
-            sessionStorage.setItem(key, JSON.stringify({ value, savedValue: current }));
+            const saved = JSON.stringify({ value, savedValue: current });
+            if (isWap) sessionStorage.setItem(key, saved);
+            else setLocalCache(key, saved);
         } else {
-            const saved = sessionStorage.getItem(key);
-            sessionStorage.removeItem(key);
+            const saved = isWap ? sessionStorage.getItem(key) : getLocalCache(key);
+            if (isWap) sessionStorage.removeItem(key);
             const draft = saved ? JSON.parse(saved) : null;
             if (!inspection.readOnly && draft && draft.savedValue === current && [0, 1].includes(draft.value)) return draft.value;
+            if (!isWap && saved) removeLocalCache(key);
         }
     } catch (error) {
-        console.warn('无法暂存是否整改选项', error);
+        console.warn('无法保存或读取是否整改选项', error);
     }
     return current;
 }

+ 1 - 1
app/view/quality/inspection_information.ejs

@@ -21,7 +21,7 @@
                     <% } else if (inspection.flowCurrentAudit && inspection.shenpiPower) { %>
                         <button type="button" class="btn btn-success btn-sm flow-action" data-action="flow-check" data-result="3" data-id="<%= inspection.flowCurrentAudit.id %>"><%= inspection.flow_stage === 1 ? '审批' : '批复' %>通过</button>
                         <button type="button" class="btn btn-warning btn-sm flow-action" data-action="<%= inspection.flow_stage === 1 ? 'flow-return' : 'flow-check' %>" data-result="5" data-id="<%= inspection.flowCurrentAudit.id %>"><%= inspection.flow_stage === 1 ? '审批退回' : '退回重新整改' %></button>
-                        <button type="button" class="btn btn-outline-danger btn-sm flow-action" data-action="flow-check" data-result="4" data-id="<%= inspection.flowCurrentAudit.id %>">关闭巡检</button>
+                        <button type="button" class="btn btn-danger btn-sm flow-action" data-action="flow-check" data-result="4" data-id="<%= inspection.flowCurrentAudit.id %>">关闭</button>
                     <% } else if (inspection.flowCurrentAudit && inspection.rectificationPower) { %>
                         <button type="button" class="btn btn-outline-primary btn-sm flow-save-rectification" data-id="<%= inspection.flowCurrentAudit.id %>">保存整改</button>
                         <button type="button" class="btn btn-success btn-sm flow-action" data-action="flow-complete-rectification" data-id="<%= inspection.flowCurrentAudit.id %>">提交整改完成</button>

+ 1 - 1
app/view/safe/inspection_information.ejs

@@ -21,7 +21,7 @@
                     <% } else if (inspection.flowCurrentAudit && inspection.shenpiPower) { %>
                         <button type="button" class="btn btn-success btn-sm flow-action" data-action="flow-check" data-result="3" data-id="<%= inspection.flowCurrentAudit.id %>"><%= inspection.flow_stage === 1 ? '审批' : '批复' %>通过</button>
                         <button type="button" class="btn btn-warning btn-sm flow-action" data-action="<%= inspection.flow_stage === 1 ? 'flow-return' : 'flow-check' %>" data-result="5" data-id="<%= inspection.flowCurrentAudit.id %>"><%= inspection.flow_stage === 1 ? '审批退回' : '退回重新整改' %></button>
-                        <button type="button" class="btn btn-outline-danger btn-sm flow-action" data-action="flow-check" data-result="4" data-id="<%= inspection.flowCurrentAudit.id %>">关闭巡检</button>
+                        <button type="button" class="btn btn-danger btn-sm flow-action" data-action="flow-check" data-result="4" data-id="<%= inspection.flowCurrentAudit.id %>">关闭</button>
                     <% } else if (inspection.flowCurrentAudit && inspection.rectificationPower) { %>
                         <button type="button" class="btn btn-outline-primary btn-sm flow-save-rectification" data-id="<%= inspection.flowCurrentAudit.id %>">保存整改</button>
                         <button type="button" class="btn btn-success btn-sm flow-action" data-action="flow-complete-rectification" data-id="<%= inspection.flowCurrentAudit.id %>">提交整改完成</button>