mirror of
https://github.com/XiaoDaiGua-Ray/ray-template.git
synced 2025-05-30 09:19:17 +08:00
2 lines
3.1 KiB
JavaScript
2 lines
3.1 KiB
JavaScript
import{n as p,d as b,h as u,p as R}from"./index-c41038ca.js";import{l as S}from"./awesome-qr@2.1.5-rc.0-7b2b96ae.js";import{k as A,D as k,n as B,f as v,b as t,F as w}from"./@vue_runtime-core@3.3.4-e708ccad.js";import{k as N}from"./@vue_reactivity@3.3.4-1f79d3d1.js";import{c as L,P as D}from"./naive-ui@2.34.4_vue@3.3.4-32c47a39.js";const F={watchText:{type:Boolean,default:!0},status:{type:String},errorDescription:{type:[String,Object],default:"二维码已过期"},errorActionDescription:{type:String,default:"重新加载"},text:{type:String,required:!0},size:{type:Number,default:160},margin:{type:Number,default:12},correctLevel:{type:Number,default:1,validator:r=>[0,1,2,3].includes(r)},maskPattern:{type:Number},version:{type:Number},components:{type:Object,default:()=>({data:{scale:1},timing:{scale:1,protectors:!1},alignment:{scale:1,protectors:!1},cornerAlignment:{scale:1,protectors:!0}})},colorDark:{type:String,default:"#000000"},colorLight:{type:String,default:"#ffffff"},autoColor:{type:Boolean,default:!0},backgroundImage:{type:String},backgroundDimming:{type:String,default:"rgba(0, 0, 0, 0)"},gifBackgroundURL:{type:String},gifBackground:{type:ArrayBuffer},whiteMargin:{type:Boolean,default:!0},logoImage:{type:String},logoScale:{type:Number,default:.4},logoMargin:{type:Number,default:6},logoCornerRadius:{type:Number,default:8},dotScale:{type:Number,default:1},onSuccess:{type:[Function,Array],default:null},onError:{type:[Function,Array],default:null},onReload:{type:[Function,Array],default:null}},q=r=>new Promise((i,c)=>{const e=new XMLHttpRequest;e.responseType="blob",e.onload=()=>{const n=new FileReader;n.onloadend=()=>{i(n.result)},n.onerror=a=>{c(a)},n.onabort=a=>{c(a)},n.readAsArrayBuffer(e.response)},e.open("GET",r),e.send()}),U=A({name:"RayQRcode",props:F,setup(r,i){const{expose:c}=i,e=N(),n={opacitySpinning:"0.1"};let a;const g=async()=>{const{gifBackgroundURL:o}=r;if(o)try{a=await q(o)}catch(f){console.error(f)}},d=()=>{const{gifBackgroundURL:o,gifBackground:f,...h}=r;new S.AwesomeQR({...h,gifBackground:a??void 0}).draw().then(l=>{const{onSuccess:s}=r;s&&u(s,l),e.value=l}).catch(l=>{const{onError:s}=r;s&&u(s,l)})},y=()=>{if(i.slots.errorAction)return;const{onReload:o}=r;o&&u(o)},m=o=>{e.value&&p(e.value,"String")&&R(e.value,o)};return k(()=>{r.watchText&&B().then(()=>{d()})}),c({downloadQRCode:m}),v(async()=>{await g(),d()}),{qrcodeURL:e,spinOverrides:n,errorActionClick:y}},render(){return t("div",{class:"ray-qrcode"},[t(L,{show:this.status==="loading",themeOverrides:this.spinOverrides},{default:()=>[t("img",{src:this.qrcodeURL},null)]}),this.status==="error"?t("div",{class:"ray-qrcode__error"},[t("div",{class:"ray-qrcode__error-content"},[p(this.errorDescription,"String")?this.errorDescription:()=>this.errorDescription]),t("div",{class:"ray-qrcode__error-btn",onClick:this.errorActionClick.bind(this)},[this.$slots.errorAction?this.$slots.errorAction():t(w,null,[t(D,{text:!0,color:"#ffffff"},{default:()=>this.errorActionDescription,icon:()=>t(b,{name:"reload",size:"16",color:"#ffffff"},null)})])])]):null])}}),_="/ray-template/assets/ray-ab649d1c.svg";export{_ as L,U as R};
|