sadais-piui 1.2.7-beta141 → 1.2.7-beta143

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.
@@ -24,14 +24,14 @@
24
24
  </view>
25
25
  </template>
26
26
  <script>
27
- import Touch from "./touch";
28
- import Vector from "./vector";
29
- import Canvas from "./canvas";
30
- import { getConfig } from "../../config";
27
+ import Touch from './touch'
28
+ import Vector from './vector'
29
+ import Canvas from './canvas'
30
+ import { getConfig } from '../../config'
31
31
 
32
- const { imgCropper } = getConfig();
32
+ const { imgCropper } = getConfig()
33
33
  export default {
34
- name: "PiImgCropper",
34
+ name: 'PiImgCropper',
35
35
  mixins: [Touch, Vector, Canvas],
36
36
  props: {
37
37
  // 自定义样式
@@ -39,97 +39,97 @@ export default {
39
39
  type: Object,
40
40
  default() {
41
41
  // {}
42
- return imgCropper.customStyle;
43
- },
42
+ return imgCropper.customStyle
43
+ }
44
44
  },
45
45
  // 自定义样式类
46
46
  customClass: {
47
47
  type: String,
48
48
  default() {
49
49
  // ''
50
- return imgCropper.customClass;
51
- },
50
+ return imgCropper.customClass
51
+ }
52
52
  },
53
53
  // 图片src
54
54
  src: {
55
55
  type: String,
56
56
  // `''`
57
- default: imgCropper.src,
57
+ default: imgCropper.src
58
58
  },
59
59
  // 图片格式
60
60
  fileType: {
61
61
  type: String,
62
62
  // `png`
63
- deault: imgCropper.fileType,
63
+ deault: imgCropper.fileType
64
64
  },
65
65
  // 图片质量(0,1]
66
66
  quality: {
67
67
  type: Number,
68
68
  // `1`
69
- default: imgCropper.quality,
69
+ default: imgCropper.quality
70
70
  },
71
71
  // 裁剪窗口大小
72
72
  cropSize: {
73
73
  // {`width`: `百分比 相对于容器宽度` or `px` or `rpx`, `height`: `百分比` or `px` or `rpx` }
74
74
  type: Object,
75
75
  // { width: `'50%'`, height: `'50%'`}
76
- default: () => imgCropper.cropSize,
76
+ default: () => imgCropper.cropSize
77
77
  },
78
78
  // 最小的裁剪窗口
79
79
  minCropSize: {
80
80
  // {`width`: `百分比 相对于容器宽度` or `px` or `rpx`, `height`: `百分比` or `px` or `rpx` }
81
81
  type: Object,
82
82
  // { width: `'50px'`, height: `'50px'`}
83
- default: () => imgCropper.minCropSize,
83
+ default: () => imgCropper.minCropSize
84
84
  },
85
85
  // true: 开启图片边界检测 保证移动图片过程,当图片的边与裁剪框的边重叠时 就无法继续移动
86
86
  boundaryDetect: {
87
87
  type: Boolean,
88
88
  // `true`
89
- default: imgCropper.boundaryDetect,
89
+ default: imgCropper.boundaryDetect
90
90
  },
91
91
  // 是否保持裁剪框的高宽比不变
92
92
  keepCropRatio: {
93
93
  type: Boolean,
94
94
  // `false`
95
- default: imgCropper.keepCropRatio,
95
+ default: imgCropper.keepCropRatio
96
96
  },
97
97
  // 是否禁止旋转
98
98
  disableRotate: {
99
99
  type: Boolean,
100
100
  // `false`
101
- default: imgCropper.disableRotate,
101
+ default: imgCropper.disableRotate
102
102
  },
103
103
  // 放大裁剪窗口的倍数
104
104
  canvasZoom: {
105
105
  type: Number,
106
106
  // `1`
107
- default: imgCropper.canvasZoom,
107
+ default: imgCropper.canvasZoom
108
108
  },
109
109
  // 遮罩层背景颜色
110
110
  maskBackground: {
111
111
  type: String,
112
112
  // 'rgba(0, 0, 0, .5)'
113
- default: imgCropper.maskBackground,
114
- },
113
+ default: imgCropper.maskBackground
114
+ }
115
115
  },
116
116
  data() {
117
117
  return {
118
118
  ratio: 1,
119
119
  root: {
120
120
  width: 0,
121
- height: 0,
121
+ height: 0
122
122
  },
123
123
  img: {
124
- path: "",
124
+ path: '',
125
125
  transform: {
126
126
  x: 0,
127
127
  y: 0,
128
128
  rotate: 0,
129
- scale: 1,
129
+ scale: 1
130
130
  },
131
131
  width: 0,
132
- height: 0,
132
+ height: 0
133
133
  },
134
134
  crop: {
135
135
  top: 0,
@@ -138,106 +138,109 @@ export default {
138
138
  left: 0,
139
139
  ratio: 0,
140
140
  width: 0,
141
- height: 0,
141
+ height: 0
142
142
  },
143
- focus: true,
144
- };
143
+ focus: true
144
+ }
145
145
  },
146
146
  computed: {
147
147
  imgStyle() {
148
148
  const {
149
149
  width,
150
150
  height,
151
- transform: { x, y, rotate, scale },
152
- } = this.img;
151
+ transform: { x, y, rotate, scale }
152
+ } = this.img
153
153
  // 指定图片的大小、位置、旋转角度、缩放系数
154
154
  const style = {
155
155
  width: `${width}px`,
156
156
  height: `${height}px`,
157
- transform: `translate3d(${x}px, ${y}px, 0) rotate(${rotate}deg) scale(${scale})`,
158
- };
159
- return style;
157
+ transform: `translate3d(${x}px, ${y}px, 0) rotate(${rotate}deg) scale(${scale})`
158
+ }
159
+ return style
160
160
  },
161
161
  cropStyle() {
162
- const { top: t, right: r, bottom: b, left: l } = this.crop;
162
+ const { top: t, right: r, bottom: b, left: l } = this.crop
163
163
  // 指定裁剪窗口的位置、大小、周边的遮罩层效果
164
164
  return {
165
165
  top: `${t}px`,
166
166
  right: `${r}px`,
167
167
  bottom: `${b}px`,
168
168
  left: `${l}px`,
169
- outline: `50000px solid ${this.maskBackground}`,
170
- };
171
- },
169
+ outline: `50000px solid ${this.maskBackground}`
170
+ }
171
+ }
172
172
  },
173
173
  watch: {
174
174
  src() {
175
- this.initImage();
176
- },
175
+ this.initImage()
176
+ }
177
177
  },
178
178
  mounted() {
179
179
  uni.getSystemInfo({
180
- success: (result) => {
181
- this.ratio = result.windowWidth / 750;
180
+ success: result => {
181
+ this.ratio = result.windowWidth / 750
182
182
  this.$nextTick(() => {
183
- this.initUI();
184
- });
185
- },
186
- });
183
+ this.initUI()
184
+ })
185
+ }
186
+ })
187
187
  },
188
188
  methods: {
189
189
  async initUI() {
190
- const { width, height } = await this.getContainerSize();
190
+ const { width, height } = (await this.getContainerSize()) || {
191
+ width: 0,
192
+ height: 0
193
+ }
191
194
  this.root = {
192
195
  width,
193
- height,
194
- };
195
- this.initImage();
196
- this.initCropWindow();
196
+ height
197
+ }
198
+ this.initImage()
199
+ this.initCropWindow()
197
200
  },
198
201
  getContainerSize() {
199
- return new Promise((resolve) => {
200
- let query = uni.createSelectorQuery();
202
+ return new Promise(resolve => {
203
+ let query = uni.createSelectorQuery()
201
204
  // #ifndef MP-ALIPAY
202
- query = query.in(this);
205
+ query = query.in(this)
203
206
  // #endif
204
- const node = query.select(".pi-img-cropper");
207
+ const node = query.select('.pi-img-cropper')
205
208
  node
206
- .boundingClientRect((result) => {
207
- resolve(result);
209
+ .boundingClientRect(result => {
210
+ resolve(result)
208
211
  })
209
- .exec();
210
- });
212
+ .exec()
213
+ })
211
214
  },
212
215
  async initImage() {
213
216
  if (!this.src) {
214
- return;
217
+ return
215
218
  }
216
- const img = await this.loadImageInfo(this.src);
219
+ const img = await this.loadImageInfo(this.src)
217
220
  let w = 0,
218
- h = 0;
219
- const root = this.root;
221
+ h = 0
222
+ const root = this.root
220
223
  if (img.height > img.width) {
221
224
  // 竖向图片:高度铺满屏幕高度、宽度等比计算
222
- h = root.height;
223
- w = (h / img.height) * img.width;
225
+ h = root.height
226
+ w = (h / img.height) * img.width
224
227
  if (w > root.width) {
225
228
  // 若计算后的宽度超出屏幕宽度 则等比缩小
226
- w = root.width;
227
- h = (w / img.width) * img.height;
229
+ w = root.width
230
+ h = (w / img.width) * img.height
228
231
  }
229
232
  } else {
230
233
  // 横向图片
231
- w = root.width;
232
- h = (w / img.width) * img.height;
234
+ w = root.width
235
+ h = (w / img.width) * img.height
233
236
  if (h > root.height) {
234
- h = root.height;
235
- w = (h / img.height) * img.width;
237
+ h = root.height
238
+ w = (h / img.height) * img.width
236
239
  }
237
240
  }
238
- const x = (root.width - img.width) / 2;
239
- const y = (root.height - img.height) / 2;
240
- const scale = w / img.width;
241
+ const x = (root.width - img.width) / 2
242
+ const y = (root.height - img.height) / 2
243
+ const scale = w / img.width
241
244
  this.img = {
242
245
  path: img.path,
243
246
  width: img.width,
@@ -246,35 +249,35 @@ export default {
246
249
  x,
247
250
  y,
248
251
  rotate: 0,
249
- scale,
250
- },
251
- };
252
+ scale
253
+ }
254
+ }
252
255
  },
253
256
  async loadImageInfo(src) {
254
- return new Promise((resolve) => {
257
+ return new Promise(resolve => {
255
258
  uni.getImageInfo({
256
259
  src: this.src,
257
- success: (result) => {
258
- resolve(result);
260
+ success: result => {
261
+ resolve(result)
259
262
  },
260
- fail: (error) => {
261
- resolve(null);
262
- },
263
- });
264
- });
263
+ fail: error => {
264
+ resolve(null)
265
+ }
266
+ })
267
+ })
265
268
  },
266
269
  initCropWindow() {
267
270
  // 初始化裁剪窗口
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;
271
+ const root = this.root
272
+ let w = this.toPx(this.cropSize.width)
273
+ let h = this.toPx(this.cropSize.height)
274
+ const minW = this.toPx(this.minCropSize.width)
275
+ const minH = this.toPx(this.minCropSize.height)
276
+ w = w < minW ? minW : w > root.width ? root.width : w
277
+ h = h < minH ? minH : h > root.height ? root.height : h
278
+ const ratio = h / w
279
+ const left = (root.width - w) / 2
280
+ const top = (root.height - h) / 2
278
281
  this.crop = {
279
282
  top,
280
283
  left,
@@ -282,28 +285,28 @@ export default {
282
285
  bottom: top,
283
286
  width: w,
284
287
  height: h,
285
- ratio,
286
- };
288
+ ratio
289
+ }
287
290
  },
288
291
  toPx(unit) {
289
- let value = 0;
292
+ let value = 0
290
293
  if (unit) {
291
294
  if (/%$/.test(unit)) {
292
- value = Number(unit.replace(/%$/, ""));
293
- value = !value ? 0 : value;
294
- value = value * 0.01 * this.root.width;
295
+ value = Number(unit.replace(/%$/, ''))
296
+ value = !value ? 0 : value
297
+ value = value * 0.01 * this.root.width
295
298
  } else if (/rpx$/i.test(unit)) {
296
- value = Number(unit.replace(/rpx$/i, ""));
297
- value = !value ? 0 : value;
298
- value = value * this.ratio;
299
+ value = Number(unit.replace(/rpx$/i, ''))
300
+ value = !value ? 0 : value
301
+ value = value * this.ratio
299
302
  } else {
300
- value = Number(unit.replace(/px$/i, ""));
303
+ value = Number(unit.replace(/px$/i, ''))
301
304
  }
302
305
  }
303
- return value;
304
- },
305
- },
306
- };
306
+ return value
307
+ }
308
+ }
309
+ }
307
310
  </script>
308
311
 
309
312
  <style lang="scss" scoped>
@@ -157,10 +157,7 @@ const PI_DEFAULT_FN_FLAG = 'PI_DEFAULT_FN_FLAG'
157
157
 
158
158
  function isImageFilename(filename) {
159
159
  const imageExtensions = /\.(jpg|jpeg|png|gif|bmp|tiff|webp)$/i
160
- return (
161
- imageExtensions.test(filename) ||
162
- filename.startsWith('data:image/jpeg;base64,')
163
- )
160
+ return imageExtensions.test(filename) || filename.startsWith('data:')
164
161
  }
165
162
 
166
163
  function isVideoFilename(filename) {
@@ -821,12 +818,18 @@ export default {
821
818
  async handleChooseFile() {
822
819
  const { sizeType, sourceType, crop } = this.getChooseFileOpts
823
820
  try {
824
- const [, result] = await uni.chooseFile({
821
+ const [cancel, result] = await uni.chooseFile({
825
822
  count: this.getUploadMaxCount,
826
823
  sizeType,
827
824
  sourceType,
828
825
  crop
829
826
  })
827
+
828
+ if (cancel && cancel?.errMsg === 'chooseFile:fail cancel') {
829
+ console.log(TAG, '用户取消选择文件')
830
+ return
831
+ }
832
+
830
833
  let { errMsg, tempFiles } = result
831
834
  console.log(TAG, '上传文件结果', result)
832
835
  if (errMsg !== 'chooseFile:ok') {
@@ -849,16 +852,18 @@ export default {
849
852
  // #ifdef MP-WEIXIN
850
853
  this.showSheet = false
851
854
  try {
852
- const [, result] = await uni.chooseMessageFile({
855
+ const [cancel, result] = await uni.chooseMessageFile({
853
856
  count: this.getUploadMaxCount,
854
857
  type:
855
858
  this.fileTypes.includes('image') || this.fileTypes.includes('video')
856
859
  ? 'all'
857
860
  : 'file'
858
861
  })
859
- if (!result) {
862
+ if (cancel && cancel?.errMsg === 'chooseMessageFile:fail cancel') {
863
+ console.log(TAG, '用户取消选择聊天文件')
860
864
  return
861
865
  }
866
+
862
867
  let { errMsg, tempFiles } = result
863
868
  console.log(TAG, '选择微信聊天记录文件', result)
864
869
  if (errMsg !== 'chooseMessageFile:ok') {
@@ -878,12 +883,18 @@ export default {
878
883
  async handleChooseImage() {
879
884
  const { sizeType, sourceType, crop } = this.getChooseImageOpts
880
885
  try {
881
- const [, result] = await uni.chooseImage({
886
+ const [cancel, result] = await uni.chooseImage({
882
887
  count: this.getUploadMaxCount,
883
888
  sizeType,
884
889
  sourceType,
885
890
  crop
886
891
  })
892
+
893
+ if (cancel && cancel?.errMsg === 'chooseImage:fail cancel') {
894
+ console.log(TAG, '用户取消选择图片')
895
+ return
896
+ }
897
+
887
898
  let { errMsg, tempFilePaths } = result
888
899
  if (errMsg !== 'chooseImage:ok') {
889
900
  throw new Error(errMsg)
@@ -916,11 +927,17 @@ export default {
916
927
  async handleChooseVideo() {
917
928
  const { sourceType, maxDuration, camera } = this.getChooseVideoOpts
918
929
  try {
919
- const [, result] = await uni.chooseVideo({
930
+ const [cancel, result] = await uni.chooseVideo({
920
931
  sourceType,
921
932
  maxDuration,
922
933
  camera
923
934
  })
935
+
936
+ if (cancel && cancel?.errMsg === 'chooseVideo:fail cancel') {
937
+ console.log(TAG, '用户取消选择视频')
938
+ return
939
+ }
940
+
924
941
  let { errMsg, tempFilePath, tempFile } = result
925
942
  if (errMsg !== 'chooseVideo:ok') {
926
943
  throw new Error(errMsg)
@@ -937,7 +954,7 @@ export default {
937
954
  const { sourceType, maxDuration, camera } =
938
955
  this.type === 'video' ? this.getChooseVideoOpts : this.getChooseFileOpts
939
956
  try {
940
- const [, result] = await uni.chooseMedia({
957
+ const [cancel, result] = await uni.chooseMedia({
941
958
  count: this.getUploadMaxCount,
942
959
  mediaType: this.type === 'video' ? ['video'] : ['mix'],
943
960
  extension: this.getExtension,
@@ -945,6 +962,12 @@ export default {
945
962
  maxDuration,
946
963
  camera
947
964
  })
965
+
966
+ if (cancel && cancel?.errMsg === 'chooseMedia:fail cancel') {
967
+ console.log(TAG, '用户取消选择媒体')
968
+ return
969
+ }
970
+
948
971
  let { errMsg, tempFiles } = result
949
972
  if (errMsg !== 'chooseMedia:ok') {
950
973
  throw new Error(errMsg)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sadais-piui",
3
- "version": "1.2.7-beta141",
3
+ "version": "1.2.7-beta143",
4
4
  "description": "piui组件库",
5
5
  "main": "index.js",
6
6
  "scripts": {