UNPKG

zview-plus

Version:

基于 Vue3 的 UI 组件库

7 lines (6 loc) 4.24 kB
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("vue"),u=require("../../../../node_modules/.pnpm/registry.npmmirror.com_@vue_shared@3.2.36/node_modules/@vue/shared/dist/shared.esm-bundler.js"),E=require("./progress.js"),C=require("../../icon/index.js"),D={key:0,class:"z-progress-bar"},N={key:0,class:"z-progress-bar-innerText"},P={viewBox:"0 0 100 100"},T=["d","stroke-width","stroke-linecap"],_=["d","stroke","opacity","stroke-linecap","stroke-width"],x={key:0},V={name:"ZProgress"},I=e.defineComponent({...V,props:E.progressProps,setup(g){const r=g,p={success:"#67c23a",error:"#f56c6c",warning:"#e6a23c",default:"#20a0ff"},y=e.computed(()=>{const{status:t,type:s,showText:l,textInside:o}=r;return{[`z-progress--${s}`]:s,[`z-progress--${t}`]:t,["z-progress-without-text"]:!l,["z-progress-text-inside"]:o}}),$=e.computed(()=>({width:`${r.percentage}%`,animationDuration:`${r.duration}s`,backgroundColor:h(r.percentage)})),c=e.computed(()=>(r.strokeWidth/r.width*100).toFixed(1)),d=e.computed(()=>["circle","dashboard"].includes(r.type)?Number.parseInt(`${50-Number.parseFloat(c.value)/2}`,10):0),f=e.computed(()=>{const t=d.value,s=r.type==="dashboard";return` M 50 50 m 0 ${s?"":"-"}${t} a ${t} ${t} 0 1 1 0 ${s?"-":""}${t*2} a ${t} ${t} 0 1 1 0 ${s?"":"-"}${t*2} `}),a=e.computed(()=>2*Math.PI*d.value),i=e.computed(()=>r.type==="dashboard"?.75:1),m=e.computed(()=>`${-1*a.value*(1-i.value)/2}px`),v=e.computed(()=>({strokeDasharray:`${a.value*i.value}px, ${a.value}px`,strokeDashoffset:m.value})),z=e.computed(()=>({strokeDasharray:`${a.value*i.value*(r.percentage/100)}px, ${a.value}px`,strokeDashoffset:m.value,transition:"stroke-dasharray 0.6s ease 0s, stroke 0.6s ease, opacity ease 0.6s"})),S=e.computed(()=>{let t;return r.color?t=h(r.percentage):t=p[r.status]||p.default,t}),w=e.computed(()=>r.status==="warning"?"warning":r.status==="success"?"success":"close"),B=e.computed(()=>r.type==="line"?12+r.strokeWidth*.4:r.width*.111111+2),k=e.computed(()=>r.format(r.percentage));function b(t){const s=100/t.length;return t.map((o,n)=>u.isString(o)?{color:o,percentage:(n+1)*s}:o).sort((o,n)=>o.percentage-n.percentage)}const h=t=>{var l;const{color:s}=r;if(u.isFunction(s))return s(t);if(u.isString(s))return s;{const o=b(s);for(const n of o)if(n.percentage>t)return n.color;return(l=o[o.length-1])==null?void 0:l.color}};return(t,s)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["z-progress",e.unref(y)])},[t.type==="line"?(e.openBlock(),e.createElementBlock("div",D,[e.createElementVNode("div",{class:"z-progress-bar-outer",style:e.normalizeStyle({height:`${t.strokeWidth}px`})},[e.createElementVNode("div",{class:e.normalizeClass(["z-progress-bar-inner",{["z-progress-bar-innerindeterminate"]:t.indeterminate}]),style:e.normalizeStyle(e.unref($))},[(t.showText||t.$slots.default)&&t.textInside?(e.openBlock(),e.createElementBlock("div",N,[e.renderSlot(t.$slots,"default",{},()=>[e.createElementVNode("span",null,e.toDisplayString(e.unref(k)),1)])])):e.createCommentVNode("",!0)],6)],4)])):(e.openBlock(),e.createElementBlock("div",{key:1,class:"z-progress-circle",style:e.normalizeStyle({height:`${t.width}px`,width:`${t.width}px`})},[(e.openBlock(),e.createElementBlock("svg",P,[e.createElementVNode("path",{class:"z-progress-circle-track",d:e.unref(f),stroke:"#e5e9f2","stroke-width":e.unref(c),fill:"none",style:e.normalizeStyle(e.unref(v)),"stroke-linecap":t.strokeLinecap},null,12,T),e.createElementVNode("path",{class:"z-progress-circle-path",d:e.unref(f),stroke:e.unref(S),fill:"none",opacity:t.percentage?1:0,"stroke-linecap":t.strokeLinecap,"stroke-width":e.unref(c),style:e.normalizeStyle(e.unref(z))},null,12,_)]))],4)),(t.showText||t.$slots.default)&&!t.textInside?(e.openBlock(),e.createElementBlock("div",{key:2,class:"z-progress-text",style:e.normalizeStyle({fontSize:`${e.unref(B)}px`})},[e.renderSlot(t.$slots,"default",{},()=>[t.status?(e.openBlock(),e.createBlock(e.unref(C.default),{key:1,name:e.unref(w)},null,8,["name"])):(e.openBlock(),e.createElementBlock("span",x,e.toDisplayString(e.unref(k)),1))])],4)):e.createCommentVNode("",!0)],2))}});exports.default=I;