sadais-piui 1.1.2-beta → 1.2.2-beta2

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 (39) hide show
  1. package/CHANGELOG.md +482 -240
  2. package/README.md +2 -3
  3. package/components/pi-bottom-bar/index.vue +15 -2
  4. package/components/pi-canvas/index.vue +400 -0
  5. package/components/pi-circle-progress/index.vue +196 -173
  6. package/components/pi-count-up/index.vue +68 -62
  7. package/components/pi-dropdown/components/dropdown-tab.vue +62 -0
  8. package/components/pi-dropdown/index.vue +152 -151
  9. package/components/pi-dropdown-item/index.vue +169 -41
  10. package/components/pi-form-item/index.vue +13 -1
  11. package/components/pi-img/index.vue +1 -0
  12. package/components/pi-img-cropper/index.vue +20 -16
  13. package/components/pi-img-cropper/touch.js +5 -3
  14. package/components/pi-input/index.vue +9 -2
  15. package/components/pi-notify/index.vue +132 -48
  16. package/components/pi-popup/index.vue +1 -3
  17. package/components/pi-radio/index.vue +10 -1
  18. package/components/pi-radio-group/index.vue +21 -2
  19. package/components/pi-select/index.vue +13 -3
  20. package/components/pi-steps/index.vue +141 -96
  21. package/components/pi-switch/index.vue +2 -3
  22. package/components/pi-tabs/index.vue +1 -2
  23. package/components/pi-upload-img/index.vue +104 -32
  24. package/config/bottomBar.js +1 -0
  25. package/config/checkbox.js +1 -1
  26. package/config/circleProgress.js +13 -0
  27. package/config/countUp.js +13 -0
  28. package/config/dropdown.js +17 -8
  29. package/config/dropdownItem.js +23 -5
  30. package/config/form.js +3 -3
  31. package/config/imgCropper.js +4 -2
  32. package/config/notify.js +6 -2
  33. package/config/radio.js +2 -1
  34. package/config/radioGroup.js +2 -1
  35. package/config/steps.js +10 -5
  36. package/config/{upload-img.js → uploadImg.js} +6 -3
  37. package/index.js +2 -2
  38. package/package.json +3 -3
  39. package/scss/variable.scss +1 -1
package/README.md CHANGED
@@ -161,7 +161,6 @@ MIT © 2021 zhangzhenfei
161
161
 
162
162
  ## 微信群
163
163
 
164
- 请扫码添加[piui客服小助手]邀请进群
165
-
166
- ![](https://sadais-oss.oss-cn-hangzhou.aliyuncs.com/piui/WechatIMG17.jpeg)
164
+ 请扫码进群
167
165
 
166
+ ![](https://m.sadais.com/piui/WechatIMG411.jpeg)
@@ -1,6 +1,10 @@
1
1
  <template>
2
2
  <view>
3
- <view class="pi-bottom-bar" :style="[{ borderTop: borderTop }]" :class="[{ fixed: fixed }]">
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;
@@ -122,5 +131,9 @@ export default {
122
131
  left: 0;
123
132
  z-index: 99;
124
133
  }
134
+ ::v-deep .pi-button[size] {
135
+ padding-left: 0;
136
+ padding-right: 0;
137
+ }
125
138
  }
126
139
  </style>
@@ -0,0 +1,400 @@
1
+ <template>
2
+ <view ref="root" :class="[customClass, 'wrapper']" :style="[customStyle]">
3
+ <canvas
4
+ ref="canvas"
5
+ :style="[canvasStyle]"
6
+ type="2d"
7
+ class="content"
8
+ :canvas-id="canvasId"
9
+ :width="canvasw"
10
+ :height="canvash"
11
+ @touchstart="start"
12
+ @touchmove="move"
13
+ @touchcancel="end"
14
+ @touchend="end"
15
+ @mousedown="start"
16
+ @mousemove="move"
17
+ @mouseup="end"
18
+ />
19
+ <canvas
20
+ ref="cropCanvas"
21
+ type="2d"
22
+ class="copy"
23
+ :style="[cropStyle]"
24
+ :canvas-id="cropId"
25
+ :width="cropw"
26
+ :height="croph"
27
+ />
28
+ </view>
29
+ </template>
30
+ <script>
31
+ export default {
32
+ name: 'PiCanvas',
33
+ props: {
34
+ // 自定义class
35
+ customClass: {
36
+ type: String,
37
+ // `''`
38
+ default: ''
39
+ },
40
+ // 自定义style
41
+ customStyle: {
42
+ type: Object,
43
+ // `{}`
44
+ default: () => ({})
45
+ },
46
+ // 是否最小化空白区域
47
+ minimal: {
48
+ type: Boolean,
49
+ // `false`
50
+ default: false
51
+ },
52
+ // 当minimal:true时,指定pandding
53
+ padding: {
54
+ type: Object,
55
+ // `{ top: 8, right: 8, bottom: 8, left: 8 }`
56
+ default: () => ({ top: 8, right: 8, bottom: 8, left: 8 })
57
+ },
58
+ // 画布背景色
59
+ bgColor: {
60
+ type: String,
61
+ // `#ffffff`
62
+ default: '#ffffff'
63
+ },
64
+ // 画笔颜色
65
+ color: {
66
+ type: String,
67
+ // `#333333`
68
+ default: '#333333'
69
+ },
70
+ // 线条宽度
71
+ lineWidth: {
72
+ type: Number,
73
+ // `1`
74
+ default: 1
75
+ }
76
+ },
77
+ data() {
78
+ return {
79
+ isBegin: false, // 标记是否先触发了touchstart or mousedown
80
+ canvasId: '', // 内容画布的ID
81
+ cropId: '', // 裁剪画布的ID
82
+ ctx: null, // 内容画布的上下文
83
+ canvasw: 0, // 内容画布的宽度
84
+ canvash: 0, // 内容画布的高度
85
+ cropw: 0, // 裁剪画布的宽度
86
+ croph: 0 // 裁剪画布的高度
87
+ }
88
+ },
89
+ computed: {
90
+ isUni() {
91
+ return window.uni != null
92
+ },
93
+ canvasStyle() {
94
+ return {
95
+ width: `${this.canvasw}px`,
96
+ height: `${this.canvash}px`
97
+ }
98
+ },
99
+ cropStyle() {
100
+ return {
101
+ width: `${this.cropw}px`,
102
+ height: `${this.croph}px`
103
+ }
104
+ }
105
+ },
106
+ created() {
107
+ this.$nextTick(() => {
108
+ this.initCanvas()
109
+ })
110
+ },
111
+ methods: {
112
+ generateId() {
113
+ // 产生16位随机的字母、数字混合的随机ID
114
+ const tmps = '0123456789'
115
+ .split('')
116
+ .concat('abcdefghijklmnopqrstuvwxyz'.split(''))
117
+ .concat('ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split(''))
118
+ let n = tmps.length
119
+ while (n--) {
120
+ const idx = Math.floor(Math.random() * n)
121
+ const tmp = tmps[idx]
122
+ tmps[idx] = tmps[n]
123
+ tmps[n] = tmp
124
+ }
125
+ return tmps.join('').substr(0, 16)
126
+ },
127
+ initCanvas() {
128
+ this.canvasId = this.generateId()
129
+ this.cropId = this.generateId()
130
+ if (!this.isUni) {
131
+ // 非uni环境
132
+ const root = this.$refs.root
133
+ const style = window.getComputedStyle(root)
134
+ this.canvasw = parseInt(style.width, 10)
135
+ this.canvash = parseInt(style.height, 10)
136
+ const canvas = this.$refs.canvas
137
+ this.ctx = canvas.getContext('2d')
138
+ this.$nextTick(() => {
139
+ this.clear()
140
+ })
141
+ } else {
142
+ // uni环境:无法操作dom 只能通过它提供的API获取布局信息
143
+ const query = uni.createSelectorQuery().in(this)
144
+ query
145
+ .select('.wrapper')
146
+ .boundingClientRect(res => {
147
+ this.canvasw = res.width - 2
148
+ this.canvash = res.height - 2
149
+ this.$nextTick(() => {
150
+ this.ctx = uni.createCanvasContext(this.canvasId, this)
151
+ this.clear()
152
+ })
153
+ })
154
+ .exec()
155
+ }
156
+ },
157
+ /**
158
+ * @vuese
159
+ * 清空画布内容
160
+ */
161
+ clear() {
162
+ this.initRange()
163
+ this.initPen()
164
+ this.ctx.clearRect(0, 0, this.canvasw, this.canvash)
165
+ this.ctx.fillRect(0, 0, this.canvasw, this.canvash)
166
+ if (this.isUni) {
167
+ this.ctx.draw()
168
+ }
169
+ },
170
+ initPen() {
171
+ // 初始化画笔
172
+ if (this.isUni) {
173
+ this.ctx.setFillStyle(this.bgColor)
174
+ this.ctx.setStrokeStyle(this.color)
175
+ this.ctx.setLineWidth(this.lineWidth)
176
+ } else {
177
+ this.ctx.fillStyle = this.bgColor
178
+ this.ctx.strokeStyle = this.color
179
+ this.ctx.lineWidth = this.lineWidth
180
+ }
181
+ },
182
+ initRange() {
183
+ // 记录画布上左上角的点 s: start
184
+ this.s = { x: Number.MAX_VALUE, y: Number.MAX_VALUE }
185
+ // 记录画布右下角的点 e: end
186
+ this.e = { x: 0, y: 0 }
187
+ },
188
+ async getImageData(x, y, w, h) {
189
+ if (this.isUni) {
190
+ return new Promise(resolve => {
191
+ uni.canvasGetImageData({
192
+ canvasId: this.canvasId,
193
+ x,
194
+ y,
195
+ width: w,
196
+ height: h,
197
+ success: res => {
198
+ resolve(res.data)
199
+ },
200
+ fail: err => {
201
+ resolve(null)
202
+ }
203
+ })
204
+ })
205
+ } else {
206
+ return this.ctx.getImageData(x, y, w, h)
207
+ }
208
+ },
209
+ /**
210
+ * @vuese
211
+ * 裁剪画布内容
212
+ */
213
+ async crop() {
214
+ if (this.s.x === Number.MAX_VALUE) {
215
+ // 标明画布无内容 不进行裁剪操作
216
+ return
217
+ }
218
+ if (this.minimal) {
219
+ // 需要最小化空白区域,计算裁剪区域
220
+ let x = this.s.x - (this.padding.left || 0)
221
+ let y = this.s.y - (this.padding.top || 0)
222
+ x = x < 0 ? 0 : x
223
+ y = y < 0 ? 0 : y
224
+
225
+ let x1 = this.e.x + (this.padding.right || 0)
226
+ let y1 = this.e.y + (this.padding.bottom || 0)
227
+ x1 = x1 > this.canvasw ? this.canvasw : x1
228
+ y1 = y1 > this.canvash ? this.canvash : y1
229
+
230
+ // 获取裁剪区域的RGBA像素点数据
231
+ const imageData = await this.getImageData(x, y, x1 - x, y1 - y)
232
+ this.emitCrop(imageData, x1 - x, y1 - y)
233
+ } else {
234
+ // 直接获取整张画布区域的像素点数据
235
+ const imageData = await this.getImageData(0, 0, this.canvasw, this.canvash)
236
+ this.emitCrop(imageData, this.canvasw, this.canvash)
237
+ }
238
+ },
239
+ async getBase64(imageData, w, h) {
240
+ // 原理:将imageData放入裁剪画布中,然后即可生成base64
241
+ if (this.isUni) {
242
+ // uni环境下 按uni提供的API进行操作
243
+ return new Promise(resolve => {
244
+ uni.canvasPutImageData(
245
+ {
246
+ canvasId: this.cropId,
247
+ data: imageData,
248
+ x: 0,
249
+ y: 0,
250
+ width: w,
251
+ height: h,
252
+ success: res => {
253
+ uni.canvasToTempFilePath({
254
+ canvasId: this.cropId,
255
+ x: 0,
256
+ y: 0,
257
+ success: res => {
258
+ resolve(res.tempFilePath)
259
+ },
260
+ fail: err => {
261
+ resolve('')
262
+ }
263
+ })
264
+ },
265
+ fail: err => {
266
+ resolve('')
267
+ }
268
+ },
269
+ this
270
+ )
271
+ })
272
+ } else {
273
+ // 否则 按常规尝试进行
274
+ const canvas = this.$refs.cropCanvas
275
+ ctx = canvas.getContext('2d')
276
+ ctx.putImageData(imageData, 0, 0)
277
+ const base64 = canvas.toDataURL()
278
+ return base64
279
+ }
280
+ },
281
+ emitCrop(imageData, w, h) {
282
+ if (!imageData) {
283
+ return
284
+ }
285
+ this.cropw = w
286
+ this.croph = h
287
+ setTimeout(async () => {
288
+ // $nextTick的目的是为了让裁剪画布的宽高生效后 再进行操作
289
+ const base64 = await this.getBase64(imageData, w, h)
290
+ const results = base64.match(/data:(.*?);.*?,(.*)/)
291
+ const mineType = results[1]
292
+ const suffix = mineType.split('/')[1]
293
+ const binstr = window.atob(results[2])
294
+ let n = binstr.length
295
+ const bytes = new Uint8Array(n)
296
+ while (n--) {
297
+ bytes[n] = binstr.charCodeAt(n)
298
+ }
299
+ const blob = new Blob([bytes], { type: mineType })
300
+ // export
301
+ // arg `{base64, blob, width, height, style}`
302
+ this.$emit('export', {
303
+ base64,
304
+ blob,
305
+ width: w,
306
+ height: h,
307
+ style: { width: `${w}px`, height: `${h}px` }
308
+ })
309
+ }, 100)
310
+ },
311
+ /**
312
+ * 随着画笔移动,不断调用此方法更新:包裹内容的矩形的左上角&右下角的坐标
313
+ */
314
+ updateRange(x, y) {
315
+ if (x < this.s.x) {
316
+ this.s.x = x
317
+ } else if (x > this.e.x) {
318
+ this.e.x = x
319
+ }
320
+ if (y < this.s.y) {
321
+ this.s.y = y
322
+ } else if (y > this.e.y) {
323
+ this.e.y = y
324
+ }
325
+ },
326
+ start(e) {
327
+ // 适配移动端的写法: e.touches移动端才有
328
+ const touches = (e && e.changedTouches) || []
329
+ let x = 0,
330
+ y = 0
331
+ const touch = touches[0]
332
+ if (/^touch/.test(e.type)) {
333
+ x = touch.x
334
+ y = touch.y
335
+ } else {
336
+ x = e.offsetX
337
+ y = e.offsetY
338
+ }
339
+ // 为了清空之前残留的路径
340
+ this.ctx.beginPath()
341
+ this.ctx.moveTo(x, y)
342
+ this.ctx.stroke()
343
+ if (this.isUni) {
344
+ this.ctx.draw(true)
345
+ }
346
+ this.isBegin = true
347
+ this.updateRange(x, y)
348
+ this.prev = { x, y }
349
+ },
350
+ move(e) {
351
+ if (!this.isBegin) {
352
+ return
353
+ }
354
+ let x = 0,
355
+ y = 0
356
+ const touches = (e && e.changedTouches) || []
357
+ const touch = touches[0]
358
+ if (/^touch/.test(e.type)) {
359
+ x = touch.x
360
+ y = touch.y
361
+ } else {
362
+ x = e.offsetX
363
+ y = e.offsetY
364
+ }
365
+ this.ctx.moveTo(this.prev.x, this.prev.y)
366
+ this.ctx.lineTo(x, y)
367
+ this.ctx.stroke()
368
+ if (this.isUni) {
369
+ this.ctx.draw(true)
370
+ }
371
+ this.updateRange(x, y)
372
+ this.prev = { x, y }
373
+ },
374
+ end(e) {
375
+ // this.move(e)
376
+ this.isBegin = false
377
+ }
378
+ }
379
+ }
380
+ </script>
381
+
382
+ <style lang="scss" scoped>
383
+ .wrapper {
384
+ position: relative;
385
+ width: 100%;
386
+ height: 100%;
387
+ border: 1px solid #aaaaaa;
388
+ }
389
+
390
+ .content {
391
+ position: relative;
392
+ margin: 0 auto;
393
+ }
394
+
395
+ .copy {
396
+ position: absolute;
397
+ top: -50000px;
398
+ left: -50000px;
399
+ }
400
+ </style>