sadais-piui 1.2.7-beta142 → 1.2.7-beta144

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>
@@ -67,7 +67,11 @@
67
67
  </view>
68
68
  </view>
69
69
  <!-- 上传框 -->
70
- <view v-if="getUploadMaxCount && !getDisabled">
70
+ <view
71
+ v-if="
72
+ getUploadMaxCount && (!getDisabled || (getDisabled && !getImgs.length))
73
+ "
74
+ >
71
75
  <view
72
76
  :style="[getUploadBtnStyle]"
73
77
  class="pi-flex-column-center"
@@ -818,12 +822,18 @@ export default {
818
822
  async handleChooseFile() {
819
823
  const { sizeType, sourceType, crop } = this.getChooseFileOpts
820
824
  try {
821
- const [, result] = await uni.chooseFile({
825
+ const [cancel, result] = await uni.chooseFile({
822
826
  count: this.getUploadMaxCount,
823
827
  sizeType,
824
828
  sourceType,
825
829
  crop
826
830
  })
831
+
832
+ if (cancel && cancel?.errMsg === 'chooseFile:fail cancel') {
833
+ console.log(TAG, '用户取消选择文件')
834
+ return
835
+ }
836
+
827
837
  let { errMsg, tempFiles } = result
828
838
  console.log(TAG, '上传文件结果', result)
829
839
  if (errMsg !== 'chooseFile:ok') {
@@ -846,16 +856,18 @@ export default {
846
856
  // #ifdef MP-WEIXIN
847
857
  this.showSheet = false
848
858
  try {
849
- const [, result] = await uni.chooseMessageFile({
859
+ const [cancel, result] = await uni.chooseMessageFile({
850
860
  count: this.getUploadMaxCount,
851
861
  type:
852
862
  this.fileTypes.includes('image') || this.fileTypes.includes('video')
853
863
  ? 'all'
854
864
  : 'file'
855
865
  })
856
- if (!result) {
866
+ if (cancel && cancel?.errMsg === 'chooseMessageFile:fail cancel') {
867
+ console.log(TAG, '用户取消选择聊天文件')
857
868
  return
858
869
  }
870
+
859
871
  let { errMsg, tempFiles } = result
860
872
  console.log(TAG, '选择微信聊天记录文件', result)
861
873
  if (errMsg !== 'chooseMessageFile:ok') {
@@ -875,12 +887,18 @@ export default {
875
887
  async handleChooseImage() {
876
888
  const { sizeType, sourceType, crop } = this.getChooseImageOpts
877
889
  try {
878
- const [, result] = await uni.chooseImage({
890
+ const [cancel, result] = await uni.chooseImage({
879
891
  count: this.getUploadMaxCount,
880
892
  sizeType,
881
893
  sourceType,
882
894
  crop
883
895
  })
896
+
897
+ if (cancel && cancel?.errMsg === 'chooseImage:fail cancel') {
898
+ console.log(TAG, '用户取消选择图片')
899
+ return
900
+ }
901
+
884
902
  let { errMsg, tempFilePaths } = result
885
903
  if (errMsg !== 'chooseImage:ok') {
886
904
  throw new Error(errMsg)
@@ -913,11 +931,17 @@ export default {
913
931
  async handleChooseVideo() {
914
932
  const { sourceType, maxDuration, camera } = this.getChooseVideoOpts
915
933
  try {
916
- const [, result] = await uni.chooseVideo({
934
+ const [cancel, result] = await uni.chooseVideo({
917
935
  sourceType,
918
936
  maxDuration,
919
937
  camera
920
938
  })
939
+
940
+ if (cancel && cancel?.errMsg === 'chooseVideo:fail cancel') {
941
+ console.log(TAG, '用户取消选择视频')
942
+ return
943
+ }
944
+
921
945
  let { errMsg, tempFilePath, tempFile } = result
922
946
  if (errMsg !== 'chooseVideo:ok') {
923
947
  throw new Error(errMsg)
@@ -934,7 +958,7 @@ export default {
934
958
  const { sourceType, maxDuration, camera } =
935
959
  this.type === 'video' ? this.getChooseVideoOpts : this.getChooseFileOpts
936
960
  try {
937
- const [, result] = await uni.chooseMedia({
961
+ const [cancel, result] = await uni.chooseMedia({
938
962
  count: this.getUploadMaxCount,
939
963
  mediaType: this.type === 'video' ? ['video'] : ['mix'],
940
964
  extension: this.getExtension,
@@ -942,6 +966,12 @@ export default {
942
966
  maxDuration,
943
967
  camera
944
968
  })
969
+
970
+ if (cancel && cancel?.errMsg === 'chooseMedia:fail cancel') {
971
+ console.log(TAG, '用户取消选择媒体')
972
+ return
973
+ }
974
+
945
975
  let { errMsg, tempFiles } = result
946
976
  if (errMsg !== 'chooseMedia:ok') {
947
977
  throw new Error(errMsg)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sadais-piui",
3
- "version": "1.2.7-beta142",
3
+ "version": "1.2.7-beta144",
4
4
  "description": "piui组件库",
5
5
  "main": "index.js",
6
6
  "scripts": {