sadais-piui 1.2.7-beta4 → 1.2.7-beta40

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.
Files changed (35) hide show
  1. package/components/pi-calendar/index.vue +1 -0
  2. package/components/pi-calendar-panel/components/calendar-days/index.vue +409 -0
  3. package/components/pi-calendar-panel/index.vue +201 -163
  4. package/components/pi-cascader/index.vue +493 -0
  5. package/components/pi-checkbox/index.vue +2 -2
  6. package/components/pi-checkbox-group/index.vue +2 -0
  7. package/components/pi-circle-progress/index.vue +65 -9
  8. package/components/pi-collapse/index.vue +124 -0
  9. package/components/pi-collapse-item/index.vue +352 -0
  10. package/components/pi-date-picker/index.vue +20 -6
  11. package/components/pi-dropdown/components/dropdown-tab.vue +33 -24
  12. package/components/pi-dropdown/index.vue +53 -21
  13. package/components/pi-dropdown-item/index.vue +73 -54
  14. package/components/pi-form-item/index.vue +7 -2
  15. package/components/pi-input/index.vue +1 -1
  16. package/components/pi-radio/index.vue +2 -2
  17. package/components/pi-radio-group/index.vue +2 -0
  18. package/components/pi-select/index.vue +14 -4
  19. package/components/pi-steps/index.vue +115 -36
  20. package/components/pi-tabs/index.vue +11 -4
  21. package/components/pi-tag/index.vue +488 -0
  22. package/components/pi-upload-img/index.vue +21 -5
  23. package/components/pi-webview/index.vue +9 -3
  24. package/config/calendarPanel.js +4 -1
  25. package/config/cascader.js +21 -0
  26. package/config/circleProgress.js +7 -8
  27. package/config/collapse.js +7 -0
  28. package/config/collapseItem.js +11 -0
  29. package/config/datePicker.js +1 -0
  30. package/config/dropdown.js +4 -1
  31. package/config/select.js +1 -0
  32. package/config/steps.js +1 -1
  33. package/config/tag.js +21 -0
  34. package/config/uploadImg.js +3 -7
  35. package/package.json +1 -1
@@ -0,0 +1,493 @@
1
+ <template>
2
+ <pi-popup-select
3
+ :value="val"
4
+ :custom-style="getPopupSelect.customStyle"
5
+ :custom-class="getPopupSelect.customClass"
6
+ :height="getPopupSelect.height"
7
+ :show-title="getPopupSelect.showTitle"
8
+ :title="getPopupSelect.title"
9
+ :title-padding="getPopupSelect.titlePadding"
10
+ :toolbar-position="getPopupSelect.toolbarPosition"
11
+ :on-confirm-close="getPopupSelect.onConfirmClose"
12
+ :on-cancel-close="getPopupSelect.onCancelClose"
13
+ :confirm-btn="getConfirmBtn"
14
+ :cancel-btn="getCancelBtn"
15
+ :popup="getPopup"
16
+ @close="handlePopupClose"
17
+ @cancel="handleCancel"
18
+ @confirm="handleConfirm"
19
+ >
20
+ <view
21
+ class="pi-cascader pi-h-100P pi-flex-column"
22
+ :style="[customStyle]"
23
+ :class="[customClass]"
24
+ >
25
+ <slot name="header" />
26
+ <view class="cascader-wrap pi-flex-sub pi-flex-column">
27
+ <!-- 顶部面包屑 -->
28
+ <scroll-view class="node-breadcrumb pi-solid-bottom-1" scroll-x>
29
+ <view
30
+ v-for="(item, index) in pathItems"
31
+ :key="index"
32
+ class="breadcrumb-item"
33
+ @click="handleClickItem(item)"
34
+ >
35
+ <pi-icon v-if="item[keyField] !== ROOT_NODE" name="right" custom-class="pi-mg-lr-6" />
36
+ <view
37
+ class="breadcrumb-item-title"
38
+ :class="{
39
+ active: currentItem && currentItem[keyField] === item[keyField]
40
+ }"
41
+ >
42
+ {{ item[displayField] }}
43
+ </view>
44
+ </view>
45
+ </scroll-view>
46
+ <!-- 选择区域 -->
47
+ <scroll-view class="scroll-view" :scroll-left="scrollLeft" scroll-x scroll-with-animation>
48
+ <scroll-view
49
+ v-for="(col, index) of columns"
50
+ :key="index"
51
+ scroll-y
52
+ class="column"
53
+ :style="[{ width: isOnlyColumn ? '100%' : '50%' }]"
54
+ >
55
+ <view
56
+ v-for="item in col"
57
+ :key="item[keyField]"
58
+ class="column-item pi-align-center"
59
+ :class="{
60
+ active: activeIds.includes(item[keyField]),
61
+ selected: selectedIds.includes(item[keyField])
62
+ }"
63
+ @click="handleClickItem(item)"
64
+ >
65
+ <view class="pi-flex-sub pi-lh-36">
66
+ <slot name="item" :item="item">
67
+ {{ item[displayField] || '' }}
68
+ </slot>
69
+ </view>
70
+ <pi-icon v-if="selectedIds.includes(item[keyField])" name="blod-check" />
71
+ <pi-icon v-if="item[childrenField] && item[childrenField].length > 0" name="right" />
72
+ </view>
73
+ </scroll-view>
74
+ </scroll-view>
75
+ <!-- 已选区域 -->
76
+ <view class="cascader-area">
77
+ <text>{{ `已选(${selectedIds.length})` }}</text>
78
+ <scroll-view class="scroll-area" scroll-x>
79
+ <view
80
+ v-for="id in selectedIds"
81
+ :key="id"
82
+ class="cascader-item"
83
+ @tap="handleRemoveItem(id)"
84
+ >
85
+ <text class="pi-mg-right-12">{{ itemsMap[id][displayField] }}</text>
86
+ <pi-icon name="close" />
87
+ </view>
88
+ </scroll-view>
89
+ </view>
90
+ </view>
91
+ <slot name="footer" />
92
+ </view>
93
+ </pi-popup-select>
94
+ </template>
95
+
96
+ <script>
97
+ import ValueSync from '../../mixin/value-sync'
98
+ import cloneDeep from 'lodash/cloneDeep'
99
+ import { getConfig } from '../../config'
100
+
101
+ const TAG = 'PiCascader'
102
+ const ROOT_NODE = 'ROOT'
103
+ const { cascader } = getConfig()
104
+
105
+ export default {
106
+ name: 'PiCascader',
107
+ // 混入v-model
108
+ mixins: [ValueSync],
109
+ props: {
110
+ // 初始值
111
+ value: {
112
+ required: false
113
+ },
114
+ // 自定义样式
115
+ customStyle: {
116
+ type: Object,
117
+ // {}
118
+ default() {
119
+ return cascader.customStyle
120
+ }
121
+ },
122
+ // 自定义样式类
123
+ customClass: {
124
+ type: String,
125
+ // ''
126
+ default() {
127
+ return cascader.customClass
128
+ }
129
+ },
130
+ // 数据源
131
+ items: {
132
+ type: Array,
133
+ default() {
134
+ return []
135
+ }
136
+ },
137
+ defaultValue: {
138
+ type: Array,
139
+ default: () => []
140
+ },
141
+ // 列表选项的唯一标识
142
+ keyField: {
143
+ type: String,
144
+ // 'id'
145
+ default: cascader.keyField
146
+ },
147
+ // 选项显示字段
148
+ displayField: {
149
+ type: String,
150
+ // 'text'
151
+ default: cascader.displayField
152
+ },
153
+ // children字段,默认为desc
154
+ childrenField: {
155
+ type: String,
156
+ // 'children'
157
+ default: cascader.childrenField
158
+ },
159
+ // 弹窗选择参数设置
160
+ popupSelect: {
161
+ type: Object,
162
+ default() {
163
+ // 参照popupSelect
164
+ return cascader.popupSelect
165
+ }
166
+ },
167
+ // 确认按钮配置
168
+ confirmBtn: {
169
+ type: Object,
170
+ default() {
171
+ return cascader.confirmBtn
172
+ }
173
+ },
174
+ // 取消按钮配置
175
+ cancelBtn: {
176
+ type: Object,
177
+ default() {
178
+ return cascader.cancelBtn
179
+ }
180
+ },
181
+ // 弹窗参数设置
182
+ popup: {
183
+ type: Object,
184
+ default() {
185
+ // 参照popup
186
+ return cascader.popup
187
+ }
188
+ }
189
+ },
190
+ data() {
191
+ const rootItem = {
192
+ [this.displayField]: '全部',
193
+ [this.keyField]: ROOT_NODE
194
+ }
195
+ return {
196
+ rootItem,
197
+ currentItem: cloneDeep(rootItem),
198
+ innerItems: [],
199
+ itemsMap: {}, // 已选数据id索引
200
+ selectedIds: [], // 已选数据
201
+ cascaderWidth: 0, // 容器宽度
202
+ scrollLeft: 0 // 视图左侧滚动区域,自动对齐到选择的栏目
203
+ }
204
+ },
205
+ computed: {
206
+ ROOT_NODE() {
207
+ return ROOT_NODE
208
+ },
209
+ getPopupSelect() {
210
+ const popupSelect = this.$pi.lang.mergeDeep(cascader.popupSelect, this.popupSelect)
211
+ if (!this.singleCancel && this.singleConfirm) {
212
+ popupSelect.toolbarPosition = 'none'
213
+ }
214
+ return popupSelect
215
+ },
216
+ getConfirmBtn() {
217
+ const cascaderConfirmBtn = this.$pi.lang.mergeDeep(
218
+ cascader.confirmBtn,
219
+ this.popupSelect.confirmBtn
220
+ )
221
+ return this.$pi.lang.mergeDeep(cascaderConfirmBtn, this.confirmBtn)
222
+ },
223
+ getCancelBtn() {
224
+ const cascaderCancelBtn = this.$pi.lang.mergeDeep(
225
+ cascader.cancelBtn,
226
+ this.popupSelect.cancelBtn
227
+ )
228
+ return this.$pi.lang.mergeDeep(cascaderCancelBtn, this.cancelBtn)
229
+ },
230
+ getPopup() {
231
+ const cascaderPopup = this.$pi.lang.mergeDeep(cascader.popup, this.popupSelect.popup)
232
+ return this.$pi.lang.mergeDeep(cascaderPopup, this.popup)
233
+ },
234
+ getItemStyle() {
235
+ return {
236
+ height: this.$pi.common.addUnit(this.itemHeight)
237
+ }
238
+ },
239
+ columns() {
240
+ let columns = []
241
+ if (this.currentItem) {
242
+ // 如果有当前显示的节点,往上找父节点下的所有children放到数组的前面
243
+ let p = this.currentItem
244
+ while (p) {
245
+ const children = p[this.childrenField] || []
246
+ if (children.length > 0) {
247
+ columns.unshift(children)
248
+ }
249
+ p = p.pid ? this.itemsMap[p.pid] : undefined
250
+ }
251
+ columns.unshift(this.innerItems)
252
+ } else {
253
+ columns = [this.innerItems]
254
+ }
255
+ return columns
256
+ },
257
+ isOnlyColumn() {
258
+ return this.columns.length === 1
259
+ },
260
+ activeIds() {
261
+ return this.pathItems.map(i => i[this.keyField])
262
+ },
263
+ pathItems() {
264
+ const pathItems = []
265
+ if (this.currentItem[this.keyField] !== ROOT_NODE) {
266
+ // 往上找构建完整路径
267
+ let p = this.currentItem
268
+ while (p) {
269
+ pathItems.unshift(p)
270
+ p = this.itemsMap[p.pid]
271
+ }
272
+ }
273
+ return [
274
+ {
275
+ [this.displayField]: '全部',
276
+ [this.keyField]: 'ROOT'
277
+ }
278
+ ].concat(pathItems)
279
+ },
280
+ syncIds() {
281
+ return `${this.innerItems.length}-${this.defaultValue.length}`
282
+ }
283
+ },
284
+ watch: {
285
+ items: {
286
+ immediate: true,
287
+ handler() {
288
+ this.rebuildItems()
289
+ }
290
+ }
291
+ },
292
+
293
+ methods: {
294
+ rebuildItems() {
295
+ /**
296
+ * 以非递归的方式 深度拷贝items 且建立父子节点关系
297
+ * 目的为了不影响外部传入的prop: items
298
+ * 写成非递归的目的 是为了防止树的层次太深,
299
+ * 递归调用太多次,导致栈溢出
300
+ */
301
+ const innerItems = []
302
+ // 初始化堆栈 为items的根节点
303
+ const stack = [...this.items]
304
+ const itemsMap = {}
305
+ while (stack.length > 0) {
306
+ // 将栈顶元素出栈进行处理
307
+ let item = stack.shift()
308
+ if (!item.pid) {
309
+ item = {
310
+ ...item,
311
+ level: 0
312
+ }
313
+ innerItems.push(item)
314
+ }
315
+ const children = item[this.childrenField] || []
316
+ const newChilds = []
317
+ for (let i = children.length - 1; i >= 0; i--) {
318
+ // 浅拷贝子孩子
319
+ const subItem = {
320
+ ...children[i],
321
+ level: item.level + 1
322
+ }
323
+ // 建立父子关系
324
+ subItem.pid = item[this.keyField]
325
+ // 放置到新数组中
326
+ newChilds.unshift(subItem)
327
+ // 入栈 模拟递归效果 等待之后的while循环出栈进行处理
328
+ stack.unshift(subItem)
329
+ }
330
+ // 更新children 为新的数组
331
+ item[this.childrenField] = newChilds
332
+ itemsMap[item[this.keyField]] = item
333
+ }
334
+ // 此时的innerItems无论怎么修改 均不影响items
335
+ this.innerItems = innerItems
336
+ // 方便通过节点的id 为key快速定位到对应的节点dto
337
+ this.itemsMap = itemsMap
338
+ },
339
+ handleRemoveItem(id) {
340
+ this.selectedIds = this.selectedIds.filter(i => i !== id)
341
+ },
342
+ handleClickItem(item) {
343
+ if (item[this.keyField] === ROOT_NODE) {
344
+ this.currentItem = cloneDeep(this.rootItem)
345
+ this.$nextTick(this.syncScrollLeft)
346
+ return
347
+ }
348
+ if (
349
+ item &&
350
+ item[this.childrenField]?.length &&
351
+ this.currentItem[this.keyField] !== item[this.keyField]
352
+ ) {
353
+ this.currentItem = item
354
+ this.$nextTick(this.syncScrollLeft)
355
+ return
356
+ }
357
+ if (item && item[this.childrenField]?.length === 0) {
358
+ // 点击的是叶子节点
359
+ if (this.selectedIds.includes(item[this.keyField])) {
360
+ this.handleRemoveItem(item[this.keyField])
361
+ } else {
362
+ // 选中
363
+ this.selectedIds.push(item[this.keyField])
364
+ }
365
+ }
366
+ },
367
+ async syncScrollLeft() {
368
+ // 调用此方法的时候,必须使用$nextTick,因为column是动态变化的,需要等待界面更新渲染后,才能正确设置scrollLeft的位置
369
+ let scrollLeft = 0
370
+ if (this.cascaderWidth === 0) {
371
+ const srollWrapRect = await this.$pi.common.queryRect(this, '.pi-cascader', false)
372
+ if (srollWrapRect) {
373
+ this.cascaderWidth = srollWrapRect.width
374
+ }
375
+ }
376
+ if (this.columns.length > 2) {
377
+ scrollLeft = (this.columns.length - 2) * (this.cascaderWidth / 2)
378
+ }
379
+ this.scrollLeft = scrollLeft
380
+ },
381
+ handlePopupClose() {
382
+ this.val = false
383
+ // 关闭弹窗
384
+ this.$emit('close')
385
+ this.handleEmitChange()
386
+ },
387
+ /**
388
+ * @vuese
389
+ * 根据id获取item
390
+ */
391
+ getItemByKeyField(keyField) {
392
+ return this.itemsMap[keyField]
393
+ },
394
+ /**
395
+ * @vuese
396
+ * 取消选择
397
+ */
398
+ handleCancel() {
399
+ this.$emit('cancel')
400
+ this.getPopupSelect.onCancelClose && this.handlePopupClose()
401
+ },
402
+ /**
403
+ * @vuese
404
+ * 确认选择
405
+ */
406
+ handleConfirm() {
407
+ this.$emit('confirm', this.selectedIds)
408
+ this.getPopupSelect.onConfirmClose && this.handlePopupClose()
409
+ }
410
+ }
411
+ }
412
+ </script>
413
+
414
+ <style lang="scss" scoped>
415
+ .cascader-wrap {
416
+ width: 100%;
417
+ height: 100%;
418
+ background: #f4f2f6;
419
+ }
420
+ .scroll-view {
421
+ width: 100%;
422
+ flex: 1;
423
+ white-space: nowrap;
424
+ overflow: auto hidden;
425
+ .column {
426
+ display: inline-block;
427
+ height: 100%;
428
+ width: 50%;
429
+ overflow: hidden auto;
430
+ &:last-child {
431
+ background: #ffffff;
432
+ }
433
+ .column-item {
434
+ position: relative;
435
+ height: 100rpx;
436
+ width: 100%;
437
+ white-space: initial;
438
+ padding: 0 16rpx 0 32rpx;
439
+ font-size: 28rpx;
440
+ color: #333333;
441
+ overflow: hidden;
442
+ &.active {
443
+ color: $pi-primary-color;
444
+ background: #ffffff;
445
+ }
446
+ &.selected {
447
+ color: $pi-primary-color;
448
+ }
449
+ }
450
+ }
451
+ }
452
+
453
+ .node-breadcrumb {
454
+ width: 100%;
455
+ padding-left: 32rpx;
456
+ background: #ffffff;
457
+ white-space: nowrap;
458
+ .breadcrumb-item {
459
+ display: inline-flex;
460
+ align-items: center;
461
+ font-size: 14px;
462
+ padding: 32rpx 0;
463
+
464
+ .breadcrumb-item-title.active {
465
+ color: $pi-primary-color;
466
+ }
467
+ }
468
+ }
469
+
470
+ .cascader-area {
471
+ background: #ffffff;
472
+ padding: 22rpx 24rpx;
473
+ color: #333333;
474
+ display: flex;
475
+ align-items: center;
476
+ white-space: nowrap;
477
+
478
+ .scroll-area {
479
+ width: calc(100% - 128rpx);
480
+ flex: 1;
481
+ white-space: nowrap;
482
+ }
483
+ .cascader-item {
484
+ display: inline-flex;
485
+ padding: 14rpx 24rpx;
486
+ background: rgba($pi-primary-color, 0.1);
487
+ align-items: center;
488
+ margin-left: 16rpx;
489
+ border-radius: 8rpx;
490
+ color: $pi-primary-color;
491
+ }
492
+ }
493
+ </style>
@@ -3,13 +3,12 @@
3
3
  class="pi-check-wrap"
4
4
  :style="[customStyle]"
5
5
  :class="[getShape, getActiveMode, { disabled: getDisable }, { active: val }, customClass]"
6
- @tap="handleCheckboxToggle(true)"
7
6
  >
8
7
  <view
9
8
  v-if="getShape !== 'text'"
10
9
  class="check-icon"
11
10
  :style="[checkStyle]"
12
- @tap.stop="handleCheckboxToggle(false)"
11
+ @tap="handleCheckboxToggle(false)"
13
12
  >
14
13
  <view v-if="getShape === 'dot'" class="dot" :style="[dotStyle]" />
15
14
  <pi-icon v-else name="blod-check" :size="getIconSize" />
@@ -19,6 +18,7 @@
19
18
  class="check-label"
20
19
  :class="{ text: getShape === 'text' }"
21
20
  :style="[textStyle]"
21
+ @tap="handleCheckboxToggle(true)"
22
22
  >
23
23
  <!-- checkbox 内容 -->
24
24
  <slot />
@@ -13,6 +13,7 @@
13
13
  </template>
14
14
 
15
15
  <script>
16
+ import Emitter from '../../mixin/emitter'
16
17
  import ValueSync from '../../mixin/value-sync'
17
18
  import { parentInit } from '../../mixin/props-sync'
18
19
  import { getConfig } from '../../config'
@@ -24,6 +25,7 @@ export default {
24
25
  name: 'PiCheckboxGroup',
25
26
  // 混入自定义样式customStyle和customClass
26
27
  mixins: [
28
+ Emitter,
27
29
  ValueSync,
28
30
  parentInit([
29
31
  'value',
@@ -96,14 +96,24 @@ export default {
96
96
  text: {
97
97
  type: String,
98
98
  default: circleProgress.text
99
+ },
100
+ linearGradient: {
101
+ type: Object,
102
+ default() {
103
+ return circleProgress.linearGradient
104
+ }
99
105
  }
100
106
  },
101
107
  data() {
102
108
  return {
109
+ // #ifdef MP-WEIXIN
103
110
  elBgId: 'pCircleProgressBgId', // 微信小程序中不能使用this.$pi形式动态生成id值,否则会报错
104
111
  elId: 'pCircleProgressElId',
112
+ // #endif
113
+ // #ifndef MP-WEIXIN
105
114
  elBgId: this.$pi.guid(), // 支付宝等小程序 动态生产ID
106
115
  elId: this.$pi.guid(),
116
+ // #endif
107
117
  progressContext: null,
108
118
  // 开始的角度
109
119
  widthPx: uni.upx2px(this.width), // 转成px后的整个组件的背景宽度
@@ -170,25 +180,50 @@ export default {
170
180
  ctx = uni.createCanvasContext(this.elId, this)
171
181
  this.progressContext = ctx
172
182
  }
183
+ let radius = this.widthPx / 2
173
184
  // 表示进度的两端为圆形
174
185
  ctx.setLineCap('round')
175
186
  // 设置线条的宽度和颜色
176
187
  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
188
+ if (
189
+ this.linearGradient &&
190
+ this.linearGradient.show &&
191
+ this.linearGradient.colorStop.length >= 2
192
+ ) {
193
+ // this.imageData.slice(pos * 4, pos * 4 + 4);
194
+ let colorData = this.createColorData()
195
+ for (let i = 0; i < progress; i++) {
196
+ const index = Math.round((i * 255) / progress)
197
+ const color = colorData.slice(index * 4, index * 4 + 4)
198
+ ctx.beginPath()
199
+
200
+ ctx.setStrokeStyle(`rgba(${color[0]},${color[1]},${color[2]},${color[3] / 255})`)
201
+ ctx.globalAlpha = color[3] / 255
202
+ let endAngle = ((2 * Math.PI) / 100) * (i + 1) + this.startAngle
203
+ let startAngle = this.startAngle + ((2 * Math.PI) / 100) * i
204
+ ctx.arc(radius, radius, radius - this.borderWidthPx, startAngle, endAngle, false)
205
+ ctx.stroke()
206
+ }
207
+ } else {
208
+ ctx.setStrokeStyle(this.circleColor)
209
+ // 结束角的计算依据为:将2π分为100份,乘以当前的进度值,得出终止点的弧度值,加起始角,为整个圆从默认的
210
+ // 3点钟方向开始画图,转为更好理解的12点钟方向开始作图,这需要起始角和终止角同时加上this.startAngle值
211
+ let endAngle = ((2 * Math.PI) / 100) * progress + this.startAngle
212
+ ctx.beginPath()
213
+ // 半径为整个canvas宽度的一半
214
+ ctx.arc(radius, radius, radius - this.borderWidthPx, this.startAngle, endAngle, false)
215
+ ctx.stroke()
216
+ }
183
217
  ctx.beginPath()
184
- // 半径为整个canvas宽度的一半
185
- let radius = this.widthPx / 2
186
- ctx.arc(radius, radius, radius - this.borderWidthPx, this.startAngle, endAngle, false)
187
218
  ctx.textAlign = 'center'
219
+ ctx.textBaseline = 'middle'
188
220
  ctx.font = this.fontSize + ' Arial'
189
221
  ctx.fillText(this.text, radius, radius)
190
222
  ctx.stroke()
191
223
  ctx.draw()
224
+
225
+ // 将总过渡时间除以100,得出每修改百分之一进度所需的时间
226
+ let time = Math.floor(this.duration / 100)
192
227
  // 如果变更后新值大于旧值,意味着增大了百分比
193
228
  if (this.newPercent > this.oldPercent) {
194
229
  // 每次递增百分之一
@@ -204,6 +239,27 @@ export default {
204
239
  // 定时器,每次操作间隔为time值,为了让进度条有动画效果
205
240
  this.drawCircleByProgress(progress)
206
241
  }, time)
242
+ },
243
+ createColorData() {
244
+ let canvas
245
+ let ctx
246
+ // #ifndef MP-WEIXIN
247
+ canvas = document.createElement('canvas')
248
+ canvas.width = 256
249
+ canvas.height = 1
250
+ ctx = canvas.getContext('2d')
251
+ // #endif
252
+ // #ifdef MP-WEIXIN
253
+ canvas = uni.createOffscreenCanvas({ type: '2d', width: 256, height: 1 })
254
+ ctx = canvas.getContext('2d')
255
+ // #endif
256
+ const linearGradient = ctx.createLinearGradient(0, 0, 256, 1)
257
+ this.linearGradient.colorStop.forEach(color => {
258
+ linearGradient.addColorStop(color.percent, color.value)
259
+ })
260
+ ctx.fillStyle = linearGradient
261
+ ctx.fillRect(0, 0, 256, 1)
262
+ return ctx.getImageData(0, 0, 256, 1).data
207
263
  }
208
264
  }
209
265
  }