Index-cb2d80ea.js 4.0 KB

1
  1. import{d as j,r as s,a as H,j as u,b as v,e as l,c as _,f as w,C as Q,k as S,y as C,E as h,p as W,n as U,_ as X}from"./index-16aedc47.js";import{B as Y}from"./index-8a614103.js";import{F as G,I as J,s as K}from"./vue-qrcode-reader-40aaedb2.js";import{I as L}from"./index-3075fd64.js";const Z=f=>(W("data-v-9fb78c87"),f=f(),U(),f),ee={key:0,style:{height:"100vh",width:"100vw",display:"flex","flex-direction":"column",overflow:"hidden"}},te={style:{padding:"10px 16px","line-height":"0","align-items":"center",display:"flex","justify-content":"space-between"}},oe={style:{"margin-left":"16px"}},ae={key:0},ne={key:1},se=Z(()=>l("div",{style:{"flex-grow":"1"}},null,-1)),ie={style:{"flex-grow":"1","border-top":"1px solid #eee","box-sizing":"border-box"}},ce=j({__name:"Index",emits:["success","close"],setup(f,{expose:T,emit:I}){const p=s(!1),B=()=>{p.value=!p.value},r=s(!1),N=()=>{r.value=!0},m=()=>{r.value=!1},E=()=>{m(),y("close")},y=I,P=()=>{const e=document.querySelector("input[name]");e.click(),console.log(e)},x=s([]);function b(e){console.log(e),x.value=e.map(t=>t.rawValue),y("success",x.value),m()}const F=s({facingMode:"environment"}),g=[{label:"rear camera",constraints:{facingMode:"environment"}},{label:"front camera",constraints:{facingMode:"user"}}],O=s(g);async function z(){const t=(await navigator.mediaDevices.enumerateDevices()).filter(({kind:a})=>a==="videoinput");O.value=[...g,...t.map(({deviceId:a,label:o})=>({label:`${o} (ID: ${a})`,constraints:{deviceId:a}}))],n.value=""}function V(e,t){for(const a of e){const[o,...d]=a.cornerPoints;t.strokeStyle="red",t.beginPath(),t.moveTo(o.x,o.y);for(const{x:i,y:c}of d)t.lineTo(i,c);t.lineTo(o.x,o.y),t.closePath(),t.stroke()}}function A(e,t){for(const a of e){const{boundingBox:{x:o,y:d,width:i,height:c}}=a;t.lineWidth=2,t.strokeStyle="#007bff",t.strokeRect(o,d,i,c)}}function q(e,t){for(const a of e){const{boundingBox:o,rawValue:d}=a,i=o.x+o.width/2,c=o.y+o.height/2,$=Math.max(12,50*o.width/t.canvas.width);t.font=`bold ${$}px sans-serif`,t.textAlign="center",t.lineWidth=3,t.strokeStyle="#35495e",t.strokeText(a.rawValue,i,c),t.fillStyle="#5cb984",t.fillText(d,i,c)}}const D=s([{text:"nothing (default)",value:void 0},{text:"outline",value:V},{text:"centered text",value:q},{text:"bounding box",value:A}][1]),k=s({aztec:!1,code_128:!1,code_39:!1,code_93:!1,codabar:!1,databar:!1,databar_expanded:!1,data_matrix:!1,dx_film_edge:!1,ean_13:!1,ean_8:!1,itf:!1,maxi_code:!1,micro_qr_code:!1,pdf417:!1,qr_code:!0,rm_qr_code:!1,upc_a:!1,upc_e:!1,linear_codes:!1,matrix_codes:!1}),M=H(()=>Object.keys(k.value).filter(e=>k.value[e])),n=s("");function R(e){n.value=`[${e.name}]: `,e.name==="NotAllowedError"?n.value+="you need to grant camera access permission":e.name==="NotFoundError"?n.value+="no camera on this device":e.name==="NotSupportedError"?n.value+="secure context required (HTTPS, localhost)":e.name==="NotReadableError"?n.value+="is the camera already in use?":e.name==="OverconstrainedError"?n.value+="installed cameras are not suitable":e.name==="StreamApiNotSupportedError"?n.value+="Stream API is not supported in this browser":e.name==="InsecureContextError"?n.value+="Camera access is only permitted in secure context. Use HTTPS or localhost rather than HTTP.":n.value+=e.message,K({type:"danger",message:n.value,zIndex:9999999})}return T({open:N,stop:m}),(e,t)=>{const a=Y,o=L;return r.value?(u(),v("div",ee,[l("div",te,[l("div",null,[_(a,{plain:"",icon:"photo-o",type:"primary",size:"small",onClick:P},{default:w(()=>[Q("打开图片")]),_:1})]),l("div",oe,[_(a,{plain:"",icon:"bulb-o",type:"primary",size:"small",onClick:B},{default:w(()=>[p.value?(u(),v("span",ae,"关闭灯光")):(u(),v("span",ne,"打开灯光"))]),_:1})]),se,l("div",null,[_(o,{name:"close",size:"30",onClick:E})])]),l("div",ie,[r.value?(u(),S(C(G),{key:0,onDetect:b,capture:null})):h("",!0),r.value?(u(),S(C(J),{key:1,torch:p.value,constraints:F.value,track:D.value.value,formats:M.value,onError:R,onDetect:b,onCameraOn:z},null,8,["torch","constraints","track","formats"])):h("",!0)])])):h("",!0)}}});const pe=X(ce,[["__scopeId","data-v-9fb78c87"]]);export{pe as Q};