sadais-piui 1.2.7-beta14 → 1.2.7-beta15
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.
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
:style="{
|
|
13
13
|
width: widthPx + 'px',
|
|
14
14
|
height: widthPx + 'px',
|
|
15
|
-
backgroundColor: bgColor
|
|
15
|
+
backgroundColor: bgColor
|
|
16
16
|
}"
|
|
17
17
|
>
|
|
18
18
|
<canvas
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
class="pi-canvas-bg"
|
|
22
22
|
:style="{
|
|
23
23
|
width: widthPx + 'px',
|
|
24
|
-
height: widthPx + 'px'
|
|
24
|
+
height: widthPx + 'px'
|
|
25
25
|
}"
|
|
26
26
|
/>
|
|
27
27
|
<canvas
|
|
@@ -30,82 +30,84 @@
|
|
|
30
30
|
class="pi-canvas"
|
|
31
31
|
:style="{
|
|
32
32
|
width: widthPx + 'px',
|
|
33
|
-
height: widthPx + 'px'
|
|
33
|
+
height: widthPx + 'px'
|
|
34
34
|
}"
|
|
35
35
|
/>
|
|
36
36
|
</view>
|
|
37
37
|
</template>
|
|
38
38
|
<script>
|
|
39
|
-
import { getConfig } from
|
|
40
|
-
const { circleProgress } = getConfig()
|
|
39
|
+
import { getConfig } from '../../config'
|
|
40
|
+
const { circleProgress } = getConfig()
|
|
41
41
|
|
|
42
42
|
export default {
|
|
43
|
-
name:
|
|
43
|
+
name: 'PiCircleProgress',
|
|
44
44
|
props: {
|
|
45
45
|
// 圆环进度百分比值
|
|
46
46
|
percent: {
|
|
47
47
|
type: Number,
|
|
48
48
|
default: circleProgress.percent,
|
|
49
49
|
// 限制值在0到100之间
|
|
50
|
-
validator:
|
|
51
|
-
return val >= 0 && val <= 100
|
|
52
|
-
}
|
|
50
|
+
validator: val => {
|
|
51
|
+
return val >= 0 && val <= 100
|
|
52
|
+
}
|
|
53
53
|
},
|
|
54
54
|
// 整个圆环进度区域的背景色
|
|
55
55
|
bgColor: {
|
|
56
56
|
type: String,
|
|
57
|
-
default: circleProgress.bgColor
|
|
57
|
+
default: circleProgress.bgColor
|
|
58
58
|
},
|
|
59
59
|
// 底部圆环的颜色(灰色的圆环)
|
|
60
60
|
inactiveColor: {
|
|
61
61
|
type: String,
|
|
62
|
-
default: circleProgress.inactiveColor
|
|
62
|
+
default: circleProgress.inactiveColor
|
|
63
63
|
},
|
|
64
64
|
// 圆环激活部分的颜色
|
|
65
65
|
activeColor: {
|
|
66
66
|
type: String,
|
|
67
|
-
default: circleProgress.activeColor
|
|
67
|
+
default: circleProgress.activeColor
|
|
68
68
|
},
|
|
69
69
|
// 圆环线条的宽度,单位rpx
|
|
70
70
|
borderWidth: {
|
|
71
71
|
type: [Number, String],
|
|
72
|
-
default: circleProgress.borderWidth
|
|
72
|
+
default: circleProgress.borderWidth
|
|
73
73
|
},
|
|
74
74
|
// 整个圆形的宽度,单位rpx
|
|
75
75
|
width: {
|
|
76
76
|
type: [Number, String],
|
|
77
|
-
default: circleProgress.width
|
|
77
|
+
default: circleProgress.width
|
|
78
78
|
},
|
|
79
79
|
// 整个圆环执行一圈的时间,单位ms
|
|
80
80
|
duration: {
|
|
81
81
|
type: [Number, String],
|
|
82
|
-
default: circleProgress.duration
|
|
82
|
+
default: circleProgress.duration
|
|
83
83
|
},
|
|
84
84
|
// 主题类型
|
|
85
85
|
type: {
|
|
86
86
|
type: String,
|
|
87
|
-
default: circleProgress.type
|
|
87
|
+
default: circleProgress.type
|
|
88
88
|
},
|
|
89
89
|
|
|
90
90
|
// 字体大小
|
|
91
91
|
fontSize: {
|
|
92
92
|
type: String,
|
|
93
|
-
default: circleProgress.fontSize
|
|
93
|
+
default: circleProgress.fontSize
|
|
94
94
|
},
|
|
95
95
|
// 显示的文字 默认为空
|
|
96
96
|
text: {
|
|
97
97
|
type: String,
|
|
98
|
-
default: circleProgress.text
|
|
98
|
+
default: circleProgress.text
|
|
99
99
|
},
|
|
100
100
|
linearGradient: {
|
|
101
101
|
type: Object,
|
|
102
|
-
default
|
|
103
|
-
|
|
102
|
+
default() {
|
|
103
|
+
return circleProgress.linearGradient
|
|
104
|
+
}
|
|
105
|
+
}
|
|
104
106
|
},
|
|
105
107
|
data() {
|
|
106
108
|
return {
|
|
107
|
-
elBgId:
|
|
108
|
-
elId:
|
|
109
|
+
// elBgId: 'pCircleProgressBgId', // 微信小程序中不能使用this.$pi形式动态生成id值,否则会报错
|
|
110
|
+
// elId: 'pCircleProgressElId',
|
|
109
111
|
elBgId: this.$pi.guid(), // 支付宝等小程序 动态生产ID
|
|
110
112
|
elId: this.$pi.guid(),
|
|
111
113
|
progressContext: null,
|
|
@@ -114,80 +116,71 @@ export default {
|
|
|
114
116
|
borderWidthPx: uni.upx2px(this.borderWidth), // 转成px后的圆环的宽度
|
|
115
117
|
startAngle: -Math.PI / 2, // canvas画圆的起始角度,默认为3点钟方向,定位到12点钟方向
|
|
116
118
|
newPercent: 0, // 当动态修改进度值的时候,保存进度值的变化前后值,用于比较用
|
|
117
|
-
oldPercent: 0
|
|
118
|
-
}
|
|
119
|
+
oldPercent: 0 // 当动态修改进度值的时候,保存进度值的变化前后值,用于比较用
|
|
120
|
+
}
|
|
119
121
|
},
|
|
120
122
|
computed: {
|
|
121
123
|
// 有type主题时,优先起作用
|
|
122
124
|
circleColor() {
|
|
123
|
-
if (
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
return this.$u.color[this.type];
|
|
128
|
-
else return this.activeColor;
|
|
129
|
-
},
|
|
125
|
+
if (['success', 'error', 'info', 'primary', 'warning'].indexOf(this.type) >= 0)
|
|
126
|
+
return this.$u.color[this.type]
|
|
127
|
+
else return this.activeColor
|
|
128
|
+
}
|
|
130
129
|
},
|
|
131
130
|
watch: {
|
|
132
131
|
// 深度监听进度
|
|
133
132
|
percent(nVal, oVal = 0) {
|
|
134
|
-
if (nVal > 100) nVal = 100
|
|
135
|
-
if (nVal < 0) oVal = 0
|
|
133
|
+
if (nVal > 100) nVal = 100
|
|
134
|
+
if (nVal < 0) oVal = 0
|
|
136
135
|
// 此值其实等于this.percent,命名一个新值
|
|
137
|
-
this.newPercent = nVal
|
|
138
|
-
this.oldPercent = oVal
|
|
136
|
+
this.newPercent = nVal
|
|
137
|
+
this.oldPercent = oVal
|
|
139
138
|
setTimeout(() => {
|
|
140
139
|
// 无论是百分比值增加还是减少,需要操作还是原来的旧的百分比值
|
|
141
140
|
// 将此值减少或者新增到新的百分比值
|
|
142
|
-
this.drawCircleByProgress(oVal)
|
|
143
|
-
}, 50)
|
|
144
|
-
}
|
|
141
|
+
this.drawCircleByProgress(oVal)
|
|
142
|
+
}, 50)
|
|
143
|
+
}
|
|
145
144
|
},
|
|
146
145
|
mounted() {
|
|
147
146
|
// 背景圆
|
|
148
|
-
this.drawProgressBg()
|
|
147
|
+
this.drawProgressBg()
|
|
149
148
|
setTimeout(() => {
|
|
150
149
|
// 进度圆
|
|
151
|
-
this.drawCircleByProgress(this.percent)
|
|
152
|
-
}, 500)
|
|
150
|
+
this.drawCircleByProgress(this.percent)
|
|
151
|
+
}, 500)
|
|
153
152
|
},
|
|
154
153
|
created() {
|
|
155
|
-
this.newPercent = this.percent
|
|
156
|
-
this.oldPercent = 0
|
|
154
|
+
this.newPercent = this.percent
|
|
155
|
+
this.oldPercent = 0
|
|
157
156
|
},
|
|
158
157
|
methods: {
|
|
159
158
|
drawProgressBg() {
|
|
160
|
-
console.log(this)
|
|
161
|
-
let ctx = uni.createCanvasContext(this.elBgId, this)
|
|
162
|
-
ctx.setLineWidth(this.borderWidthPx)
|
|
163
|
-
ctx.setStrokeStyle(this.inactiveColor)
|
|
164
|
-
ctx.beginPath()
|
|
159
|
+
console.log(this)
|
|
160
|
+
let ctx = uni.createCanvasContext(this.elBgId, this)
|
|
161
|
+
ctx.setLineWidth(this.borderWidthPx) // 设置圆环宽度
|
|
162
|
+
ctx.setStrokeStyle(this.inactiveColor) // 线条颜色
|
|
163
|
+
ctx.beginPath() // 开描绘路径
|
|
165
164
|
// 设置一个原点(110,110),半径为100的圆的路径到当前路径
|
|
166
|
-
let radius = this.widthPx / 2
|
|
165
|
+
let radius = this.widthPx / 2
|
|
167
166
|
// 用于绘制圆弧context.arc(x坐标,y坐标,半径,起始角度,终止角度,顺时针/逆时针)
|
|
168
|
-
ctx.arc(
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
radius - this.borderWidthPx,
|
|
172
|
-
0,
|
|
173
|
-
2 * Math.PI,
|
|
174
|
-
false
|
|
175
|
-
);
|
|
176
|
-
ctx.stroke(); // 对路径进行描绘
|
|
177
|
-
ctx.draw();
|
|
167
|
+
ctx.arc(radius, radius, radius - this.borderWidthPx, 0, 2 * Math.PI, false)
|
|
168
|
+
ctx.stroke() // 对路径进行描绘
|
|
169
|
+
ctx.draw()
|
|
178
170
|
},
|
|
179
171
|
// 激活部分
|
|
180
172
|
drawCircleByProgress(progress) {
|
|
181
173
|
// 第一次操作进度环时将上下文保存到了this.data中,直接使用即可
|
|
182
|
-
let ctx = this.progressContext
|
|
174
|
+
let ctx = this.progressContext
|
|
183
175
|
if (!ctx) {
|
|
184
|
-
ctx = uni.createCanvasContext(this.elId, this)
|
|
185
|
-
this.progressContext = ctx
|
|
176
|
+
ctx = uni.createCanvasContext(this.elId, this)
|
|
177
|
+
this.progressContext = ctx
|
|
186
178
|
}
|
|
179
|
+
let radius = this.widthPx / 2
|
|
187
180
|
// 表示进度的两端为圆形
|
|
188
|
-
ctx.setLineCap(
|
|
181
|
+
ctx.setLineCap('round')
|
|
189
182
|
// 设置线条的宽度和颜色
|
|
190
|
-
ctx.setLineWidth(this.borderWidthPx)
|
|
183
|
+
ctx.setLineWidth(this.borderWidthPx)
|
|
191
184
|
if (
|
|
192
185
|
this.linearGradient &&
|
|
193
186
|
this.linearGradient.show &&
|
|
@@ -195,85 +188,75 @@ export default {
|
|
|
195
188
|
) {
|
|
196
189
|
// this.imageData.slice(pos * 4, pos * 4 + 4);
|
|
197
190
|
let colorData = this.createColorData()
|
|
198
|
-
for(let i = 0;i < progress;i++){
|
|
199
|
-
const index= Math.round(i*255/progress)
|
|
200
|
-
const color = colorData.slice(index * 4,index * 4 + 4)
|
|
191
|
+
for (let i = 0; i < progress; i++) {
|
|
192
|
+
const index = Math.round((i * 255) / progress)
|
|
193
|
+
const color = colorData.slice(index * 4, index * 4 + 4)
|
|
201
194
|
ctx.beginPath()
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
let
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
radius - this.borderWidthPx,
|
|
210
|
-
startAngle,
|
|
211
|
-
endAngle,
|
|
212
|
-
false
|
|
213
|
-
);
|
|
214
|
-
ctx.stroke();
|
|
195
|
+
|
|
196
|
+
ctx.setStrokeStyle(`rgba(${color[0]},${color[1]},${color[2]},${color[3] / 255})`)
|
|
197
|
+
ctx.globalAlpha = color[3] / 255
|
|
198
|
+
let endAngle = ((2 * Math.PI) / 100) * (i + 1) + this.startAngle
|
|
199
|
+
let startAngle = this.startAngle + ((2 * Math.PI) / 100) * i
|
|
200
|
+
ctx.arc(radius, radius, radius - this.borderWidthPx, startAngle, endAngle, false)
|
|
201
|
+
ctx.stroke()
|
|
215
202
|
}
|
|
216
203
|
} else {
|
|
217
|
-
ctx.setStrokeStyle(this.circleColor)
|
|
204
|
+
ctx.setStrokeStyle(this.circleColor)
|
|
218
205
|
// 结束角的计算依据为:将2π分为100份,乘以当前的进度值,得出终止点的弧度值,加起始角,为整个圆从默认的
|
|
219
206
|
// 3点钟方向开始画图,转为更好理解的12点钟方向开始作图,这需要起始角和终止角同时加上this.startAngle值
|
|
220
|
-
let endAngle = ((2 * Math.PI) / 100) * progress + this.startAngle
|
|
221
|
-
ctx.beginPath()
|
|
207
|
+
let endAngle = ((2 * Math.PI) / 100) * progress + this.startAngle
|
|
208
|
+
ctx.beginPath()
|
|
222
209
|
// 半径为整个canvas宽度的一半
|
|
223
|
-
|
|
224
|
-
ctx.
|
|
225
|
-
radius,
|
|
226
|
-
radius,
|
|
227
|
-
radius - this.borderWidthPx,
|
|
228
|
-
this.startAngle,
|
|
229
|
-
endAngle,
|
|
230
|
-
false
|
|
231
|
-
);
|
|
232
|
-
ctx.stroke();
|
|
210
|
+
ctx.arc(radius, radius, radius - this.borderWidthPx, this.startAngle, endAngle, false)
|
|
211
|
+
ctx.stroke()
|
|
233
212
|
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
213
|
+
ctx.beginPath()
|
|
214
|
+
ctx.textAlign = 'center'
|
|
215
|
+
ctx.textBaseline = 'middle'
|
|
216
|
+
ctx.font = this.fontSize + ' Arial'
|
|
217
|
+
ctx.fillText(this.text, radius, radius)
|
|
218
|
+
ctx.stroke()
|
|
219
|
+
ctx.draw()
|
|
220
|
+
|
|
238
221
|
// 将总过渡时间除以100,得出每修改百分之一进度所需的时间
|
|
239
|
-
let time = Math.floor(this.duration / 100)
|
|
240
|
-
ctx.draw();
|
|
222
|
+
let time = Math.floor(this.duration / 100)
|
|
241
223
|
// 如果变更后新值大于旧值,意味着增大了百分比
|
|
242
224
|
if (this.newPercent > this.oldPercent) {
|
|
243
225
|
// 每次递增百分之一
|
|
244
|
-
progress
|
|
226
|
+
progress++
|
|
245
227
|
// 如果新增后的值,大于需要设置的值百分比值,停止继续增加
|
|
246
|
-
if (progress > this.newPercent) return
|
|
228
|
+
if (progress > this.newPercent) return
|
|
247
229
|
} else {
|
|
248
230
|
// 同理于上面
|
|
249
|
-
progress
|
|
250
|
-
if (progress < this.newPercent) return
|
|
231
|
+
progress--
|
|
232
|
+
if (progress < this.newPercent) return
|
|
251
233
|
}
|
|
252
234
|
setTimeout(() => {
|
|
253
235
|
// 定时器,每次操作间隔为time值,为了让进度条有动画效果
|
|
254
|
-
this.drawCircleByProgress(progress)
|
|
255
|
-
}, time)
|
|
236
|
+
this.drawCircleByProgress(progress)
|
|
237
|
+
}, time)
|
|
256
238
|
},
|
|
257
|
-
createColorData(){
|
|
239
|
+
createColorData() {
|
|
240
|
+
let canvas
|
|
258
241
|
// #ifndef MP-WEIXIN
|
|
259
|
-
|
|
242
|
+
canvas = document.createElement('canvas')
|
|
260
243
|
canvas.width = 256
|
|
261
244
|
canvas.height = 1
|
|
262
|
-
let ctx = canvas.getContext('2d')
|
|
245
|
+
let ctx = canvas.getContext('2d')
|
|
263
246
|
// #endif
|
|
264
|
-
//ifdef MP-WEIXIN
|
|
265
|
-
|
|
247
|
+
// #ifdef MP-WEIXIN
|
|
248
|
+
canvas = uni.createOffscreenCanvas({ type: '2d', width: 256, height: 1 })
|
|
266
249
|
// #endif
|
|
267
|
-
const linearGradient =
|
|
250
|
+
const linearGradient = ctx.createLinearGradient(0, 0, 256, 1)
|
|
268
251
|
this.linearGradient.colorStop.forEach(color => {
|
|
269
|
-
linearGradient.addColorStop(color.percent,color.value)
|
|
252
|
+
linearGradient.addColorStop(color.percent, color.value)
|
|
270
253
|
})
|
|
271
254
|
ctx.fillStyle = linearGradient
|
|
272
|
-
ctx.fillRect(0,0,256,1)
|
|
273
|
-
return ctx.getImageData(0,0,256,1).data
|
|
255
|
+
ctx.fillRect(0, 0, 256, 1)
|
|
256
|
+
return ctx.getImageData(0, 0, 256, 1).data
|
|
274
257
|
}
|
|
275
|
-
}
|
|
276
|
-
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
277
260
|
</script>
|
|
278
261
|
<style scoped lang="scss">
|
|
279
262
|
.circle-progress {
|
package/config/circleProgress.js
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
export default {
|
|
2
|
-
percent:50,
|
|
3
|
-
bgColor:'#ffffff', // 环形进度区域背景色,字符串形式,默认值:'#ffffff'
|
|
2
|
+
percent: 50, // 环形进度条,限制0-100之间,数字形式,默认值:50
|
|
3
|
+
bgColor: '#ffffff', // 环形进度区域背景色,字符串形式,默认值:'#ffffff'
|
|
4
4
|
inactiveColor: '#ececec', // 环形进度条底色,字符串形式,默认值:'#ececec'
|
|
5
5
|
activeColor: '#19be6b', // 环形进度条激活的颜色,字符串形式,默认值:'#19be6b'
|
|
6
|
-
borderWidth:14,
|
|
7
|
-
width:200
|
|
6
|
+
borderWidth: 14, // 环形进度条的线条宽度,字符串/数字形式,默认值:14
|
|
7
|
+
width: 200, // 环形进度条整个圆的宽度,字符串/数字形式,默认值:200
|
|
8
8
|
duration: 1500, // 整个圆环执行至进度条所需的时间,单位ms,字符串/数字形式,默认值:1500
|
|
9
|
-
type:''
|
|
10
|
-
fontSize:'16px'
|
|
11
|
-
text:''
|
|
12
|
-
linearGradient:{
|
|
13
|
-
show:false,
|
|
14
|
-
colorStop:[]
|
|
15
|
-
}
|
|
9
|
+
type: '', // 环形进度条的主题
|
|
10
|
+
fontSize: '16px', // 环形进度条中间显示文字的大小,字符串形式,默认值:'16px'
|
|
11
|
+
text: '' // 环形进度条中间显示的文字,字符串形式,默认值:''
|
|
16
12
|
}
|