sadais-piui 1.1.2-beta → 1.2.0
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 +482 -240
- package/components/pi-bottom-bar/index.vue +11 -2
- package/components/pi-circle-progress/index.vue +196 -173
- package/components/pi-count-up/index.vue +68 -62
- package/components/pi-dropdown/components/dropdown-tab.vue +62 -0
- package/components/pi-dropdown/index.vue +152 -151
- package/components/pi-dropdown-item/index.vue +169 -41
- package/components/pi-form-item/index.vue +13 -1
- package/components/pi-img-cropper/index.vue +20 -16
- package/components/pi-img-cropper/touch.js +5 -3
- package/components/pi-input/index.vue +9 -2
- package/components/pi-notify/index.vue +132 -48
- package/components/pi-popup/index.vue +1 -3
- package/components/pi-select/index.vue +2 -2
- package/components/pi-steps/index.vue +141 -96
- package/components/pi-switch/index.vue +2 -3
- package/components/pi-tabs/index.vue +1 -2
- package/components/pi-upload-img/index.vue +104 -32
- package/config/bottomBar.js +1 -0
- package/config/checkbox.js +1 -1
- package/config/circleProgress.js +13 -0
- package/config/countUp.js +13 -0
- package/config/dropdown.js +17 -8
- package/config/dropdownItem.js +23 -5
- package/config/form.js +3 -3
- package/config/imgCropper.js +4 -2
- package/config/notify.js +6 -2
- package/config/steps.js +10 -5
- package/config/{upload-img.js → uploadImg.js} +6 -3
- package/index.js +2 -2
- package/package.json +3 -3
- package/scss/variable.scss +1 -1
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<view>
|
|
3
|
-
<view
|
|
3
|
+
<view
|
|
4
|
+
class="pi-bottom-bar"
|
|
5
|
+
:style="[{ borderTop: borderTop, background: background }]"
|
|
6
|
+
:class="[{ fixed: fixed }]"
|
|
7
|
+
>
|
|
4
8
|
<!-- 默认插槽 -->
|
|
5
9
|
<view
|
|
6
10
|
class="pi-w-100P"
|
|
@@ -63,6 +67,12 @@ export default {
|
|
|
63
67
|
return bottomBar.safeArea
|
|
64
68
|
}
|
|
65
69
|
},
|
|
70
|
+
// 背景
|
|
71
|
+
background: {
|
|
72
|
+
type: String,
|
|
73
|
+
// '#ffffff'
|
|
74
|
+
default: bottomBar.background
|
|
75
|
+
},
|
|
66
76
|
// 安全区域背景颜色
|
|
67
77
|
safeAreaBgColor: {
|
|
68
78
|
type: String,
|
|
@@ -114,7 +124,6 @@ export default {
|
|
|
114
124
|
<style lang="scss" scoped>
|
|
115
125
|
.pi-bottom-bar {
|
|
116
126
|
width: 100%;
|
|
117
|
-
background: #ffffff;
|
|
118
127
|
&.fixed {
|
|
119
128
|
position: fixed;
|
|
120
129
|
right: 0;
|
|
@@ -1,201 +1,224 @@
|
|
|
1
1
|
<!--
|
|
2
2
|
* @Author: zhouxianpan
|
|
3
3
|
* @Date: 2021-09-06 10:07:33
|
|
4
|
-
* @LastEditTime: 2021-
|
|
5
|
-
* @LastEditors:
|
|
4
|
+
* @LastEditTime: 2021-11-23 16:45:30
|
|
5
|
+
* @LastEditors: zhangzhenfei
|
|
6
6
|
* @Description:
|
|
7
|
-
* @FilePath: \
|
|
7
|
+
* @FilePath: \piui-awesome\src\piui\components\pi-circle-progress\index.vue
|
|
8
8
|
-->
|
|
9
9
|
<template>
|
|
10
|
-
<view
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
<view
|
|
11
|
+
class="circle-progress"
|
|
12
|
+
:style="{
|
|
13
|
+
width: widthPx + 'px',
|
|
14
|
+
height: widthPx + 'px',
|
|
15
|
+
backgroundColor: bgColor
|
|
16
|
+
}"
|
|
17
|
+
>
|
|
18
|
+
<canvas
|
|
19
|
+
:id="elBgId"
|
|
20
|
+
:canvas-id="elBgId"
|
|
21
|
+
class="pi-canvas-bg"
|
|
22
|
+
:style="{
|
|
23
|
+
width: widthPx + 'px',
|
|
24
|
+
height: widthPx + 'px'
|
|
25
|
+
}"
|
|
26
|
+
/>
|
|
27
|
+
<canvas
|
|
28
|
+
:id="elId"
|
|
29
|
+
:canvas-id="elId"
|
|
30
|
+
class="pi-canvas"
|
|
31
|
+
:style="{
|
|
32
|
+
width: widthPx + 'px',
|
|
33
|
+
height: widthPx + 'px'
|
|
34
|
+
}"
|
|
35
|
+
/>
|
|
36
|
+
</view>
|
|
14
37
|
</template>
|
|
38
|
+
<script>
|
|
39
|
+
import { getConfig } from '../../config'
|
|
40
|
+
const { circleProgress } = getConfig()
|
|
15
41
|
|
|
16
|
-
<script >
|
|
17
42
|
export default {
|
|
43
|
+
name: 'PiCircleProgress',
|
|
18
44
|
props: {
|
|
19
|
-
|
|
45
|
+
// 圆环进度百分比值
|
|
20
46
|
percent: {
|
|
21
|
-
type:
|
|
22
|
-
default
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
duration: {
|
|
27
|
-
type:number,
|
|
28
|
-
default() {
|
|
29
|
-
return 1000
|
|
47
|
+
type: Number,
|
|
48
|
+
default: circleProgress.percent,
|
|
49
|
+
// 限制值在0到100之间
|
|
50
|
+
validator: val => {
|
|
51
|
+
return val >= 0 && val <= 100
|
|
30
52
|
}
|
|
31
53
|
},
|
|
32
|
-
//
|
|
33
|
-
|
|
34
|
-
type:
|
|
35
|
-
default
|
|
36
|
-
return 100
|
|
37
|
-
}
|
|
54
|
+
// 整个圆环进度区域的背景色
|
|
55
|
+
bgColor: {
|
|
56
|
+
type: String,
|
|
57
|
+
default: circleProgress.bgColor
|
|
38
58
|
},
|
|
39
|
-
//
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
default
|
|
43
|
-
return 10
|
|
44
|
-
}
|
|
59
|
+
// 底部圆环的颜色(灰色的圆环)
|
|
60
|
+
inactiveColor: {
|
|
61
|
+
type: String,
|
|
62
|
+
default: circleProgress.inactiveColor
|
|
45
63
|
},
|
|
46
|
-
//
|
|
47
|
-
|
|
48
|
-
type:
|
|
49
|
-
default
|
|
50
|
-
return '#40E0D0'
|
|
51
|
-
}
|
|
64
|
+
// 圆环激活部分的颜色
|
|
65
|
+
activeColor: {
|
|
66
|
+
type: String,
|
|
67
|
+
default: circleProgress.activeColor
|
|
52
68
|
},
|
|
53
|
-
//
|
|
54
|
-
|
|
55
|
-
type:
|
|
56
|
-
default
|
|
57
|
-
return '#FFFF00'
|
|
58
|
-
}
|
|
69
|
+
// 圆环线条的宽度,单位rpx
|
|
70
|
+
borderWidth: {
|
|
71
|
+
type: [Number, String],
|
|
72
|
+
default: circleProgress.borderWidth
|
|
59
73
|
},
|
|
60
|
-
//
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
default
|
|
64
|
-
return 'round'
|
|
65
|
-
}
|
|
74
|
+
// 整个圆形的宽度,单位rpx
|
|
75
|
+
width: {
|
|
76
|
+
type: [Number, String],
|
|
77
|
+
default: circleProgress.width
|
|
66
78
|
},
|
|
67
|
-
//
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
return '文字显示'
|
|
72
|
-
}
|
|
79
|
+
// 整个圆环执行一圈的时间,单位ms
|
|
80
|
+
duration: {
|
|
81
|
+
type: [Number, String],
|
|
82
|
+
default: circleProgress.duration
|
|
73
83
|
},
|
|
74
|
-
//
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
return '#000000'
|
|
79
|
-
}
|
|
84
|
+
// 主题类型
|
|
85
|
+
type: {
|
|
86
|
+
type: String,
|
|
87
|
+
default: circleProgress.type
|
|
80
88
|
},
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
89
|
+
|
|
90
|
+
// 字体大小
|
|
91
|
+
fontSize: {
|
|
92
|
+
type: String,
|
|
93
|
+
default: circleProgress.fontSize
|
|
87
94
|
},
|
|
95
|
+
// 显示的文字 默认为空
|
|
96
|
+
text: {
|
|
97
|
+
type: String,
|
|
98
|
+
default: circleProgress.text
|
|
99
|
+
}
|
|
88
100
|
},
|
|
89
101
|
data() {
|
|
90
|
-
return {
|
|
102
|
+
return {
|
|
103
|
+
elBgId: 'pCircleProgressBgId', // 微信小程序中不能使用this.$pi形式动态生成id值,否则会报错
|
|
104
|
+
elId: 'pCircleProgressElId',
|
|
105
|
+
elBgId: this.$pi.guid(), // 支付宝等小程序 动态生产ID
|
|
106
|
+
elId: this.$pi.guid(),
|
|
91
107
|
progressContext: null,
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
watch: {
|
|
107
|
-
// 深度监听进度
|
|
108
|
-
percent: {
|
|
109
|
-
handler(newVal, oldVal) {
|
|
110
|
-
console.log(newVal);
|
|
111
|
-
console.log(oldVal);
|
|
112
|
-
if (newVal > 100) newVal = 100;
|
|
113
|
-
if (newVal < 0) oldVal = 0
|
|
114
|
-
this.newVal = newVal
|
|
115
|
-
this.oldVal = oldVal
|
|
116
|
-
this.drawCircleByProgress(oldVal)
|
|
117
|
-
},
|
|
118
|
-
deep: true
|
|
119
|
-
}
|
|
120
|
-
},
|
|
121
|
-
computed: {
|
|
122
|
-
// 圆的实际半径 =半径+环形进度条的宽度
|
|
123
|
-
moveWith() {
|
|
124
|
-
return this.radius + this.lineWidth
|
|
125
|
-
},
|
|
126
|
-
|
|
127
|
-
},
|
|
128
|
-
created() {
|
|
129
|
-
this.newVal = this.percent
|
|
130
|
-
this.oldVal = 0
|
|
131
|
-
console.log(-Math.PI / 2);
|
|
132
|
-
|
|
133
|
-
},
|
|
134
|
-
methods: {
|
|
135
|
-
|
|
136
|
-
drawProgressBg() {
|
|
137
|
-
let canvas = document.getElementById(this.elBgId)
|
|
138
|
-
// 宽高
|
|
139
|
-
canvas.width = this.moveWith * 2
|
|
140
|
-
canvas.height = this.moveWith * 2
|
|
141
|
-
let ctx = canvas.getContext('2d')
|
|
142
|
-
ctx.beginPath();
|
|
143
|
-
// X,Y轴中心点+半径+起始方向+结束 +是否顺逆
|
|
144
|
-
ctx.arc(this.moveWith, this.moveWith, this.radius, 0, Math.PI * 2, false);
|
|
145
|
-
ctx.lineWidth = this.lineWidth;
|
|
146
|
-
ctx.strokeStyle = this.strokeStyle;
|
|
147
|
-
// 文字
|
|
148
|
-
ctx.font = 'bold ' + this.fontSize + 'px' + ' Arial'
|
|
149
|
-
ctx.fillStyle = this.fontColor;
|
|
150
|
-
ctx.textAlign = 'center';
|
|
151
|
-
ctx.textBaseline = 'middle';
|
|
152
|
-
ctx.fillText(this.text, this.moveWith, this.moveWith, this.radius);
|
|
153
|
-
ctx.stroke();
|
|
154
|
-
ctx.closePath();
|
|
155
|
-
|
|
156
|
-
},
|
|
157
|
-
// 激活部分
|
|
158
|
-
drawCircleByProgress(progress) {
|
|
159
|
-
let canvas = document.getElementById(this.elId)
|
|
160
|
-
canvas.width = this.moveWith * 2
|
|
161
|
-
canvas.height = this.moveWith * 2
|
|
162
|
-
let ctx = canvas.getContext('2d')
|
|
163
|
-
let endAngel = ((2 * Math.PI) / 100) * progress + this.startAngle
|
|
164
|
-
ctx.beginPath()
|
|
165
|
-
ctx.lineWidth = this.lineWidth;
|
|
166
|
-
ctx.strokeStyle = this.circleColor;
|
|
167
|
-
ctx.lineCap = this.lineCap
|
|
168
|
-
ctx.arc(this.moveWith, this.moveWith, this.radius, this.startAngle, endAngel, false);
|
|
169
|
-
ctx.stroke();
|
|
170
|
-
ctx.closePath();
|
|
171
|
-
// 实际时间
|
|
172
|
-
let time = Math.floor(this.duration / 100)
|
|
173
|
-
if (this.newVal > this.oldVal) {
|
|
174
|
-
|
|
175
|
-
progress++;
|
|
176
|
-
|
|
177
|
-
if (progress > this.newVal) return;
|
|
178
|
-
} else {
|
|
179
|
-
|
|
180
|
-
progress--;
|
|
181
|
-
if (progress < this.newVal) return;
|
|
182
|
-
}
|
|
183
|
-
// 动画
|
|
184
|
-
setTimeout(() => {
|
|
185
|
-
// 定时器 进度条有动画效果
|
|
186
|
-
this.drawCircleByProgress(progress);
|
|
187
|
-
}, time);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
108
|
+
// 开始的角度
|
|
109
|
+
widthPx: uni.upx2px(this.width), // 转成px后的整个组件的背景宽度
|
|
110
|
+
borderWidthPx: uni.upx2px(this.borderWidth), // 转成px后的圆环的宽度
|
|
111
|
+
startAngle: -Math.PI / 2, // canvas画圆的起始角度,默认为3点钟方向,定位到12点钟方向
|
|
112
|
+
newPercent: 0, // 当动态修改进度值的时候,保存进度值的变化前后值,用于比较用
|
|
113
|
+
oldPercent: 0 // 当动态修改进度值的时候,保存进度值的变化前后值,用于比较用
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
computed: {
|
|
117
|
+
// 有type主题时,优先起作用
|
|
118
|
+
circleColor() {
|
|
119
|
+
if (['success', 'error', 'info', 'primary', 'warning'].indexOf(this.type) >= 0)
|
|
120
|
+
return this.$u.color[this.type]
|
|
121
|
+
else return this.activeColor
|
|
190
122
|
}
|
|
123
|
+
},
|
|
124
|
+
watch: {
|
|
125
|
+
// 深度监听进度
|
|
126
|
+
percent(nVal, oVal = 0) {
|
|
127
|
+
if (nVal > 100) nVal = 100
|
|
128
|
+
if (nVal < 0) oVal = 0
|
|
129
|
+
// 此值其实等于this.percent,命名一个新值
|
|
130
|
+
this.newPercent = nVal
|
|
131
|
+
this.oldPercent = oVal
|
|
132
|
+
setTimeout(() => {
|
|
133
|
+
// 无论是百分比值增加还是减少,需要操作还是原来的旧的百分比值
|
|
134
|
+
// 将此值减少或者新增到新的百分比值
|
|
135
|
+
this.drawCircleByProgress(oVal)
|
|
136
|
+
}, 50)
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
mounted() {
|
|
140
|
+
// 背景圆
|
|
141
|
+
this.drawProgressBg()
|
|
142
|
+
setTimeout(() => {
|
|
143
|
+
// 进度圆
|
|
144
|
+
this.drawCircleByProgress(this.percent)
|
|
145
|
+
}, 500)
|
|
146
|
+
},
|
|
147
|
+
created() {
|
|
148
|
+
this.newPercent = this.percent
|
|
149
|
+
this.oldPercent = 0
|
|
150
|
+
},
|
|
151
|
+
methods: {
|
|
152
|
+
drawProgressBg() {
|
|
153
|
+
console.log(this)
|
|
154
|
+
let ctx = uni.createCanvasContext(this.elBgId, this)
|
|
155
|
+
ctx.setLineWidth(this.borderWidthPx) // 设置圆环宽度
|
|
156
|
+
ctx.setStrokeStyle(this.inactiveColor) // 线条颜色
|
|
157
|
+
ctx.beginPath() // 开描绘路径
|
|
158
|
+
// 设置一个原点(110,110),半径为100的圆的路径到当前路径
|
|
159
|
+
let radius = this.widthPx / 2
|
|
160
|
+
// 用于绘制圆弧context.arc(x坐标,y坐标,半径,起始角度,终止角度,顺时针/逆时针)
|
|
161
|
+
ctx.arc(radius, radius, radius - this.borderWidthPx, 0, 2 * Math.PI, false)
|
|
162
|
+
ctx.stroke() // 对路径进行描绘
|
|
163
|
+
ctx.draw()
|
|
164
|
+
},
|
|
165
|
+
// 激活部分
|
|
166
|
+
drawCircleByProgress(progress) {
|
|
167
|
+
// 第一次操作进度环时将上下文保存到了this.data中,直接使用即可
|
|
168
|
+
let ctx = this.progressContext
|
|
169
|
+
if (!ctx) {
|
|
170
|
+
ctx = uni.createCanvasContext(this.elId, this)
|
|
171
|
+
this.progressContext = ctx
|
|
172
|
+
}
|
|
173
|
+
// 表示进度的两端为圆形
|
|
174
|
+
ctx.setLineCap('round')
|
|
175
|
+
// 设置线条的宽度和颜色
|
|
176
|
+
ctx.setLineWidth(this.borderWidthPx)
|
|
177
|
+
ctx.setStrokeStyle(this.circleColor)
|
|
178
|
+
// 将总过渡时间除以100,得出每修改百分之一进度所需的时间
|
|
179
|
+
let time = Math.floor(this.duration / 100)
|
|
180
|
+
// 结束角的计算依据为:将2π分为100份,乘以当前的进度值,得出终止点的弧度值,加起始角,为整个圆从默认的
|
|
181
|
+
// 3点钟方向开始画图,转为更好理解的12点钟方向开始作图,这需要起始角和终止角同时加上this.startAngle值
|
|
182
|
+
let endAngle = ((2 * Math.PI) / 100) * progress + this.startAngle
|
|
183
|
+
ctx.beginPath()
|
|
184
|
+
// 半径为整个canvas宽度的一半
|
|
185
|
+
let radius = this.widthPx / 2
|
|
186
|
+
ctx.arc(radius, radius, radius - this.borderWidthPx, this.startAngle, endAngle, false)
|
|
187
|
+
ctx.textAlign = 'center'
|
|
188
|
+
ctx.font = this.fontSize + ' Arial'
|
|
189
|
+
ctx.fillText(this.text, radius, radius)
|
|
190
|
+
ctx.stroke()
|
|
191
|
+
ctx.draw()
|
|
192
|
+
// 如果变更后新值大于旧值,意味着增大了百分比
|
|
193
|
+
if (this.newPercent > this.oldPercent) {
|
|
194
|
+
// 每次递增百分之一
|
|
195
|
+
progress++
|
|
196
|
+
// 如果新增后的值,大于需要设置的值百分比值,停止继续增加
|
|
197
|
+
if (progress > this.newPercent) return
|
|
198
|
+
} else {
|
|
199
|
+
// 同理于上面
|
|
200
|
+
progress--
|
|
201
|
+
if (progress < this.newPercent) return
|
|
202
|
+
}
|
|
203
|
+
setTimeout(() => {
|
|
204
|
+
// 定时器,每次操作间隔为time值,为了让进度条有动画效果
|
|
205
|
+
this.drawCircleByProgress(progress)
|
|
206
|
+
}, time)
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
191
210
|
</script>
|
|
192
211
|
<style scoped lang="scss">
|
|
212
|
+
.circle-progress {
|
|
213
|
+
position: relative;
|
|
214
|
+
display: inline-flex;
|
|
215
|
+
align-items: center;
|
|
216
|
+
justify-content: center;
|
|
217
|
+
}
|
|
193
218
|
.pi-canvas-bg {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
</style>
|
|
219
|
+
position: absolute;
|
|
220
|
+
}
|
|
221
|
+
.pi-canvas {
|
|
222
|
+
position: absolute;
|
|
223
|
+
}
|
|
224
|
+
</style>
|
|
@@ -11,67 +11,86 @@
|
|
|
11
11
|
</template>
|
|
12
12
|
|
|
13
13
|
<script>
|
|
14
|
+
import { getConfig } from '../../config'
|
|
15
|
+
const { countUp } = getConfig()
|
|
16
|
+
|
|
14
17
|
export default {
|
|
15
18
|
name: 'PiCountUp',
|
|
16
19
|
props: {
|
|
20
|
+
// 自定义样式,对象形式
|
|
21
|
+
customStyle: {
|
|
22
|
+
type: Object,
|
|
23
|
+
default() {
|
|
24
|
+
// {}
|
|
25
|
+
return countUp.customStyle
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
// 自定义样式类,字符串形式
|
|
29
|
+
customClass: {
|
|
30
|
+
type: String,
|
|
31
|
+
default() {
|
|
32
|
+
// ''
|
|
33
|
+
return countUp.customClass
|
|
34
|
+
}
|
|
35
|
+
},
|
|
17
36
|
// 开始的数值,默认从0增长到某一个数
|
|
18
37
|
startNum: {
|
|
19
38
|
type: [Number, String],
|
|
20
|
-
default:
|
|
39
|
+
default: countUp.startNum
|
|
21
40
|
},
|
|
22
41
|
// 要滚动的目标数值,必须
|
|
23
42
|
endNum: {
|
|
24
43
|
type: [Number, String],
|
|
25
44
|
default: 0,
|
|
26
|
-
required:
|
|
45
|
+
required: countUp.endNum
|
|
27
46
|
},
|
|
28
47
|
// 滚动到目标数值的动画持续时间,单位为毫秒(ms)
|
|
29
48
|
duration: {
|
|
30
49
|
type: [Number, String],
|
|
31
|
-
default:
|
|
50
|
+
default: countUp.duration
|
|
32
51
|
},
|
|
33
52
|
// 设置数值后是否自动开始滚动
|
|
34
53
|
autoplay: {
|
|
35
54
|
type: Boolean,
|
|
36
|
-
default:
|
|
55
|
+
default: countUp.autoplay
|
|
37
56
|
},
|
|
38
57
|
// 要显示的小数位数
|
|
39
58
|
decimals: {
|
|
40
59
|
type: [Number, String],
|
|
41
|
-
default:
|
|
60
|
+
default: countUp.decimals
|
|
61
|
+
},
|
|
62
|
+
// 千位符分隔符,默认为空
|
|
63
|
+
thousands: {
|
|
64
|
+
type: [String],
|
|
65
|
+
default: countUp.thousands
|
|
42
66
|
},
|
|
43
67
|
// 是否在即将到达目标数值的时候,使用缓慢滚动的效果
|
|
44
68
|
isEase: {
|
|
45
69
|
type: Boolean,
|
|
46
|
-
default:
|
|
47
|
-
},
|
|
48
|
-
// 十进制分割
|
|
49
|
-
decimal: {
|
|
50
|
-
type: [Number, String],
|
|
51
|
-
default: '.'
|
|
70
|
+
default: countUp.isEase
|
|
52
71
|
},
|
|
53
72
|
// 字体颜色
|
|
54
73
|
fontColor: {
|
|
55
74
|
type: String,
|
|
56
|
-
default:
|
|
75
|
+
default: countUp.fontColor
|
|
57
76
|
},
|
|
58
77
|
// 字体大小
|
|
59
78
|
fontSize: {
|
|
60
79
|
type: [Number, String],
|
|
61
|
-
default:
|
|
80
|
+
default: countUp.fontSize
|
|
62
81
|
}
|
|
63
82
|
},
|
|
64
83
|
data() {
|
|
65
84
|
return {
|
|
66
|
-
|
|
85
|
+
startNumCache: this.startNum,
|
|
67
86
|
showingVal: this.formatNumber(this.startNum),
|
|
68
87
|
printVal: null,
|
|
69
|
-
|
|
70
|
-
|
|
88
|
+
isPaused: false, // 是否暂停
|
|
89
|
+
durationCache: Number(this.duration),
|
|
71
90
|
startTime: null, // 开始的时间
|
|
72
91
|
timestamp: null, // 时间戳
|
|
73
92
|
remaining: null, // 停留的时间
|
|
74
|
-
|
|
93
|
+
timer: null,
|
|
75
94
|
lastTime: 0 // 上一次的时间
|
|
76
95
|
}
|
|
77
96
|
},
|
|
@@ -95,7 +114,7 @@ export default {
|
|
|
95
114
|
easingFn(t, b, c, d) {
|
|
96
115
|
return (c * (-Math.pow(2, (-10 * t) / d) + 1) * 1024) / 1023 + b
|
|
97
116
|
},
|
|
98
|
-
|
|
117
|
+
requestTimeout(callback) {
|
|
99
118
|
const currTime = new Date().getTime()
|
|
100
119
|
// 为了使setTimteout的尽可能的接近每秒60帧的效果
|
|
101
120
|
const timeToCall = Math.max(0, 16 - (currTime - this.lastTime)) // 计算当前一帧内还剩多少时间
|
|
@@ -105,80 +124,68 @@ export default {
|
|
|
105
124
|
this.lastTime = currTime + timeToCall
|
|
106
125
|
return id
|
|
107
126
|
},
|
|
108
|
-
|
|
109
|
-
cancelAnimationFrame(id) {
|
|
110
|
-
clearTimeout(id)
|
|
111
|
-
},
|
|
112
127
|
// 开始滚动数字
|
|
113
128
|
start() {
|
|
114
|
-
this.
|
|
129
|
+
this.startNumCache = this.startNum
|
|
115
130
|
this.startTime = null
|
|
116
|
-
this.
|
|
117
|
-
this.
|
|
118
|
-
this.
|
|
131
|
+
this.durationCache = this.duration
|
|
132
|
+
this.isPaused = false
|
|
133
|
+
this.timer = this.requestTimeout(this.count)
|
|
119
134
|
},
|
|
120
135
|
// 暂定状态,重新再开始滚动;或者滚动状态下,暂停
|
|
121
136
|
reStart() {
|
|
122
|
-
if (this.
|
|
137
|
+
if (this.isPaused) {
|
|
123
138
|
this.resume()
|
|
124
|
-
this.
|
|
139
|
+
this.isPaused = false
|
|
125
140
|
} else {
|
|
126
141
|
this.stop()
|
|
127
|
-
this.
|
|
142
|
+
this.isPaused = true
|
|
128
143
|
}
|
|
129
144
|
},
|
|
130
145
|
// 暂停
|
|
131
146
|
stop() {
|
|
132
|
-
|
|
147
|
+
clearTimeout(this.timer)
|
|
133
148
|
},
|
|
134
149
|
// 重新开始(暂停的情况下)
|
|
135
150
|
resume() {
|
|
136
151
|
this.startTime = null
|
|
137
|
-
this.
|
|
138
|
-
this.
|
|
139
|
-
this.
|
|
152
|
+
this.durationCache = this.remaining
|
|
153
|
+
this.startNumCache = this.printVal
|
|
154
|
+
this.requestTimeout(this.count)
|
|
140
155
|
},
|
|
141
156
|
// 重置
|
|
142
157
|
reset() {
|
|
143
158
|
this.startTime = null
|
|
144
|
-
|
|
159
|
+
clearTimeout(this.timer)
|
|
145
160
|
this.showingVal = this.formatNumber(this.startNum)
|
|
146
161
|
},
|
|
147
162
|
count(timestamp) {
|
|
148
163
|
if (!this.startTime) this.startTime = timestamp
|
|
149
164
|
this.timestamp = timestamp
|
|
150
165
|
const progress = timestamp - this.startTime
|
|
151
|
-
this.remaining = this.
|
|
152
|
-
if (this.
|
|
153
|
-
|
|
154
|
-
this.
|
|
155
|
-
this.
|
|
156
|
-
|
|
157
|
-
} else {
|
|
158
|
-
this.printVal = this.easingFn(
|
|
159
|
-
progress,
|
|
160
|
-
this.localStartNum,
|
|
161
|
-
this.endNum - this.localStartNum,
|
|
162
|
-
this.localDuration
|
|
163
|
-
)
|
|
164
|
-
}
|
|
166
|
+
this.remaining = this.durationCache - progress
|
|
167
|
+
if (this.countDown) {
|
|
168
|
+
this.printVal =
|
|
169
|
+
this.startNumCache - this.isEase
|
|
170
|
+
? this.easingFn(progress, 0, this.startNumCache - this.endNum, this.durationCache)
|
|
171
|
+
: (this.startNumCache - this.endNum) * (progress / this.durationCache)
|
|
165
172
|
} else {
|
|
166
|
-
|
|
167
|
-
this.
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
173
|
+
this.printVal = this.isEase
|
|
174
|
+
? this.easingFn(
|
|
175
|
+
progress,
|
|
176
|
+
this.startNumCache,
|
|
177
|
+
this.endNum - this.startNumCache,
|
|
178
|
+
this.durationCache
|
|
179
|
+
)
|
|
180
|
+
: this.startNumCache +
|
|
181
|
+
(this.endNum - this.startNumCache) * (progress / this.durationCache)
|
|
175
182
|
}
|
|
176
183
|
this.printVal = this.countDown
|
|
177
184
|
? Math.max(this.printVal, this.endNum)
|
|
178
185
|
: Math.min(this.printVal, this.endNum)
|
|
179
186
|
this.showingVal = this.formatNumber(this.printVal)
|
|
180
|
-
if (progress < this.
|
|
181
|
-
this.
|
|
187
|
+
if (progress < this.durationCache) {
|
|
188
|
+
this.timer = this.requestTimeout(this.count)
|
|
182
189
|
} else {
|
|
183
190
|
this.$emit('end')
|
|
184
191
|
}
|
|
@@ -190,11 +197,10 @@ export default {
|
|
|
190
197
|
formatNumber(num) {
|
|
191
198
|
num = Number(num)
|
|
192
199
|
num = num.toFixed(Number(this.decimals))
|
|
193
|
-
num
|
|
194
|
-
return num.replace('.', this.decimal)
|
|
200
|
+
return this.$pi.format.numFormat(num, this.decimals, this.thousands)
|
|
195
201
|
},
|
|
196
202
|
destroyed() {
|
|
197
|
-
|
|
203
|
+
clearTimeout(this.timer)
|
|
198
204
|
}
|
|
199
205
|
}
|
|
200
206
|
}
|