sadais-piui 1.2.7-beta67 → 1.2.7-beta68
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/components/pi-calendar/index.vue +187 -186
- package/components/pi-circle-progress/index.vue +135 -110
- package/package.json +1 -1
|
@@ -1,186 +1,187 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<pi-popup
|
|
3
|
-
ref="popup"
|
|
4
|
-
:value="val"
|
|
5
|
-
:custom-class="getPopup.customClass"
|
|
6
|
-
:custom-style="getPopup.customStyle"
|
|
7
|
-
:position="getPopup.position"
|
|
8
|
-
:border-radius="getPopup.borderRadius"
|
|
9
|
-
:show-close-icon="showTitle && getPopup.showCloseIcon"
|
|
10
|
-
:close-icon="getPopup.closeIcon"
|
|
11
|
-
:safe-area-inset-bottom="getPopup.safeAreaInsetBottom"
|
|
12
|
-
:mask="getPopup.mask"
|
|
13
|
-
:hide-tab-bar="getPopup.hideTabBar"
|
|
14
|
-
:append-to-body="getPopup.appendToBody"
|
|
15
|
-
:z-index="getPopup.zIndex"
|
|
16
|
-
:background="getPopup.background"
|
|
17
|
-
@close="handlePopupClose"
|
|
18
|
-
@closed="$emit('closed', $event)"
|
|
19
|
-
@show="$emit('show', $event)"
|
|
20
|
-
@showed="$emit('showed', $event)"
|
|
21
|
-
>
|
|
22
|
-
<view class="pi-calendar" :style="[customStyle]" :class="[customClass]">
|
|
23
|
-
<!-- 标题栏 -->
|
|
24
|
-
<view class="pi-justify-center pi-fz-32 pi-fw-500" :style="[{ padding: getTitlePadding }]">
|
|
25
|
-
<slot v-if="$slots.title" name="title" />
|
|
26
|
-
<template v-else>{{ title }}</template>
|
|
27
|
-
</view>
|
|
28
|
-
<pi-calendar-panel
|
|
29
|
-
v-model="calendarValue"
|
|
30
|
-
:type="getCalendarPanel.type"
|
|
31
|
-
:min-year="getCalendarPanel.minYear"
|
|
32
|
-
:max-year="getCalendarPanel.maxYear"
|
|
33
|
-
:min-date="getCalendarPanel.minDate"
|
|
34
|
-
:max-date="getCalendarPanel.maxDate"
|
|
35
|
-
:show-back-today="getCalendarPanel.showBackToday"
|
|
36
|
-
:today-active-border-color="getCalendarPanel.todayActiveBorderColor"
|
|
37
|
-
:active-color="getCalendarPanel.activeColor"
|
|
38
|
-
:active-bg="getCalendarPanel.activeBg"
|
|
39
|
-
:active-border-radius="getCalendarPanel.activeBorderRadius"
|
|
40
|
-
:range-color="getCalendarPanel.rangeColor"
|
|
41
|
-
:range-bg="getCalendarPanel.rangeBg"
|
|
42
|
-
:start-text="getCalendarPanel.startText"
|
|
43
|
-
:end-text="getCalendarPanel.endText"
|
|
44
|
-
:
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
<
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
</
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
import
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
this
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
*
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
this.
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
1
|
+
<template>
|
|
2
|
+
<pi-popup
|
|
3
|
+
ref="popup"
|
|
4
|
+
:value="val"
|
|
5
|
+
:custom-class="getPopup.customClass"
|
|
6
|
+
:custom-style="getPopup.customStyle"
|
|
7
|
+
:position="getPopup.position"
|
|
8
|
+
:border-radius="getPopup.borderRadius"
|
|
9
|
+
:show-close-icon="showTitle && getPopup.showCloseIcon"
|
|
10
|
+
:close-icon="getPopup.closeIcon"
|
|
11
|
+
:safe-area-inset-bottom="getPopup.safeAreaInsetBottom"
|
|
12
|
+
:mask="getPopup.mask"
|
|
13
|
+
:hide-tab-bar="getPopup.hideTabBar"
|
|
14
|
+
:append-to-body="getPopup.appendToBody"
|
|
15
|
+
:z-index="getPopup.zIndex"
|
|
16
|
+
:background="getPopup.background"
|
|
17
|
+
@close="handlePopupClose"
|
|
18
|
+
@closed="$emit('closed', $event)"
|
|
19
|
+
@show="$emit('show', $event)"
|
|
20
|
+
@showed="$emit('showed', $event)"
|
|
21
|
+
>
|
|
22
|
+
<view class="pi-calendar" :style="[customStyle]" :class="[customClass]">
|
|
23
|
+
<!-- 标题栏 -->
|
|
24
|
+
<view class="pi-justify-center pi-fz-32 pi-fw-500" :style="[{ padding: getTitlePadding }]">
|
|
25
|
+
<slot v-if="$slots.title" name="title" />
|
|
26
|
+
<template v-else>{{ title }}</template>
|
|
27
|
+
</view>
|
|
28
|
+
<pi-calendar-panel
|
|
29
|
+
v-model="calendarValue"
|
|
30
|
+
:type="getCalendarPanel.type"
|
|
31
|
+
:min-year="getCalendarPanel.minYear"
|
|
32
|
+
:max-year="getCalendarPanel.maxYear"
|
|
33
|
+
:min-date="getCalendarPanel.minDate"
|
|
34
|
+
:max-date="getCalendarPanel.maxDate"
|
|
35
|
+
:show-back-today="getCalendarPanel.showBackToday"
|
|
36
|
+
:today-active-border-color="getCalendarPanel.todayActiveBorderColor"
|
|
37
|
+
:active-color="getCalendarPanel.activeColor"
|
|
38
|
+
:active-bg="getCalendarPanel.activeBg"
|
|
39
|
+
:active-border-radius="getCalendarPanel.activeBorderRadius"
|
|
40
|
+
:range-color="getCalendarPanel.rangeColor"
|
|
41
|
+
:range-bg="getCalendarPanel.rangeBg"
|
|
42
|
+
:start-text="getCalendarPanel.startText"
|
|
43
|
+
:end-text="getCalendarPanel.endText"
|
|
44
|
+
:marks="getCalendarPanel.marks"
|
|
45
|
+
:date-format="getCalendarPanel.dateFormat"
|
|
46
|
+
@date-change="$emit('date-change', $event)"
|
|
47
|
+
/>
|
|
48
|
+
<!-- footer -->
|
|
49
|
+
<view class="pi-w-100P pi-align-center pi-pd-24 pi-solid-top-1">
|
|
50
|
+
<view class="pi-flex-sub pi-fz-30 pi-fw-500">{{ getDisplayValue }}</view>
|
|
51
|
+
<pi-button type="primary" size="medium" @click="handleConfirm">确定</pi-button>
|
|
52
|
+
</view>
|
|
53
|
+
</view>
|
|
54
|
+
</pi-popup>
|
|
55
|
+
</template>
|
|
56
|
+
|
|
57
|
+
<script>
|
|
58
|
+
import ValueSync from '../../mixin/value-sync'
|
|
59
|
+
import { getConfig } from '../../config'
|
|
60
|
+
|
|
61
|
+
const TAG = 'PiCalendar'
|
|
62
|
+
const { calendar } = getConfig()
|
|
63
|
+
|
|
64
|
+
export default {
|
|
65
|
+
name: 'PiCalendar',
|
|
66
|
+
// 混入v-model
|
|
67
|
+
mixins: [ValueSync],
|
|
68
|
+
props: {
|
|
69
|
+
// 初始值
|
|
70
|
+
value: {
|
|
71
|
+
required: false
|
|
72
|
+
},
|
|
73
|
+
// 自定义样式,对象形式
|
|
74
|
+
customStyle: {
|
|
75
|
+
type: Object,
|
|
76
|
+
// {}
|
|
77
|
+
default() {
|
|
78
|
+
return calendar.customStyle
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
// 自定义样式类,字符串形式
|
|
82
|
+
customClass: {
|
|
83
|
+
type: String,
|
|
84
|
+
// ''
|
|
85
|
+
default() {
|
|
86
|
+
return calendar.customClass
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
// 是否显示title
|
|
90
|
+
showTitle: {
|
|
91
|
+
type: Boolean,
|
|
92
|
+
// true
|
|
93
|
+
default: calendar.showTitle
|
|
94
|
+
},
|
|
95
|
+
// 标题
|
|
96
|
+
title: {
|
|
97
|
+
type: String,
|
|
98
|
+
// '日期选择'
|
|
99
|
+
default: calendar.title
|
|
100
|
+
},
|
|
101
|
+
// 标题 padding
|
|
102
|
+
titlePadding: {
|
|
103
|
+
type: [String, Number],
|
|
104
|
+
// 24
|
|
105
|
+
default: calendar.titlePadding
|
|
106
|
+
},
|
|
107
|
+
// 日历面板参数设置
|
|
108
|
+
calendarPanel: {
|
|
109
|
+
type: Object,
|
|
110
|
+
default() {
|
|
111
|
+
// 参照calendarPanel
|
|
112
|
+
return calendar.calendarPanel
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
// 弹窗参数设置
|
|
116
|
+
popup: {
|
|
117
|
+
type: Object,
|
|
118
|
+
default() {
|
|
119
|
+
// 参照popup
|
|
120
|
+
return calendar.popup
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
data() {
|
|
125
|
+
const mergeCalendarPanel = this.$pi.lang.mergeDeep(calendar.calendarPanel, this.calendarPanel)
|
|
126
|
+
return {
|
|
127
|
+
calendarValue: mergeCalendarPanel.value
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
computed: {
|
|
131
|
+
getCalendarPanel() {
|
|
132
|
+
return this.$pi.lang.mergeDeep(calendar.calendarPanel, this.calendarPanel)
|
|
133
|
+
},
|
|
134
|
+
getPopup() {
|
|
135
|
+
return this.$pi.lang.mergeDeep(calendar.popup, this.popup)
|
|
136
|
+
},
|
|
137
|
+
getTitlePadding() {
|
|
138
|
+
return this.$pi.common.addUnit(this.titlePadding)
|
|
139
|
+
},
|
|
140
|
+
getDisplayValue() {
|
|
141
|
+
return [].concat(this.calendarValue).join(' - ')
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
watch: {
|
|
145
|
+
'getCalendarPanel.value'(val) {
|
|
146
|
+
this.calendarValue = val
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
methods: {
|
|
150
|
+
handlePopupClose() {
|
|
151
|
+
this.val = false
|
|
152
|
+
// 关闭
|
|
153
|
+
this.$emit('close')
|
|
154
|
+
this.handleEmitChange()
|
|
155
|
+
},
|
|
156
|
+
/**
|
|
157
|
+
* @vuese
|
|
158
|
+
* 确认选择
|
|
159
|
+
*/
|
|
160
|
+
handleConfirm() {
|
|
161
|
+
this.$emit('confirm', this.calendarValue)
|
|
162
|
+
this.handlePopupClose()
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
</script>
|
|
167
|
+
|
|
168
|
+
<style lang="scss" scoped>
|
|
169
|
+
.pi-calendar {
|
|
170
|
+
max-width: 960rpx;
|
|
171
|
+
margin: 0 auto;
|
|
172
|
+
}
|
|
173
|
+
.date-item {
|
|
174
|
+
position: relative;
|
|
175
|
+
z-index: 2;
|
|
176
|
+
width: calc(100% / 7);
|
|
177
|
+
overflow: hidden;
|
|
178
|
+
}
|
|
179
|
+
.back-today {
|
|
180
|
+
padding: 12rpx 24rpx;
|
|
181
|
+
overflow: hidden;
|
|
182
|
+
font-size: 20rpx;
|
|
183
|
+
color: #ffffff;
|
|
184
|
+
background: $pi-primary-color;
|
|
185
|
+
border-radius: 50rpx 0 0 50rpx;
|
|
186
|
+
}
|
|
187
|
+
</style>
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
<!--
|
|
2
2
|
* @Author: zhouxianpan
|
|
3
3
|
* @Date: 2021-09-06 10:07:33
|
|
4
|
-
* @LastEditTime: 2023-
|
|
4
|
+
* @LastEditTime: 2023-04-13 10:15:03
|
|
5
5
|
* @LastEditors: zhangzhenfei
|
|
6
6
|
* @Description:
|
|
7
|
-
* @FilePath: \piui
|
|
7
|
+
* @FilePath: \piui\components\pi-circle-progress\index.vue
|
|
8
8
|
-->
|
|
9
9
|
<template>
|
|
10
10
|
<view
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
width: parentWidthPx + 'px',
|
|
14
14
|
height: parentWidthPx + 'px',
|
|
15
15
|
backgroundColor: getType.bgColor,
|
|
16
|
-
borderRadius: '50%'
|
|
16
|
+
borderRadius: '50%',
|
|
17
17
|
}"
|
|
18
18
|
>
|
|
19
19
|
<canvas
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
class="pi-canvas-bg"
|
|
23
23
|
:style="{
|
|
24
24
|
width: widthPx + 'px',
|
|
25
|
-
height: widthPx + 'px'
|
|
25
|
+
height: widthPx + 'px',
|
|
26
26
|
}"
|
|
27
27
|
/>
|
|
28
28
|
<canvas
|
|
@@ -31,95 +31,97 @@
|
|
|
31
31
|
class="pi-canvas"
|
|
32
32
|
:style="{
|
|
33
33
|
width: widthPx + 'px',
|
|
34
|
-
height: widthPx + 'px'
|
|
34
|
+
height: widthPx + 'px',
|
|
35
35
|
}"
|
|
36
36
|
/>
|
|
37
37
|
</view>
|
|
38
38
|
</template>
|
|
39
39
|
<script>
|
|
40
|
-
import { getConfig } from
|
|
41
|
-
const { circleProgress } = getConfig()
|
|
40
|
+
import { getConfig } from "../../config";
|
|
41
|
+
const { circleProgress } = getConfig();
|
|
42
42
|
|
|
43
43
|
export default {
|
|
44
|
-
name:
|
|
44
|
+
name: "PiCircleProgress",
|
|
45
45
|
props: {
|
|
46
46
|
// 圆环进度百分比值
|
|
47
47
|
percent: {
|
|
48
48
|
type: Number,
|
|
49
49
|
default: circleProgress.percent,
|
|
50
50
|
// 限制值在0到100之间
|
|
51
|
-
validator: val => {
|
|
52
|
-
return val >= 0 && val <= 100
|
|
53
|
-
}
|
|
51
|
+
validator: (val) => {
|
|
52
|
+
return val >= 0 && val <= 100;
|
|
53
|
+
},
|
|
54
54
|
},
|
|
55
55
|
// 整个圆环进度区域的背景色
|
|
56
56
|
bgColor: {
|
|
57
57
|
type: String,
|
|
58
|
-
default: circleProgress.bgColor
|
|
58
|
+
default: circleProgress.bgColor,
|
|
59
59
|
},
|
|
60
60
|
// 底部圆环的颜色(灰色的圆环)
|
|
61
61
|
inactiveColor: {
|
|
62
62
|
type: String,
|
|
63
|
-
default: circleProgress.inactiveColor
|
|
63
|
+
default: circleProgress.inactiveColor,
|
|
64
64
|
},
|
|
65
65
|
// 圆环激活部分的颜色
|
|
66
66
|
activeColor: {
|
|
67
67
|
type: String,
|
|
68
|
-
default: circleProgress.activeColor
|
|
68
|
+
default: circleProgress.activeColor,
|
|
69
69
|
},
|
|
70
70
|
// 圆环线条的宽度,单位rpx
|
|
71
71
|
borderWidth: {
|
|
72
72
|
type: [Number, String],
|
|
73
|
-
default: circleProgress.borderWidth
|
|
73
|
+
default: circleProgress.borderWidth,
|
|
74
74
|
},
|
|
75
75
|
// 整个圆形的宽度,单位rpx
|
|
76
76
|
width: {
|
|
77
77
|
type: [Number, String],
|
|
78
|
-
default: circleProgress.width
|
|
78
|
+
default: circleProgress.width,
|
|
79
79
|
},
|
|
80
80
|
// 整个圆环执行一圈的时间,单位ms
|
|
81
81
|
duration: {
|
|
82
82
|
type: [Number, String],
|
|
83
|
-
default: circleProgress.duration
|
|
83
|
+
default: circleProgress.duration,
|
|
84
84
|
},
|
|
85
85
|
// 主题类型
|
|
86
86
|
type: {
|
|
87
87
|
type: String,
|
|
88
88
|
default: circleProgress.type,
|
|
89
|
-
validator: function(value) {
|
|
90
|
-
return [
|
|
91
|
-
|
|
89
|
+
validator: function (value) {
|
|
90
|
+
return ["success", "error", "info", "primary", "warning"].includes(
|
|
91
|
+
value
|
|
92
|
+
);
|
|
93
|
+
},
|
|
92
94
|
},
|
|
93
95
|
// 主题列表
|
|
94
96
|
typeList: {
|
|
95
97
|
type: Object,
|
|
96
98
|
default() {
|
|
97
|
-
return circleProgress.typeList
|
|
98
|
-
}
|
|
99
|
+
return circleProgress.typeList;
|
|
100
|
+
},
|
|
99
101
|
},
|
|
100
102
|
|
|
101
103
|
// 字体大小
|
|
102
104
|
fontSize: {
|
|
103
105
|
type: String,
|
|
104
|
-
default: circleProgress.fontSize
|
|
106
|
+
default: circleProgress.fontSize,
|
|
105
107
|
},
|
|
106
108
|
// 显示的文字 默认为空
|
|
107
109
|
text: {
|
|
108
110
|
type: String,
|
|
109
|
-
default: circleProgress.text
|
|
111
|
+
default: circleProgress.text,
|
|
110
112
|
},
|
|
111
113
|
linearGradient: {
|
|
112
114
|
type: Object,
|
|
113
115
|
default() {
|
|
114
|
-
return circleProgress.linearGradient
|
|
115
|
-
}
|
|
116
|
-
}
|
|
116
|
+
return circleProgress.linearGradient;
|
|
117
|
+
},
|
|
118
|
+
},
|
|
117
119
|
},
|
|
118
120
|
data() {
|
|
119
121
|
return {
|
|
120
122
|
// #ifdef MP-WEIXIN
|
|
121
|
-
elBgId:
|
|
122
|
-
elId:
|
|
123
|
+
elBgId: "pCircleProgressBgId", // 微信小程序中不能使用this.$pi形式动态生成id值,否则会报错
|
|
124
|
+
elId: "pCircleProgressElId",
|
|
123
125
|
// #endif
|
|
124
126
|
// #ifndef MP-WEIXIN
|
|
125
127
|
elBgId: this.$pi.guid(), // 支付宝等小程序 动态生产ID
|
|
@@ -132,8 +134,8 @@ export default {
|
|
|
132
134
|
borderWidthPx: uni.upx2px(this.borderWidth), // 转成px后的圆环的宽度
|
|
133
135
|
startAngle: -Math.PI / 2, // canvas画圆的起始角度,默认为3点钟方向,定位到12点钟方向
|
|
134
136
|
newPercent: 0, // 当动态修改进度值的时候,保存进度值的变化前后值,用于比较用
|
|
135
|
-
oldPercent: 0 // 当动态修改进度值的时候,保存进度值的变化前后值,用于比较用
|
|
136
|
-
}
|
|
137
|
+
oldPercent: 0, // 当动态修改进度值的时候,保存进度值的变化前后值,用于比较用
|
|
138
|
+
};
|
|
137
139
|
},
|
|
138
140
|
computed: {
|
|
139
141
|
/**
|
|
@@ -141,14 +143,14 @@ export default {
|
|
|
141
143
|
* 如果有传入 进度条底部颜色、进度条颜色、背景颜色时就使用它们的
|
|
142
144
|
*/
|
|
143
145
|
getType() {
|
|
144
|
-
const { type, inactiveColor, activeColor, bgColor } = this
|
|
145
|
-
const typeData = this.$pi.lang.mergeDeep(
|
|
146
|
+
const { type, inactiveColor, activeColor, bgColor } = this;
|
|
147
|
+
const typeData = this.$pi.lang.mergeDeep(this.typeList[type], {
|
|
146
148
|
inactiveColor,
|
|
147
149
|
activeColor,
|
|
148
|
-
bgColor
|
|
149
|
-
})
|
|
150
|
-
return typeData
|
|
151
|
-
}
|
|
150
|
+
bgColor,
|
|
151
|
+
});
|
|
152
|
+
return typeData;
|
|
153
|
+
},
|
|
152
154
|
// 有type主题时,优先起作用(弃用)
|
|
153
155
|
// circleColor() {
|
|
154
156
|
// if (['success', 'error', 'info', 'primary', 'warning'].indexOf(this.type) >= 0)
|
|
@@ -159,137 +161,160 @@ export default {
|
|
|
159
161
|
watch: {
|
|
160
162
|
// 深度监听进度
|
|
161
163
|
percent(nVal, oVal = 0) {
|
|
162
|
-
if (nVal > 100) nVal = 100
|
|
163
|
-
if (nVal < 0) oVal = 0
|
|
164
|
+
if (nVal > 100) nVal = 100;
|
|
165
|
+
if (nVal < 0) oVal = 0;
|
|
164
166
|
// 此值其实等于this.percent,命名一个新值
|
|
165
|
-
this.newPercent = nVal
|
|
166
|
-
this.oldPercent = oVal
|
|
167
|
+
this.newPercent = nVal;
|
|
168
|
+
this.oldPercent = oVal;
|
|
167
169
|
setTimeout(() => {
|
|
168
170
|
// 无论是百分比值增加还是减少,需要操作还是原来的旧的百分比值
|
|
169
171
|
// 将此值减少或者新增到新的百分比值
|
|
170
|
-
this.drawCircleByProgress(oVal)
|
|
171
|
-
}, 50)
|
|
172
|
-
}
|
|
172
|
+
this.drawCircleByProgress(oVal);
|
|
173
|
+
}, 50);
|
|
174
|
+
},
|
|
173
175
|
},
|
|
174
176
|
mounted() {
|
|
175
177
|
// 背景圆
|
|
176
|
-
this.drawProgressBg()
|
|
178
|
+
this.drawProgressBg();
|
|
177
179
|
setTimeout(() => {
|
|
178
180
|
// 进度圆
|
|
179
|
-
this.drawCircleByProgress(this.percent)
|
|
180
|
-
}, 500)
|
|
181
|
+
this.drawCircleByProgress(this.percent);
|
|
182
|
+
}, 500);
|
|
181
183
|
},
|
|
182
184
|
created() {
|
|
183
|
-
this.newPercent = this.percent
|
|
184
|
-
this.oldPercent = 0
|
|
185
|
+
this.newPercent = this.percent;
|
|
186
|
+
this.oldPercent = 0;
|
|
185
187
|
},
|
|
186
188
|
methods: {
|
|
187
189
|
drawProgressBg() {
|
|
188
190
|
// console.log(this)
|
|
189
|
-
let ctx = uni.createCanvasContext(this.elBgId, this)
|
|
190
|
-
ctx.setLineWidth(this.borderWidthPx) // 设置圆环宽度
|
|
191
|
+
let ctx = uni.createCanvasContext(this.elBgId, this);
|
|
192
|
+
ctx.setLineWidth(this.borderWidthPx); // 设置圆环宽度
|
|
191
193
|
// ctx.setStrokeStyle(this.inactiveColor) // 线条颜色
|
|
192
|
-
ctx.setStrokeStyle(this.getType.inactiveColor) // 线条颜色
|
|
193
|
-
ctx.beginPath() // 开描绘路径
|
|
194
|
+
ctx.setStrokeStyle(this.getType.inactiveColor); // 线条颜色
|
|
195
|
+
ctx.beginPath(); // 开描绘路径
|
|
194
196
|
// 设置一个原点(110,110),半径为100的圆的路径到当前路径
|
|
195
|
-
let radius = this.widthPx / 2
|
|
197
|
+
let radius = this.widthPx / 2;
|
|
196
198
|
// 用于绘制圆弧context.arc(x坐标,y坐标,半径,起始角度,终止角度,顺时针/逆时针)
|
|
197
|
-
ctx.arc(
|
|
198
|
-
|
|
199
|
-
|
|
199
|
+
ctx.arc(
|
|
200
|
+
radius,
|
|
201
|
+
radius,
|
|
202
|
+
radius - this.borderWidthPx,
|
|
203
|
+
0,
|
|
204
|
+
2 * Math.PI,
|
|
205
|
+
false
|
|
206
|
+
);
|
|
207
|
+
ctx.stroke(); // 对路径进行描绘
|
|
208
|
+
ctx.draw();
|
|
200
209
|
},
|
|
201
210
|
// 激活部分
|
|
202
211
|
drawCircleByProgress(progress) {
|
|
203
212
|
// 第一次操作进度环时将上下文保存到了this.data中,直接使用即可
|
|
204
|
-
let ctx = this.progressContext
|
|
213
|
+
let ctx = this.progressContext;
|
|
205
214
|
if (!ctx) {
|
|
206
|
-
ctx = uni.createCanvasContext(this.elId, this)
|
|
207
|
-
this.progressContext = ctx
|
|
215
|
+
ctx = uni.createCanvasContext(this.elId, this);
|
|
216
|
+
this.progressContext = ctx;
|
|
208
217
|
}
|
|
209
|
-
let radius = this.widthPx / 2
|
|
218
|
+
let radius = this.widthPx / 2;
|
|
210
219
|
// 表示进度的两端为圆形
|
|
211
|
-
ctx.setLineCap(
|
|
220
|
+
ctx.setLineCap("round");
|
|
212
221
|
// 设置线条的宽度和颜色
|
|
213
|
-
ctx.setLineWidth(this.borderWidthPx)
|
|
222
|
+
ctx.setLineWidth(this.borderWidthPx);
|
|
214
223
|
if (
|
|
215
224
|
this.linearGradient &&
|
|
216
225
|
this.linearGradient.show &&
|
|
217
226
|
this.linearGradient.colorStop.length >= 2
|
|
218
227
|
) {
|
|
219
228
|
// this.imageData.slice(pos * 4, pos * 4 + 4);
|
|
220
|
-
let colorData = this.createColorData()
|
|
229
|
+
let colorData = this.createColorData();
|
|
221
230
|
for (let i = 0; i < progress; i++) {
|
|
222
|
-
const index = Math.round((i * 255) / progress)
|
|
223
|
-
const color = colorData.slice(index * 4, index * 4 + 4)
|
|
224
|
-
ctx.beginPath()
|
|
231
|
+
const index = Math.round((i * 255) / progress);
|
|
232
|
+
const color = colorData.slice(index * 4, index * 4 + 4);
|
|
233
|
+
ctx.beginPath();
|
|
225
234
|
|
|
226
|
-
ctx.setStrokeStyle(
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
235
|
+
ctx.setStrokeStyle(
|
|
236
|
+
`rgba(${color[0]},${color[1]},${color[2]},${color[3] / 255})`
|
|
237
|
+
);
|
|
238
|
+
ctx.globalAlpha = color[3] / 255;
|
|
239
|
+
let endAngle = ((2 * Math.PI) / 100) * (i + 1) + this.startAngle;
|
|
240
|
+
let startAngle = this.startAngle + ((2 * Math.PI) / 100) * i;
|
|
241
|
+
ctx.arc(
|
|
242
|
+
radius,
|
|
243
|
+
radius,
|
|
244
|
+
radius - this.borderWidthPx,
|
|
245
|
+
startAngle,
|
|
246
|
+
endAngle,
|
|
247
|
+
false
|
|
248
|
+
);
|
|
249
|
+
ctx.stroke();
|
|
232
250
|
}
|
|
233
251
|
} else {
|
|
234
252
|
// ctx.setStrokeStyle(this.circleColor)
|
|
235
|
-
ctx.setStrokeStyle(this.getType.activeColor)
|
|
253
|
+
ctx.setStrokeStyle(this.getType.activeColor);
|
|
236
254
|
// 结束角的计算依据为:将2π分为100份,乘以当前的进度值,得出终止点的弧度值,加起始角,为整个圆从默认的
|
|
237
255
|
// 3点钟方向开始画图,转为更好理解的12点钟方向开始作图,这需要起始角和终止角同时加上this.startAngle值
|
|
238
|
-
let endAngle = ((2 * Math.PI) / 100) * progress + this.startAngle
|
|
239
|
-
ctx.beginPath()
|
|
256
|
+
let endAngle = ((2 * Math.PI) / 100) * progress + this.startAngle;
|
|
257
|
+
ctx.beginPath();
|
|
240
258
|
// 半径为整个canvas宽度的一半
|
|
241
|
-
ctx.arc(
|
|
242
|
-
|
|
259
|
+
ctx.arc(
|
|
260
|
+
radius,
|
|
261
|
+
radius,
|
|
262
|
+
radius - this.borderWidthPx,
|
|
263
|
+
this.startAngle,
|
|
264
|
+
endAngle,
|
|
265
|
+
false
|
|
266
|
+
);
|
|
267
|
+
ctx.stroke();
|
|
243
268
|
}
|
|
244
|
-
ctx.beginPath()
|
|
245
|
-
ctx.textAlign =
|
|
246
|
-
ctx.textBaseline =
|
|
247
|
-
ctx.font = this.fontSize +
|
|
248
|
-
ctx.fillText(this.text, radius, radius)
|
|
249
|
-
ctx.stroke()
|
|
250
|
-
ctx.draw()
|
|
269
|
+
ctx.beginPath();
|
|
270
|
+
ctx.textAlign = "center";
|
|
271
|
+
ctx.textBaseline = "middle";
|
|
272
|
+
ctx.font = this.fontSize + " Arial";
|
|
273
|
+
ctx.fillText(this.text, radius, radius);
|
|
274
|
+
ctx.stroke();
|
|
275
|
+
ctx.draw();
|
|
251
276
|
|
|
252
277
|
// 将总过渡时间除以100,得出每修改百分之一进度所需的时间
|
|
253
|
-
let time = Math.floor(this.duration / 100)
|
|
278
|
+
let time = Math.floor(this.duration / 100);
|
|
254
279
|
// 如果变更后新值大于旧值,意味着增大了百分比
|
|
255
280
|
if (this.newPercent > this.oldPercent) {
|
|
256
281
|
// 每次递增百分之一
|
|
257
|
-
progress
|
|
282
|
+
progress++;
|
|
258
283
|
// 如果新增后的值,大于需要设置的值百分比值,停止继续增加
|
|
259
|
-
if (progress > this.newPercent) return
|
|
284
|
+
if (progress > this.newPercent) return;
|
|
260
285
|
} else {
|
|
261
286
|
// 同理于上面
|
|
262
|
-
progress
|
|
263
|
-
if (progress < this.newPercent) return
|
|
287
|
+
progress--;
|
|
288
|
+
if (progress < this.newPercent) return;
|
|
264
289
|
}
|
|
265
290
|
setTimeout(() => {
|
|
266
291
|
// 定时器,每次操作间隔为time值,为了让进度条有动画效果
|
|
267
|
-
this.drawCircleByProgress(progress)
|
|
268
|
-
}, time)
|
|
292
|
+
this.drawCircleByProgress(progress);
|
|
293
|
+
}, time);
|
|
269
294
|
},
|
|
270
295
|
createColorData() {
|
|
271
|
-
let canvas
|
|
272
|
-
let ctx
|
|
296
|
+
let canvas;
|
|
297
|
+
let ctx;
|
|
273
298
|
// #ifndef MP-WEIXIN
|
|
274
|
-
canvas = document.createElement(
|
|
275
|
-
canvas.width = 256
|
|
276
|
-
canvas.height = 1
|
|
277
|
-
ctx = canvas.getContext(
|
|
299
|
+
canvas = document.createElement("canvas");
|
|
300
|
+
canvas.width = 256;
|
|
301
|
+
canvas.height = 1;
|
|
302
|
+
ctx = canvas.getContext("2d");
|
|
278
303
|
// #endif
|
|
279
304
|
// #ifdef MP-WEIXIN
|
|
280
|
-
canvas = uni.createOffscreenCanvas({ type:
|
|
281
|
-
ctx = canvas.getContext(
|
|
305
|
+
canvas = uni.createOffscreenCanvas({ type: "2d", width: 256, height: 1 });
|
|
306
|
+
ctx = canvas.getContext("2d");
|
|
282
307
|
// #endif
|
|
283
|
-
const linearGradient = ctx.createLinearGradient(0, 0, 256, 1)
|
|
284
|
-
this.linearGradient.colorStop.forEach(color => {
|
|
285
|
-
linearGradient.addColorStop(color.percent, color.value)
|
|
286
|
-
})
|
|
287
|
-
ctx.fillStyle = linearGradient
|
|
288
|
-
ctx.fillRect(0, 0, 256, 1)
|
|
289
|
-
return ctx.getImageData(0, 0, 256, 1).data
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
}
|
|
308
|
+
const linearGradient = ctx.createLinearGradient(0, 0, 256, 1);
|
|
309
|
+
this.linearGradient.colorStop.forEach((color) => {
|
|
310
|
+
linearGradient.addColorStop(color.percent, color.value);
|
|
311
|
+
});
|
|
312
|
+
ctx.fillStyle = linearGradient;
|
|
313
|
+
ctx.fillRect(0, 0, 256, 1);
|
|
314
|
+
return ctx.getImageData(0, 0, 256, 1).data;
|
|
315
|
+
},
|
|
316
|
+
},
|
|
317
|
+
};
|
|
293
318
|
</script>
|
|
294
319
|
<style scoped lang="scss">
|
|
295
320
|
.circle-progress {
|