uview-plus 3.1.51 → 3.2.3
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/changelog.md +47 -0
- package/components/u-action-sheet/u-action-sheet.vue +1 -1
- package/components/u-album/u-album.vue +261 -261
- package/components/u-avatar/u-avatar.vue +3 -2
- package/components/u-avatar-group/u-avatar-group.vue +106 -106
- package/components/u-button/u-button.vue +12 -7
- package/components/u-calendar/u-calendar.vue +4 -3
- package/components/u-cell/u-cell.vue +6 -3
- package/components/u-checkbox/props.js +5 -0
- package/components/u-checkbox/u-checkbox.vue +27 -15
- package/components/u-code/u-code.vue +1 -1
- package/components/u-copy/u-copy.vue +70 -0
- package/components/u-dropdown/props.js +8 -14
- package/components/u-dropdown/u-dropdown.vue +202 -77
- package/components/u-dropdown-item/props.js +45 -36
- package/components/u-dropdown-item/u-dropdown-item.vue +121 -148
- package/components/u-form/u-form.vue +1 -1
- package/components/u-form-item/props.js +6 -1
- package/components/u-form-item/u-form-item.vue +1 -1
- package/components/u-gap/u-gap.vue +5 -4
- package/components/u-grid/u-grid.vue +4 -2
- package/components/u-grid-item/u-grid-item.vue +8 -7
- package/components/u-input/u-input.vue +1 -1
- package/components/u-lazy-load/u-lazy-load.vue +251 -0
- package/components/u-picker/u-picker.vue +4 -1
- package/components/u-popup/u-popup.vue +1 -1
- package/components/u-read-more/u-read-more.vue +164 -160
- package/components/u-slider/u-slider.vue +6 -6
- package/components/u-steps-item/u-steps-item.vue +318 -318
- package/components/u-subsection/u-subsection.vue +14 -8
- package/components/u-swiper/u-swiper.vue +6 -8
- package/components/u-tabs/u-tabs.vue +1 -0
- package/components/u-tag/props.js +5 -2
- package/components/u-text/u-text.vue +226 -226
- package/components/u-textarea/u-textarea.vue +275 -275
- package/components/u-transition/u-transition.vue +1 -1
- package/components/u-waterfall/u-waterfall.vue +225 -0
- package/index.js +5 -1
- package/libs/config/props/formItem.js +1 -0
- package/libs/config/props/tag.js +30 -29
- package/libs/css/common.scss +1 -1
- package/libs/css/components.scss +5 -5
- package/libs/function/colorGradient.js +8 -8
- package/libs/function/debounce.js +2 -2
- package/libs/function/digit.js +5 -5
- package/libs/function/index.js +29 -29
- package/libs/function/test.js +28 -28
- package/libs/function/throttle.js +2 -2
- package/libs/mixin/mixin.js +2 -2
- package/package.json +2 -2
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view class="u-waterfall">
|
|
3
|
+
<view id="u-left-column" class="u-column">
|
|
4
|
+
<slot name="left" :leftList="leftList"></slot>
|
|
5
|
+
</view>
|
|
6
|
+
<view id="u-right-column" class="u-column">
|
|
7
|
+
<slot name="right" :rightList="rightList"></slot>
|
|
8
|
+
</view>
|
|
9
|
+
</view>
|
|
10
|
+
</template>
|
|
11
|
+
|
|
12
|
+
<script>
|
|
13
|
+
/**
|
|
14
|
+
* waterfall 瀑布流
|
|
15
|
+
* @description 这是一个瀑布流形式的组件,内容分为左右两列,结合uview的懒加载组件效果更佳。相较于某些只是奇偶数左右分别,或者没有利用vue作用域插槽的做法,uview的瀑布流实现了真正的 组件化,搭配LazyLoad 懒加载和loadMore 加载更多组件,让您开箱即用,眼前一亮。
|
|
16
|
+
* @tutorial https://uview-plus.jiangruyi.com/components/waterfall.html
|
|
17
|
+
* @property {Array} flow-list 用于渲染的数据
|
|
18
|
+
* @property {String Number} add-time 单条数据添加到队列的时间间隔,单位ms,见上方注意事项说明(默认200)
|
|
19
|
+
* @example <u-waterfall :flowList="flowList"></u-waterfall>
|
|
20
|
+
*/
|
|
21
|
+
export default {
|
|
22
|
+
name: "u-waterfall",
|
|
23
|
+
props: {
|
|
24
|
+
// #ifdef VUE2
|
|
25
|
+
value: {
|
|
26
|
+
// 瀑布流数据
|
|
27
|
+
type: Array,
|
|
28
|
+
required: true,
|
|
29
|
+
default: function() {
|
|
30
|
+
return [];
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
// #endif
|
|
34
|
+
// #ifdef VUE3
|
|
35
|
+
modelValue: {
|
|
36
|
+
// 瀑布流数据
|
|
37
|
+
type: Array,
|
|
38
|
+
required: true,
|
|
39
|
+
default: function() {
|
|
40
|
+
return [];
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
// #endif
|
|
44
|
+
// 每次向结构插入数据的时间间隔,间隔越长,越能保证两列高度相近,但是对用户体验越不好
|
|
45
|
+
// 单位ms
|
|
46
|
+
addTime: {
|
|
47
|
+
type: [Number, String],
|
|
48
|
+
default: 200
|
|
49
|
+
},
|
|
50
|
+
// id值,用于清除某一条数据时,根据此idKey名称找到并移除,如数据为{idx: 22, name: 'lisa'}
|
|
51
|
+
// 那么该把idKey设置为idx
|
|
52
|
+
idKey: {
|
|
53
|
+
type: String,
|
|
54
|
+
default: 'id'
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
data() {
|
|
58
|
+
return {
|
|
59
|
+
leftList: [],
|
|
60
|
+
rightList: [],
|
|
61
|
+
tempList: [],
|
|
62
|
+
children: []
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
watch: {
|
|
66
|
+
copyFlowList(nVal, oVal) {
|
|
67
|
+
// 取差值,即这一次数组变化新增的部分
|
|
68
|
+
let startIndex = Array.isArray(oVal) && oVal.length > 0 ? oVal.length : 0;
|
|
69
|
+
// 拼接上原有数据
|
|
70
|
+
this.tempList = this.tempList.concat(this.cloneData(nVal.slice(startIndex)));
|
|
71
|
+
this.splitData();
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
mounted() {
|
|
75
|
+
this.tempList = this.cloneData(this.copyFlowList);
|
|
76
|
+
this.splitData();
|
|
77
|
+
},
|
|
78
|
+
computed: {
|
|
79
|
+
// 破坏flowList变量的引用,否则watch的结果新旧值是一样的
|
|
80
|
+
copyFlowList() {
|
|
81
|
+
// #ifdef VUE2
|
|
82
|
+
return this.cloneData(this.value);
|
|
83
|
+
// #endif
|
|
84
|
+
// #ifdef VUE3
|
|
85
|
+
return this.cloneData(this.modelValue);
|
|
86
|
+
// #endif
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
emits: ['update:modelValue'],
|
|
90
|
+
methods: {
|
|
91
|
+
async splitData() {
|
|
92
|
+
if (!this.tempList.length) return;
|
|
93
|
+
let leftRect = await this.$uGetRect('#u-left-column');
|
|
94
|
+
let rightRect = await this.$uGetRect('#u-right-column');
|
|
95
|
+
// 如果左边小于或等于右边,就添加到左边,否则添加到右边
|
|
96
|
+
let item = this.tempList[0];
|
|
97
|
+
// 解决多次快速上拉后,可能数据会乱的问题,因为经过上面的两个await节点查询阻塞一定时间,加上后面的定时器干扰
|
|
98
|
+
// 数组可能变成[],导致此item值可能为undefined
|
|
99
|
+
if (!item) return;
|
|
100
|
+
if (leftRect.height < rightRect.height) {
|
|
101
|
+
this.leftList.push(item);
|
|
102
|
+
} else if (leftRect.height > rightRect.height) {
|
|
103
|
+
this.rightList.push(item);
|
|
104
|
+
} else {
|
|
105
|
+
// 这里是为了保证第一和第二张添加时,左右都能有内容
|
|
106
|
+
// 因为添加第一张,实际队列的高度可能还是0,这时需要根据队列元素长度判断下一个该放哪边
|
|
107
|
+
if (this.leftList.length <= this.rightList.length) {
|
|
108
|
+
this.leftList.push(item);
|
|
109
|
+
} else {
|
|
110
|
+
this.rightList.push(item);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
// 移除临时列表的第一项
|
|
114
|
+
this.tempList.splice(0, 1);
|
|
115
|
+
// 如果临时数组还有数据,继续循环
|
|
116
|
+
if (this.tempList.length) {
|
|
117
|
+
setTimeout(() => {
|
|
118
|
+
this.splitData();
|
|
119
|
+
}, this.addTime)
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
// 复制而不是引用对象和数组
|
|
123
|
+
cloneData(data) {
|
|
124
|
+
return JSON.parse(JSON.stringify(data));
|
|
125
|
+
},
|
|
126
|
+
// 清空数据列表
|
|
127
|
+
clear() {
|
|
128
|
+
this.leftList = [];
|
|
129
|
+
this.rightList = [];
|
|
130
|
+
// 同时清除父组件列表中的数据
|
|
131
|
+
// #ifdef VUE2
|
|
132
|
+
this.$emit('input', []);
|
|
133
|
+
// #endif
|
|
134
|
+
// #ifdef VUE3
|
|
135
|
+
this.$emit('update:modelValue', []);
|
|
136
|
+
// #endif
|
|
137
|
+
this.tempList = [];
|
|
138
|
+
},
|
|
139
|
+
// 清除某一条指定的数据,根据id实现
|
|
140
|
+
remove(id) {
|
|
141
|
+
// 如果findIndex找不到合适的条件,就会返回-1
|
|
142
|
+
let index = -1;
|
|
143
|
+
index = this.leftList.findIndex(val => val[this.idKey] == id);
|
|
144
|
+
if (index != -1) {
|
|
145
|
+
// 如果index不等于-1,说明已经找到了要找的id,根据index索引删除这一条数据
|
|
146
|
+
this.leftList.splice(index, 1);
|
|
147
|
+
} else {
|
|
148
|
+
// 同理于上方面的方法
|
|
149
|
+
index = this.rightList.findIndex(val => val[this.idKey] == id);
|
|
150
|
+
if (index != -1) this.rightList.splice(index, 1);
|
|
151
|
+
}
|
|
152
|
+
// 同时清除父组件的数据中的对应id的条目
|
|
153
|
+
// #ifdef VUE2
|
|
154
|
+
index = this.value.findIndex(val => val[this.idKey] == id);
|
|
155
|
+
if (index != -1) this.$emit('input', this.value.splice(index, 1));
|
|
156
|
+
// #endif
|
|
157
|
+
// #ifdef VUE3
|
|
158
|
+
index = this.modelvalue.findIndex(val => val[this.idKey] == id);
|
|
159
|
+
if (index != -1) this.$emit('input', this.modelvalue.splice(index, 1));
|
|
160
|
+
// #endif
|
|
161
|
+
},
|
|
162
|
+
// 修改某条数据的某个属性
|
|
163
|
+
modify(id, key, value) {
|
|
164
|
+
// 如果findIndex找不到合适的条件,就会返回-1
|
|
165
|
+
let index = -1;
|
|
166
|
+
index = this.leftList.findIndex(val => val[this.idKey] == id);
|
|
167
|
+
if (index != -1) {
|
|
168
|
+
// 如果index不等于-1,说明已经找到了要找的id,修改对应key的值
|
|
169
|
+
this.leftList[index][key] = value;
|
|
170
|
+
} else {
|
|
171
|
+
// 同理于上方面的方法
|
|
172
|
+
index = this.rightList.findIndex(val => val[this.idKey] == id);
|
|
173
|
+
if (index != -1) this.rightList[index][key] = value;
|
|
174
|
+
}
|
|
175
|
+
// 修改父组件的数据中的对应id的条目
|
|
176
|
+
// #ifdef VUE2
|
|
177
|
+
index = this.value.findIndex(val => val[this.idKey] == id);
|
|
178
|
+
// #endif
|
|
179
|
+
// #ifdef VUE3
|
|
180
|
+
index = this.modelvalue.findIndex(val => val[this.idKey] == id);
|
|
181
|
+
// #endif
|
|
182
|
+
if (index != -1) {
|
|
183
|
+
// 首先复制一份value的数据
|
|
184
|
+
// #ifdef VUE2
|
|
185
|
+
let data = this.cloneData(this.value);
|
|
186
|
+
// #endif
|
|
187
|
+
// #ifdef VUE3
|
|
188
|
+
let data = this.cloneData(this.modelvalue);
|
|
189
|
+
// #endif
|
|
190
|
+
// 修改对应索引的key属性的值为value
|
|
191
|
+
data[index][key] = value;
|
|
192
|
+
// 修改父组件通过v-model绑定的变量的值
|
|
193
|
+
// #ifdef VUE2
|
|
194
|
+
this.$emit('input', data);
|
|
195
|
+
// #endif
|
|
196
|
+
// #ifdef VUE3
|
|
197
|
+
this.$emit('update:modelValue', data);
|
|
198
|
+
// #endif
|
|
199
|
+
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
</script>
|
|
205
|
+
|
|
206
|
+
<style lang="scss" scoped>
|
|
207
|
+
@import "../../libs/css/components.scss";
|
|
208
|
+
|
|
209
|
+
.u-waterfall {
|
|
210
|
+
@include flex;
|
|
211
|
+
flex-direction: row;
|
|
212
|
+
align-items: flex-start;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
.u-column {
|
|
216
|
+
@include flex;
|
|
217
|
+
flex: 1;
|
|
218
|
+
flex-direction: column;
|
|
219
|
+
height: auto;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
.u-image {
|
|
223
|
+
width: 100%;
|
|
224
|
+
}
|
|
225
|
+
</style>
|
package/index.js
CHANGED
|
@@ -33,6 +33,10 @@ import color from './libs/config/color.js'
|
|
|
33
33
|
// 平台
|
|
34
34
|
import platform from './libs/function/platform'
|
|
35
35
|
|
|
36
|
+
// 导出
|
|
37
|
+
export * from './libs/function/index.js'
|
|
38
|
+
export const http = new Request()
|
|
39
|
+
|
|
36
40
|
const $u = {
|
|
37
41
|
route,
|
|
38
42
|
date: index.timeFormat, // 另名date
|
|
@@ -42,7 +46,7 @@ const $u = {
|
|
|
42
46
|
colorToRgba: colorGradient.colorToRgba,
|
|
43
47
|
test,
|
|
44
48
|
type: ['primary', 'success', 'error', 'warning', 'info'],
|
|
45
|
-
http
|
|
49
|
+
http,
|
|
46
50
|
config, // uview-plus配置信息相关,比如版本号
|
|
47
51
|
zIndex,
|
|
48
52
|
debounce,
|
package/libs/config/props/tag.js
CHANGED
|
@@ -1,29 +1,30 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @Author : LQ
|
|
3
|
-
* @Description :
|
|
4
|
-
* @version : 1.0
|
|
5
|
-
* @Date : 2021-08-20 16:44:21
|
|
6
|
-
* @LastAuthor : LQ
|
|
7
|
-
* @lastTime : 2021-08-20 17:23:37
|
|
8
|
-
* @FilePath : /u-view2.0/uview-ui/libs/config/props/tag.js
|
|
9
|
-
*/
|
|
10
|
-
export default {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
1
|
+
/*
|
|
2
|
+
* @Author : LQ
|
|
3
|
+
* @Description :
|
|
4
|
+
* @version : 1.0
|
|
5
|
+
* @Date : 2021-08-20 16:44:21
|
|
6
|
+
* @LastAuthor : LQ
|
|
7
|
+
* @lastTime : 2021-08-20 17:23:37
|
|
8
|
+
* @FilePath : /u-view2.0/uview-ui/libs/config/props/tag.js
|
|
9
|
+
*/
|
|
10
|
+
export default {
|
|
11
|
+
// tag 组件
|
|
12
|
+
tag: {
|
|
13
|
+
type: 'primary',
|
|
14
|
+
disabled: false,
|
|
15
|
+
size: 'medium',
|
|
16
|
+
shape: 'square',
|
|
17
|
+
text: '',
|
|
18
|
+
bgColor: '',
|
|
19
|
+
color: '',
|
|
20
|
+
borderColor: '',
|
|
21
|
+
closeColor: '#C6C7CB',
|
|
22
|
+
name: '',
|
|
23
|
+
plainFill: false,
|
|
24
|
+
plain: false,
|
|
25
|
+
closable: false,
|
|
26
|
+
show: true,
|
|
27
|
+
icon: '',
|
|
28
|
+
iconColor: ''
|
|
29
|
+
}
|
|
30
|
+
}
|
package/libs/css/common.scss
CHANGED
package/libs/css/components.scss
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
@import "./mixin.scss";
|
|
2
2
|
|
|
3
3
|
/* #ifndef APP-NVUE */
|
|
4
|
-
// 由于
|
|
5
|
-
// 所以在非nvue中,需要对元素进行重置为flex-direction: column; 否则可能会表现异常
|
|
6
|
-
|
|
7
|
-
scroll-view,
|
|
8
|
-
swiper-item,
|
|
4
|
+
// 由于uview-plus是基于nvue环境进行开发的,此环境中普通元素默认为flex-direction: column;
|
|
5
|
+
// 所以在非nvue中,需要对元素进行重置为flex-direction: column; 否则可能会表现异常
|
|
6
|
+
// 2024-04-09由于微信小程序会提示 Some selectors are not allowed in component wxss所以注释以下几行
|
|
7
|
+
// scroll-view,
|
|
8
|
+
// swiper-item,
|
|
9
9
|
.u-empty,
|
|
10
10
|
.u-empty__wrap,
|
|
11
11
|
.u-tabs,
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @param {string} endColor 结束的颜色
|
|
5
5
|
* @param {number} step 颜色等分的份额
|
|
6
6
|
* */
|
|
7
|
-
function colorGradient(startColor = 'rgb(0, 0, 0)', endColor = 'rgb(255, 255, 255)', step = 10) {
|
|
7
|
+
export function colorGradient(startColor = 'rgb(0, 0, 0)', endColor = 'rgb(255, 255, 255)', step = 10) {
|
|
8
8
|
const startRGB = hexToRgb(startColor, false) // 转换为rgb数组模式
|
|
9
9
|
const startR = startRGB[0]
|
|
10
10
|
const startG = startRGB[1]
|
|
@@ -33,7 +33,7 @@ function colorGradient(startColor = 'rgb(0, 0, 0)', endColor = 'rgb(255, 255, 25
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
// 将hex表示方式转换为rgb表示方式(这里返回rgb数组模式)
|
|
36
|
-
function hexToRgb(sColor, str = true) {
|
|
36
|
+
export function hexToRgb(sColor, str = true) {
|
|
37
37
|
const reg = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/
|
|
38
38
|
sColor = String(sColor).toLowerCase()
|
|
39
39
|
if (sColor && reg.test(sColor)) {
|
|
@@ -52,16 +52,16 @@ function hexToRgb(sColor, str = true) {
|
|
|
52
52
|
if (!str) {
|
|
53
53
|
return sColorChange
|
|
54
54
|
}
|
|
55
|
-
return `rgb(${sColorChange[0]},${sColorChange[1]},${sColorChange[2]})`
|
|
55
|
+
return `rgb(${sColorChange[0]},${sColorChange[1]},${sColorChange[2]})`
|
|
56
56
|
} if (/^(rgb|RGB)/.test(sColor)) {
|
|
57
57
|
const arr = sColor.replace(/(?:\(|\)|rgb|RGB)*/g, '').split(',')
|
|
58
58
|
return arr.map((val) => Number(val))
|
|
59
59
|
}
|
|
60
|
-
return sColor
|
|
60
|
+
return sColor
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
// 将rgb表示方式转换为hex表示方式
|
|
64
|
-
function rgbToHex(rgb) {
|
|
64
|
+
export function rgbToHex(rgb) {
|
|
65
65
|
const _this = rgb
|
|
66
66
|
const reg = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/
|
|
67
67
|
if (/^(rgb|RGB)/.test(_this)) {
|
|
@@ -100,7 +100,7 @@ function rgbToHex(rgb) {
|
|
|
100
100
|
* sHex为传入的十六进制的色值
|
|
101
101
|
* alpha为rgba的透明度
|
|
102
102
|
*/
|
|
103
|
-
function colorToRgba(color, alpha) {
|
|
103
|
+
export function colorToRgba(color, alpha) {
|
|
104
104
|
color = rgbToHex(color)
|
|
105
105
|
// 十六进制颜色值的正则表达式
|
|
106
106
|
const reg = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/
|
|
@@ -123,7 +123,7 @@ function colorToRgba(color, alpha) {
|
|
|
123
123
|
return `rgba(${sColorChange.join(',')},${alpha})`
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
-
return sColor
|
|
126
|
+
return sColor
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
export default {
|
|
@@ -131,4 +131,4 @@ export default {
|
|
|
131
131
|
hexToRgb,
|
|
132
132
|
rgbToHex,
|
|
133
133
|
colorToRgba
|
|
134
|
-
}
|
|
134
|
+
}
|
|
@@ -8,7 +8,7 @@ let timeout = null
|
|
|
8
8
|
* @param {Boolean} immediate 是否立即执行
|
|
9
9
|
* @return null
|
|
10
10
|
*/
|
|
11
|
-
function debounce(func, wait = 500, immediate = false) {
|
|
11
|
+
export function debounce(func, wait = 500, immediate = false) {
|
|
12
12
|
// 清除定时器
|
|
13
13
|
if (timeout !== null) clearTimeout(timeout)
|
|
14
14
|
// 立即执行,此类情况一般用不到
|
|
@@ -23,7 +23,7 @@ function debounce(func, wait = 500, immediate = false) {
|
|
|
23
23
|
timeout = setTimeout(() => {
|
|
24
24
|
typeof func === 'function' && func()
|
|
25
25
|
}, wait)
|
|
26
|
-
}
|
|
26
|
+
}
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
export default debounce
|
package/libs/function/digit.js
CHANGED
|
@@ -5,7 +5,7 @@ let _boundaryCheckingState = true; // 是否进行越界检查的全局开关
|
|
|
5
5
|
* @private
|
|
6
6
|
* @example strip(0.09999999999999998)=0.1
|
|
7
7
|
*/
|
|
8
|
-
function strip(num, precision = 15) {
|
|
8
|
+
export function strip(num, precision = 15) {
|
|
9
9
|
return +parseFloat(Number(num).toPrecision(precision));
|
|
10
10
|
}
|
|
11
11
|
|
|
@@ -14,7 +14,7 @@ function strip(num, precision = 15) {
|
|
|
14
14
|
* @private
|
|
15
15
|
* @param {*number} num Input number
|
|
16
16
|
*/
|
|
17
|
-
function digitLength(num) {
|
|
17
|
+
export function digitLength(num) {
|
|
18
18
|
// Get digit length of e
|
|
19
19
|
const eSplit = num.toString().split(/[eE]/);
|
|
20
20
|
const len = (eSplit[0].split('.')[1] || '').length - +(eSplit[1] || 0);
|
|
@@ -26,7 +26,7 @@ function digitLength(num) {
|
|
|
26
26
|
* @private
|
|
27
27
|
* @param {*number} num 输入数
|
|
28
28
|
*/
|
|
29
|
-
function float2Fixed(num) {
|
|
29
|
+
export function float2Fixed(num) {
|
|
30
30
|
if (num.toString().indexOf('e') === -1) {
|
|
31
31
|
return Number(num.toString().replace('.', ''));
|
|
32
32
|
}
|
|
@@ -39,7 +39,7 @@ function float2Fixed(num) {
|
|
|
39
39
|
* @private
|
|
40
40
|
* @param {*number} num 输入数
|
|
41
41
|
*/
|
|
42
|
-
function checkBoundary(num) {
|
|
42
|
+
export function checkBoundary(num) {
|
|
43
43
|
if (_boundaryCheckingState) {
|
|
44
44
|
if (num > Number.MAX_SAFE_INTEGER || num < Number.MIN_SAFE_INTEGER) {
|
|
45
45
|
console.warn(`${num} 超出了精度限制,结果可能不正确`);
|
|
@@ -53,7 +53,7 @@ function checkBoundary(num) {
|
|
|
53
53
|
* @param {function} operation 迭代操作
|
|
54
54
|
* @private
|
|
55
55
|
*/
|
|
56
|
-
function iteratorOperation(arr, operation) {
|
|
56
|
+
export function iteratorOperation(arr, operation) {
|
|
57
57
|
const [num1, num2, ...others] = arr;
|
|
58
58
|
let res = operation(num1, num2);
|
|
59
59
|
|