mirror of
https://github.com/XiaoDaiGua-Ray/ray-template.git
synced 2025-05-29 00:19:28 +08:00
2 lines
3.5 KiB
JavaScript
2 lines
3.5 KiB
JavaScript
import{c as l}from"./lodash-es@4.17.21-e8d1949e.js";import{c as r}from"./currency.js@2.0.4-57f74176.js";const a=(t,u,e)=>t!=null&&t.length?t.length===1?r(t[0]):t.reduce((i,o,s,d)=>(i=e==null?void 0:e(i,o,s,d),i),u):0,c=(t,u,e="number")=>e==="number"?r(t,u).value:r(t,u).toString(),p=(...t)=>a(t,0,(u,e)=>r(u).add(e)),V=(...t)=>{if(t.length===2){const[n,i]=t;return r(n).subtract(i)}const u=l(t),e=u.shift();return u.length?a(u,e,(n,i)=>r(n).subtract(i)):e},h=(...t)=>a(t,1,(u,e)=>r(u).multiply(e)),F=(...t)=>{if(t.length===2){const[n,i]=t;return r(n).divide(i)}const u=l(t),e=u.shift();return u.length?a(u,e,(n,i)=>r(n).divide(i)):e},N=(t,u,e)=>u<=1?[t||0]:t?r(t,e).distribute(u).map(i=>c(i,e)):new Array(u).fill(0),v=Vue.defineComponent({name:"CalculatePrecision",setup(){const t=Vue.reactive({addOptions:["1","0.2","0.1","1.1"],subtractOptions:["1","0.2","0.1","1.1"],multiplyOptions:["1","0.2","0.1","1.1"],divideOptions:["1","0.2","0.1","1.1"],distributeValue:12,distributeOutputValue:[],distributeLength:3}),u={addOptions:p,subtractOptions:V,multiplyOptions:h,divideOptions:F},e=(i,o)=>{const s=u[o],d=s(...i);return"结果: "+c(d)},n=()=>{Vue.nextTick().then(()=>{t.distributeOutputValue=N(t.distributeValue,t.distributeLength)})};return n(),{...Vue.toRefs(t),copilotFunc:e,updateDistributeValue:n}},render(){return Vue.createVNode(naive.NLayout,null,{default:()=>[Vue.createVNode("h2",{style:"margin: 0 0 20px 0"},[Vue.createTextVNode("计算方法,默认都保留两位小数与四舍五入,可以根据 format 方法自行转换")]),Vue.createVNode("h3",{style:"margin: 0 0 20px 0"},[Vue.createTextVNode("示例方法都基于 currency.js 封装,利用其精度处理能力封装了常用的一些计算方法,解决精度问题。如果需要其他的方法请阅读官方文档 https://currency.js.org/#subtract")]),Vue.createVNode(naive.NSpace,{vertical:!0},{default:()=>[Vue.createVNode(naive.NCard,{title:"加法"},{default:()=>Vue.createVNode(naive.NDynamicTags,{value:this.addOptions,"onUpdate:value":t=>this.addOptions=t,onUpdateValue:t=>{this.copilotFunc(t,"addOptions")}},null),footer:()=>this.copilotFunc(this.addOptions,"addOptions")}),Vue.createVNode(naive.NCard,{title:"减法"},{default:()=>Vue.createVNode(naive.NDynamicTags,{value:this.subtractOptions,"onUpdate:value":t=>this.subtractOptions=t,onUpdateValue:t=>{this.copilotFunc(t,"subtractOptions")}},null),footer:()=>this.copilotFunc(this.subtractOptions,"subtractOptions")}),Vue.createVNode(naive.NCard,{title:"乘法"},{default:()=>Vue.createVNode(naive.NDynamicTags,{value:this.multiplyOptions,"onUpdate:value":t=>this.multiplyOptions=t,onUpdateValue:t=>{this.copilotFunc(t,"multiplyOptions")}},null),footer:()=>this.copilotFunc(this.multiplyOptions,"multiplyOptions")}),Vue.createVNode(naive.NCard,{title:"除法(非取模)"},{default:()=>Vue.createVNode(naive.NDynamicTags,{value:this.divideOptions,"onUpdate:value":t=>this.divideOptions=t,onUpdateValue:t=>{this.copilotFunc(t,"divideOptions")}},null),footer:()=>this.copilotFunc(this.divideOptions,"divideOptions")}),Vue.createVNode(naive.NCard,{title:"平分一个值"},{default:()=>Vue.createVNode(naive.NSpace,{wrapItem:!1},{default:()=>[Vue.createVNode(naive.NInputNumber,{value:this.distributeValue,"onUpdate:value":t=>this.distributeValue=t,onUpdateValue:()=>{this.updateDistributeValue()}},null),Vue.createVNode(naive.NInputNumber,{value:this.distributeLength,"onUpdate:value":t=>this.distributeLength=t,onUpdateValue:()=>{this.updateDistributeValue()}},null)]}),footer:()=>"结果: "+this.distributeOutputValue.join(", ")})]})]})}});export{v as default};
|