dfish-widget 1.0.109 → 1.0.110

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.esm.js CHANGED
@@ -13150,10 +13150,35 @@ var script$1 = {
13150
13150
 
13151
13151
  script$1.__file = "src/widgets/Rate.vue";
13152
13152
 
13153
- var script = {
13153
+ // 获取小数点后面有几位
13154
+ function getDecimalPlacesFinal(num, { trimZeros = false } = {}) {
13155
+ // Step 1: 转换为非科学计数法的字符串
13156
+ let numStr = Number(num).toLocaleString('fullwide', {
13157
+ useGrouping: false,
13158
+ minimumFractionDigits: 0,
13159
+ maximumFractionDigits: 20 // 限制精度防止溢出
13160
+ });
13161
+
13162
+ // Step 2: 处理科学计数法(如 0.0000001 → 1e-7)
13163
+ if (numStr.includes('e')) {
13164
+ const [sig, exp] = numStr.split('e');
13165
+ const exponent = parseInt(exp, 10);
13166
+ numStr = Number(num).toFixed(Math.abs(exponent) + (sig.split('.')?.length || 0));
13167
+ }
13168
+
13169
+ // Step 3: 分割整数和小数部分
13170
+ const [integer, decimal] = numStr.split('.');
13171
+ if (!decimal) return 0;
13172
+
13173
+ // Step 4: 可选去除末尾零
13174
+ const trimmed = trimZeros ? decimal.replace(/0+$/, '') : decimal;
13175
+ return trimmed.length;
13176
+ }
13177
+
13178
+ var script = {
13154
13179
  name: 'w-slider',
13155
13180
  mixins: [script$B],
13156
- props: ['minValue', 'maxValue'],
13181
+ props: ['minValue', 'maxValue', 'step'],
13157
13182
  emits: ['drop'],
13158
13183
  data() {
13159
13184
  return {
@@ -13164,7 +13189,8 @@ var script = {
13164
13189
  x_default() {
13165
13190
  return {
13166
13191
  minValue: 0,
13167
- maxValue: 100
13192
+ maxValue: 100,
13193
+ step: 1,
13168
13194
  }
13169
13195
  },
13170
13196
  onmousedown(e) {
@@ -13172,10 +13198,12 @@ var script = {
13172
13198
  let mv = $$1.number(this.x.modelValue);
13173
13199
  let dn_x = e.clientX;
13174
13200
  this.grabbing = true;
13201
+ const fixed = getDecimalPlacesFinal(this.x.step);
13175
13202
  $$1.moveup((e) => {
13176
13203
  let dist = e.clientX - dn_x;
13177
13204
  let v = mv + (dist / bar.width) * (this.x.maxValue - this.x.minValue);
13178
13205
  v = $$1.numRange(v, this.x.minValue, this.x.maxValue);
13206
+ v = Number(Number(v).toFixed(fixed));
13179
13207
  this.val(v);
13180
13208
  }, (e) => {
13181
13209
  this.grabbing = false;
@@ -13187,7 +13215,9 @@ var script = {
13187
13215
  const bar = $$1.bcr(this.$refs.form);
13188
13216
  let dist = e.clientX - bar.left;
13189
13217
  let v = (dist / (bar.width)) * (this.x.maxValue - this.x.minValue);
13218
+ const fixed = getDecimalPlacesFinal(this.x.step);
13190
13219
  v = $$1.numRange(v, this.x.minValue, this.x.maxValue);
13220
+ v = Number(Number(v).toFixed(fixed));
13191
13221
  this.val(v);
13192
13222
  this.trigger('drop', v);
13193
13223
  }
@@ -13215,7 +13245,7 @@ var script = {
13215
13245
  },
13216
13246
  computed: {
13217
13247
  percent() {
13218
- let v = this.x.modelValue;
13248
+ let v = (this.x.modelValue - this.x.minValue) * 100 / (this.x.maxValue - this.x.minValue);
13219
13249
  if (!v) return 0
13220
13250
  return v
13221
13251
  },