BW6H2G9j.js
2.97 KB
import{a9 as g,aa as A}from"./BtEn9SvP.js";const m=["pending","in_progress","pending_test","failed","rework","completed","skipped"],l=["start","complete_assembly","complete_rework","submit_test","skip"];function c(t){return typeof t=="object"&&t!==null}function s(t,e=""){return typeof t=="string"?t:e}function E(t,e=0){const n=Number(t);return Number.isFinite(n)?n:e}function a(t){return typeof t=="string"&&m.includes(t)}function p(t){return typeof t=="string"&&l.includes(t)}function S(t){return t==="pending"||t==="pass"||t==="fail"}function h(t){return Array.isArray(t)?t.filter(c).map(e=>{const n=Array.isArray(e.auditEvents)?e.auditEvents:[];return{id:E(e.id),workOrderNo:s(e.workOrderNo),sn:s(e.sn),stepName:s(e.stepName),workstation:s(e.workstation),device:s(e.device),operator:s(e.operator),startedAt:s(e.startedAt,void 0),endedAt:s(e.endedAt,void 0),result:S(e.result)?e.result:"pending",status:a(e.status)?e.status:"pending",nextAction:s(e.nextAction),auditEvents:n.filter(c).map(r=>({id:s(r.id),action:p(r.action)?r.action:"start",fromStatus:a(r.fromStatus)?r.fromStatus:null,toStatus:a(r.toStatus)?r.toStatus:"pending",operator:s(r.operator),at:s(r.at),remark:s(r.remark,void 0),evidencePath:s(r.evidencePath,void 0),nextAction:s(r.nextAction)}))}}).filter(e=>e.id>0&&e.sn.length>0):[]}function O(t,e){return c(t)?{success:!!t.success,errorCode:typeof t.errorCode=="string"?t.errorCode:null,message:typeof t.message=="string"&&t.message.length>0?t.message:e,state:a(t.state)?t.state:void 0,nextAction:typeof t.nextAction=="string"?t.nextAction:void 0}:{success:!1,errorCode:"REQUEST_FAILED",message:e}}function T(t,e){return c(t)?{success:!!t.success,errorCode:typeof t.errorCode=="string"?t.errorCode:null,message:typeof t.message=="string"&&t.message.length>0?t.message:e,relativePath:typeof t.relativePath=="string"&&t.relativePath.length>0?t.relativePath:void 0}:{success:!1,errorCode:"REQUEST_FAILED",message:e}}function _(t){const e=new URLSearchParams;t.workstation&&e.set("workstation",t.workstation),t.stepName&&e.set("stepName",t.stepName),t.operator&&e.set("operator",t.operator),t.status&&e.set("status",t.status),t.sn&&e.set("sn",t.sn);const n=e.toString();return n.length>0?`?${n}`:""}const w=()=>{const t=A();return{getOperationTasks:async i=>{const o=await t.request(`/api/operations${_(i)}`,{method:"GET"});return h(o)},runOperationAction:async(i,o,u)=>{if(!p(o))return{success:!1,errorCode:"VALIDATION_ERROR",message:"工序任务动作不支持。"};const d=`/api/operations/${i}/actions/${o}`;try{const f=await t.request(d,{method:"POST",body:u,remotePath:d});return O(f,"工序任务状态更新失败。")}catch{return{success:!1,errorCode:"REQUEST_FAILED",message:"工序任务状态更新失败。"}}},uploadOperationEvidence:async i=>{const o=new FormData;o.append("file",i);try{const u=await t.request("/api/files/operation-evidence",{method:"POST",body:o});return T(u,"附件上传失败。")}catch{return{success:!1,errorCode:"REQUEST_FAILED",message:"附件上传失败。"}}}}},N=g(w);export{N as u};