bri-components 1.5.13 → 1.5.15

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.
Files changed (151) hide show
  1. package/README.md +83 -83
  2. package/lib/0.bri-components.min.js +1 -1
  3. package/lib/1.bri-components.min.js +1 -1
  4. package/lib/10.bri-components.min.js +1 -1
  5. package/lib/2.bri-components.min.js +1 -1
  6. package/lib/3.bri-components.min.js +1 -1
  7. package/lib/4.bri-components.min.js +1 -1
  8. package/lib/5.bri-components.min.js +1 -1
  9. package/lib/6.bri-components.min.js +1 -1
  10. package/lib/7.bri-components.min.js +1 -1
  11. package/lib/8.bri-components.min.js +1 -1
  12. package/lib/9.bri-components.min.js +1 -1
  13. package/lib/bri-components.min.js +4 -4
  14. package/lib/styles/bundle.css +12 -12
  15. package/lib/styles/font/fontello.svg +31 -31
  16. package/package.json +125 -125
  17. package/src/components/Error/Error403.vue +42 -42
  18. package/src/components/Error/Error404.vue +40 -40
  19. package/src/components/Error/Error500.vue +51 -51
  20. package/src/components/Error/error.less +162 -162
  21. package/src/components/Error/errorBack.vue +40 -40
  22. package/src/components/controls/DshControlInput.vue +195 -195
  23. package/src/components/controls/base/BriUpload/BriUpload.vue +434 -434
  24. package/src/components/controls/base/BriUpload/BriUploadImage.vue +377 -377
  25. package/src/components/controls/base/BriUpload/uploadList.vue +727 -731
  26. package/src/components/controls/base/BriUpload/uploadMixin.js +446 -446
  27. package/src/components/controls/base/DshCascader/DshCascader.vue +215 -215
  28. package/src/components/controls/base/DshCascader/components/cascaderModal.vue +366 -366
  29. package/src/components/controls/base/DshCascader/components/cascaderPicker.vue +416 -416
  30. package/src/components/controls/base/DshCascader/components/cascaderSimple.vue +141 -141
  31. package/src/components/controls/base/DshCascader/components/cascaderTree.vue +151 -151
  32. package/src/components/controls/base/DshCoordinates.vue +577 -577
  33. package/src/components/controls/base/DshDate/DshDate.vue +191 -191
  34. package/src/components/controls/base/DshDate/DshDaterange.vue +186 -186
  35. package/src/components/controls/base/DshDivider.vue +201 -201
  36. package/src/components/controls/base/DshEditor.vue +274 -274
  37. package/src/components/controls/base/DshInput/BriInputs.vue +166 -166
  38. package/src/components/controls/base/DshInput/DshInput.vue +260 -260
  39. package/src/components/controls/base/DshNumber/BriInputNumber/BriInputNumber.vue +435 -435
  40. package/src/components/controls/base/DshNumber/BriInputNumber/mixins/emitter.js +34 -34
  41. package/src/components/controls/base/DshNumber/BriInputNumber/mixins/form.js +14 -14
  42. package/src/components/controls/base/DshNumber/BriInputNumber/utils/assist.js +322 -322
  43. package/src/components/controls/base/DshNumber/DshNumber.vue +143 -143
  44. package/src/components/controls/base/DshNumber/DshNumberange.vue +109 -109
  45. package/src/components/controls/base/DshSelect/DshCheckbox.vue +168 -168
  46. package/src/components/controls/base/DshSelect/DshSelect.vue +180 -180
  47. package/src/components/controls/base/DshSwitch/DshSwitch.vue +115 -115
  48. package/src/components/controls/control.less +324 -324
  49. package/src/components/controls/controlMap.js +114 -114
  50. package/src/components/controls/extra/DshColor.vue +81 -81
  51. package/src/components/controls/extra/DshThemeColor.vue +100 -100
  52. package/src/components/controls/extra/DshThemeIcon.vue +122 -122
  53. package/src/components/controls/mixins/cascaderMixin.js +325 -327
  54. package/src/components/controls/mixins/cascaderPickerMixin.js +227 -227
  55. package/src/components/controls/mixins/cascaderTableMixin.js +130 -130
  56. package/src/components/controls/mixins/controlMixin.js +393 -393
  57. package/src/components/controls/mixins/dateMixin.js +149 -149
  58. package/src/components/controls/mixins/flatTableMixin.js +111 -111
  59. package/src/components/controls/mixins/numberMixin.js +112 -112
  60. package/src/components/controls/mixins/selectMixin.js +233 -233
  61. package/src/components/controls/mixins/switchMixin.js +87 -87
  62. package/src/components/controls/mixins/userAndDepartMixin.js +260 -260
  63. package/src/components/controls/senior/DshLabels.vue +333 -333
  64. package/src/components/controls/senior/DshPackage.vue +57 -57
  65. package/src/components/controls/senior/cascaderTable.vue +213 -213
  66. package/src/components/controls/senior/flatTable.vue +138 -138
  67. package/src/components/controls/senior/selectDepartments.vue +399 -399
  68. package/src/components/controls/senior/selectUsers/departMenu.vue +293 -293
  69. package/src/components/controls/senior/selectUsers/selectUsers.vue +712 -712
  70. package/src/components/controls/special/DshBack.vue +42 -42
  71. package/src/components/controls/special/DshUndeveloped.vue +41 -41
  72. package/src/components/form/DshAdvSearch.vue +510 -510
  73. package/src/components/form/DshDefaultSearch.vue +260 -260
  74. package/src/components/form/DshForm.vue +494 -494
  75. package/src/components/form/searchMixin.js +376 -376
  76. package/src/components/list/BriCard.vue +95 -95
  77. package/src/components/list/BriTable.vue +205 -205
  78. package/src/components/list/BriTree.vue +529 -529
  79. package/src/components/list/BriTreeItem.vue +163 -163
  80. package/src/components/list/DshBox/DshBox.vue +219 -219
  81. package/src/components/list/DshBox/DshCard.vue +446 -446
  82. package/src/components/list/DshBox/DshCrossTable.vue +827 -827
  83. package/src/components/list/DshBox/DshList.vue +404 -404
  84. package/src/components/list/DshBox/DshPanel.vue +669 -669
  85. package/src/components/list/DshBox/DshSingleData.vue +119 -119
  86. package/src/components/list/DshBox/DshTable.vue +239 -239
  87. package/src/components/list/DshCascaderTable.vue +115 -115
  88. package/src/components/list/DshFlatTable.vue +337 -337
  89. package/src/components/list/DshPage.vue +194 -194
  90. package/src/components/list/DshTreeTable.vue +113 -113
  91. package/src/components/list/common/importModal.vue +243 -243
  92. package/src/components/list/common/quoteListModal.vue +206 -206
  93. package/src/components/list/mixins/DshCascaderTableMixin.js +278 -278
  94. package/src/components/list/mixins/DshFlatTableMixin.js +509 -509
  95. package/src/components/list/mixins/DshTreeTableMixin.js +286 -286
  96. package/src/components/list/mixins/tableBaseMixin.js +1653 -1653
  97. package/src/components/list/mixins/treeTableBaseMixin.js +145 -145
  98. package/src/components/other/BriAvatar.vue +166 -166
  99. package/src/components/other/BriCode.vue +125 -125
  100. package/src/components/other/BriCollapseTree.vue +207 -207
  101. package/src/components/other/BriGantt.vue +1087 -1087
  102. package/src/components/other/BriIframe.vue +116 -116
  103. package/src/components/other/BriLoading.vue +171 -171
  104. package/src/components/other/BriSvg.vue +27 -27
  105. package/src/components/other/DshColorPanel.vue +128 -128
  106. package/src/components/other/DshMenuNav.vue +188 -188
  107. package/src/components/small/BriButton.vue +71 -71
  108. package/src/components/small/BriDrawer.vue +169 -169
  109. package/src/components/small/BriTooltip.vue +87 -87
  110. package/src/components/small/DshBtnModal.vue +68 -68
  111. package/src/components/small/DshButtons.vue +324 -324
  112. package/src/components/small/DshDropdown.vue +225 -225
  113. package/src/components/small/DshIcons.vue +59 -59
  114. package/src/components/small/DshListRender.js +21 -21
  115. package/src/components/small/DshModal.vue +160 -160
  116. package/src/components/small/DshSteps.vue +141 -141
  117. package/src/components/small/DshTabs.vue +598 -598
  118. package/src/components/small/DshTabsSet.vue +309 -309
  119. package/src/components/small/DshTags.vue +251 -251
  120. package/src/components/small/DshTitle.vue +50 -50
  121. package/src/components/small/render.js +20 -20
  122. package/src/components/unit/DshFormUnit.vue +398 -398
  123. package/src/components/unit/DshListUnit.vue +115 -115
  124. package/src/components/unit/unitMixin.js +86 -86
  125. package/src/data/index.js +4 -9
  126. package/src/index.js +282 -282
  127. package/src/styles/bundle.css +12 -12
  128. package/src/styles/components/BriButton.less +307 -307
  129. package/src/styles/components/BriTable.less +344 -344
  130. package/src/styles/components/DshModal.less +257 -257
  131. package/src/styles/components/index.less +3 -3
  132. package/src/styles/global/animate.less +11 -11
  133. package/src/styles/global/base.less +45 -45
  134. package/src/styles/global/box.less +186 -186
  135. package/src/styles/global/control.less +122 -122
  136. package/src/styles/global/flex.less +282 -282
  137. package/src/styles/global/global.less +8 -8
  138. package/src/styles/global/text.less +59 -59
  139. package/src/styles/global/variables.less +85 -85
  140. package/src/styles/iconfont/iconfont.css +254 -254
  141. package/src/styles/iconfont/iconfont.json +422 -422
  142. package/src/styles/iconfont/iconfont.svg +137 -137
  143. package/src/styles/index.less +26 -26
  144. package/src/styles/reset-easytable.less +21 -21
  145. package/src/styles/reset-iview-controls.less +145 -145
  146. package/src/styles/reset-iview-other.less +49 -49
  147. package/src/styles/reset-iview-variables.less +43 -43
  148. package/src/styles/reset.less +45 -45
  149. package/src/utils/index.js +5 -5
  150. package/src/utils/table.js +175 -175
  151. package/lib/11.bri-components.min.js +0 -1
@@ -1,435 +1,435 @@
1
- <template>
2
- <div :class="wrapClasses">
3
- <!-- <div :class="suffixClasses">
4
- <slot name="suffix"></slot>
5
- </div> -->
6
-
7
- <div
8
- :class="inputWrapClasses"
9
- style="display:flex"
10
- >
11
- <input
12
- style="flex: 1; min-width: 0px;"
13
- :id="elementId"
14
- :class="inputClasses"
15
- :disabled="itemDisabled"
16
- autocomplete="off"
17
- spellcheck="false"
18
- :autofocus="autofocus"
19
- @focus="focus"
20
- @blur="blur"
21
- @keydown.stop="keyDown"
22
- @input="change"
23
- @mouseup="preventDefault"
24
- @change="change"
25
- :readonly="readonly || !editable"
26
- :name="name"
27
- :value="formatterValue"
28
- :placeholder="placeholder"
29
- >
30
-
31
- <slot name="suffix">
32
- <div
33
- :class="handlerClasses"
34
- :style="handlerStyle"
35
- >
36
- <a
37
- @click="up"
38
- :class="upClasses"
39
- >
40
- <span
41
- :class="innerUpClasses"
42
- @click="preventDefault"
43
- ></span>
44
- </a>
45
- <a
46
- @click="down"
47
- :class="downClasses"
48
- >
49
- <span
50
- :class="innerDownClasses"
51
- @click="preventDefault"
52
- ></span>
53
- </a>
54
- </div>
55
- </slot>
56
- </div>
57
- </div>
58
- </template>
59
-
60
- <script>
61
- import { findComponentUpward } from "./utils/assist";
62
- import Emitter from "./mixins/emitter";
63
- import mixinsForm from "./mixins/form";
64
-
65
- const prefixCls = "ivu-input-number";
66
- const iconPrefixCls = "ivu-icon";
67
-
68
- function addNum (num1, num2) {
69
- let sq1, sq2, m;
70
- try {
71
- sq1 = num1.toString().split(".")[1].length;
72
- }
73
- catch (e) {
74
- sq1 = 0;
75
- }
76
- try {
77
- sq2 = num2.toString().split(".")[1].length;
78
- }
79
- catch (e) {
80
- sq2 = 0;
81
- }
82
- // if (sq1 === 0 || sq2 === 0) {
83
- // return num1 + num2;
84
- // } else {
85
- // m = Math.pow(10, Math.max(sq1, sq2));
86
- // return (num1 * m + num2 * m) / m;
87
- // }
88
- m = Math.pow(10, Math.max(sq1, sq2));
89
- return (Math.round(num1 * m) + Math.round(num2 * m)) / m;
90
- }
91
-
92
- /* function _debounce (fn, delayTime) {
93
- let delay = delayTime || 1000;
94
- let timer;
95
- return function () {
96
- let that = this;
97
- let args = arguments;
98
- if (timer) {
99
- clearTimeout(timer);
100
- }
101
- timer = setTimeout(() => {
102
- timer = null;
103
- fn.apply(that, args);
104
- }, delay);
105
- };
106
- } */
107
-
108
- export default {
109
- name: "BriInputNumber",
110
- mixins: [ Emitter, mixinsForm ],
111
- props: {
112
- max: {
113
- type: Number,
114
- default: Infinity
115
- },
116
- min: {
117
- type: Number,
118
- default: -Infinity
119
- },
120
- step: {
121
- type: Number,
122
- default: 1
123
- },
124
- activeChange: {
125
- type: Boolean,
126
- default: true
127
- },
128
- value: {
129
- type: [Number, String],
130
- default: null
131
- },
132
- size: {
133
- default () {
134
- return !this.$IVIEW || this.$IVIEW.size === "" ? "default" : this.$IVIEW.size;
135
- },
136
- validator (val) {
137
- return ["small", "large", "default"].includes(val);
138
- }
139
- },
140
- disabled: {
141
- type: Boolean,
142
- default: false
143
- },
144
- autofocus: {
145
- type: Boolean,
146
- default: false
147
- },
148
- readonly: {
149
- type: Boolean,
150
- default: false
151
- },
152
- editable: {
153
- type: Boolean,
154
- default: true
155
- },
156
- name: {
157
- type: String
158
- },
159
- precision: {
160
- type: Number
161
- },
162
- elementId: {
163
- type: String
164
- },
165
- formatter: {
166
- type: Function
167
- },
168
- parser: {
169
- type: Function
170
- },
171
- placeholder: {
172
- type: String,
173
- default: ""
174
- },
175
- handlerStyle: {
176
- type: Object,
177
- default () {
178
- return {};
179
- }
180
- },
181
- isPositive: {
182
- type: Boolean,
183
- default: false
184
- }
185
- },
186
- data () {
187
- return {
188
- focused: false,
189
- upDisabled: false,
190
- downDisabled: false,
191
- currentValue: this.value,
192
- transferValue: null
193
- };
194
- },
195
- computed: {
196
- wrapClasses () {
197
- return [
198
- `${prefixCls}`,
199
- {
200
- [`${prefixCls}-${this.size}`]: !!this.size,
201
- [`${prefixCls}-disabled`]: this.itemDisabled,
202
- [`${prefixCls}-focused`]: this.focused
203
- }
204
- ];
205
- },
206
- suffixClasses () {
207
- return `${prefixCls}-suffix-wrap`;
208
- },
209
- handlerClasses () {
210
- return `${prefixCls}-handler-wrap`;
211
- },
212
- upClasses () {
213
- return [
214
- `${prefixCls}-handler`,
215
- `${prefixCls}-handler-up`,
216
- {
217
- [`${prefixCls}-handler-up-disabled`]: this.upDisabled
218
- }
219
- ];
220
- },
221
- innerUpClasses () {
222
- return `${prefixCls}-handler-up-inner ${iconPrefixCls} ${iconPrefixCls}-ios-arrow-up`;
223
- },
224
- downClasses () {
225
- return [
226
- `${prefixCls}-handler`,
227
- `${prefixCls}-handler-down`,
228
- {
229
- [`${prefixCls}-handler-down-disabled`]: this.downDisabled
230
- }
231
- ];
232
- },
233
- innerDownClasses () {
234
- return `${prefixCls}-handler-down-inner ${iconPrefixCls} ${iconPrefixCls}-ios-arrow-down`;
235
- },
236
- inputWrapClasses () {
237
- return `${prefixCls}-input-wrap`;
238
- },
239
- inputClasses () {
240
- return `${prefixCls}-input`;
241
- },
242
- precisionValue () {
243
- // can not display 1.0
244
- if (!this.currentValue) return this.currentValue;
245
- return this.precision ? this.currentValue.toFixed(this.precision) : this.currentValue;
246
- },
247
- formatterValue () {
248
- if (this.formatter && this.precisionValue !== null) {
249
- let formatterStr = this.formatter(this.precisionValue);
250
- if (this.isPositive) {
251
- return formatterStr.replace("整", "正");
252
- } else {
253
- return formatterStr;
254
- }
255
- } else {
256
- return this.precisionValue;
257
- }
258
- }
259
- },
260
- methods: {
261
- preventDefault (e) {
262
- e.preventDefault();
263
- },
264
- up (e) {
265
- const targetVal = Number(e.target.value);
266
- if (this.upDisabled && isNaN(targetVal)) {
267
- return false;
268
- }
269
- this.changeStep("up", e);
270
- },
271
- down (e) {
272
- const targetVal = Number(e.target.value);
273
- if (this.downDisabled && isNaN(targetVal)) {
274
- return false;
275
- }
276
- this.changeStep("down", e);
277
- },
278
- changeStep (type, e) {
279
- if (this.itemDisabled || this.readonly) {
280
- return false;
281
- }
282
-
283
- const targetVal = Number(e.target.value);
284
- let val = Number(this.currentValue);
285
- const step = Number(this.step);
286
- if (isNaN(val)) {
287
- return false;
288
- }
289
-
290
- // input a number, and key up or down
291
- if (!isNaN(targetVal)) {
292
- if (type === "up") {
293
- if (addNum(targetVal, step) <= this.max) {
294
- val = targetVal;
295
- } else {
296
- return false;
297
- }
298
- } else if (type === "down") {
299
- if (addNum(targetVal, -step) >= this.min) {
300
- val = targetVal;
301
- } else {
302
- return false;
303
- }
304
- }
305
- }
306
-
307
- if (type === "up") {
308
- val = addNum(val, step);
309
- } else if (type === "down") {
310
- val = addNum(val, -step);
311
- }
312
-
313
- this.setValue(val, "step");
314
- },
315
- setValue (val, setType) {
316
- // 如果 step 是小数,且没有设置 precision,是有问题的
317
- if (val && !isNaN(this.precision)) {
318
- val = Number(Number(val).toFixed(this.precision));
319
- }
320
-
321
- // 处理最大值最小值
322
- const {min, max} = this;
323
- if (val !== null) {
324
- if (val > max) {
325
- val = max;
326
- } else if (val < min) {
327
- val = min;
328
- }
329
- }
330
-
331
- // emit事件
332
- this.$nextTick(() => {
333
- this.transferValue = val;
334
- if (setType && setType === "step") {
335
- this.$emit("input", val);
336
- this.$emit("on-change", val);
337
- this.dispatch("FormItem", "on-form-change", val);
338
- }
339
- });
340
- },
341
- focus (event) {
342
- this.focused = true;
343
- this.$emit("on-focus", event);
344
- },
345
- blur () {
346
- this.focused = false;
347
- if (this.transferValue !== this.currentValue) {
348
- this.currentValue = this.transferValue;
349
- this.$emit("input", this.transferValue);
350
- this.$emit("on-change", this.transferValue);
351
- this.dispatch("FormItem", "on-form-change", this.transferValue);
352
- this.focused = false;
353
- this.$emit("on-blur");
354
- if (!findComponentUpward(this, ["DatePicker", "TimePicker", "Cascader", "Search"])) {
355
- this.dispatch("FormItem", "on-form-blur", this.transferValue);
356
- }
357
- }
358
- },
359
- keyDown (e) {
360
- if (e.keyCode === 38) {
361
- e.preventDefault();
362
- this.up(e);
363
- } else if (e.keyCode === 40) {
364
- e.preventDefault();
365
- this.down(e);
366
- }
367
- },
368
- change (event) {
369
- if (event.type == "change" && this.activeChange) {
370
-
371
- } else if (event.type == "input" && !this.activeChange) {
372
-
373
- } else {
374
- let val = event.target.value.trim();
375
- if (this.parser) {
376
- val = this.parser(val);
377
- }
378
-
379
- const isEmptyString = val.length === 0;
380
- if (isEmptyString) {
381
- this.setValue(null);
382
- } else {
383
- if (event.type == "input" && val.match(/^-?\.?$|\.$/)) {
384
- // prevent fire early if decimal. If no more input the change event will fire later
385
- } else {
386
- // eslint认为\为无用的转义符(-不需要转义)
387
- // if (event.type == "input" && val.match(/^\-?\.?$|\.$/)) return; // prevent fire early if decimal. If no more input the change event will fire later
388
- val = Number(val);
389
-
390
- if (!isNaN(val)) {
391
- // this.currentValue = val;
392
- this.setValue(val);
393
- } else {
394
- event.target.value = this.currentValue;
395
- }
396
- }
397
- }
398
- }
399
- },
400
- changeVal (val) {
401
- val = Number(val);
402
- if (!isNaN(val)) {
403
- const step = this.step;
404
-
405
- this.upDisabled = val + step > this.max;
406
- this.downDisabled = val - step < this.min;
407
- } else {
408
- this.upDisabled = true;
409
- this.downDisabled = true;
410
- }
411
- }
412
- },
413
- mounted () {
414
- this.transferValue = this.value;
415
- this.changeVal(this.currentValue);
416
- },
417
- watch: {
418
- value (val) {
419
- if (val) {
420
- this.transferValue = this.value;
421
- }
422
- this.currentValue = val;
423
- },
424
- currentValue (val) {
425
- this.changeVal(val);
426
- },
427
- min () {
428
- this.changeVal(this.currentValue);
429
- },
430
- max () {
431
- this.changeVal(this.currentValue);
432
- }
433
- }
434
- };
435
- </script>
1
+ <template>
2
+ <div :class="wrapClasses">
3
+ <!-- <div :class="suffixClasses">
4
+ <slot name="suffix"></slot>
5
+ </div> -->
6
+
7
+ <div
8
+ :class="inputWrapClasses"
9
+ style="display:flex"
10
+ >
11
+ <input
12
+ style="flex: 1; min-width: 0px;"
13
+ :id="elementId"
14
+ :class="inputClasses"
15
+ :disabled="itemDisabled"
16
+ autocomplete="off"
17
+ spellcheck="false"
18
+ :autofocus="autofocus"
19
+ @focus="focus"
20
+ @blur="blur"
21
+ @keydown.stop="keyDown"
22
+ @input="change"
23
+ @mouseup="preventDefault"
24
+ @change="change"
25
+ :readonly="readonly || !editable"
26
+ :name="name"
27
+ :value="formatterValue"
28
+ :placeholder="placeholder"
29
+ >
30
+
31
+ <slot name="suffix">
32
+ <div
33
+ :class="handlerClasses"
34
+ :style="handlerStyle"
35
+ >
36
+ <a
37
+ @click="up"
38
+ :class="upClasses"
39
+ >
40
+ <span
41
+ :class="innerUpClasses"
42
+ @click="preventDefault"
43
+ ></span>
44
+ </a>
45
+ <a
46
+ @click="down"
47
+ :class="downClasses"
48
+ >
49
+ <span
50
+ :class="innerDownClasses"
51
+ @click="preventDefault"
52
+ ></span>
53
+ </a>
54
+ </div>
55
+ </slot>
56
+ </div>
57
+ </div>
58
+ </template>
59
+
60
+ <script>
61
+ import { findComponentUpward } from "./utils/assist";
62
+ import Emitter from "./mixins/emitter";
63
+ import mixinsForm from "./mixins/form";
64
+
65
+ const prefixCls = "ivu-input-number";
66
+ const iconPrefixCls = "ivu-icon";
67
+
68
+ function addNum (num1, num2) {
69
+ let sq1, sq2, m;
70
+ try {
71
+ sq1 = num1.toString().split(".")[1].length;
72
+ }
73
+ catch (e) {
74
+ sq1 = 0;
75
+ }
76
+ try {
77
+ sq2 = num2.toString().split(".")[1].length;
78
+ }
79
+ catch (e) {
80
+ sq2 = 0;
81
+ }
82
+ // if (sq1 === 0 || sq2 === 0) {
83
+ // return num1 + num2;
84
+ // } else {
85
+ // m = Math.pow(10, Math.max(sq1, sq2));
86
+ // return (num1 * m + num2 * m) / m;
87
+ // }
88
+ m = Math.pow(10, Math.max(sq1, sq2));
89
+ return (Math.round(num1 * m) + Math.round(num2 * m)) / m;
90
+ }
91
+
92
+ /* function _debounce (fn, delayTime) {
93
+ let delay = delayTime || 1000;
94
+ let timer;
95
+ return function () {
96
+ let that = this;
97
+ let args = arguments;
98
+ if (timer) {
99
+ clearTimeout(timer);
100
+ }
101
+ timer = setTimeout(() => {
102
+ timer = null;
103
+ fn.apply(that, args);
104
+ }, delay);
105
+ };
106
+ } */
107
+
108
+ export default {
109
+ name: "BriInputNumber",
110
+ mixins: [ Emitter, mixinsForm ],
111
+ props: {
112
+ max: {
113
+ type: Number,
114
+ default: Infinity
115
+ },
116
+ min: {
117
+ type: Number,
118
+ default: -Infinity
119
+ },
120
+ step: {
121
+ type: Number,
122
+ default: 1
123
+ },
124
+ activeChange: {
125
+ type: Boolean,
126
+ default: true
127
+ },
128
+ value: {
129
+ type: [Number, String],
130
+ default: null
131
+ },
132
+ size: {
133
+ default () {
134
+ return !this.$IVIEW || this.$IVIEW.size === "" ? "default" : this.$IVIEW.size;
135
+ },
136
+ validator (val) {
137
+ return ["small", "large", "default"].includes(val);
138
+ }
139
+ },
140
+ disabled: {
141
+ type: Boolean,
142
+ default: false
143
+ },
144
+ autofocus: {
145
+ type: Boolean,
146
+ default: false
147
+ },
148
+ readonly: {
149
+ type: Boolean,
150
+ default: false
151
+ },
152
+ editable: {
153
+ type: Boolean,
154
+ default: true
155
+ },
156
+ name: {
157
+ type: String
158
+ },
159
+ precision: {
160
+ type: Number
161
+ },
162
+ elementId: {
163
+ type: String
164
+ },
165
+ formatter: {
166
+ type: Function
167
+ },
168
+ parser: {
169
+ type: Function
170
+ },
171
+ placeholder: {
172
+ type: String,
173
+ default: ""
174
+ },
175
+ handlerStyle: {
176
+ type: Object,
177
+ default () {
178
+ return {};
179
+ }
180
+ },
181
+ isPositive: {
182
+ type: Boolean,
183
+ default: false
184
+ }
185
+ },
186
+ data () {
187
+ return {
188
+ focused: false,
189
+ upDisabled: false,
190
+ downDisabled: false,
191
+ currentValue: this.value,
192
+ transferValue: null
193
+ };
194
+ },
195
+ computed: {
196
+ wrapClasses () {
197
+ return [
198
+ `${prefixCls}`,
199
+ {
200
+ [`${prefixCls}-${this.size}`]: !!this.size,
201
+ [`${prefixCls}-disabled`]: this.itemDisabled,
202
+ [`${prefixCls}-focused`]: this.focused
203
+ }
204
+ ];
205
+ },
206
+ suffixClasses () {
207
+ return `${prefixCls}-suffix-wrap`;
208
+ },
209
+ handlerClasses () {
210
+ return `${prefixCls}-handler-wrap`;
211
+ },
212
+ upClasses () {
213
+ return [
214
+ `${prefixCls}-handler`,
215
+ `${prefixCls}-handler-up`,
216
+ {
217
+ [`${prefixCls}-handler-up-disabled`]: this.upDisabled
218
+ }
219
+ ];
220
+ },
221
+ innerUpClasses () {
222
+ return `${prefixCls}-handler-up-inner ${iconPrefixCls} ${iconPrefixCls}-ios-arrow-up`;
223
+ },
224
+ downClasses () {
225
+ return [
226
+ `${prefixCls}-handler`,
227
+ `${prefixCls}-handler-down`,
228
+ {
229
+ [`${prefixCls}-handler-down-disabled`]: this.downDisabled
230
+ }
231
+ ];
232
+ },
233
+ innerDownClasses () {
234
+ return `${prefixCls}-handler-down-inner ${iconPrefixCls} ${iconPrefixCls}-ios-arrow-down`;
235
+ },
236
+ inputWrapClasses () {
237
+ return `${prefixCls}-input-wrap`;
238
+ },
239
+ inputClasses () {
240
+ return `${prefixCls}-input`;
241
+ },
242
+ precisionValue () {
243
+ // can not display 1.0
244
+ if (!this.currentValue) return this.currentValue;
245
+ return this.precision ? this.currentValue.toFixed(this.precision) : this.currentValue;
246
+ },
247
+ formatterValue () {
248
+ if (this.formatter && this.precisionValue !== null) {
249
+ let formatterStr = this.formatter(this.precisionValue);
250
+ if (this.isPositive) {
251
+ return formatterStr.replace("整", "正");
252
+ } else {
253
+ return formatterStr;
254
+ }
255
+ } else {
256
+ return this.precisionValue;
257
+ }
258
+ }
259
+ },
260
+ methods: {
261
+ preventDefault (e) {
262
+ e.preventDefault();
263
+ },
264
+ up (e) {
265
+ const targetVal = Number(e.target.value);
266
+ if (this.upDisabled && isNaN(targetVal)) {
267
+ return false;
268
+ }
269
+ this.changeStep("up", e);
270
+ },
271
+ down (e) {
272
+ const targetVal = Number(e.target.value);
273
+ if (this.downDisabled && isNaN(targetVal)) {
274
+ return false;
275
+ }
276
+ this.changeStep("down", e);
277
+ },
278
+ changeStep (type, e) {
279
+ if (this.itemDisabled || this.readonly) {
280
+ return false;
281
+ }
282
+
283
+ const targetVal = Number(e.target.value);
284
+ let val = Number(this.currentValue);
285
+ const step = Number(this.step);
286
+ if (isNaN(val)) {
287
+ return false;
288
+ }
289
+
290
+ // input a number, and key up or down
291
+ if (!isNaN(targetVal)) {
292
+ if (type === "up") {
293
+ if (addNum(targetVal, step) <= this.max) {
294
+ val = targetVal;
295
+ } else {
296
+ return false;
297
+ }
298
+ } else if (type === "down") {
299
+ if (addNum(targetVal, -step) >= this.min) {
300
+ val = targetVal;
301
+ } else {
302
+ return false;
303
+ }
304
+ }
305
+ }
306
+
307
+ if (type === "up") {
308
+ val = addNum(val, step);
309
+ } else if (type === "down") {
310
+ val = addNum(val, -step);
311
+ }
312
+
313
+ this.setValue(val, "step");
314
+ },
315
+ setValue (val, setType) {
316
+ // 如果 step 是小数,且没有设置 precision,是有问题的
317
+ if (val && !isNaN(this.precision)) {
318
+ val = Number(Number(val).toFixed(this.precision));
319
+ }
320
+
321
+ // 处理最大值最小值
322
+ const {min, max} = this;
323
+ if (val !== null) {
324
+ if (val > max) {
325
+ val = max;
326
+ } else if (val < min) {
327
+ val = min;
328
+ }
329
+ }
330
+
331
+ // emit事件
332
+ this.$nextTick(() => {
333
+ this.transferValue = val;
334
+ if (setType && setType === "step") {
335
+ this.$emit("input", val);
336
+ this.$emit("on-change", val);
337
+ this.dispatch("FormItem", "on-form-change", val);
338
+ }
339
+ });
340
+ },
341
+ focus (event) {
342
+ this.focused = true;
343
+ this.$emit("on-focus", event);
344
+ },
345
+ blur () {
346
+ this.focused = false;
347
+ if (this.transferValue !== this.currentValue) {
348
+ this.currentValue = this.transferValue;
349
+ this.$emit("input", this.transferValue);
350
+ this.$emit("on-change", this.transferValue);
351
+ this.dispatch("FormItem", "on-form-change", this.transferValue);
352
+ this.focused = false;
353
+ this.$emit("on-blur");
354
+ if (!findComponentUpward(this, ["DatePicker", "TimePicker", "Cascader", "Search"])) {
355
+ this.dispatch("FormItem", "on-form-blur", this.transferValue);
356
+ }
357
+ }
358
+ },
359
+ keyDown (e) {
360
+ if (e.keyCode === 38) {
361
+ e.preventDefault();
362
+ this.up(e);
363
+ } else if (e.keyCode === 40) {
364
+ e.preventDefault();
365
+ this.down(e);
366
+ }
367
+ },
368
+ change (event) {
369
+ if (event.type == "change" && this.activeChange) {
370
+
371
+ } else if (event.type == "input" && !this.activeChange) {
372
+
373
+ } else {
374
+ let val = event.target.value.trim();
375
+ if (this.parser) {
376
+ val = this.parser(val);
377
+ }
378
+
379
+ const isEmptyString = val.length === 0;
380
+ if (isEmptyString) {
381
+ this.setValue(null);
382
+ } else {
383
+ if (event.type == "input" && val.match(/^-?\.?$|\.$/)) {
384
+ // prevent fire early if decimal. If no more input the change event will fire later
385
+ } else {
386
+ // eslint认为\为无用的转义符(-不需要转义)
387
+ // if (event.type == "input" && val.match(/^\-?\.?$|\.$/)) return; // prevent fire early if decimal. If no more input the change event will fire later
388
+ val = Number(val);
389
+
390
+ if (!isNaN(val)) {
391
+ // this.currentValue = val;
392
+ this.setValue(val);
393
+ } else {
394
+ event.target.value = this.currentValue;
395
+ }
396
+ }
397
+ }
398
+ }
399
+ },
400
+ changeVal (val) {
401
+ val = Number(val);
402
+ if (!isNaN(val)) {
403
+ const step = this.step;
404
+
405
+ this.upDisabled = val + step > this.max;
406
+ this.downDisabled = val - step < this.min;
407
+ } else {
408
+ this.upDisabled = true;
409
+ this.downDisabled = true;
410
+ }
411
+ }
412
+ },
413
+ mounted () {
414
+ this.transferValue = this.value;
415
+ this.changeVal(this.currentValue);
416
+ },
417
+ watch: {
418
+ value (val) {
419
+ if (val) {
420
+ this.transferValue = this.value;
421
+ }
422
+ this.currentValue = val;
423
+ },
424
+ currentValue (val) {
425
+ this.changeVal(val);
426
+ },
427
+ min () {
428
+ this.changeVal(this.currentValue);
429
+ },
430
+ max () {
431
+ this.changeVal(this.currentValue);
432
+ }
433
+ }
434
+ };
435
+ </script>