mirror of
https://gitee.com/wot-design-uni/wot-design-uni.git
synced 2025-12-07 09:38:44 +08:00
2 lines
6.2 KiB
JavaScript
2 lines
6.2 KiB
JavaScript
var e=Object.defineProperty,t=Object.defineProperties,n=Object.getOwnPropertyDescriptors,i=Object.getOwnPropertySymbols,s=Object.prototype.hasOwnProperty,a=Object.prototype.propertyIsEnumerable,u=(t,n,i)=>n in t?e(t,n,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[n]=i,r=(e,t)=>{for(var n in t||(t={}))s.call(t,n)&&u(e,n,t[n]);if(i)for(var n of i(t))a.call(t,n)&&u(e,n,t[n]);return e},o=(e,i)=>t(e,n(i));import{aa as l,d as c,r as d,c as p,C as m,au as f,B as b,b as h,g as v,w as g,h as w,z as N,i as _,K as y,q as M,ao as x,E as S,aD as j}from"./index-ChV97F5w.js";import{a as O,c as P,d as C,m as I,e as W,b as V,n as T,w as F,_ as E}from"./base64.D3gEw_Hf.js";const k=o(r({},V),{modelValue:W(T),min:I(1),max:I(Number.MAX_SAFE_INTEGER),step:I(1),stepStrictly:P(!1),precision:C(0),disabled:P(!1),disableInput:P(!1),disableMinus:P(!1),disablePlus:P(!1),withoutInput:P(!1),inputWidth:C(36),allowNull:P(!1),placeholder:O(""),adjustPosition:P(!0),beforeChange:Function,longPress:P(!1),immediateChange:P(!0),updateOnInit:P(!0),inputType:O("digit")});function $(){}function A(e,{args:t=[],done:n,canceled:i,error:s}){if(e){const a=e.apply(null,t);l(a)?a.then((e=>{e?n():i&&i()})).catch(s||$):a?n():i&&i()}else n()}const B=E(c(o(r({},{name:"wd-input-number",options:{virtualHost:!0,addGlobalClass:!0,styleIsolation:"shared"}}),{props:k,emits:["change","focus","blur","update:modelValue"],setup(e,{emit:t}){const n=e,i=t,s=d(function(){if(!n.updateOnInit)return function(e){if(n.allowNull&&(!b(e)||""===e))return"";if(!b(e)||""===e)return n.min;let t=Number(e);if(isNaN(t))return n.min;const i=Number(n.precision);if(!b(n.precision))return t;return 0===i?Number(t.toFixed(0)):t.toFixed(i)}(n.modelValue);const e=P(n.modelValue);f(String(e),String(n.modelValue))||i("update:modelValue",e);return e}());let a=null;const u=p((()=>{const e=c(s.value);return n.disabled||e<=n.min||I(e,-n.step)<n.min})),r=p((()=>{const e=c(s.value);return n.disabled||e>=n.max||I(e,n.step)>n.max}));function o(e){if(!b(e))return 0;const t=e.toString(),n=t.indexOf(".");return-1===n?0:t.length-n-1}function l(e){const t=Number(n.precision);return Math.round(e*Math.pow(10,t))/Math.pow(10,t)}function c(e){if(n.allowNull&&(!b(e)||""===e))return NaN;if(!b(e)||""===e)return n.min;let t=String(e);if(t.endsWith(".")&&(t=t.slice(0,-1)),t.startsWith(".")&&(t="0"+t),t.startsWith("-.")&&(t="-0"+t.substring(1)),"-"===t||""===t)return n.min;let i=Number(t);return isNaN(i)&&(i=n.min),O(i)}function O(e){let t=e;if(n.stepStrictly){const e=o(n.step),i=Math.pow(10,e);t=Math.round(t/n.step)*i*n.step/i}return t=n.stepStrictly?function(e,t,i){if(e>=t&&e<=i)return e;const s=o(n.step),a=Math.pow(10,s);if(e<t){const e=l(Math.ceil(t*a/(n.step*a))*n.step*a/a);if(e>i){return l(Math.floor(i*a/(n.step*a))*n.step*a/a)}return e}if(e>i){const e=l(Math.floor(i*a/(n.step*a))*n.step*a/a);if(e<t){return l(Math.ceil(t*a/(n.step*a))*n.step*a/a)}return e}return e}(t,n.min,n.max):Math.min(Math.max(t,n.min),n.max),b(n.precision)&&(t=l(t)),t}function P(e){if(n.allowNull&&(!b(e)||""===e))return"";const t=c(e),i=Number(n.precision);return b(n.precision)?0===i?Number(t.toFixed(0)):t.toFixed(i):t}function C(e){if(n.allowNull&&(!b(e)||""===e)){if(f("",String(n.modelValue)))return void(s.value="");const e=()=>{s.value="",i("update:modelValue",""),i("change",{value:""})};return void A(n.beforeChange,{args:[""],done:e})}const t=c(e),a=P(e);if(f(String(t),String(n.modelValue)))return void(s.value=a);A(n.beforeChange,{args:[t],done:()=>{s.value=a,i("update:modelValue",t),i("change",{value:t})}})}function I(e,t){const i=Number(e);if(isNaN(i))return O(n.min);const s=Math.max(o(i),o(t)),a=Math.pow(10,s);return O((i*a+t*a)/a)}function W(e){const t="add"===e?n.step:-n.step;if(t<0&&(u.value||n.disableMinus)||t>0&&(r.value||n.disablePlus))return;C(I(s.value,t))}function V(e){const t=e.detail.value||"";s.value=t,j((()=>{if(""===t)return s.value="",void(n.immediateChange&&n.allowNull&&C(""));const e=function(e){if(!e)return"";let t=e.replace(/[^\d.-]/g,"");const i=t.startsWith("-");if(t=t.replace(/-/g,""),i&&(t="-"+t),Number(n.precision)>0){const e=t.split(".");e.length>2&&(t=e[0]+"."+e.slice(1).join(""))}else t=t.split(".")[0];return t.startsWith(".")?"0"+t:t.startsWith("-.")?"-0"+t.substring(1):t}(t);Number(n.precision)>0&&function(e){if(!e)return!1;const t=String(e);return t.endsWith(".")||t.startsWith(".")||t.startsWith("-.")||"-"===t||Number(n.precision)>0&&-1===t.indexOf(".")}(e)?s.value=e:(s.value=e,n.immediateChange&&C(e))}))}function T(e){const t=e.detail.value||"";C(t),i("blur",{value:t})}function E(e){i("focus",e.detail)}function k(e){D(),a=setTimeout((()=>{W(e),k(e)}),250)}function $(e){n.longPress&&(D(),a=setTimeout((()=>{W(e),k(e)}),600))}function B(){n.longPress&&D()}function D(){a&&(clearTimeout(a),a=null)}return m((()=>n.modelValue),(e=>{s.value=P(e)})),m([()=>n.max,()=>n.min,()=>n.precision],(()=>{const e=c(s.value);s.value=P(e)})),(e,t)=>{const n=_,i=x;return v(),h(n,{class:M(`wd-input-number ${e.customClass} ${e.disabled?"is-disabled":""} ${e.withoutInput?"is-without-input":""}`),style:S(e.customStyle)},{default:g((()=>[w(n,{class:M("wd-input-number__action "+(u.value||e.disableMinus?"is-disabled":"")),onClick:t[0]||(t[0]=e=>W("sub")),onTouchstart:t[1]||(t[1]=e=>$("sub")),onTouchend:y(B,["stop"])},{default:g((()=>[w(F,{name:"decrease","custom-class":"wd-input-number__action-icon"})])),_:1},8,["class"]),e.withoutInput?N("",!0):(v(),h(n,{key:0,class:"wd-input-number__inner",onClick:t[2]||(t[2]=y((()=>{}),["stop"]))},{default:g((()=>[w(i,{class:"wd-input-number__input",style:S(""+(e.inputWidth?"width: "+e.inputWidth:"")),type:e.inputType,"input-mode":e.precision?"decimal":"numeric",disabled:e.disabled||e.disableInput,value:String(s.value),placeholder:e.placeholder,"adjust-position":e.adjustPosition,onInput:V,onFocus:E,onBlur:T},null,8,["style","type","input-mode","disabled","value","placeholder","adjust-position"]),w(n,{class:"wd-input-number__input-border"})])),_:1})),w(n,{class:M("wd-input-number__action "+(r.value||e.disablePlus?"is-disabled":"")),onClick:t[3]||(t[3]=e=>W("add")),onTouchstart:t[4]||(t[4]=e=>$("add")),onTouchend:y(B,["stop"])},{default:g((()=>[w(F,{name:"add","custom-class":"wd-input-number__action-icon"})])),_:1},8,["class"])])),_:1},8,["class","style"])}}})),[["__scopeId","data-v-975db815"]]);export{B as _};
|