n20-common-lib 2.1.22 → 2.1.23
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/package.json +1 -1
- package/src/components/ApprovalButtons/index.vue +1 -7
- package/src/components/InputNumber/index.vue +64 -72
- package/src/components/Statis/statisItem.vue +2 -2
- package/src/components/Table/filters.js +2 -2
- package/src/index.js +10 -6
- package/src/utils/element-ui-emitter.js +19 -0
- package/src/utils/numberPor.js +238 -132
package/package.json
CHANGED
|
@@ -52,13 +52,7 @@
|
|
|
52
52
|
/>
|
|
53
53
|
</el-form-item>
|
|
54
54
|
<template v-if="taskId && showBtn">
|
|
55
|
-
<show-app-opi
|
|
56
|
-
v-if="authList.includes('showAppOpi')"
|
|
57
|
-
class="flex-1 m-l-s"
|
|
58
|
-
:task-id="taskId"
|
|
59
|
-
:message.sync="messageC"
|
|
60
|
-
style="width: 20%"
|
|
61
|
-
/>
|
|
55
|
+
<show-app-opi class="flex-1 m-l-s" :task-id="taskId" :message.sync="messageC" style="width: 20%" />
|
|
62
56
|
<show-other-att
|
|
63
57
|
v-if="authList.includes('showOtherAtt')"
|
|
64
58
|
class="flex-1 m-l"
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<div class="n20-num-w" @mouseenter="isHove = true" @mouseleave="isHove = false">
|
|
3
3
|
<el-input
|
|
4
|
+
ref="input"
|
|
4
5
|
v-model="valueStr"
|
|
5
6
|
class="n20-stc"
|
|
6
7
|
:disabled="disabled"
|
|
7
8
|
:placeholder="phd"
|
|
8
9
|
:clearable="isClearable"
|
|
10
|
+
:validate-event="false"
|
|
9
11
|
@clear="closeFn"
|
|
10
12
|
@focus="focusFn"
|
|
11
13
|
@input="inputFn"
|
|
@@ -24,9 +26,12 @@
|
|
|
24
26
|
|
|
25
27
|
<script>
|
|
26
28
|
import { $lc } from '../../utils/i18n/index'
|
|
27
|
-
import
|
|
29
|
+
import emitter from '../../utils/element-ui-emitter'
|
|
30
|
+
import N from '../../utils/numberPor'
|
|
31
|
+
|
|
28
32
|
export default {
|
|
29
33
|
name: 'InputNumber',
|
|
34
|
+
mixins: [emitter],
|
|
30
35
|
props: {
|
|
31
36
|
value: {
|
|
32
37
|
type: [Number, String],
|
|
@@ -41,11 +46,11 @@ export default {
|
|
|
41
46
|
},
|
|
42
47
|
min: {
|
|
43
48
|
type: Number,
|
|
44
|
-
default: -9999999999999
|
|
49
|
+
default: -9999999999999.99
|
|
45
50
|
},
|
|
46
51
|
max: {
|
|
47
52
|
type: Number,
|
|
48
|
-
default: 9999999999999
|
|
53
|
+
default: 9999999999999.99
|
|
49
54
|
},
|
|
50
55
|
step: {
|
|
51
56
|
type: Number,
|
|
@@ -78,6 +83,10 @@ export default {
|
|
|
78
83
|
suffix: {
|
|
79
84
|
type: String,
|
|
80
85
|
default: '%'
|
|
86
|
+
},
|
|
87
|
+
rangeAuto: {
|
|
88
|
+
type: Boolean,
|
|
89
|
+
default: false
|
|
81
90
|
}
|
|
82
91
|
},
|
|
83
92
|
data() {
|
|
@@ -98,36 +107,37 @@ export default {
|
|
|
98
107
|
} else {
|
|
99
108
|
return $lc('请输入金额')
|
|
100
109
|
}
|
|
110
|
+
},
|
|
111
|
+
fNum() {
|
|
112
|
+
if (this.format) {
|
|
113
|
+
let i_f = this.format.indexOf('.')
|
|
114
|
+
return i_f === -1 ? 0 : this.format.length - i_f - 1
|
|
115
|
+
}
|
|
116
|
+
if (this.dNum) {
|
|
117
|
+
return this.dNum
|
|
118
|
+
}
|
|
119
|
+
if (this.type === 'rate') {
|
|
120
|
+
return 4
|
|
121
|
+
}
|
|
122
|
+
if (this.type === 'money') {
|
|
123
|
+
return 2
|
|
124
|
+
}
|
|
125
|
+
return 2
|
|
101
126
|
}
|
|
102
127
|
},
|
|
103
128
|
watch: {
|
|
104
129
|
value: {
|
|
105
130
|
handler(val) {
|
|
106
|
-
if (
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
this
|
|
110
|
-
this.valueStr = this.num2str(val)
|
|
111
|
-
return
|
|
131
|
+
if (this.rangeAuto) {
|
|
132
|
+
this.valueStr = N.addThousands(val)
|
|
133
|
+
} else {
|
|
134
|
+
this.valueStr = N.addThousands(N.subFixed(val, this.fNum))
|
|
112
135
|
}
|
|
113
|
-
this.valueStr = this.num2str(val)
|
|
114
136
|
},
|
|
115
137
|
immediate: true
|
|
116
138
|
}
|
|
117
139
|
},
|
|
118
140
|
methods: {
|
|
119
|
-
num2str(val = '') {
|
|
120
|
-
if (val === '' || val === null || val === undefined) {
|
|
121
|
-
return ''
|
|
122
|
-
}
|
|
123
|
-
switch (this.type) {
|
|
124
|
-
case 'rate':
|
|
125
|
-
return numerify(val, this.format || '0.0000')
|
|
126
|
-
case 'money':
|
|
127
|
-
default:
|
|
128
|
-
return numerify(val, this.format || '0,0.00')
|
|
129
|
-
}
|
|
130
|
-
},
|
|
131
141
|
focusFn() {
|
|
132
142
|
this.isFocus = true
|
|
133
143
|
if (!this.disabled && this.valueStr) {
|
|
@@ -143,7 +153,7 @@ export default {
|
|
|
143
153
|
},
|
|
144
154
|
stepFn(ev) {
|
|
145
155
|
if ((ev.code === 'ArrowUp' || ev.code === 'ArrowDown') && !this.disabled) {
|
|
146
|
-
let val =
|
|
156
|
+
let val = N(this.valueStr)
|
|
147
157
|
if (!isNaN(val)) {
|
|
148
158
|
ev.preventDefault()
|
|
149
159
|
val = ev.code === 'ArrowUp' ? val + this.step : val - this.step
|
|
@@ -152,9 +162,11 @@ export default {
|
|
|
152
162
|
} else if (val > this.max) {
|
|
153
163
|
val = this.max
|
|
154
164
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
165
|
+
if (this.rangeAuto) {
|
|
166
|
+
this.valueStr = N.toString(val)
|
|
167
|
+
} else {
|
|
168
|
+
this.valueStr = N.subFixed(val, this.fNum)
|
|
169
|
+
}
|
|
158
170
|
}
|
|
159
171
|
}
|
|
160
172
|
},
|
|
@@ -172,51 +184,42 @@ export default {
|
|
|
172
184
|
this.changeIng = false
|
|
173
185
|
})
|
|
174
186
|
|
|
175
|
-
|
|
176
|
-
let val = NumberP(valStr)
|
|
177
|
-
|
|
187
|
+
let val = N(valStr)
|
|
178
188
|
if (isNaN(val)) {
|
|
179
189
|
this.valueStr = ''
|
|
180
190
|
this.$emit('input', undefined)
|
|
181
191
|
this.$emit('change', undefined)
|
|
192
|
+
this.dispatch('ElFormItem', 'el.form.change', [undefined])
|
|
182
193
|
return
|
|
183
194
|
}
|
|
184
195
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
} else
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
196
|
+
let nStr
|
|
197
|
+
if (this.rangeAuto) {
|
|
198
|
+
nStr = N.toString(val)
|
|
199
|
+
this.valueStr = N.addThousands(valStr)
|
|
200
|
+
} else {
|
|
201
|
+
if (this.stepStrictly) {
|
|
202
|
+
let N = val / this.step
|
|
203
|
+
if (val % this.step !== 0) {
|
|
204
|
+
val = Math.round(N) * this.step
|
|
205
|
+
}
|
|
193
206
|
}
|
|
207
|
+
if (val < this.min) {
|
|
208
|
+
val = this.min
|
|
209
|
+
} else if (val > this.max) {
|
|
210
|
+
val = this.max
|
|
211
|
+
}
|
|
212
|
+
nStr = N.subFixed(val, this.fNum)
|
|
213
|
+
this.valueStr = N.addThousands(nStr)
|
|
194
214
|
}
|
|
195
|
-
this.valueStr = this.num2str(val)
|
|
196
215
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
this.$emit('change', nVar)
|
|
205
|
-
})
|
|
206
|
-
}
|
|
207
|
-
break
|
|
208
|
-
case 'money':
|
|
209
|
-
default:
|
|
210
|
-
{
|
|
211
|
-
let dNum = this.dNum !== undefined ? this.dNum : 2
|
|
212
|
-
let nVar = Number(val.toFixed(dNum))
|
|
213
|
-
this.$nextTick(() => {
|
|
214
|
-
this.$emit('input', nVar)
|
|
215
|
-
this.$emit('change', nVar)
|
|
216
|
-
})
|
|
217
|
-
}
|
|
218
|
-
break
|
|
219
|
-
}
|
|
216
|
+
this.$nextTick(() => {
|
|
217
|
+
let nVar = Number(nStr)
|
|
218
|
+
this.$emit('input', nVar)
|
|
219
|
+
this.$emit('change', nVar)
|
|
220
|
+
|
|
221
|
+
this.dispatch('ElFormItem', 'el.form.change', [nVar])
|
|
222
|
+
})
|
|
220
223
|
},
|
|
221
224
|
closeFn() {
|
|
222
225
|
this.$emit('input', undefined)
|
|
@@ -224,15 +227,4 @@ export default {
|
|
|
224
227
|
}
|
|
225
228
|
}
|
|
226
229
|
}
|
|
227
|
-
|
|
228
|
-
function NumberP(val) {
|
|
229
|
-
if (typeof val === 'string') {
|
|
230
|
-
val = val.replace(/,/g, '').trim()
|
|
231
|
-
}
|
|
232
|
-
if (val === undefined || val === null || val === '') {
|
|
233
|
-
return NaN
|
|
234
|
-
} else {
|
|
235
|
-
return Number(val)
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
230
|
</script>
|
|
@@ -21,12 +21,12 @@ export default {
|
|
|
21
21
|
numerify({ label, value }, f, w, unit = '') {
|
|
22
22
|
unit = unit ? (unit === true ? $lc('元') : unit) : ''
|
|
23
23
|
if (!w) {
|
|
24
|
-
return numerify(value, f) + unit
|
|
24
|
+
return numerify(value, f, Math.floor) + unit
|
|
25
25
|
} else {
|
|
26
26
|
if (value > n) {
|
|
27
27
|
return numerify(value / n, f) + $lc('万') + unit
|
|
28
28
|
} else {
|
|
29
|
-
return numerify(value, f) + unit
|
|
29
|
+
return numerify(value, f, Math.floor) + unit
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
}
|
|
@@ -14,10 +14,10 @@ function tplFn(row, sc, mck, map = {}) {
|
|
|
14
14
|
let type = kA[1]
|
|
15
15
|
switch (type) {
|
|
16
16
|
case 'money':
|
|
17
|
-
str += numerify(row[key], '0,0.00')
|
|
17
|
+
str += numerify(row[key], '0,0.00', Math.floor)
|
|
18
18
|
break
|
|
19
19
|
case 'rate':
|
|
20
|
-
str += numerify(row[key], '0.000000')
|
|
20
|
+
str += numerify(row[key], '0.000000', Math.floor)
|
|
21
21
|
break
|
|
22
22
|
case 'map':
|
|
23
23
|
str += map[row[key]]
|
package/src/index.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import importG from './utils/importGlobal.js' // 联合加载组件保存位置
|
|
2
1
|
import './utils/storagePro.js' // 扩展Storage
|
|
3
|
-
import './utils/numberPor.js' // 扩展Number
|
|
4
2
|
/** 提供组件给外部使用的入口 */
|
|
5
3
|
import ContentLoading from './components/ContentLoading/index.vue'
|
|
6
4
|
import ContentNull from './components/ContentNull/index.vue'
|
|
@@ -88,7 +86,10 @@ import VHas from './directives/VHas/index.js'
|
|
|
88
86
|
|
|
89
87
|
/** 注入方法 */
|
|
90
88
|
import dayjs from 'dayjs'
|
|
91
|
-
import
|
|
89
|
+
import _numerify from 'numerify'
|
|
90
|
+
function numerify(input, formatType, roundingFunction) {
|
|
91
|
+
return _numerify(input, formatType, roundingFunction || Math.floor)
|
|
92
|
+
}
|
|
92
93
|
import axios from './utils/axios.js'
|
|
93
94
|
import auth from './utils/auth.js'
|
|
94
95
|
import { msgPor, msgboxPor } from './utils/msgboxPor.js'
|
|
@@ -101,6 +102,8 @@ import list2tree from './utils/list2tree'
|
|
|
101
102
|
import { has as isHas } from './directives/VHas/index.js'
|
|
102
103
|
import { hasG as isHasG } from './directives/VHas/index.js'
|
|
103
104
|
import asyncGetRelaNos from './utils/asyncGetRelaNos.js'
|
|
105
|
+
import importG from './utils/importGlobal.js' // 联合加载组件保存位置
|
|
106
|
+
import N from './utils/numberPor.js' // 扩展Number
|
|
104
107
|
|
|
105
108
|
/** 国际化 */
|
|
106
109
|
import i18n, { $l } from './utils/i18n'
|
|
@@ -221,8 +224,8 @@ export {
|
|
|
221
224
|
// 方法
|
|
222
225
|
auth,
|
|
223
226
|
axios,
|
|
224
|
-
|
|
225
|
-
|
|
227
|
+
$l,
|
|
228
|
+
N,
|
|
226
229
|
downloadBlob,
|
|
227
230
|
forEachs,
|
|
228
231
|
list2tree,
|
|
@@ -235,7 +238,8 @@ export {
|
|
|
235
238
|
dayjs,
|
|
236
239
|
numerify,
|
|
237
240
|
asyncGetRelaNos,
|
|
238
|
-
|
|
241
|
+
getJsonc,
|
|
242
|
+
importG,
|
|
239
243
|
// 组件
|
|
240
244
|
ContentLoading,
|
|
241
245
|
ContentNull,
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
methods: {
|
|
3
|
+
dispatch(componentName, eventName, params) {
|
|
4
|
+
var parent = this.$parent || this.$root
|
|
5
|
+
var name = parent.$options.componentName
|
|
6
|
+
|
|
7
|
+
while (parent && (!name || name !== componentName)) {
|
|
8
|
+
parent = parent.$parent
|
|
9
|
+
|
|
10
|
+
if (parent) {
|
|
11
|
+
name = parent.$options.componentName
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
if (parent) {
|
|
15
|
+
parent.$emit.apply(parent, [eventName].concat(params))
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
package/src/utils/numberPor.js
CHANGED
|
@@ -1,168 +1,274 @@
|
|
|
1
1
|
/* eslint-disable no-extend-native */
|
|
2
|
-
|
|
3
|
-
let i = 1
|
|
2
|
+
let i = 1
|
|
4
3
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
// 去括号
|
|
5
|
+
const splitPts = function (obj) {
|
|
6
|
+
let mc = obj.mEl.match(/\([^()]+\)/g)
|
|
7
|
+
if (mc) {
|
|
8
|
+
mc.forEach((m) => {
|
|
9
|
+
let vk = 'El' + i++
|
|
10
|
+
obj.Els[vk] = m.replace(/\(|\)/g, '')
|
|
11
|
+
obj.mEl = obj.mEl.replace(m, vk)
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
return splitPts(obj)
|
|
15
|
+
} else {
|
|
16
|
+
return obj
|
|
12
17
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
18
|
+
}
|
|
19
|
+
// 负数转括号
|
|
20
|
+
const negToPts = function (Els, k) {
|
|
21
|
+
if (/\+-/.test(Els[k])) {
|
|
22
|
+
Els[k] = Els[k].replace(/\+-/, '-')
|
|
16
23
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
24
|
+
|
|
25
|
+
if (/--/.test(Els[k])) {
|
|
26
|
+
Els[k] = Els[k].replace(/--/, '+')
|
|
20
27
|
}
|
|
21
28
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
let mc = obj.mEl.match(/\([^()]+\)/g)
|
|
29
|
+
if (/\*-/.test(Els[k])) {
|
|
30
|
+
let mc = Els[k].match(/\*-[^+|-|*|/]+/g)
|
|
25
31
|
if (mc) {
|
|
26
32
|
mc.forEach((m) => {
|
|
27
33
|
let vk = 'El' + i++
|
|
28
|
-
|
|
29
|
-
|
|
34
|
+
Els[vk] = m.replace('*', '0')
|
|
35
|
+
Els[k] = Els[k].replace(m, '*' + vk)
|
|
30
36
|
})
|
|
37
|
+
}
|
|
38
|
+
}
|
|
31
39
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
40
|
+
if (/\/-/.test(Els[k])) {
|
|
41
|
+
let mc = Els[k].match(/\/-[^+|-|*|/]+/g)
|
|
42
|
+
if (mc) {
|
|
43
|
+
mc.forEach((m) => {
|
|
44
|
+
let vk = 'El' + i++
|
|
45
|
+
Els[vk] = m.replace('/', '0')
|
|
46
|
+
Els[k] = Els[k].replace(m, '/' + vk)
|
|
47
|
+
})
|
|
35
48
|
}
|
|
36
49
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
50
|
+
}
|
|
51
|
+
// 乘除转括号
|
|
52
|
+
const muldivToPts = function (Els, k) {
|
|
53
|
+
if (/\*|\//.test(Els[k]) && /\+|-/.test(Els[k])) {
|
|
54
|
+
let mc = Els[k].match(/[^+|-]*[*|/][^+|-]*/g)
|
|
55
|
+
if (mc) {
|
|
56
|
+
mc.forEach((m) => {
|
|
57
|
+
let vk = 'El' + i++
|
|
58
|
+
Els[vk] = m.replace(/\(|\)/g, '')
|
|
59
|
+
Els[k] = Els[k].replace(m, vk)
|
|
60
|
+
})
|
|
41
61
|
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
// 符号切割运算
|
|
65
|
+
const splitSmb = function (Els) {
|
|
66
|
+
for (let k in Els) {
|
|
67
|
+
Els[k + 'O'] = Els[k]
|
|
68
|
+
Els[k] = Els[k].replace(/\+|-|\*|\//g, (v) => ',' + v + ',')
|
|
69
|
+
Els[k] = Els[k].split(',')
|
|
70
|
+
}
|
|
71
|
+
}
|
|
42
72
|
|
|
43
|
-
|
|
44
|
-
|
|
73
|
+
const compute = function (Els, k, fc) {
|
|
74
|
+
let El = Els[k]
|
|
75
|
+
El.forEach((e, i) => {
|
|
76
|
+
if (/^El/.test(e)) {
|
|
77
|
+
El[i] = compute(Els, e, fc)
|
|
45
78
|
}
|
|
79
|
+
})
|
|
46
80
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
81
|
+
let L = El.length
|
|
82
|
+
let Val = Number(El[0])
|
|
83
|
+
for (let i = 1; i < L; i) {
|
|
84
|
+
if (['+', '-', '*', '/'].includes(El[i])) {
|
|
85
|
+
switch (El[i]) {
|
|
86
|
+
case '+':
|
|
87
|
+
Val = add(Val, Number(El[i + 1]), fc)
|
|
88
|
+
break
|
|
89
|
+
case '-':
|
|
90
|
+
Val = sub(Val, Number(El[i + 1]), fc)
|
|
91
|
+
break
|
|
92
|
+
case '*':
|
|
93
|
+
Val = mul(Val, Number(El[i + 1]), fc)
|
|
94
|
+
break
|
|
95
|
+
case '/':
|
|
96
|
+
Val = div(Val, Number(El[i + 1]), fc)
|
|
97
|
+
break
|
|
55
98
|
}
|
|
99
|
+
i += 2
|
|
56
100
|
}
|
|
101
|
+
}
|
|
102
|
+
return Val
|
|
103
|
+
}
|
|
57
104
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
105
|
+
function nFloor(n, f) {
|
|
106
|
+
return Number(subFixed(n, f))
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export function add(m, n, decimal = 10) {
|
|
110
|
+
if (decimal) {
|
|
111
|
+
return nFloor(nFloor(m, decimal) + nFloor(n, decimal), decimal)
|
|
112
|
+
} else {
|
|
113
|
+
return m + n
|
|
68
114
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
let vk = 'El' + i++
|
|
76
|
-
Els[vk] = m.replace(/\(|\)/g, '')
|
|
77
|
-
Els[k] = Els[k].replace(m, vk)
|
|
78
|
-
})
|
|
79
|
-
}
|
|
80
|
-
}
|
|
115
|
+
}
|
|
116
|
+
export function sub(m, n, decimal = 10) {
|
|
117
|
+
if (decimal) {
|
|
118
|
+
return nFloor(nFloor(m, decimal) - nFloor(n, decimal), decimal)
|
|
119
|
+
} else {
|
|
120
|
+
return m - n
|
|
81
121
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
122
|
+
}
|
|
123
|
+
export function mul(m, n, decimal = 10) {
|
|
124
|
+
if (decimal) {
|
|
125
|
+
return nFloor(nFloor(m, decimal) * nFloor(n, decimal), decimal)
|
|
126
|
+
} else {
|
|
127
|
+
return m * n
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
export function div(m, n, decimal = 10) {
|
|
131
|
+
if (decimal) {
|
|
132
|
+
return nFloor(nFloor(m, decimal) / nFloor(n, decimal), decimal)
|
|
133
|
+
} else {
|
|
134
|
+
return m / n
|
|
89
135
|
}
|
|
136
|
+
}
|
|
90
137
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
138
|
+
/**
|
|
139
|
+
* @param {string} [evalStr='']
|
|
140
|
+
* @param {number} [decimal=10]
|
|
141
|
+
* @param {number} proceDecimal
|
|
142
|
+
* @return {number}
|
|
143
|
+
*/
|
|
144
|
+
export function evaluate(evalStr = '', decimal = 10, proceDecimal) {
|
|
145
|
+
if (decimal) {
|
|
146
|
+
i = 1
|
|
147
|
+
let obj = { mEl: evalStr.replace(/\s/g, ''), Els: {} }
|
|
98
148
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
case '/':
|
|
114
|
-
Val = Val.div(Number(El[i + 1]), fc)
|
|
115
|
-
break
|
|
116
|
-
}
|
|
117
|
-
i += 2
|
|
118
|
-
}
|
|
149
|
+
splitPts(obj)
|
|
150
|
+
|
|
151
|
+
let Els = obj.Els
|
|
152
|
+
Els['Elm'] = obj.mEl
|
|
153
|
+
obj = undefined
|
|
154
|
+
|
|
155
|
+
negToPts(Els, 'Elm')
|
|
156
|
+
for (let k in Els) {
|
|
157
|
+
k !== 'Elm' && negToPts(Els, k)
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
muldivToPts(Els, 'Elm')
|
|
161
|
+
for (let k in Els) {
|
|
162
|
+
k !== 'Elm' && muldivToPts(Els, k)
|
|
119
163
|
}
|
|
120
|
-
|
|
164
|
+
|
|
165
|
+
splitSmb(Els)
|
|
166
|
+
|
|
167
|
+
let RES = compute(Els, 'Elm', proceDecimal || decimal)
|
|
168
|
+
RES = nFloor(RES, decimal)
|
|
169
|
+
return RES
|
|
170
|
+
} else {
|
|
171
|
+
// eslint-disable-next-line no-eval
|
|
172
|
+
eval('window._number_eval_res=' + evalStr)
|
|
173
|
+
let RES = window._number_eval_res
|
|
174
|
+
delete window._number_eval_res
|
|
175
|
+
return RES
|
|
121
176
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* @param {number}
|
|
180
|
+
* @return {string}
|
|
181
|
+
*/
|
|
182
|
+
export const subFixed = function (n, decimal = 6) {
|
|
183
|
+
let res = ''
|
|
184
|
+
if (n === undefined || n === null || n === '') return ''
|
|
185
|
+
let ns = toString(n)
|
|
186
|
+
if (isNaN(ns)) return ''
|
|
126
187
|
|
|
127
|
-
|
|
188
|
+
let nss = ns.split('.')
|
|
189
|
+
let intC = nss[0] || '0'
|
|
190
|
+
let floatC = nss[1] || ''
|
|
191
|
+
if (decimal > 0) {
|
|
192
|
+
let floatCn = ''
|
|
193
|
+
for (let i = 0; i < decimal; i++) {
|
|
194
|
+
let fIs = floatC[i] || '0'
|
|
195
|
+
floatCn = floatCn + fIs
|
|
196
|
+
}
|
|
197
|
+
res = intC + '.' + floatCn
|
|
198
|
+
} else {
|
|
199
|
+
res = intC
|
|
200
|
+
}
|
|
201
|
+
return res
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* @param {number}
|
|
205
|
+
* @return {string}
|
|
206
|
+
*/
|
|
207
|
+
export const addThousands = function (n) {
|
|
208
|
+
let res = ''
|
|
209
|
+
if (n === undefined || n === null || n === '') {
|
|
210
|
+
return res
|
|
211
|
+
}
|
|
128
212
|
|
|
129
|
-
|
|
130
|
-
Els['Elm'] = obj.mEl
|
|
131
|
-
obj = undefined
|
|
213
|
+
let ns = toString(n)
|
|
132
214
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
215
|
+
let intC = ''
|
|
216
|
+
let floatC = ''
|
|
217
|
+
let nss = ns.split('.')
|
|
218
|
+
if (nss.length === 2) {
|
|
219
|
+
intC = nss[0] || '0'
|
|
220
|
+
floatC = nss[1] || ''
|
|
221
|
+
} else {
|
|
222
|
+
intC = ns
|
|
223
|
+
}
|
|
137
224
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
225
|
+
let L = intC.length
|
|
226
|
+
let intT = ''
|
|
227
|
+
for (let i = 1; i <= L; i++) {
|
|
228
|
+
intT = intC[L - i] + intT
|
|
229
|
+
if (i % 3 === 0 && i !== L) {
|
|
230
|
+
intT = ',' + intT
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
if (floatC) {
|
|
234
|
+
res = intT + '.' + floatC
|
|
235
|
+
} else {
|
|
236
|
+
res = intT
|
|
237
|
+
}
|
|
238
|
+
return res
|
|
239
|
+
}
|
|
142
240
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
// eslint-disable-next-line no-eval
|
|
150
|
-
eval('window._number_eval_res=' + evalStr)
|
|
151
|
-
let RES = window._number_eval_res
|
|
152
|
-
delete window._number_eval_res
|
|
153
|
-
return RES
|
|
241
|
+
export const toString = function (n) {
|
|
242
|
+
let ns = n
|
|
243
|
+
if (typeof n === 'number') {
|
|
244
|
+
ns = n.toString()
|
|
245
|
+
if (ns.includes('e+')) {
|
|
246
|
+
ns = n.toLocaleString().replace(/,/g, '')
|
|
154
247
|
}
|
|
248
|
+
} else if (typeof n === 'string') {
|
|
249
|
+
ns = n.replace(/,/g, '').trim()
|
|
155
250
|
}
|
|
251
|
+
return ns
|
|
252
|
+
}
|
|
156
253
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
*/
|
|
167
|
-
Number.eval = evaluate
|
|
254
|
+
function N(val) {
|
|
255
|
+
if (typeof val === 'string') {
|
|
256
|
+
val = val.replace(/,/g, '').trim()
|
|
257
|
+
}
|
|
258
|
+
if (val === undefined || val === null || val === '') {
|
|
259
|
+
return NaN
|
|
260
|
+
} else {
|
|
261
|
+
return Number(val)
|
|
262
|
+
}
|
|
168
263
|
}
|
|
264
|
+
N.add = add
|
|
265
|
+
N.sub = sub
|
|
266
|
+
N.mul = mul
|
|
267
|
+
N.div = div
|
|
268
|
+
N.eval = evaluate
|
|
269
|
+
N.evaluate = evaluate
|
|
270
|
+
N.toString = toString
|
|
271
|
+
N.subFixed = subFixed
|
|
272
|
+
N.addThousands = addThousands
|
|
273
|
+
|
|
274
|
+
export default N
|