1 |
- import{a as I}from"./avatars.4a5a14d5.js";import M from"./Line.92adcf13.js";import{_ as P,q as B,a9 as L,E as q,B as c,au as V,o as f,x as _,M as i,p as d,A as r,n as O,t as G,F as $,X as b,a1 as z,a2 as R,C as U}from"./index.41f763da.js";const v=function(e,l){if(l=l||{},!(this instanceof v))return new v(e,l);this.conf={styleStr:"",setDomHeightArr:[],echartDomArr:[],printBeforeFn:null,printDoneCallBack:null};for(const o in this.conf)o&&l.hasOwnProperty(o)&&(this.conf[o]=l[o]);typeof e=="string"?this.dom=document.querySelector(e):this.dom=this.isDOM(e)?e:e.$el,this.conf.setDomHeightArr&&this.conf.setDomHeightArr.length&&this.setDomHeight(this.conf.setDomHeightArr),this.init()};v.prototype={init:function(){const e=this.getStyle()+this.getHtml();this.writeIframe(e)},extendOptions:function(e,l){for(const o in l)e[o]=l[o];return e},getStyle:function(){let e="";const l=document.querySelectorAll("style,link");for(let o=0;o<l.length;o++)e+=l[o].outerHTML;return e+=`<style>.no-print{display:none;}${this.conf.styleStr}</style>`,e},getHtml:function(){const e=document.querySelectorAll("input"),l=document.querySelectorAll("select"),o=document.querySelectorAll("textarea");for(let t=0;t<e.length;t++)e[t].type=="checkbox"||e[t].type=="radio"?e[t].checked==!0?e[t].setAttribute("checked","checked"):e[t].removeAttribute("checked"):(e[t].type=="text",e[t].setAttribute("value",e[t].value));for(let t=0;t<o.length;t++)o[t].type=="textarea"&&(o[t].innerHTML=o[t].value);for(let t=0;t<l.length;t++)if(l[t].type=="select-one"){const n=l[t].children;for(const a in n)n[a].tagName=="OPTION"&&(n[a].selected==!0?n[a].setAttribute("selected","selected"):n[a].removeAttribute("selected"))}return this.dom.outerHTML},writeIframe:function(e){let l,o;const t=document.createElement("iframe"),n=document.body.appendChild(t);t.id="myIframe",t.setAttribute("style","position:absolute;width:0;height:0;top:-10px;left:-10px;"),l=n.contentWindow||n.contentDocument,o=n.contentDocument||n.contentWindow.document,o.open(),o.write(e),o.close();const a=this;t.onload=function(){a.conf.printBeforeFn&&a.conf.printBeforeFn({doc:o}),a.drawEchartImg(o).then(()=>{a.toPrint(l),setTimeout(function(){document.body.removeChild(t),a.conf.printDoneCallBack&&a.conf.printDoneCallBack()},100)})}},drawEchartImg(e){return new Promise(l=>{this.conf.echartDomArr&&this.conf.echartDomArr.length>0&&this.conf.echartDomArr.forEach(o=>{const t=e.querySelector("#"+o.$el.id),n=new Image,a=t.offsetWidth+"px",x=t.offsetHeight+"px";n.style.width=a,n.style.height=x,n.src=o.imgSrc,t.innerHTML="",t.appendChild(n)}),l()})},toPrint:function(e){try{setTimeout(function(){e.focus();try{e.document.execCommand("print",!1,null)||e.print()}catch{e.print()}e.close()},10)}catch(l){console.error(l)}},isDOM:typeof HTMLElement=="object"?function(e){return e instanceof HTMLElement}:function(e){return e&&typeof e=="object"&&e.nodeType===1&&typeof e.nodeName=="string"},setDomHeight(e){e&&e.length&&e.forEach(l=>{document.querySelectorAll(l).forEach(t=>{t.style.height=t.offsetHeight+"px"})})}};const p=e=>(z("data-v-7dd9f25b"),e=e(),R(),e),W={class:"card-header"},X=p(()=>d("span",{class:"font-medium"},"\u6253\u5370\u529F\u80FD\uFF08\u62A5\u8868\u3001\u56FE\u8868\u3001\u56FE\u7247\uFF09",-1)),J=U("\u6253\u5370"),K=p(()=>d("p",{class:"font-medium pt-1"},"Element-Plus Table",-1)),Q=p(()=>d("p",{class:"font-medium pt-1"},"Vxe Table",-1)),Y=p(()=>d("p",{class:"font-medium pt-1"},"Echart",-1)),Z=p(()=>d("p",{class:"font-medium pt-1"},"Image",-1)),j=p(()=>d("img",{src:I,alt:"avatars",class:"img",style:{width:"200px",height:"200px",margin:"50px auto"}},null,-1)),ee={name:"Print"},te=B({...ee,setup(e){const l=L({tableData:[{id:10001,name:"Test1",role:"Develop",sex:"Man",age:28,address:"test abc"},{id:10002,name:"Test2",role:"Test",sex:"Women",age:22,address:"Guangzhou"},{id:10003,name:"Test3",role:"PM",sex:"Man",age:32,address:"Shanghai"},{id:10004,name:"Test4",role:"Designer",sex:"Women",age:24,address:"Shanghai"}]}),o=q("1"),t=[{value:"1",el:".el-table",label:"Element-Plus Table"},{value:"2",el:".vxe-table",label:"Vxe Table"},{value:"3",el:".echart",label:"Echart"},{value:"4",el:".img",label:"Image"}];function n(){var u;let s=(u=t.filter(w=>w.value===o.value)[0])==null?void 0:u.el;v(s).toPrint}const a=({column:s})=>{if(s.property==="name")return{backgroundColor:"#f60",color:"#ffffff"}},x=({rowIndex:s})=>{if([2,3,5].includes(s))return{backgroundColor:"red",color:"#ffffff"}},D=({row:s,column:u})=>{if(u.property==="sex"){if(s.sex>="1")return{backgroundColor:"#187"};if(s.age===26)return{backgroundColor:"#2db7f5"}}},S=({rowIndex:s})=>s===1?"warning-row":s===3?"success-row":"",T=[{date:"2016-05-03",name:"Tom",address:"No. 189, Grove St, Los Angeles"},{date:"2016-05-02",name:"Tom",address:"No. 189, Grove St, Los Angeles"},{date:"2016-05-04",name:"Tom",address:"No. 189, Grove St, Los Angeles"},{date:"2016-05-01",name:"Tom",address:"No. 189, Grove St, Los Angeles"}];return(s,u)=>{const w=c("el-option"),k=c("el-select"),C=c("el-button"),A=c("el-table-column"),H=c("el-table"),y=c("el-col"),m=c("vxe-column"),E=c("vxe-table"),F=c("el-row"),N=c("el-card"),g=V("motion");return f(),_(N,null,{header:i(()=>[d("div",W,[X,d("div",null,[r(k,{modelValue:o.value,"onUpdate:modelValue":u[0]||(u[0]=h=>o.value=h),class:"m-2",placeholder:"Select",size:"small"},{default:i(()=>[(f(),O($,null,G(t,h=>r(w,{key:h.value,label:h.label,value:h.value},null,8,["label","value"])),64))]),_:1},8,["modelValue"]),r(C,{size:"small",type:"primary",onClick:n},{default:i(()=>[J]),_:1})])])]),default:i(()=>[r(F,{gutter:24},{default:i(()=>[b((f(),_(y,{xs:22,sm:22,md:11,lg:11,xl:11,style:{margin:"10px",border:"0.01rem solid var(--el-color-primary)"},initial:{opacity:0,y:100},enter:{opacity:1,y:0,transition:{delay:200}}},{default:i(()=>[K,r(H,{class:"el-table",data:T,border:"",style:{margin:"40px auto",width:"100%"},"row-class-name":S},{default:i(()=>[r(A,{prop:"date",label:"Date",width:"180"}),r(A,{prop:"name",label:"Name",width:"180"}),r(A,{prop:"address",label:"Address"})]),_:1})]),_:1})),[[g]]),b((f(),_(y,{xs:22,sm:22,md:11,lg:11,xl:11,style:{margin:"10px",border:"0.01rem solid var(--el-color-primary)"},initial:{opacity:0,y:100},enter:{opacity:1,y:0,transition:{delay:200}}},{default:i(()=>[Q,r(E,{class:"vxe-table",border:"",style:{margin:"40px auto"},"header-cell-style":a,"row-style":x,"cell-style":D,data:l.tableData},{default:i(()=>[r(m,{type:"seq",width:"60"}),r(m,{field:"name",title:"Name"}),r(m,{field:"sex",title:"Sex"}),r(m,{field:"age",title:"Age"}),r(m,{field:"attr1",title:"Attr1"}),r(m,{field:"address",title:"Address","show-overflow":""})]),_:1},8,["data"])]),_:1})),[[g]]),b((f(),_(y,{xs:22,sm:22,md:11,lg:11,xl:11,style:{width:"200px",height:"300px",margin:"10px",border:"0.01rem solid var(--el-color-primary)"},initial:{opacity:0,y:100},enter:{opacity:1,y:0,transition:{delay:200}}},{default:i(()=>[Y,r(M,{class:"echart",style:{margin:"0 auto"}})]),_:1})),[[g]]),b((f(),_(y,{xs:22,sm:22,md:11,lg:11,xl:11,style:{width:"200px",height:"300px",margin:"10px",border:"0.01rem solid var(--el-color-primary)"},initial:{opacity:0,y:100},enter:{opacity:1,y:0,transition:{delay:200}}},{default:i(()=>[Z,j]),_:1})),[[g]])]),_:1})]),_:1})}}});var re=P(te,[["__scopeId","data-v-7dd9f25b"]]);export{re as default};
|