sadais-piui 1.1.1 → 1.2.2-beta1
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/README.md +2 -3
- package/components/pi-bottom-bar/index.vue +15 -2
- package/components/pi-canvas/index.vue +400 -0
- package/components/pi-circle-progress/index.vue +196 -173
- package/components/pi-count-up/index.vue +209 -0
- package/components/pi-dropdown/components/dropdown-tab.vue +62 -0
- package/components/pi-dropdown/index.vue +155 -149
- package/components/pi-dropdown-item/index.vue +169 -41
- package/components/pi-form-item/index.vue +13 -1
- package/components/pi-img/index.vue +1 -0
- package/components/pi-img-cropper/canvas.js +2 -2
- package/components/pi-img-cropper/index.vue +34 -16
- package/components/pi-img-cropper/touch.js +5 -3
- package/components/pi-input/index.vue +9 -2
- package/components/pi-notify/index.vue +133 -49
- package/components/pi-popup/index.vue +1 -3
- package/components/pi-radio/index.vue +1 -1
- package/components/pi-select/index.vue +16 -6
- package/components/pi-steps/index.vue +153 -97
- package/components/pi-switch/index.vue +2 -3
- package/components/pi-tabs/index.vue +1 -2
- package/components/pi-upload-img/index.vue +144 -39
- 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 +7 -1
- package/config/notify.js +6 -2
- package/config/steps.js +11 -7
- package/config/{upload-img.js → uploadImg.js} +5 -1
- package/index.js +2 -2
- package/package.json +3 -3
- package/scss/common.scss +4 -0
- package/scss/variable.scss +1 -1
|
@@ -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>
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view
|
|
3
|
+
class="pi-count-up-wrapper"
|
|
4
|
+
:style="{
|
|
5
|
+
fontSize: fontSize + 'rpx',
|
|
6
|
+
color: fontColor
|
|
7
|
+
}"
|
|
8
|
+
>
|
|
9
|
+
<slot :val="showingVal">{{ showingVal }}</slot>
|
|
10
|
+
</view>
|
|
11
|
+
</template>
|
|
12
|
+
|
|
13
|
+
<script>
|
|
14
|
+
import { getConfig } from '../../config'
|
|
15
|
+
const { countUp } = getConfig()
|
|
16
|
+
|
|
17
|
+
export default {
|
|
18
|
+
name: 'PiCountUp',
|
|
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
|
+
},
|
|
36
|
+
// 开始的数值,默认从0增长到某一个数
|
|
37
|
+
startNum: {
|
|
38
|
+
type: [Number, String],
|
|
39
|
+
default: countUp.startNum
|
|
40
|
+
},
|
|
41
|
+
// 要滚动的目标数值,必须
|
|
42
|
+
endNum: {
|
|
43
|
+
type: [Number, String],
|
|
44
|
+
default: 0,
|
|
45
|
+
required: countUp.endNum
|
|
46
|
+
},
|
|
47
|
+
// 滚动到目标数值的动画持续时间,单位为毫秒(ms)
|
|
48
|
+
duration: {
|
|
49
|
+
type: [Number, String],
|
|
50
|
+
default: countUp.duration
|
|
51
|
+
},
|
|
52
|
+
// 设置数值后是否自动开始滚动
|
|
53
|
+
autoplay: {
|
|
54
|
+
type: Boolean,
|
|
55
|
+
default: countUp.autoplay
|
|
56
|
+
},
|
|
57
|
+
// 要显示的小数位数
|
|
58
|
+
decimals: {
|
|
59
|
+
type: [Number, String],
|
|
60
|
+
default: countUp.decimals
|
|
61
|
+
},
|
|
62
|
+
// 千位符分隔符,默认为空
|
|
63
|
+
thousands: {
|
|
64
|
+
type: [String],
|
|
65
|
+
default: countUp.thousands
|
|
66
|
+
},
|
|
67
|
+
// 是否在即将到达目标数值的时候,使用缓慢滚动的效果
|
|
68
|
+
isEase: {
|
|
69
|
+
type: Boolean,
|
|
70
|
+
default: countUp.isEase
|
|
71
|
+
},
|
|
72
|
+
// 字体颜色
|
|
73
|
+
fontColor: {
|
|
74
|
+
type: String,
|
|
75
|
+
default: countUp.fontColor
|
|
76
|
+
},
|
|
77
|
+
// 字体大小
|
|
78
|
+
fontSize: {
|
|
79
|
+
type: [Number, String],
|
|
80
|
+
default: countUp.fontSize
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
data() {
|
|
84
|
+
return {
|
|
85
|
+
startNumCache: this.startNum,
|
|
86
|
+
showingVal: this.formatNumber(this.startNum),
|
|
87
|
+
printVal: null,
|
|
88
|
+
isPaused: false, // 是否暂停
|
|
89
|
+
durationCache: Number(this.duration),
|
|
90
|
+
startTime: null, // 开始的时间
|
|
91
|
+
timestamp: null, // 时间戳
|
|
92
|
+
remaining: null, // 停留的时间
|
|
93
|
+
timer: null,
|
|
94
|
+
lastTime: 0 // 上一次的时间
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
computed: {
|
|
98
|
+
countDown() {
|
|
99
|
+
return this.startNum > this.endNum
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
watch: {
|
|
103
|
+
startNum() {
|
|
104
|
+
this.autoplay && this.start()
|
|
105
|
+
},
|
|
106
|
+
endNum() {
|
|
107
|
+
this.autoplay && this.start()
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
mounted() {
|
|
111
|
+
this.autoplay && this.start()
|
|
112
|
+
},
|
|
113
|
+
methods: {
|
|
114
|
+
easingFn(t, b, c, d) {
|
|
115
|
+
return (c * (-Math.pow(2, (-10 * t) / d) + 1) * 1024) / 1023 + b
|
|
116
|
+
},
|
|
117
|
+
requestTimeout(callback) {
|
|
118
|
+
const currTime = new Date().getTime()
|
|
119
|
+
// 为了使setTimteout的尽可能的接近每秒60帧的效果
|
|
120
|
+
const timeToCall = Math.max(0, 16 - (currTime - this.lastTime)) // 计算当前一帧内还剩多少时间
|
|
121
|
+
const id = setTimeout(() => {
|
|
122
|
+
callback(currTime + timeToCall)
|
|
123
|
+
}, timeToCall)
|
|
124
|
+
this.lastTime = currTime + timeToCall
|
|
125
|
+
return id
|
|
126
|
+
},
|
|
127
|
+
// 开始滚动数字
|
|
128
|
+
start() {
|
|
129
|
+
this.startNumCache = this.startNum
|
|
130
|
+
this.startTime = null
|
|
131
|
+
this.durationCache = this.duration
|
|
132
|
+
this.isPaused = false
|
|
133
|
+
this.timer = this.requestTimeout(this.count)
|
|
134
|
+
},
|
|
135
|
+
// 暂定状态,重新再开始滚动;或者滚动状态下,暂停
|
|
136
|
+
reStart() {
|
|
137
|
+
if (this.isPaused) {
|
|
138
|
+
this.resume()
|
|
139
|
+
this.isPaused = false
|
|
140
|
+
} else {
|
|
141
|
+
this.stop()
|
|
142
|
+
this.isPaused = true
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
// 暂停
|
|
146
|
+
stop() {
|
|
147
|
+
clearTimeout(this.timer)
|
|
148
|
+
},
|
|
149
|
+
// 重新开始(暂停的情况下)
|
|
150
|
+
resume() {
|
|
151
|
+
this.startTime = null
|
|
152
|
+
this.durationCache = this.remaining
|
|
153
|
+
this.startNumCache = this.printVal
|
|
154
|
+
this.requestTimeout(this.count)
|
|
155
|
+
},
|
|
156
|
+
// 重置
|
|
157
|
+
reset() {
|
|
158
|
+
this.startTime = null
|
|
159
|
+
clearTimeout(this.timer)
|
|
160
|
+
this.showingVal = this.formatNumber(this.startNum)
|
|
161
|
+
},
|
|
162
|
+
count(timestamp) {
|
|
163
|
+
if (!this.startTime) this.startTime = timestamp
|
|
164
|
+
this.timestamp = timestamp
|
|
165
|
+
const progress = timestamp - this.startTime
|
|
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)
|
|
172
|
+
} else {
|
|
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)
|
|
182
|
+
}
|
|
183
|
+
this.printVal = this.countDown
|
|
184
|
+
? Math.max(this.printVal, this.endNum)
|
|
185
|
+
: Math.min(this.printVal, this.endNum)
|
|
186
|
+
this.showingVal = this.formatNumber(this.printVal)
|
|
187
|
+
if (progress < this.durationCache) {
|
|
188
|
+
this.timer = this.requestTimeout(this.count)
|
|
189
|
+
} else {
|
|
190
|
+
this.$emit('end')
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
// 判断是否数字
|
|
194
|
+
isNumber(val) {
|
|
195
|
+
return !isNaN(parseFloat(val))
|
|
196
|
+
},
|
|
197
|
+
formatNumber(num) {
|
|
198
|
+
num = Number(num)
|
|
199
|
+
num = num.toFixed(Number(this.decimals))
|
|
200
|
+
return this.$pi.format.numFormat(num, this.decimals, this.thousands)
|
|
201
|
+
},
|
|
202
|
+
destroyed() {
|
|
203
|
+
clearTimeout(this.timer)
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
</script>
|
|
208
|
+
|
|
209
|
+
<style lang="scss" scoped></style>
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view class="dropdown-tab-item" :class="[{ opened: item.opened }]">
|
|
3
|
+
<!-- 注意:slot内不能使用父组件data -->
|
|
4
|
+
<view
|
|
5
|
+
class="pi-align-center"
|
|
6
|
+
:style="{ color: item.opened && item.activeColor ? item.activeColor : 'inherit' }"
|
|
7
|
+
@tap.stop="handleClick"
|
|
8
|
+
>
|
|
9
|
+
<pi-icon
|
|
10
|
+
v-if="item.showIcon"
|
|
11
|
+
:name="item.iconOption.name"
|
|
12
|
+
:dot="item.iconOption.dot"
|
|
13
|
+
:badge="item.iconOption.badge"
|
|
14
|
+
:color="item.iconOption.color"
|
|
15
|
+
:size="item.iconOption.size"
|
|
16
|
+
:class-prefix="item.iconOption.classPrefix"
|
|
17
|
+
:custom-style="item.iconOption.customStyle"
|
|
18
|
+
:custom-class="`pi-mg-right-8 ${item.iconOption.customClass}`"
|
|
19
|
+
/>
|
|
20
|
+
|
|
21
|
+
<text class=" pi-pd-right-8 pi-fz-28">
|
|
22
|
+
{{ item.text }}
|
|
23
|
+
</text>
|
|
24
|
+
<pi-icon :class="{ rotate: item.opened }" name="unfold" size="26" />
|
|
25
|
+
</view>
|
|
26
|
+
</view>
|
|
27
|
+
</template>
|
|
28
|
+
|
|
29
|
+
<script>
|
|
30
|
+
const TAG = 'PiDropdownTab'
|
|
31
|
+
|
|
32
|
+
export default {
|
|
33
|
+
name: TAG,
|
|
34
|
+
props: {
|
|
35
|
+
item: {
|
|
36
|
+
required: true,
|
|
37
|
+
default() {
|
|
38
|
+
return {}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
methods: {
|
|
43
|
+
handleClick() {
|
|
44
|
+
this.$emit('click', this.item)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
</script>
|
|
49
|
+
|
|
50
|
+
<style lang="scss" scoped>
|
|
51
|
+
.dropdown-tab-item {
|
|
52
|
+
font-size: 33rpx;
|
|
53
|
+
&.opened {
|
|
54
|
+
color: $pi-primary-color;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.rotate {
|
|
59
|
+
transition: all $pi-animation-duration $pi-animation-timing-function;
|
|
60
|
+
transform: rotate(180deg);
|
|
61
|
+
}
|
|
62
|
+
</style>
|