驭风行PC站
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

1 lines
5.2 KiB

import{f as oe,P as W,k as S,h as i,ap as _,aq as q,ah as T,L as U,l as pe,o as c,c as m,F as D,y as he,n as v,u as o,b as G,w as X,x as J,z as V,ak as w,O as Q,g as N,i as k,t as be}from"./Ca9y1zsW.js";import{b as ye,h as H,au as x,av as Ve,i as Y,u as we,E as Z,_ as xe,af as ee,w as Ce}from"./BPRC2v3K.js";import{m as ae}from"./CeUmO8rY.js";import{i as le}from"./Immh241S.js";import{b as ge}from"./YeUNH851.js";import{u as Ie}from"./CPNNouYu.js";import{C as Ee,U as g}from"./BB_Ol6Sd.js";import{f as Se,e as _e,b as Te,d as De}from"./DaX0k22-.js";import{E as C}from"./BUADUvnR.js";const Ne=ye({modelValue:{type:Number,default:0},id:{type:String,default:void 0},lowThreshold:{type:Number,default:2},highThreshold:{type:Number,default:4},max:{type:Number,default:5},colors:{type:H([Array,Object]),default:()=>ae(["","",""])},voidColor:{type:String,default:""},disabledVoidColor:{type:String,default:""},icons:{type:H([Array,Object]),default:()=>[x,x,x]},voidIcon:{type:le,default:()=>Ve},disabledVoidIcon:{type:le,default:()=>x},disabled:Boolean,allowHalf:Boolean,showText:Boolean,showScore:Boolean,textColor:{type:String,default:""},texts:{type:H(Array),default:()=>ae(["Extremely bad","Disappointed","Fair","Satisfied","Surprise"])},scoreTemplate:{type:String,default:"{value}"},size:ge,clearable:Boolean,...Ie(["ariaLabel"])}),ke={[Ee]:p=>Y(p),[g]:p=>Y(p)},He=oe({name:"ElRate"}),Me=oe({...He,props:Ne,emits:ke,setup(p,{expose:te,emit:h}){const e=p;function I(a,l){const t=n=>q(n),u=Object.keys(l).map(n=>+n).filter(n=>{const y=l[n];return(t(y)?y.excluded:!1)?a<n:a<=n}).sort((n,y)=>n-y),b=l[u[0]];return t(b)&&b.value||b}const M=W(Se,void 0),B=W(_e,void 0),se=Te(),r=we("rate"),{inputId:re,isLabeledByFormItem:P}=De(e,{formItemContext:B}),s=S(e.modelValue),E=S(-1),f=S(!0),ne=i(()=>[r.b(),r.m(se.value)]),d=i(()=>e.disabled||(M==null?void 0:M.disabled)),ie=i(()=>r.cssVarBlock({"void-color":e.voidColor,"disabled-void-color":e.disabledVoidColor,"fill-color":z.value})),A=i(()=>{let a="";return e.showScore?a=e.scoreTemplate.replace(/\{\s*value\s*\}/,d.value?`${e.modelValue}`:`${s.value}`):e.showText&&(a=e.texts[Math.ceil(s.value)-1]),a}),O=i(()=>e.modelValue*100-Math.floor(e.modelValue)*100),ue=i(()=>_(e.colors)?{[e.lowThreshold]:e.colors[0],[e.highThreshold]:{value:e.colors[1],excluded:!0},[e.max]:e.colors[2]}:e.colors),z=i(()=>{const a=I(s.value,ue.value);return q(a)?"":a}),ce=i(()=>{let a="";return d.value?a=`${O.value}%`:e.allowHalf&&(a="50%"),{color:z.value,width:a}}),F=i(()=>{let a=_(e.icons)?[...e.icons]:{...e.icons};return a=T(a),_(a)?{[e.lowThreshold]:a[0],[e.highThreshold]:{value:a[1],excluded:!0},[e.max]:a[2]}:a}),de=i(()=>I(e.modelValue,F.value)),L=i(()=>d.value?U(e.disabledVoidIcon)?e.disabledVoidIcon:T(e.disabledVoidIcon):U(e.voidIcon)?e.voidIcon:T(e.voidIcon)),fe=i(()=>I(s.value,F.value));function j(a){const l=d.value&&O.value>0&&a-1<e.modelValue&&a>e.modelValue,t=e.allowHalf&&f.value&&a-.5<=s.value&&a>s.value;return l||t}function K(a){e.clearable&&a===e.modelValue&&(a=0),h(g,a),e.modelValue!==a&&h("change",a)}function me(a){d.value||(e.allowHalf&&f.value?K(s.value):K(a))}function ve(a){if(d.value)return;let l=s.value;const t=a.code;return t===C.up||t===C.right?(e.allowHalf?l+=.5:l+=1,a.stopPropagation(),a.preventDefault()):(t===C.left||t===C.down)&&(e.allowHalf?l-=.5:l-=1,a.stopPropagation(),a.preventDefault()),l=l<0?0:l,l=l>e.max?e.max:l,h(g,l),h("change",l),l}function $(a,l){if(!d.value){if(e.allowHalf&&l){let t=l.target;ee(t,r.e("item"))&&(t=t.querySelector(`.${r.e("icon")}`)),(t.clientWidth===0||ee(t,r.e("decimal")))&&(t=t.parentNode),f.value=l.offsetX*2<=t.clientWidth,s.value=f.value?a-.5:a}else s.value=a;E.value=a}}function R(){d.value||(e.allowHalf&&(f.value=e.modelValue!==Math.floor(e.modelValue)),s.value=e.modelValue,E.value=-1)}return pe(()=>e.modelValue,a=>{s.value=a,f.value=e.modelValue!==Math.floor(e.modelValue)}),e.modelValue||h(g,0),te({setCurrentValue:$,resetCurrentValue:R}),(a,l)=>{var t;return c(),m("div",{id:o(re),class:v([o(ne),o(r).is("disabled",o(d))]),role:"slider","aria-label":o(P)?void 0:a.ariaLabel||"rating","aria-labelledby":o(P)?(t=o(B))==null?void 0:t.labelId:void 0,"aria-valuenow":s.value,"aria-valuetext":o(A)||void 0,"aria-valuemin":"0","aria-valuemax":a.max,tabindex:"0",style:k(o(ie)),onKeydown:ve},[(c(!0),m(D,null,he(a.max,(u,b)=>(c(),m("span",{key:b,class:v(o(r).e("item")),onMousemove:n=>$(u,n),onMouseleave:R,onClick:n=>me(u)},[G(o(Z),{class:v([o(r).e("icon"),{hover:E.value===u},o(r).is("active",u<=s.value)])},{default:X(()=>[j(u)?N("v-if",!0):(c(),m(D,{key:0},[J((c(),V(w(o(fe)),null,null,512)),[[Q,u<=s.value]]),J((c(),V(w(o(L)),null,null,512)),[[Q,!(u<=s.value)]])],64)),j(u)?(c(),m(D,{key:1},[(c(),V(w(o(L)),{class:v([o(r).em("decimal","box")])},null,8,["class"])),G(o(Z),{style:k(o(ce)),class:v([o(r).e("icon"),o(r).e("decimal")])},{default:X(()=>[(c(),V(w(o(de))))]),_:1},8,["style","class"])],64)):N("v-if",!0)]),_:2},1032,["class"])],42,["onMousemove","onClick"]))),128)),a.showText||a.showScore?(c(),m("span",{key:0,class:v(o(r).e("text")),style:k({color:a.textColor})},be(o(A)),7)):N("v-if",!0)],46,["id","aria-label","aria-labelledby","aria-valuenow","aria-valuetext","aria-valuemax"])}}});var Be=xe(Me,[["__file","rate.vue"]]);const We=Ce(Be);export{We as E};