| 123 |
- import{a as Se,r as b,Z as Fe,aj as k,at as Te,c as z,o as P,S as s,a8 as Be,K as v,b as w,P as V,M as te,L as le,an as $e,a7 as ae,Y as Le,u as Pe,Q as G,R as ne,a9 as Ee,J as j,t as Ae}from"./vue.D1BjjNmv.js";import{G as O,S as Ne,a as Ue,C as qe,b as oe}from"./api.s5aw6UzV.js";import{s as Ke,E as p}from"./index.Cz1Myhn_.js";import{_ as Me}from"./_plugin-vue_export-helper.DlAUqK2U.js";const Oe={class:"form-row"},ze=["disabled","onKeydown"],Ge={key:0,class:"pending-list",style:{"margin-top":"15px","margin-bottom":"15px"}},je={class:"pending-header"},Je={class:"pending-title"},Qe={class:"pending-actions"},Xe={class:"pending-tags"},Ye={class:"dialog-footer"},se=500,Ze=Se({__name:"index",emits:["completed"],setup(He,{expose:ue,emit:ie}){const J=ie,E=b(!1),C=b(""),_=b(""),S=b([]),D=b(null),F=b(!1),Q=b(null),m=b([]),A=b(!1),T=b(!1),i=b({rfidLength:24,rfidPrefix:"E280",separator:" ",customSeparator:"",autoSplitSticky:!0,allowDuplicate:!0,enableRFIDBuffer:!0,rfidInputTimeout:120}),X=b("等待输入..."),Y=b(""),B=b([]);let $=null;const R=b("");let L=null;const re=async(t,e)=>{if(console.log("checkNo::::::",t,"id::::::",e),_.value=t,e!=null)D.value=e;else try{const a=await O();if((a==null?void 0:a.code)===2e3){const o=q(t,a.data);D.value=(o==null?void 0:o.id)??null,console.log("通过 check_no 查询到的 id::",D.value)}}catch(a){console.error("查询盘点记录失败:",a),D.value=null}},N=async()=>{T.value||(await Ae(),setTimeout(()=>{const t=Q.value;!t||F.value||(t.focus(),setTimeout(()=>{t==null||t.select()},10))},100))},U=()=>{L&&(clearTimeout(L),L=null)},ce=()=>{i.value.enableRFIDBuffer&&R.value&&(C.value=R.value,R.value="",U())},Z=()=>{if(!i.value.enableRFIDBuffer||!R.value)return;const t=R.value;R.value="",U(),C.value=t,M(!0)},de=()=>{if(!i.value.enableRFIDBuffer)return;U();const t=Math.max(i.value.rfidInputTimeout||120,30);L=setTimeout(()=>{},t)},x=(t,e="",a=0)=>{X.value=t,Y.value=e,$&&clearTimeout($),a>0&&($=setTimeout(()=>{X.value="等待输入...",Y.value="",$=null},a))},fe=()=>{x("输入中...","#4b6cb7")},ve=t=>{if(i.value.enableRFIDBuffer&&!(t.ctrlKey||t.metaKey||t.altKey)){if(t.key==="Enter"){t.preventDefault(),Z();return}if(t.key==="Backspace"){t.preventDefault(),R.value=R.value.slice(0,-1),C.value=R.value;return}t.key.length===1&&(t.preventDefault(),R.value+=t.key,C.value=R.value,de())}},pe=()=>{T.value||setTimeout(()=>{N()},10)},me=t=>{if(!t.shiftKey){if(i.value.enableRFIDBuffer){t.preventDefault(),Z();return}t.preventDefault(),M()}},H=t=>{const e=/^\d+$/.test(t),a=Math.max(i.value.rfidLength,8);return e&&t.length>=a?"RFID":"二维码"},ge=t=>{const e=new Date().toLocaleString(),a=t.map(o=>({code:o,type:H(o),time:e}));B.value.unshift(...a),B.value.length>se&&B.value.splice(se)},he=()=>{i.value={rfidLength:24,rfidPrefix:"E280",separator:" ",customSeparator:"",autoSplitSticky:!0,allowDuplicate:!0,enableRFIDBuffer:!0,rfidInputTimeout:120},p.success("已重置为默认规则")},_e=()=>{if(i.value.rfidLength<1){p.warning("RFID标签长度必须大于0");return}if(i.value.separator==="custom"&&!i.value.customSeparator){p.warning("请设置自定义分隔符");return}if(i.value.rfidInputTimeout<30){p.warning("缓冲判定时间需大于等于30ms");return}T.value=!1,p.success("读取规则已保存")},ye=()=>{C.value="",S.value=[],D.value=null,m.value=[],A.value=!1,B.value=[],x("等待输入..."),R.value="",U()},be=()=>{N()},q=(t,e)=>(console.log("lists::::",e),Array.isArray(e)?e.find(a=>a.check_no===t):null),W=t=>{t.forEach(e=>{const a=S.value.findIndex(o=>o.device_code===e.device_code&&o.check_no===e.check_no);a!==-1?S.value[a]={...e,scanned_quantity:e.scanned_quantity||1}:S.value.push({...e,scanned_quantity:e.scanned_quantity||1})})},K=(t,e=!1)=>{if(!t)return[];const{rfidLength:a,rfidPrefix:o,autoSplitSticky:d}=i.value;if(!d)return[t];if(e){if(t.length<=a)return[t];if(t.length>a*2&&t.length%a===0){if(o&&o.trim()){const y=o.length,h=a-y;if(h>0)try{const f=o.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),l=new RegExp(`${f}[0-9A-F]{${h}}`,"gi"),u=t.match(l);if(u&&u.length>1)return u}catch(f){console.warn("RFID前缀正则表达式构建失败:",f)}}const g=[];for(let y=0;y<t.length;y+=a){const h=t.substring(y,y+a);h.trim()&&g.push(h)}if(g.length>1)return g}return[t]}if(o&&o.trim()){const g=o.length,y=a-g;if(y>0)try{const h=o.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),f=new RegExp(`${h}[0-9A-F]{${y}}`,"gi"),l=t.match(f);if(l&&l.length>1)return l}catch(h){console.warn("RFID前缀正则表达式构建失败:",h)}}if(t.length>a&&t.length%a===0){const g=[];for(let y=0;y<t.length;y+=a){const h=t.substring(y,y+a);h.trim()&&g.push(h)}if(g.length>1)return g}return[t]},we=t=>{const e=t.trim();if(!e)return[];const{separator:a,customSeparator:o}=i.value,d=a==="custom"?o:a;if(console.log("splitRFIDCodes - 输入:",e,"分隔符配置:",a,"实际分隔符:",d,"分隔符类型:",typeof d,"长度:",d==null?void 0:d.length),/[\r\n]/.test(e)){const f=e.split(/[\r\n]+/).filter(l=>l.trim());if(console.log("检测到换行符,分割结果:",f),f.length>1){const l=[];for(const u of f){const n=u.trim();if(n){const r=K(n,!0);l.push(...r)}}return console.log("换行符分割最终结果:",l),l.length>0?l:[e]}}if(d&&d.trim()!==""&&d!==`
- `&&d!==`\r
- `&&d!=="\r"){let f=[],l=!1;if(d===" ")l=e.includes(" "),l&&(f=e.split(/\t+/).filter(u=>u.trim()));else if(l=e.includes(d),l)try{const u=d.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),n=new RegExp(u+"+","g");f=e.split(n).filter(r=>r.trim())}catch(u){console.warn("分隔符正则表达式构建失败,使用字符串分割:",u),f=e.split(d).filter(n=>n.trim())}if(l&&f.length>0){const u=[];for(const n of f){const r=n.trim();if(r){const I=K(r,!0);u.push(...I)}}return console.log("配置分隔符分割最终结果:",u),u.length>0?u:[e]}}if(/\s/.test(e)){const f=e.split(/\s+/).filter(l=>l.trim());if(console.log("检测到空格,分割结果:",f),f.length>1){const l=[];for(const u of f){const n=u.trim();if(n){const r=K(n,!0);l.push(...r)}}return console.log("空格分割最终结果:",l),l.length>0?l:[e]}}const h=K(e);return console.log("粘连处理结果:",h),h},M=(t=!1)=>{if(t||ce(),!C.value||!_.value){p.warning("请输入设备编号"),x("输入为空,请重新输入","#e74c3c",2e3);return}const e=C.value.trim();if(!e){p.warning("设备编号不能为空"),x("输入为空,请重新输入","#e74c3c",2e3);return}const a=we(e);if(console.log("分割结果:",a,"输入:",e,"配置:",i.value),a.length===0){p.warning("未识别到有效的设备编号"),x("未识别到有效设备","#e74c3c",2e3);return}let o=a;if(!i.value.allowDuplicate&&(o=a.filter(d=>!m.value.includes(d)),o.length<a.length)){const d=a.length-o.length;p.warning(`已过滤 ${d} 个重复的设备编号(与待提交列表中的编码重复)`)}if(o.length===0){p.warning("没有可添加的设备编号(可能全部重复)"),x("全部重复,未添加","#e67e22",2e3);return}m.value.push(...o),ge(o),a.length>1?x(`已录入 ${o.length} 个编码`,"#27ae60",1500):x(`成功录入${H(o[0])}`,"#27ae60",1500),C.value="",R.value="",N()},De=t=>{m.value.splice(t,1)},Re=()=>{m.value=[]},Ie=async()=>{var a,o,d,g,y,h;if(m.value.length===0||!_.value){p.warning("没有待提交的设备编号");return}F.value=!0;const t=[],e=[];try{const f={check_no:_.value,device_codes:[...m.value]};try{const l=await Ne(f);if((l==null?void 0:l.code)===2e3){const u=await O();if((u==null?void 0:u.code)===2e3){const n=q(_.value,u.data);D.value=(n==null?void 0:n.id)??null,l.data&&Array.isArray(l.data)?l.data.forEach(r=>{t.push({device_code:r.device_code||r.deviceCode,check_no:_.value,productName:r.productName||"未知商品",id:(n==null?void 0:n.id)||0,status_display:(n==null?void 0:n.status_display)||"",device_name:r.device_name||r.deviceName||"未知设备",device_category:r.device_category||r.deviceCategory||"未知分类",scanned_quantity:r.scanned_quantity||0})}):(a=l.data)!=null&&a.success_codes&&Array.isArray(l.data.success_codes)?(l.data.success_codes.forEach(r=>{t.push({device_code:r,check_no:_.value,productName:"未知商品",id:(n==null?void 0:n.id)||0,status_display:(n==null?void 0:n.status_display)||"",device_name:"未知设备",device_category:"未知分类",scanned_quantity:1})}),(o=l.data)!=null&&o.fail_codes&&Array.isArray(l.data.fail_codes)&&e.push(...l.data.fail_codes)):m.value.forEach(r=>{t.push({device_code:r,check_no:_.value,productName:"未知商品",id:(n==null?void 0:n.id)||0,status_display:(n==null?void 0:n.status_display)||"",device_name:"未知设备",device_category:"未知分类",scanned_quantity:1})}),W(t),t.length>0&&e.length===0?(m.value=[],p.success("提交成功")):t.length>0&&e.length>0?(m.value=e,p.warning(`成功提交 ${t.length} 个,失败 ${e.length} 个`)):(m.value=e,p.error(`提交失败,共 ${e.length} 个设备编号`));return}}else console.warn("批量提交失败,尝试逐个提交:",l)}catch(l){console.warn("批量提交接口不可用,使用逐个提交方式:",l)}for(const l of m.value)try{const u={device_code:l,check_no:_.value},n=await Ue(u);if((n==null?void 0:n.code)===2e3){const r=await O();if((r==null?void 0:r.code)===2e3){const I=q(_.value,r.data);t.push({...u,productName:((d=n.data)==null?void 0:d.productName)||"未知商品",id:(I==null?void 0:I.id)||0,status_display:(I==null?void 0:I.status_display)||"",device_name:((g=n.data)==null?void 0:g.device_name)||"未知设备",device_category:((y=n.data)==null?void 0:y.device_category)||"未知分类",scanned_quantity:((h=n.data)==null?void 0:h.scanned_quantity)||1}),D.value=(I==null?void 0:I.id)??null}}else e.push(l)}catch(u){console.error(`提交设备编号 ${l} 失败:`,u),e.push(l)}W(t),t.length>0&&e.length===0?(m.value=[],p.success(`成功提交 ${t.length} 个设备编号`)):t.length>0&&e.length>0?(m.value=e,p.warning(`成功提交 ${t.length} 个,失败 ${e.length} 个`)):(m.value=e,p.error(`提交失败,共 ${e.length} 个设备编号`))}finally{F.value=!1,N()}},ke=async()=>{if(!_.value)return;const t=await qe({check_no:_.value});(t==null?void 0:t.code)===2e3&&(p.success("完成盘点!"),A.value=!0,E.value=!1,J("completed"))},Ce=async()=>{if(!D.value)return;const t=await oe(D.value);(t==null?void 0:t.code)===2e3&&(p.success("取消盘点成功!"),A.value=!0,E.value=!1,J("completed"))};ue({visible:E,setCheckNo:re});const xe=async()=>{if(A.value){A.value=!1,_.value="",m.value=[],S.value=[],D.value=null,B.value=[],x("等待输入...");return}console.log("currentRecordId.value::",D.value,"check_no.value::",_.value);let t=D.value;if(!t&&_.value)try{const e=await O();if((e==null?void 0:e.code)===2e3){const a=q(_.value,e.data);t=(a==null?void 0:a.id)??null,console.log("通过 check_no 查询到的 id::",t)}}catch(e){console.error("查询盘点记录失败:",e)}if(t)try{const e=await oe(t);(e==null?void 0:e.code)===2e3?p.success("取消盘点成功!"):p.warning((e==null?void 0:e.msg)||"取消盘点失败")}catch(e){console.error("取消盘点失败:",e),p.error("取消盘点失败")}_.value="",m.value=[],S.value=[],D.value=null,B.value=[],x("等待输入...")};return Fe(()=>{$&&clearTimeout($),L&&clearTimeout(L)}),(t,e)=>{const a=k("el-input"),o=k("el-button"),d=k("el-tag"),g=k("el-table-column"),y=k("el-table"),h=k("el-dialog"),f=k("el-input-number"),l=k("el-form-item"),u=k("el-option"),n=k("el-select"),r=k("el-switch"),I=k("el-form"),Ve=Te("loading");return P(),z(ne,null,[s(h,{modelValue:E.value,"onUpdate:modelValue":e[3]||(e[3]=c=>E.value=c),title:"开始盘点",width:"800px",onOpen:ye,onOpened:be,onClose:xe},Be({default:v(()=>[w("div",null,[w("div",Oe,[le(w("textarea",{ref_key:"deviceCodeInputRef",ref:Q,"onUpdate:modelValue":e[0]||(e[0]=c=>C.value=c),class:"device-code-input",placeholder:"设备编号(支持扫码枪/RFID批量录入)",disabled:F.value,autocomplete:"off",rows:"3",onInput:fe,onKeydown:[ve,ae(Le(me,["prevent"]),["enter"])],onBlur:pe},null,40,ze),[[$e,C.value]]),s(a,{modelValue:_.value,"onUpdate:modelValue":e[1]||(e[1]=c=>_.value=c),placeholder:"盘点编号",onKeyup:ae(M,["enter"]),disabled:!0},null,8,["modelValue"]),s(o,{type:"success",onClick:M,disabled:F.value},{default:v(()=>e[13]||(e[13]=[V("添加到待提交列表")])),_:1},8,["disabled"]),s(o,{type:"info",icon:Pe(Ke),onClick:e[2]||(e[2]=c=>T.value=!0),disabled:F.value},{default:v(()=>e[14]||(e[14]=[V("读取规则")])),_:1},8,["icon","disabled"])]),m.value.length>0?(P(),z("div",Ge,[w("div",je,[w("div",Je,"待提交设备编号 ("+G(m.value.length)+"个):",1),w("div",Qe,[s(o,{type:"primary",onClick:Ie,loading:F.value,size:"small"},{default:v(()=>[V("批量提交("+G(m.value.length)+")",1)]),_:1},8,["loading"]),s(o,{type:"text",size:"small",onClick:Re},{default:v(()=>e[15]||(e[15]=[V("清空")])),_:1})])]),w("div",Xe,[(P(!0),z(ne,null,Ee(m.value,(c,ee)=>(P(),j(d,{key:ee,closable:"",onClose:We=>De(ee),style:{"margin-right":"8px","margin-bottom":"8px"}},{default:v(()=>[V(G(c),1)]),_:2},1032,["onClose"]))),128))])])):te("",!0),le((P(),j(y,{data:S.value,style:{"margin-top":"20px"}},{default:v(()=>[s(g,{type:"index",label:"序号",width:"60"}),s(g,{prop:"device_code",label:"设备编号"}),s(g,{prop:"device_name",label:"设备名称"}),s(g,{prop:"device_category",label:"设备分类"}),s(g,{prop:"check_no",label:"盘点编号"}),s(g,{prop:"scanned_quantity",label:"盘点数量"}),s(g,{prop:"status_display",label:"状态"})]),_:1},8,["data"])),[[Ve,F.value]])])]),_:2},[S.value.length>0?{name:"footer",fn:v(()=>[w("div",Ye,[s(o,{onClick:Ce,disabled:!D.value},{default:v(()=>e[16]||(e[16]=[V("取消盘点")])),_:1},8,["disabled"]),s(o,{type:"primary",onClick:ke,disabled:!_.value},{default:v(()=>e[17]||(e[17]=[V("完成盘点")])),_:1},8,["disabled"])])]),key:"0"}:void 0]),1032,["modelValue"]),s(h,{modelValue:T.value,"onUpdate:modelValue":e[12]||(e[12]=c=>T.value=c),title:"设置读取规则",width:"600px","close-on-click-modal":!1,"append-to-body":""},{footer:v(()=>[s(o,{onClick:he},{default:v(()=>e[25]||(e[25]=[V("重置默认")])),_:1}),s(o,{type:"primary",onClick:_e},{default:v(()=>e[26]||(e[26]=[V("保存")])),_:1})]),default:v(()=>[s(I,{model:i.value,"label-width":"140px"},{default:v(()=>[s(l,{label:"RFID标签长度"},{default:v(()=>[s(f,{modelValue:i.value.rfidLength,"onUpdate:modelValue":e[4]||(e[4]=c=>i.value.rfidLength=c),min:1,max:100,style:{width:"100%"}},null,8,["modelValue"]),e[18]||(e[18]=w("div",{class:"form-tip"},"RFID标签的固定长度(字符数)",-1))]),_:1}),s(l,{label:"RFID标签前缀"},{default:v(()=>[s(a,{modelValue:i.value.rfidPrefix,"onUpdate:modelValue":e[5]||(e[5]=c=>i.value.rfidPrefix=c),placeholder:"例如:E280",style:{width:"100%"}},null,8,["modelValue"]),e[19]||(e[19]=w("div",{class:"form-tip"},"RFID标签的前缀(可选,留空则不限制前缀)",-1))]),_:1}),s(l,{label:"分隔符"},{default:v(()=>[s(n,{modelValue:i.value.separator,"onUpdate:modelValue":e[6]||(e[6]=c=>i.value.separator=c),placeholder:"选择分隔符",style:{width:"100%"},"popper-class":"separator-select-popper",teleported:""},{default:v(()=>[s(u,{label:"空格",value:" "}),s(u,{label:"逗号",value:","}),s(u,{label:"分号",value:";"}),s(u,{label:"制表符",value:"\\t"}),s(u,{label:"回车换行",value:"\\n"}),s(u,{label:"自定义",value:"custom"})]),_:1},8,["modelValue"]),i.value.separator==="custom"?(P(),j(a,{key:0,modelValue:i.value.customSeparator,"onUpdate:modelValue":e[7]||(e[7]=c=>i.value.customSeparator=c),placeholder:"请输入自定义分隔符",style:{width:"100%","margin-top":"10px"}},null,8,["modelValue"])):te("",!0),e[20]||(e[20]=w("div",{class:"form-tip"},"用于分割多个设备编号的分隔符",-1))]),_:1}),s(l,{label:"自动分割粘连"},{default:v(()=>[s(r,{modelValue:i.value.autoSplitSticky,"onUpdate:modelValue":e[8]||(e[8]=c=>i.value.autoSplitSticky=c)},null,8,["modelValue"]),e[21]||(e[21]=w("div",{class:"form-tip"},"是否自动分割粘连在一起的RFID标签",-1))]),_:1}),s(l,{label:"允许重复添加"},{default:v(()=>[s(r,{modelValue:i.value.allowDuplicate,"onUpdate:modelValue":e[9]||(e[9]=c=>i.value.allowDuplicate=c)},null,8,["modelValue"]),e[22]||(e[22]=w("div",{class:"form-tip"},"是否允许添加重复的设备编号",-1))]),_:1}),s(l,{label:"启用高速缓冲"},{default:v(()=>[s(r,{modelValue:i.value.enableRFIDBuffer,"onUpdate:modelValue":e[10]||(e[10]=c=>i.value.enableRFIDBuffer=c)},null,8,["modelValue"]),e[23]||(e[23]=w("div",{class:"form-tip"},"开启后使用缓冲区整包处理RFID高速输入",-1))]),_:1}),s(l,{label:"缓冲判定时间(ms)"},{default:v(()=>[s(f,{modelValue:i.value.rfidInputTimeout,"onUpdate:modelValue":e[11]||(e[11]=c=>i.value.rfidInputTimeout=c),min:30,max:1e3,step:10,style:{width:"100%"}},null,8,["modelValue"]),e[24]||(e[24]=w("div",{class:"form-tip"},"超出该间隔判定一次扫码完成",-1))]),_:1})]),_:1},8,["model"])]),_:1},8,["modelValue"])],64)}}}),nt=Me(Ze,[["__scopeId","data-v-cf6a54ae"]]);export{nt as default};
|