sadais-piui 1.0.182 → 1.2.0

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 (40) hide show
  1. package/CHANGELOG.md +482 -240
  2. package/README.md +27 -17
  3. package/components/pi-bottom-bar/index.vue +11 -2
  4. package/components/pi-calendar-panel/index.vue +10 -4
  5. package/components/pi-checkbox-group/index.vue +5 -0
  6. package/components/pi-circle-progress/index.vue +196 -173
  7. package/components/pi-count-up/index.vue +209 -0
  8. package/components/pi-dropdown/components/dropdown-tab.vue +62 -0
  9. package/components/pi-dropdown/index.vue +316 -0
  10. package/components/pi-dropdown-item/index.vue +233 -0
  11. package/components/pi-form-item/index.vue +13 -1
  12. package/components/pi-img-cropper/canvas.js +112 -0
  13. package/components/pi-img-cropper/index.vue +357 -0
  14. package/components/pi-img-cropper/touch.js +163 -0
  15. package/components/pi-img-cropper/vector.js +35 -0
  16. package/components/pi-input/index.vue +9 -2
  17. package/components/pi-line/index.vue +78 -0
  18. package/components/pi-notify/index.vue +239 -0
  19. package/components/pi-popup/index.vue +1 -3
  20. package/components/pi-select/index.vue +5 -5
  21. package/components/pi-steps/index.vue +299 -0
  22. package/components/pi-switch/index.vue +2 -3
  23. package/components/pi-tabs/index.vue +1 -1
  24. package/components/pi-upload-img/index.vue +145 -40
  25. package/config/bottomBar.js +1 -0
  26. package/config/checkbox.js +1 -1
  27. package/config/circleProgress.js +13 -0
  28. package/config/countUp.js +13 -0
  29. package/config/dropdown.js +21 -0
  30. package/config/dropdownItem.js +26 -0
  31. package/config/form.js +3 -3
  32. package/config/imgCropper.js +26 -0
  33. package/config/line.js +8 -0
  34. package/config/notify.js +13 -0
  35. package/config/steps.js +19 -0
  36. package/config/{upload-img.js → uploadImg.js} +5 -1
  37. package/index.js +2 -2
  38. package/package.json +3 -3
  39. package/scss/common.scss +4 -0
  40. package/scss/variable.scss +1 -1
@@ -0,0 +1,357 @@
1
+ <template>
2
+ <view
3
+ :class="[customClass, 'pi-img-cropper']"
4
+ :style="[customStyle]"
5
+ @touchstart.stop.prevent="handleStart"
6
+ @touchmove.stop.prevent="handleMove"
7
+ @touchcancel.stop.prevent="handleEnd"
8
+ @touchend.stop.prevent="handleEnd"
9
+ >
10
+ <image class="img" mode="aspectFit" :style="[imgStyle]" :src="src" />
11
+ <view class="crop" :style="[cropStyle]">
12
+ <view class="corner lt" @touchstart="setCutMode('lt')" />
13
+ <view class="corner rt" @touchstart="setCutMode('rt')" />
14
+ <view class="corner rb" @touchstart="setCutMode('rb')" />
15
+ <view class="corner lb" @touchstart="setCutMode('lb')" />
16
+ </view>
17
+ <canvas
18
+ v-if="canvasId"
19
+ :id="canvasId"
20
+ :canvas-id="canvasId"
21
+ style="position: absolute; left: -500000px; top: -500000px;"
22
+ :style="canvasStyle"
23
+ />
24
+ </view>
25
+ </template>
26
+ <script>
27
+ import Touch from './touch'
28
+ import Vector from './vector'
29
+ import Canvas from './canvas'
30
+ import { getConfig } from '../../config'
31
+
32
+ const { imgCropper } = getConfig()
33
+ export default {
34
+ name: 'PiImgCropper',
35
+ mixins: [Touch, Vector, Canvas],
36
+ props: {
37
+ // 自定义样式
38
+ customStyle: {
39
+ type: Object,
40
+ default() {
41
+ // {}
42
+ return imgCropper.customStyle
43
+ }
44
+ },
45
+ // 自定义样式类
46
+ customClass: {
47
+ type: String,
48
+ default() {
49
+ // ''
50
+ return imgCropper.customClass
51
+ }
52
+ },
53
+ // 图片src
54
+ src: {
55
+ type: String,
56
+ // `''`
57
+ default: imgCropper.src
58
+ },
59
+ // 图片格式
60
+ fileType: {
61
+ type: String,
62
+ // `png`
63
+ deault: imgCropper.fileType
64
+ },
65
+ // 图片质量(0,1]
66
+ quality: {
67
+ type: Number,
68
+ // `1`
69
+ default: imgCropper.quality
70
+ },
71
+ // 裁剪窗口大小
72
+ cropSize: {
73
+ // {`width`: `百分比 相对于容器宽度` or `px` or `rpx`, `height`: `百分比` or `px` or `rpx` }
74
+ type: Object,
75
+ // { width: `'50%'`, height: `'50%'`}
76
+ default: () => imgCropper.cropSize
77
+ },
78
+ // 最小的裁剪窗口
79
+ minCropSize: {
80
+ // {`width`: `百分比 相对于容器宽度` or `px` or `rpx`, `height`: `百分比` or `px` or `rpx` }
81
+ type: Object,
82
+ // { width: `'50px'`, height: `'50px'`}
83
+ default: () => imgCropper.minCropSize
84
+ },
85
+ // true: 开启图片边界检测 保证移动图片过程,当图片的边与裁剪框的边重叠时 就无法继续移动
86
+ boundaryDetect: {
87
+ type: Boolean,
88
+ // `true`
89
+ default: imgCropper.boundaryDetect
90
+ },
91
+ // 是否保持裁剪框的高宽比不变
92
+ keepCropRatio: {
93
+ type: Boolean,
94
+ // `false`
95
+ default: imgCropper.keepCropRatio
96
+ },
97
+ // 是否禁止旋转
98
+ disableRotate: {
99
+ type: Boolean,
100
+ // `false`
101
+ default: imgCropper.disableRotate
102
+ },
103
+ // 放大裁剪窗口的倍数
104
+ canvasZoom: {
105
+ type: Number,
106
+ // `1`
107
+ default: imgCropper.canvasZoom
108
+ },
109
+ // 遮罩层背景颜色
110
+ maskBackground: {
111
+ type: String,
112
+ // 'rgba(0, 0, 0, .5)'
113
+ default: imgCropper.maskBackground
114
+ }
115
+ },
116
+ data() {
117
+ return {
118
+ ratio: 1,
119
+ root: {
120
+ width: 0,
121
+ height: 0
122
+ },
123
+ img: {
124
+ path: '',
125
+ transform: {
126
+ x: 0,
127
+ y: 0,
128
+ rotate: 0,
129
+ scale: 1
130
+ },
131
+ width: 0,
132
+ height: 0
133
+ },
134
+ crop: {
135
+ top: 0,
136
+ right: 0,
137
+ bottom: 0,
138
+ left: 0,
139
+ ratio: 0,
140
+ width: 0,
141
+ height: 0
142
+ },
143
+ focus: true
144
+ }
145
+ },
146
+ computed: {
147
+ imgStyle() {
148
+ const {
149
+ width,
150
+ height,
151
+ transform: { x, y, rotate, scale }
152
+ } = this.img
153
+ // 指定图片的大小、位置、旋转角度、缩放系数
154
+ const style = {
155
+ width: `${width}px`,
156
+ height: `${height}px`,
157
+ transform: `translate3d(${x}px, ${y}px, 0) rotate(${rotate}deg) scale(${scale})`
158
+ }
159
+ return style
160
+ },
161
+ cropStyle() {
162
+ const { top: t, right: r, bottom: b, left: l } = this.crop
163
+ // 指定裁剪窗口的位置、大小、周边的遮罩层效果
164
+ return {
165
+ top: `${t}px`,
166
+ right: `${r}px`,
167
+ bottom: `${b}px`,
168
+ left: `${l}px`,
169
+ outline: `50000px solid ${this.maskBackground}`
170
+ }
171
+ }
172
+ },
173
+ watch: {
174
+ src() {
175
+ this.initImage()
176
+ }
177
+ },
178
+ created() {
179
+ uni.getSystemInfo({
180
+ success: result => {
181
+ this.ratio = result.windowWidth / 750
182
+ this.$nextTick(() => {
183
+ this.initUI()
184
+ })
185
+ }
186
+ })
187
+ },
188
+ methods: {
189
+ async initUI() {
190
+ const { width, height } = await this.getContainerSize()
191
+ this.root = {
192
+ width,
193
+ height
194
+ }
195
+ this.initImage()
196
+ this.initCropWindow()
197
+ },
198
+ getContainerSize() {
199
+ return new Promise(resolve => {
200
+ let query = uni.createSelectorQuery()
201
+ // #ifndef MP-ALIPAY
202
+ query = query.in(this)
203
+ // #endif
204
+ const node = query.select('.pi-img-cropper')
205
+ node
206
+ .boundingClientRect(result => {
207
+ resolve(result)
208
+ })
209
+ .exec()
210
+ })
211
+ },
212
+ async initImage() {
213
+ if (!this.src) {
214
+ return
215
+ }
216
+ const img = await this.loadImageInfo(this.src)
217
+ let w = 0,
218
+ h = 0
219
+ const root = this.root
220
+ if (img.height > img.width) {
221
+ // 竖向图片:高度铺满屏幕高度、宽度等比计算
222
+ h = root.height
223
+ w = (h / img.height) * img.width
224
+ if (w > root.width) {
225
+ // 若计算后的宽度超出屏幕宽度 则等比缩小
226
+ w = root.width
227
+ h = (w / img.width) * img.height
228
+ }
229
+ } else {
230
+ // 横向图片
231
+ w = root.width
232
+ h = (w / img.width) * img.height
233
+ if (h > root.height) {
234
+ h = root.height
235
+ w = (h / img.height) * img.width
236
+ }
237
+ }
238
+ const x = (root.width - img.width) / 2
239
+ const y = (root.height - img.height) / 2
240
+ const scale = w / img.width
241
+ this.img = {
242
+ path: img.path,
243
+ width: img.width,
244
+ height: img.height,
245
+ transform: {
246
+ x,
247
+ y,
248
+ rotate: 0,
249
+ scale
250
+ }
251
+ }
252
+ },
253
+ async loadImageInfo(src) {
254
+ return new Promise(resolve => {
255
+ uni.getImageInfo({
256
+ src: this.src,
257
+ success: result => {
258
+ resolve(result)
259
+ },
260
+ fail: error => {
261
+ resolve(null)
262
+ }
263
+ })
264
+ })
265
+ },
266
+ initCropWindow() {
267
+ // 初始化裁剪窗口
268
+ const root = this.root
269
+ let w = this.toPx(this.cropSize.width)
270
+ let h = this.toPx(this.cropSize.height)
271
+ const minW = this.toPx(this.minCropSize.width)
272
+ const minH = this.toPx(this.minCropSize.height)
273
+ w = w < minW ? minW : w > root.width ? root.width : w
274
+ h = h < minH ? minH : h > root.height ? root.height : h
275
+ const ratio = h / w
276
+ const left = (root.width - w) / 2
277
+ const top = (root.height - h) / 2
278
+ this.crop = {
279
+ top,
280
+ left,
281
+ right: left,
282
+ bottom: top,
283
+ width: w,
284
+ height: h,
285
+ ratio
286
+ }
287
+ },
288
+ toPx(unit) {
289
+ let value = 0
290
+ if (unit) {
291
+ if (/%$/.test(unit)) {
292
+ value = Number(unit.replace(/%$/, ''))
293
+ value = !value ? 0 : value
294
+ value = value * 0.01 * this.root.width
295
+ } else if (/rpx$/i.test(unit)) {
296
+ value = Number(unit.replace(/rpx$/i, ''))
297
+ value = !value ? 0 : value
298
+ value = value * this.ratio
299
+ } else {
300
+ value = Number(unit.replace(/px$/i, ''))
301
+ }
302
+ }
303
+ return value
304
+ }
305
+ }
306
+ }
307
+ </script>
308
+
309
+ <style lang="scss" scoped>
310
+ .pi-img-cropper {
311
+ position: relative;
312
+ width: 100%;
313
+ height: 100%;
314
+ overflow: hidden;
315
+ }
316
+
317
+ .img {
318
+ position: absolute;
319
+ transform-origin: 50% 50%;
320
+ }
321
+
322
+ .crop {
323
+ position: absolute;
324
+ background: transparent;
325
+ }
326
+
327
+ .corner {
328
+ position: absolute;
329
+ width: 40rpx;
330
+ height: 40rpx;
331
+ border: 8rpx solid #ffffff;
332
+ &.lt {
333
+ top: 0;
334
+ left: 0;
335
+ border-right: none;
336
+ border-bottom: none;
337
+ }
338
+ &.rt {
339
+ top: 0;
340
+ right: 0;
341
+ border-left: none;
342
+ border-bottom: none;
343
+ }
344
+ &.rb {
345
+ right: 0;
346
+ bottom: 0;
347
+ border-top: none;
348
+ border-left: none;
349
+ }
350
+ &.lb {
351
+ left: 0;
352
+ bottom: 0;
353
+ border-top: none;
354
+ border-right: none;
355
+ }
356
+ }
357
+ </style>
@@ -0,0 +1,163 @@
1
+ import { debounce } from '@sadais/piui-tool/tools/common'
2
+
3
+ export default {
4
+ data() {
5
+ return {
6
+ touch: {
7
+ prev: null,
8
+ deltaX: 0,
9
+ deltaY: 0,
10
+ prevVector: null
11
+ },
12
+ cutMode: null
13
+ }
14
+ },
15
+ methods: {
16
+ setCutMode(mode) {
17
+ this.cutMode = mode
18
+ console.log('setCutMode: ', mode)
19
+ },
20
+ handleStart(e) {
21
+ const touches = (e && e.touches) || []
22
+ const touch = touches[0] || e
23
+ this.touch.prev = { x: touch.pageX, y: touch.pageY }
24
+ this.focus = false
25
+ if (touches.length > 1) {
26
+ const p = touches[1]
27
+ this.touch.prevVector = {
28
+ x: p.pageX - touch.pageX,
29
+ y: p.pageY - touch.pageY
30
+ }
31
+ }
32
+ },
33
+ handleMove(e) {
34
+ const touches = (e && e.touches) || []
35
+ const touch = touches[0] || e
36
+ this.focus = false
37
+ if (this.touch.prev) {
38
+ this.touch.deltaX = touch.pageX - this.touch.prev.x
39
+ this.touch.deltaY = touch.pageY - this.touch.prev.y
40
+ this.cutMode ? this.updateCrop() : this.updateImgTranslate()
41
+ }
42
+ if (touches.length > 1) {
43
+ const p = touches[1]
44
+ const curVector = { x: p.pageX - touch.pageX, y: p.pageY - touch.pageY }
45
+ if (this.touch.prevVector) {
46
+ if (!this.disableRotate) {
47
+ this.img.transform.rotate += this.angle(this.touch.prevVector, curVector)
48
+ }
49
+ const zoom = this.mod(curVector) / this.mod(this.touch.prevVector)
50
+ this.img.transform.scale *= zoom
51
+ }
52
+ this.touch.prevVector = curVector
53
+ }
54
+ this.touch.prev = { x: touch.pageX, y: touch.pageY }
55
+ },
56
+ handleEnd(e) {
57
+ this.touch = {}
58
+ this.cutMode = null
59
+ this.focus = true
60
+ this.draw()
61
+ },
62
+ updateImgTranslate() {
63
+ const transform = this.img.transform
64
+ transform.x += this.touch.deltaX
65
+ transform.y += this.touch.deltaY
66
+ this.detectBoundary()
67
+ },
68
+ ensureCropMinSize() {
69
+ const crop = this.crop
70
+ const touch = this.touch
71
+ const mode = this.cutMode
72
+ const minW = this.toPx(this.minCropSize.width)
73
+ const minH = this.toPx(this.minCropSize.height)
74
+ switch (mode) {
75
+ case 'lt': {
76
+ if (touch.deltaX > 0 || touch.deltaY > 0) {
77
+ touch.deltaX = Math.min(touch.deltaX, crop.width - minW)
78
+ touch.deltaY = Math.min(touch.deltaY, crop.height - minH)
79
+ }
80
+ break
81
+ }
82
+ case 'rt': {
83
+ if (touch.deltaX < 0 || touch.deltaY > 0) {
84
+ touch.deltaX = Math.max(touch.deltaX, minW - crop.width)
85
+ touch.deltaY = Math.min(touch.deltaY, crop.height - minH)
86
+ }
87
+ break
88
+ }
89
+ case 'rb': {
90
+ if (touch.deltaX < 0 || touch.deltaY < 0) {
91
+ touch.deltaX = Math.max(touch.deltaX, minW - crop.width)
92
+ touch.deltaY = Math.max(touch.deltaY, minH - crop.height)
93
+ }
94
+ break
95
+ }
96
+ case 'lb': {
97
+ if (touch.deltaX > 0 || touch.deltaY < 0) {
98
+ touch.deltaX = Math.min(touch.deltaX, crop.width - minW)
99
+ touch.deltaY = Math.max(touch.deltaY, minH - crop.height)
100
+ }
101
+ break
102
+ }
103
+ }
104
+ },
105
+ updateCrop() {
106
+ this.ensureCropMinSize()
107
+ let { deltaX, deltaY } = this.touch
108
+ if (this.keepCropRatio) {
109
+ deltaY = deltaX * this.crop.ratio
110
+ }
111
+
112
+ const crop = this.crop
113
+ switch (this.cutMode) {
114
+ case 'lt': {
115
+ crop.top += deltaY
116
+ crop.left += deltaX
117
+ break
118
+ }
119
+ case 'rt': {
120
+ crop.right += -deltaX
121
+ crop.top += this.keepCropRatio ? -deltaY : deltaY
122
+ break
123
+ }
124
+ case 'rb': {
125
+ crop.right += -deltaX
126
+ crop.bottom += -deltaY
127
+ break
128
+ }
129
+ case 'lb': {
130
+ crop.left += deltaX
131
+ crop.bottom -= deltaY
132
+ break
133
+ }
134
+ }
135
+ crop.width = this.root.width - crop.left - crop.right
136
+ crop.height = this.root.height - crop.top - crop.bottom
137
+ },
138
+ detectBoundary: debounce(function(e) {
139
+ if (this.boundaryDetect) {
140
+ console.log('图片剪裁插件 -> 边界检查')
141
+ const angle = (this.img.transform.rotate * Math.PI) / 180
142
+ const cos = Math.cos,
143
+ sin = Math.sin,
144
+ abs = Math.abs
145
+ const { width: w, height: h } = this.img
146
+ const scale = this.img.transform.scale
147
+ const realW = (w * abs(cos(angle)) + h * abs(sin(angle))) * scale
148
+ const realH = (w * abs(sin(angle)) + h * abs(cos(angle))) * scale
149
+ const minX = this.crop.left + this.crop.width - w - (realW - w) / 2
150
+ const maxX = this.crop.left + (realW - w) / 2
151
+ let x = this.img.transform.x
152
+ x = Math.floor(x < minX ? minX : x > maxX ? maxX : x)
153
+ this.img.transform.x = x
154
+
155
+ const minY = this.crop.top + this.crop.height - h - (realH - h) / 2
156
+ const maxY = this.crop.top + (realH - h) / 2
157
+ let y = this.img.transform.y
158
+ y = Math.floor(y < minY ? minY : y > maxY ? maxY : y)
159
+ this.img.transform.y = y
160
+ }
161
+ }, 200)
162
+ }
163
+ }
@@ -0,0 +1,35 @@
1
+ export default {
2
+ methods: {
3
+ /**
4
+ * 计算向量vector1旋转到vector2的角度
5
+ * @param vector1 旋转的起始向量
6
+ * @param vector2 旋转的目标向量
7
+ * @return 旋转角度(弧度)
8
+ * > 0:顺时针旋转
9
+ * < 0:逆时针旋转
10
+ */
11
+ angle(vector1, vector2) {
12
+ const dot = vector1.x * vector2.x + vector1.y * vector2.y
13
+ const mod1 = this.mod(vector1)
14
+ const mod2 = this.mod(vector2)
15
+ const l = mod1 * mod2
16
+ if (l) {
17
+ let cosValue = dot / l
18
+ cosValue = Math.min(cosValue, 1)
19
+ let angle = Math.acos(cosValue)
20
+ const tmp = vector1.x * vector2.y - vector1.y * vector2.x
21
+ angle = tmp > 0 ? angle : -angle
22
+ return angle * 180 / Math.PI
23
+ }
24
+ return 0
25
+ },
26
+ /**
27
+ * 计算给定向量的模 即勾股定理
28
+ * @param vector
29
+ * @return 向量的模
30
+ */
31
+ mod(vector) {
32
+ return Math.sqrt(vector.x * vector.x + vector.y * vector.y)
33
+ }
34
+ }
35
+ }
@@ -10,7 +10,7 @@
10
10
  :placeholder="placeholder"
11
11
  :placeholder-style="placeholderStyle"
12
12
  :placeholder-class="placeholderClass"
13
- :disabled="disabled"
13
+ :disabled="getDisabled"
14
14
  :maxlength="maxlength"
15
15
  :cursor-spacing="cursorSpacing"
16
16
  :focus="focus"
@@ -44,7 +44,7 @@
44
44
  :placeholder="placeholder"
45
45
  :placeholder-style="placeholderStyle"
46
46
  :placeholder-class="placeholderClass"
47
- :disabled="disabled"
47
+ :disabled="getDisabled"
48
48
  :maxlength="maxlength"
49
49
  :cursor-spacing="cursorSpacing"
50
50
  :focus="focus"
@@ -242,6 +242,13 @@ export default {
242
242
  focused: this.focus
243
243
  }
244
244
  },
245
+ computed: {
246
+ getDisabled() {
247
+ const parentFormItem = this.$pi.parent(this, 'PiFormItem')
248
+ const disabled = this.disabled || (parentFormItem && parentFormItem.getDisabled)
249
+ return disabled
250
+ }
251
+ },
245
252
  methods: {
246
253
  handleItemClick(e) {
247
254
  this.$emit('click', e)
@@ -0,0 +1,78 @@
1
+ <template>
2
+ <view class="pi-line" :style="[lineStyle]" />
3
+ </template>
4
+
5
+ <script>
6
+ import ValueSync from '../../mixin/value-sync'
7
+ import { getConfig } from '../../config'
8
+ const TAG = 'PiLine'
9
+ const { line } = getConfig()
10
+ export default {
11
+ name: 'PiLine',
12
+ // 混入v-model
13
+ mixins: [ValueSync],
14
+ props: {
15
+ color: {
16
+ type: String,
17
+ default: line.color
18
+ },
19
+ // 长度,竖向时为高度,横向时为长度,可以为百分比,带rpx单位的值等
20
+ length: {
21
+ type: String,
22
+ default: line.length
23
+ },
24
+ // 排列方向,row|column
25
+ direction: {
26
+ type: String,
27
+ default: line.direction
28
+ },
29
+ // 是否显示细边框
30
+ hairLine: {
31
+ type: Boolean,
32
+ default: line.hairLine
33
+ },
34
+ // 边距
35
+ margin: {
36
+ type: String,
37
+ default: line.margin
38
+ },
39
+ // 线条的类型,solid-实线,dashed-方形虚线,dotted-圆点虚线
40
+ borderStyle: {
41
+ type: String,
42
+ default: line.borderStyle
43
+ }
44
+ },
45
+ data() {
46
+ return {}
47
+ },
48
+ computed: {
49
+ lineStyle() {
50
+ let style = {}
51
+ style.margin = this.margin
52
+ if (this.direction == 'row') {
53
+ style.borderBottomWidth = '1px'
54
+ style.borderBottomStyle = this.borderStyle
55
+ style.width = this.length
56
+ // 边框高度缩小一半
57
+ if (this.hairLine) style.transform = 'scaleY(0.5)'
58
+ } else {
59
+ style.borderLeftWidth = '1px'
60
+ style.borderLeftStyle = this.borderStyle
61
+ style.height = this.length
62
+ // 边框宽度缩小一半
63
+ if (this.hairLine) style.transform = 'scaleX(0.5)'
64
+ }
65
+ style.borderColor = this.color
66
+ return style
67
+ }
68
+ },
69
+ watch: {},
70
+ methods: {}
71
+ }
72
+ </script>
73
+
74
+ <style lang="scss" scoped>
75
+ .pi-line {
76
+ vertical-align: middle;
77
+ }
78
+ </style>