sadais-piui 1.2.7-beta94 → 1.2.7-beta95

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.
@@ -36,11 +36,11 @@
36
36
  </template>
37
37
 
38
38
  <script>
39
- import ValueSync from '../../mixin/value-sync'
40
- import { getConfig } from '../../config'
41
- const { stepper } = getConfig()
39
+ import ValueSync from "../../mixin/value-sync";
40
+ import { getConfig } from "../../config";
41
+ const { stepper } = getConfig();
42
42
 
43
- const TAG = 'PiStepper'
43
+ const TAG = "PiStepper";
44
44
 
45
45
  export default {
46
46
  name: TAG,
@@ -49,87 +49,87 @@ export default {
49
49
  props: {
50
50
  // 初始值
51
51
  value: {
52
- required: false
52
+ required: false,
53
53
  },
54
54
  // 自定义样式,对象形式
55
55
  customStyle: {
56
56
  type: Object,
57
57
  // {}
58
58
  default() {
59
- return stepper.customStyle
60
- }
59
+ return stepper.customStyle;
60
+ },
61
61
  },
62
62
  // 自定义输入样式,对象形式(默认值:{})
63
63
  inputStyle: {
64
64
  type: Object,
65
65
  // {}
66
66
  default() {
67
- return stepper.inputStyle
68
- }
67
+ return stepper.inputStyle;
68
+ },
69
69
  },
70
70
  // 自定义样式类,字符串形式
71
71
  customClass: {
72
72
  type: String,
73
73
  // ''
74
74
  default() {
75
- return stepper.customClass
76
- }
75
+ return stepper.customClass;
76
+ },
77
77
  },
78
78
  // 最小值
79
79
  min: {
80
80
  type: Number,
81
81
  // 1
82
82
  default() {
83
- return stepper.min
84
- }
83
+ return stepper.min;
84
+ },
85
85
  },
86
86
  // 最大值
87
87
  max: {
88
88
  type: Number,
89
89
  // -
90
90
  default() {
91
- return stepper.max
92
- }
91
+ return stepper.max;
92
+ },
93
93
  },
94
94
  // 步长,每次点击时改变的值
95
95
  step: {
96
96
  type: Number,
97
97
  // 1
98
98
  default() {
99
- return stepper.step
100
- }
99
+ return stepper.step;
100
+ },
101
101
  },
102
102
  // 输入框宽度,默认单位为rpx
103
103
  inputWidth: {
104
104
  type: [String, Number],
105
105
  // 64
106
106
  default() {
107
- return stepper.inputWidth
108
- }
107
+ return stepper.inputWidth;
108
+ },
109
109
  },
110
110
  // 按钮大小
111
111
  buttonSize: {
112
112
  type: [String, Number],
113
113
  // 32
114
114
  default() {
115
- return stepper.buttonSize
116
- }
115
+ return stepper.buttonSize;
116
+ },
117
117
  },
118
118
  // 按钮颜色
119
119
  buttonColor: {
120
120
  type: [String, Number],
121
121
  // -
122
122
  default() {
123
- return stepper.buttonColor
124
- }
123
+ return stepper.buttonColor;
124
+ },
125
125
  },
126
126
  // 小数位
127
127
  decimal: {
128
128
  type: Number,
129
129
  // 0
130
130
  default() {
131
- return stepper.decimal
132
- }
131
+ return stepper.decimal;
132
+ },
133
133
  },
134
134
  // 形状
135
135
  shape: {
@@ -137,9 +137,9 @@ export default {
137
137
  type: String,
138
138
  // round
139
139
  default: stepper.shape,
140
- validator: function(value) {
141
- return ['square', 'round'].includes(value)
142
- }
140
+ validator: function (value) {
141
+ return ["square", "round"].includes(value);
142
+ },
143
143
  },
144
144
  // 主题模式
145
145
  theme: {
@@ -147,199 +147,203 @@ export default {
147
147
  type: String,
148
148
  // 'line'
149
149
  default: stepper.theme,
150
- validator: function(value) {
151
- return ['line', 'fill'].includes(value)
152
- }
150
+ validator: function (value) {
151
+ return ["line", "fill"].includes(value);
152
+ },
153
153
  },
154
154
  // 是否只允许输入整数
155
155
  integer: {
156
156
  type: Boolean,
157
157
  // false
158
158
  default() {
159
- return stepper.integer
160
- }
159
+ return stepper.integer;
160
+ },
161
161
  },
162
162
  // 是否显示增加按钮
163
163
  showAdd: {
164
164
  type: Boolean,
165
165
  // true
166
166
  default() {
167
- return stepper.showAdd
168
- }
167
+ return stepper.showAdd;
168
+ },
169
169
  },
170
170
  // 是否显示减少按钮
171
171
  showSubtract: {
172
172
  type: Boolean,
173
173
  // false
174
174
  default() {
175
- return stepper.showSubtract
176
- }
175
+ return stepper.showSubtract;
176
+ },
177
177
  },
178
178
  // 是否禁用步进器
179
179
  disabled: {
180
180
  type: Boolean,
181
181
  // false
182
182
  default() {
183
- return stepper.disabled
184
- }
183
+ return stepper.disabled;
184
+ },
185
185
  },
186
186
  // 是否禁用输入框
187
187
  disableInput: {
188
188
  type: Boolean,
189
189
  // true
190
190
  default() {
191
- return stepper.disableInput
192
- }
193
- }
191
+ return stepper.disableInput;
192
+ },
193
+ },
194
194
  },
195
195
  data() {
196
- return {}
196
+ return {};
197
197
  },
198
198
  computed: {
199
199
  disableAdd() {
200
- return this.max !== null && this.val >= this.max
200
+ return this.max !== null && this.val >= this.max;
201
201
  },
202
202
  disableSubtract() {
203
- return this.min !== null && this.val <= this.min
203
+ return this.min !== null && this.val <= this.min;
204
204
  },
205
205
  getInputWidth() {
206
- return this.$pi.common.addUnit(this.inputWidth)
206
+ return this.$pi.common.addUnit(this.inputWidth);
207
207
  },
208
208
  getButtonSize() {
209
- return this.$pi.common.addUnit(this.buttonSize)
209
+ return this.$pi.common.addUnit(this.buttonSize);
210
210
  },
211
211
  iconStyle() {
212
212
  const style = {
213
213
  width: this.getButtonSize,
214
214
  height: this.getButtonSize,
215
215
  lineHeight: this.getButtonSize,
216
- fontSize: this.getButtonSize
217
- }
216
+ fontSize: this.getButtonSize,
217
+ };
218
218
  if (this.buttonColor) {
219
- if (this.theme === 'line') {
220
- style.color = this.buttonColor
221
- style.borderColor = this.buttonColor
219
+ if (this.theme === "line") {
220
+ style.color = this.buttonColor;
221
+ style.borderColor = this.buttonColor;
222
222
  } else {
223
- style.backgroundColor = this.buttonColor
223
+ style.backgroundColor = this.buttonColor;
224
224
  }
225
225
  }
226
- return style
227
- }
226
+ return style;
227
+ },
228
228
  },
229
229
  methods: {
230
230
  // 点击减少按钮时触发
231
231
  minus() {
232
- this.computeVal('minus')
232
+ this.computeVal("minus");
233
233
  },
234
234
  // 点击增加按钮时触发
235
235
  plus() {
236
- this.computeVal('plus')
236
+ this.computeVal("plus");
237
237
  },
238
238
  // 为了保证小数相加出现精度溢出的问题
239
239
  numAdd(num1, num2) {
240
- let baseNum, baseNum1, baseNum2
240
+ let baseNum, baseNum1, baseNum2;
241
241
  try {
242
- baseNum1 = num1.toString().split('.')[1].length
242
+ baseNum1 = num1.toString().split(".")[1].length;
243
243
  } catch (e) {
244
- baseNum1 = 0
244
+ baseNum1 = 0;
245
245
  }
246
246
  try {
247
- baseNum2 = num2.toString().split('.')[1].length
247
+ baseNum2 = num2.toString().split(".")[1].length;
248
248
  } catch (e) {
249
- baseNum2 = 0
249
+ baseNum2 = 0;
250
250
  }
251
- baseNum = Math.pow(10, Math.max(baseNum1, baseNum2))
252
- let precision = baseNum1 >= baseNum2 ? baseNum1 : baseNum2 // 精度
253
- return ((num1 * baseNum + num2 * baseNum) / baseNum).toFixed(precision)
251
+ baseNum = Math.pow(10, Math.max(baseNum1, baseNum2));
252
+ let precision = baseNum1 >= baseNum2 ? baseNum1 : baseNum2; // 精度
253
+ return ((num1 * baseNum + num2 * baseNum) / baseNum).toFixed(precision);
254
254
  },
255
255
  // 为了保证小数相减出现精度溢出的问题
256
256
  numSub(num1, num2) {
257
- let baseNum, baseNum1, baseNum2
257
+ let baseNum, baseNum1, baseNum2;
258
258
  try {
259
- baseNum1 = num1.toString().split('.')[1].length
259
+ baseNum1 = num1.toString().split(".")[1].length;
260
260
  } catch (e) {
261
- baseNum1 = 0
261
+ baseNum1 = 0;
262
262
  }
263
263
  try {
264
- baseNum2 = num2.toString().split('.')[1].length
264
+ baseNum2 = num2.toString().split(".")[1].length;
265
265
  } catch (e) {
266
- baseNum2 = 0
266
+ baseNum2 = 0;
267
267
  }
268
- baseNum = Math.pow(10, Math.max(baseNum1, baseNum2))
269
- let precision = baseNum1 >= baseNum2 ? baseNum1 : baseNum2
270
- return ((num1 * baseNum - num2 * baseNum) / baseNum).toFixed(precision)
268
+ baseNum = Math.pow(10, Math.max(baseNum1, baseNum2));
269
+ let precision = baseNum1 >= baseNum2 ? baseNum1 : baseNum2;
270
+ return ((num1 * baseNum - num2 * baseNum) / baseNum).toFixed(precision);
271
271
  },
272
272
  computeVal(type) {
273
- if (this.disabled) return
274
- let value = 0
273
+ if (this.disabled) return;
274
+ let value = 0;
275
275
  // 减
276
- if (type === 'minus') {
276
+ if (type === "minus") {
277
277
  // this.value 当前值 this.step 增加步长后的值
278
- value = this.numSub(this.value, this.step)
279
- } else if (type === 'plus') {
280
- value = this.numAdd(this.value, this.step)
278
+ value = this.numSub(this.value, this.step);
279
+ } else if (type === "plus") {
280
+ value = this.numAdd(this.value, this.step);
281
281
  }
282
282
  // 判断是否小于最小值和大于最大值
283
283
  if (value < this.min || value > this.max) {
284
- return
284
+ return;
285
285
  }
286
286
  // this.inputVal = value
287
287
  },
288
288
  handleChange(range) {
289
- if (this.disabled) return
289
+ if (this.disabled) return;
290
290
  // 增加/减少步长后的值
291
291
  // let val = this.val + range * this.step
292
- let val = range === 1 ? this.numAdd(this.val, this.step) : this.numSub(this.val, this.step)
292
+ let val =
293
+ range === 1
294
+ ? this.numAdd(this.val, this.step)
295
+ : this.numSub(this.val, this.step);
293
296
  if (this.max !== null && val > this.max) {
294
- val = this.max
297
+ val = this.max;
295
298
  }
296
299
  if (this.min !== null && val < this.min) {
297
- val = this.min
300
+ val = this.min;
298
301
  }
299
- this.handleInputChange({ detail: { value: `${val}` } })
302
+ this.handleInputChange({ detail: { value: `${val}` } });
300
303
  },
301
304
  handleInputChange(e) {
302
- let val = e.detail.value
303
- const reg = /^-?\d*\.?\d+$/
304
- const result = val.match(reg)
305
- const decimal = this.decimal
306
- if (!result) {
305
+ let val = e.detail.value;
306
+ const reg = /^-?\d*\.?\d+$/;
307
+ const decimal = this.decimal;
308
+ if (!reg.test(val)) {
307
309
  // 说明开头就不是数字 直接初始化为0
308
- this.val = this.min != null ? this.min : 0
309
- this.handleEmitChange()
310
+ this.val = this.min != null ? this.min : 0;
311
+ this.handleEmitChange();
310
312
  } else {
313
+ const result = val.split(".");
314
+ const dot = ".";
311
315
  // 分离出 小数点、及其左右2边的数字
312
- const left = result[1]
313
- const dot = result[2]
314
- const right = result[3]
315
- let tmpVal = ''
316
+ const left = result?.[0] || "";
317
+ // const dot = result[2]
318
+ const right = result?.[1] || "";
319
+ let tmpVal = "";
316
320
 
317
321
  if (!dot || !right) {
318
- tmpVal = dot ? `${left}${dot}` : left
322
+ tmpVal = dot ? `${left}${dot}` : left;
319
323
  } else if (/^\d+/.test(right)) {
320
324
  // 限制小数点位数
321
- const digit = right.match(/^\d+/)[0]
322
- const len = Math.min(digit.length, decimal)
323
- tmpVal = `${left}${dot}${digit.substr(0, len)}`
325
+ const digit = right.match(/^\d+/)[0];
326
+ const len = Math.min(digit.length, decimal);
327
+ tmpVal = `${left}${dot}${digit.substr(0, len)}`;
324
328
  } else {
325
329
  // 若小数点右边不是以数字开头
326
- tmpVal = `${left}${dot}`
330
+ tmpVal = `${left}${dot}`;
327
331
  }
328
- this.val = 0
332
+ this.val = 0;
329
333
  this.$nextTick(() => {
330
- let tmp = parseFloat(tmpVal)
334
+ let tmp = parseFloat(tmpVal);
331
335
  if (this.integer) {
332
- tmp = parseInt(tmpVal)
336
+ tmp = parseInt(tmpVal);
333
337
  }
334
- tmp = tmp <= this.max ? tmp : this.max
335
- tmp = tmp >= this.min ? tmp : this.min
336
- this.val = tmp
337
- this.handleEmitChange()
338
- })
338
+ tmp = tmp <= this.max ? tmp : this.max;
339
+ tmp = tmp >= this.min ? tmp : this.min;
340
+ this.val = tmp;
341
+ this.handleEmitChange();
342
+ });
339
343
  }
340
- }
341
- }
342
- }
344
+ },
345
+ },
346
+ };
343
347
  </script>
344
348
 
345
349
  <style lang="scss" scoped>
@@ -357,7 +361,7 @@ export default {
357
361
  transform: scale(0.8);
358
362
  }
359
363
  &::after {
360
- content: '';
364
+ content: "";
361
365
  }
362
366
  &.disabled {
363
367
  opacity: $pi-disabled-opacity;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sadais-piui",
3
- "version": "1.2.7-beta94",
3
+ "version": "1.2.7-beta95",
4
4
  "description": "piui组件库",
5
5
  "main": "index.js",
6
6
  "scripts": {