uview-plus 3.5.5 → 3.5.10

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.
package/changelog.md CHANGED
@@ -1,3 +1,19 @@
1
+ ## 3.5.10(2025-08-22)
2
+ feat: 新增poster海报生成组件
3
+
4
+
5
+ ## 3.5.9(2025-08-22)
6
+ feat: 优化qrcode组件支持toTempFilePath方法
7
+
8
+ ## 3.5.8(2025-08-22)
9
+ fix: 优化rpx下calendar高度计算强制px
10
+
11
+ ## 3.5.7(2025-08-22)
12
+ feat: input和search新增onlyClearableOnFocused参数支持控制是否仅聚焦时显示清除按钮
13
+
14
+ ## 3.5.6(2025-08-21)
15
+ feat: picker弹窗及datetime-picker组件支持页面内模式
16
+
1
17
  ## 3.5.5(2025-08-21)
2
18
  feat: popup弹窗及canlendar组件支持页面内插入无弹窗模式
3
19
 
@@ -169,7 +169,7 @@
169
169
  // #ifdef APP-NVUE
170
170
  style.width = addUnit(dayWidth, 'px')
171
171
  // #endif
172
- style.height = addUnit(this.rowHeight)
172
+ style.height = addUnit(this.rowHeight, 'px')
173
173
  if (index2 === 0) {
174
174
  // 获取当前为星期几,如果为0,则为星期天,减一为每月第一天时,需要向左偏移的item个数
175
175
  week = (week === 0 ? 7 : week) - 1
@@ -18,7 +18,7 @@
18
18
  ></uHeader>
19
19
  <scroll-view
20
20
  :style="{
21
- height: addUnit(listHeight)
21
+ height: addUnit(listHeight, 'px')
22
22
  }"
23
23
  scroll-y
24
24
  @scroll="onScroll"
@@ -77,7 +77,7 @@ import dayjs from '../u-datetime-picker/dayjs.esm.min.js';
77
77
  import Calendar from '../../libs/util/calendar.js'
78
78
  import { mpMixin } from '../../libs/mixin/mpMixin.js'
79
79
  import { mixin } from '../../libs/mixin/mixin.js'
80
- import { addUnit, range, error, padZero } from '../../libs/function/index';
80
+ import { addUnit, getPx, range, error, padZero } from '../../libs/function/index';
81
81
  import test from '../../libs/function/test';
82
82
  /**
83
83
  * Calendar 日历
@@ -39,5 +39,6 @@ export default {
39
39
  disabledColor: '',
40
40
  placeholder: t("up.common.pleaseChoose"),
41
41
  inputProps: {},
42
+ pageInline: false
42
43
  }
43
44
  }
@@ -163,6 +163,11 @@ export const props = defineMixin({
163
163
  defaultIndex: {
164
164
  type: Array,
165
165
  default: () => defProps.datetimePicker.defaultIndex
166
+ },
167
+ // 是否页面内展示
168
+ pageInline:{
169
+ type: Boolean,
170
+ default: () => defProps.datetimePicker.pageInline
166
171
  }
167
172
  }
168
173
  })
@@ -9,13 +9,13 @@
9
9
  v-model="inputValue"
10
10
  v-bind="inputPropsInner"
11
11
  ></up-input>
12
- <div class="input-cover">
13
- </div>
12
+ <view class="input-cover">
13
+ </view>
14
14
  </slot>
15
15
  </view>
16
16
  <u-picker
17
17
  ref="picker"
18
- :show="show || (hasInput && showByClickInput)"
18
+ :show="pageInline || show || (hasInput && showByClickInput)"
19
19
  :popupMode="popupMode"
20
20
  :closeOnClickOverlay="closeOnClickOverlay"
21
21
  :columns="columns"
@@ -29,6 +29,7 @@
29
29
  :cancelColor="cancelColor"
30
30
  :confirmColor="confirmColor"
31
31
  :toolbarRightSlot="toolbarRightSlot"
32
+ :pageInline="pageInline"
32
33
  @close="close"
33
34
  @cancel="cancel"
34
35
  @confirm="confirm"
@@ -44,7 +44,12 @@ export const props = defineMixin({
44
44
  // 是否显示清除控件
45
45
  clearable: {
46
46
  type: Boolean,
47
- default: () => defProps.input.clearable
47
+ default: false
48
+ },
49
+ // 是否仅在聚焦时显示清除控件
50
+ onlyClearableOnFocused: {
51
+ type: Boolean,
52
+ default: true
48
53
  },
49
54
  // 是否密码类型
50
55
  password: {
@@ -205,8 +205,15 @@ export default {
205
205
  },
206
206
  // 是否显示清除控件
207
207
  isShowClear() {
208
- const { clearable, readonly, focused, innerValue } = this;
209
- return !!clearable && !readonly && !!focused && innerValue !== "";
208
+ const { clearable, readonly, focused, innerValue, onlyClearableOnFocused } = this;
209
+ if (!clearable || readonly) {
210
+ return false;
211
+ }
212
+ if (onlyClearableOnFocused) {
213
+ return !!focused && innerValue !== "";
214
+ } else {
215
+ return innerValue !== "";
216
+ }
210
217
  },
211
218
  // 组件的类名
212
219
  inputClass() {
@@ -36,6 +36,7 @@ export default {
36
36
  bgColor: '',
37
37
  round: 0,
38
38
  duration: 300,
39
- overlayOpacity: 0.5
39
+ overlayOpacity: 0.5,
40
+ pageInline: false
40
41
  }
41
42
  }
@@ -142,6 +142,11 @@ export const props = defineMixin({
142
142
  overlayOpacity: {
143
143
  type: [Number, String],
144
144
  default: () => defProps.picker.overlayOpacity
145
- }
145
+ },
146
+ // 是否页面内展示
147
+ pageInline:{
148
+ type: Boolean,
149
+ default: () => defProps.picker.pageInline
150
+ }
146
151
  }
147
152
  })
@@ -11,7 +11,7 @@
11
11
  v-model="inputLabel"
12
12
  v-bind="inputPropsInner">
13
13
  </up-input>
14
- <div class="input-cover"></div>
14
+ <view class="input-cover"></view>
15
15
  </view>
16
16
  <u-popup
17
17
  :show="show || (hasInput && showByClickInput)"
@@ -20,6 +20,7 @@
20
20
  :bgColor="bgColor"
21
21
  :round="round"
22
22
  :duration="duration"
23
+ :pageInline="pageInline"
23
24
  :overlayOpacity="overlayOpacity"
24
25
  @close="closeHandler"
25
26
  >
@@ -80,7 +80,7 @@ export const props = defineMixin({
80
80
  // 是否页面内展示
81
81
  pageInline:{
82
82
  type: Boolean,
83
- default: defProps.popup.pageInline
84
- },
83
+ default: () => defProps.popup.pageInline
84
+ }
85
85
  }
86
86
  })
@@ -0,0 +1,622 @@
1
+ <template>
2
+ <view class="up-poster">
3
+ <!-- canvas用于绘制海报 -->
4
+ <canvas
5
+ v-if="showCanvas"
6
+ class="up-poster__hidden-canvas"
7
+ :canvas-id="canvasId"
8
+ :id="canvasId"
9
+ :style="{ width: canvasWidth + 'px', height: canvasHeight + 'px' }">
10
+ </canvas>
11
+ <!-- 隐藏的二维码组件,用于生成二维码图片 -->
12
+ <up-qrcode
13
+ ref="qrCode"
14
+ :val="qrCodeValue"
15
+ :size="qrCodeSize"
16
+ :margin="0"
17
+ :loadMake="false"
18
+ background="#ffffff"
19
+ foreground="#000000"
20
+ :class="['up-poster__hidden-qrcode', qrCodeShow ? '' : 'up-poster__hidden-qrcode--hidden']"
21
+ />
22
+ </view>
23
+ </template>
24
+
25
+ <script>
26
+ /**
27
+ * Poster 海报组件
28
+ * @description 用于生成海报的组件,支持文本、图片、二维码等元素
29
+ * @tutorial https://ijry.github.io/uview-plus/components/poster.html
30
+ *
31
+ * @property {Object} json 海报配置JSON数据
32
+ * @property {Object} json.css 海报容器样式
33
+ * @property {Array} json.views 海报元素列表
34
+ * @property {String} json.views.type 元素类型(text/image/qrcode/view)
35
+ * @property {String} json.views.text 文本内容(仅text类型)
36
+ * @property {String} json.views.src 图片地址(仅image/qrcode类型)
37
+ * @property {Object} json.views.css 元素样式
38
+ *
39
+ * @example <up-poster :json="posterJson"></up-poster>
40
+ */
41
+ export default {
42
+ name: 'up-poster',
43
+ props: {
44
+ json: {
45
+ type: Object,
46
+ default: () => ({})
47
+ }
48
+ },
49
+ data() {
50
+ return {
51
+ canvasId: 'u-poster-canvas-' + Date.now(),
52
+ showCanvas: false,
53
+ canvasWidth: 0,
54
+ canvasHeight: 0,
55
+ // 二维码相关数据
56
+ qrCodeValue: '',
57
+ qrCodeSize: 200,
58
+ qrCodeShow: false,
59
+ // 存储多个二维码的数据
60
+ qrCodeMap: new Map()
61
+ }
62
+ },
63
+ computed: {
64
+ // 根据传入的css生成文本样式
65
+ getTextStyle() {
66
+ return (css) => {
67
+ const style = {};
68
+ if (css.color) style.color = css.color;
69
+ if (css.fontSize) style.fontSize = css.fontSize;
70
+ if (css.fontWeight) style.fontWeight = css.fontWeight;
71
+ if (css.lineHeight) style.lineHeight = css.lineHeight;
72
+ if (css.textAlign) style.textAlign = css.textAlign;
73
+ return style;
74
+ }
75
+ }
76
+ },
77
+ methods: {
78
+ /**
79
+ * 导出海报图片
80
+ * @description 根据json配置生成海报并导出为临时图片路径
81
+ * @returns {Promise<Object>} 返回包含图片信息的对象
82
+ * @author jry ijry@qq.com
83
+ */
84
+ async exportImage() {
85
+ return new Promise(async(resolve, reject) => {
86
+ try {
87
+ // 获取海报尺寸信息
88
+ const posterSize = this.json.css;
89
+ // 将rpx转换为px
90
+ const width = this.convertRpxToPx(posterSize.width || '750rpx');
91
+ const height = this.convertRpxToPx(posterSize.height || '1114rpx');
92
+
93
+ // 设置canvas尺寸
94
+ this.canvasWidth = width;
95
+ this.canvasHeight = height;
96
+ this.showCanvas = true;
97
+
98
+ // 等待DOM更新
99
+ await this.$nextTick();
100
+
101
+ // 创建canvas上下文
102
+ const ctx = uni.createCanvasContext(this.canvasId, this);
103
+
104
+ // 绘制背景
105
+ if (posterSize.background) {
106
+ // 支持渐变背景色
107
+ if (posterSize.background.includes('linear-gradient') || posterSize.background.includes('radial-gradient')) {
108
+ this.drawGradientBackground(ctx, posterSize, 0, 0, width, height);
109
+ } else {
110
+ ctx.setFillStyle(posterSize.background);
111
+ ctx.fillRect(0, 0, width, height);
112
+ }
113
+ }
114
+
115
+ // 绘制所有元素
116
+ for (const item of this.json.views) {
117
+ await this.drawItem(ctx, item, width, height);
118
+ }
119
+
120
+ // 绘制到canvas
121
+ ctx.draw(false, () => {
122
+ // 等待绘制完成
123
+ setTimeout(() => {
124
+ // 导出图片
125
+ uni.canvasToTempFilePath({
126
+ canvasId: this.canvasId,
127
+ success: (res) => {
128
+ // 隐藏canvas
129
+ this.showCanvas = false;
130
+ // 返回图片路径
131
+ resolve({
132
+ width: width,
133
+ height: height,
134
+ path: res.tempFilePath,
135
+ // H5下添加blob格式
136
+ blob: this.dataURLToBlob(res.tempFilePath)
137
+ });
138
+ },
139
+ fail: (err) => {
140
+ // 隐藏canvas
141
+ this.showCanvas = false;
142
+ reject(new Error('导出图片失败: ' + JSON.stringify(err)));
143
+ }
144
+ }, this);
145
+ }, 300);
146
+ });
147
+
148
+ // 超时处理
149
+ setTimeout(() => {
150
+ this.showCanvas = false;
151
+ reject(new Error('导出图片超时'));
152
+ }, 10000);
153
+ } catch (error) {
154
+ this.showCanvas = false;
155
+ reject(error);
156
+ }
157
+ });
158
+ },
159
+
160
+ /**
161
+ * 绘制单个元素
162
+ * @description 根据元素类型绘制文本、图片、矩形或二维码到canvas
163
+ * @param {Object} ctx canvas上下文
164
+ * @param {Object} item 元素配置信息
165
+ * @param {Number} canvasWidth canvas宽度
166
+ * @param {Number} canvasHeight canvas高度
167
+ * @returns {Promise} 绘制完成的Promise
168
+ * @author jry ijry@qq.com
169
+ */
170
+ async drawItem(ctx, item, canvasWidth, canvasHeight) {
171
+ const css = item.css || {};
172
+ const left = this.convertRpxToPx(css.left || '0rpx');
173
+ const top = this.convertRpxToPx(css.top || '0rpx');
174
+ const width = this.convertRpxToPx(css.width || '0rpx');
175
+ const height = this.convertRpxToPx(css.height || '0rpx');
176
+
177
+ switch (item.type) {
178
+ case 'view':
179
+ // 绘制矩形背景
180
+ if (css.background) {
181
+ // 支持渐变背景色
182
+ if (css.background.includes('linear-gradient') || css.background.includes('radial-gradient')) {
183
+ this.drawGradientBackground(ctx, css, left, top, width, height);
184
+ } else {
185
+ ctx.setFillStyle(css.background);
186
+ // 处理圆角
187
+ if (css.radius) {
188
+ const radius = this.convertRpxToPx(css.radius);
189
+ this.drawRoundRect(ctx, left, top, width, height, radius, css.background);
190
+ } else {
191
+ ctx.fillRect(left, top, width, height);
192
+ }
193
+ }
194
+ }
195
+ break;
196
+
197
+ case 'text':
198
+ // 设置文本样式
199
+ if (css.color) ctx.setFillStyle(css.color);
200
+ if (css.fontSize) {
201
+ const fontSize = this.convertRpxToPx(css.fontSize);
202
+ ctx.setFontSize(fontSize);
203
+ }
204
+ if (css.fontWeight) {
205
+ ctx.setLineWidth(css.fontWeight === 'bold' ? 2 : 1);
206
+ }
207
+
208
+ // 处理文本换行
209
+ if (css.lineClamp) {
210
+ this.drawTextWithLineClamp(ctx, item.text, left, top, width, css);
211
+ } else {
212
+ // 修复:文本垂直居中对齐问题
213
+ const textBaseLine = css.fontSize ? this.convertRpxToPx(css.fontSize) / 2 : 10;
214
+ ctx.fillText(item.text, left, top + textBaseLine);
215
+ }
216
+ break;
217
+
218
+ case 'image':
219
+ // 绘制图片
220
+ return new Promise((resolve) => {
221
+ uni.getImageInfo({
222
+ src: item.src,
223
+ success: (res) => {
224
+ // 处理圆角
225
+ if (css.radius) {
226
+ const radius = this.convertRpxToPx(css.radius);
227
+ this.clipRoundRect(ctx, left, top, width, height, radius);
228
+ }
229
+ ctx.drawImage(item.src, left, top, width, height);
230
+ // 恢复剪切区域
231
+ ctx.restore();
232
+ resolve();
233
+ },
234
+ fail: () => {
235
+ // 图片加载失败时绘制占位符
236
+ ctx.setFillStyle('#f5f5f5');
237
+ ctx.fillRect(left, top, width, height);
238
+ resolve();
239
+ }
240
+ });
241
+ });
242
+
243
+ case 'qrcode':
244
+ // 绘制二维码
245
+ if (item.text) {
246
+ // 使用u-qrcode生成二维码图片
247
+ const qrCodeImageUrl = await this.generateQRCode(item.text, width, height);
248
+ return new Promise((resolve) => {
249
+ uni.getImageInfo({
250
+ src: qrCodeImageUrl,
251
+ success: (res) => {
252
+ ctx.drawImage(res.path, left, top, width, height);
253
+ resolve();
254
+ },
255
+ fail: () => {
256
+ // 二维码加载失败时绘制占位符
257
+ ctx.setFillStyle('#f5f5f5');
258
+ ctx.fillRect(left, top, width, height);
259
+ ctx.setFillStyle('#999');
260
+ ctx.setFontSize(12);
261
+ ctx.setTextAlign('center');
262
+ ctx.fillText('QR', left + width/2, top + height/2);
263
+ ctx.setTextAlign('left');
264
+ resolve();
265
+ }
266
+ });
267
+ });
268
+ } else {
269
+ // 绘制二维码占位符
270
+ ctx.setFillStyle('#f5f5f5');
271
+ ctx.fillRect(left, top, width, height);
272
+ ctx.setFillStyle('#999');
273
+ ctx.setFontSize(12);
274
+ ctx.setTextAlign('center');
275
+ ctx.fillText('QR', left + width/2, top + height/2);
276
+ ctx.setTextAlign('left');
277
+ }
278
+ break;
279
+ }
280
+ },
281
+
282
+ /**
283
+ * 绘制圆角矩形
284
+ * @description 绘制指定位置和尺寸的圆角矩形
285
+ * @param {Object} ctx canvas上下文
286
+ * @param {Number} x x坐标
287
+ * @param {Number} y y坐标
288
+ * @param {Number} width 宽度
289
+ * @param {Number} height 高度
290
+ * @param {Number} radius 圆角半径
291
+ * @param {String} fillColor 填充颜色
292
+ * @author jry ijry@qq.com
293
+ */
294
+ drawRoundRect(ctx, x, y, width, height, radius, fillColor) {
295
+ ctx.save();
296
+ ctx.beginPath();
297
+ ctx.moveTo(x + radius, y);
298
+ ctx.lineTo(x + width - radius, y);
299
+ ctx.quadraticCurveTo(x + width, y, x + width, y + radius);
300
+ ctx.lineTo(x + width, y + height - radius);
301
+ ctx.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
302
+ ctx.lineTo(x + radius, y + height);
303
+ ctx.quadraticCurveTo(x, y + height, x, y + height - radius);
304
+ ctx.lineTo(x, y + radius);
305
+ ctx.quadraticCurveTo(x, y, x + radius, y);
306
+ ctx.closePath();
307
+ if (fillColor) {
308
+ ctx.setFillStyle(fillColor);
309
+ ctx.fill();
310
+ }
311
+ ctx.restore();
312
+ },
313
+
314
+ /**
315
+ * 裁剪圆角矩形区域
316
+ * @description 在canvas上创建圆角矩形裁剪区域
317
+ * @param {Object} ctx canvas上下文
318
+ * @param {Number} x x坐标
319
+ * @param {Number} y y坐标
320
+ * @param {Number} width 宽度
321
+ * @param {Number} height 高度
322
+ * @param {Number} radius 圆角半径
323
+ * @author jry ijry@qq.com
324
+ */
325
+ clipRoundRect(ctx, x, y, width, height, radius) {
326
+ ctx.save();
327
+ ctx.beginPath();
328
+ ctx.arc(x + radius, y + radius, radius, Math.PI, Math.PI * 1.5);
329
+ ctx.lineTo(x + width - radius, y);
330
+ ctx.arc(x + width - radius, y + radius, radius, Math.PI * 1.5, Math.PI * 2);
331
+ ctx.lineTo(x + width, y + height - radius);
332
+ ctx.arc(x + width - radius, y + height - radius, radius, 0, Math.PI * 0.5);
333
+ ctx.lineTo(x + radius, y + height);
334
+ ctx.arc(x + radius, y + height - radius, radius, Math.PI * 0.5, Math.PI);
335
+ ctx.closePath();
336
+ ctx.clip();
337
+ },
338
+
339
+ /**
340
+ * 绘制带行数限制的文本
341
+ * @description 绘制可控制最大行数的文本,超出部分显示省略号
342
+ * @param {Object} ctx canvas上下文
343
+ * @param {String} text 文本内容
344
+ * @param {Number} x x坐标
345
+ * @param {Number} y y坐标
346
+ * @param {Number} maxWidth 最大宽度
347
+ * @param {Object} css 样式配置
348
+ * @author jry ijry@qq.com
349
+ */
350
+ drawTextWithLineClamp(ctx, text, x, y, maxWidth, css) {
351
+ const lineClamp = parseInt(css.lineClamp) || 1;
352
+ const lineHeight = css.lineHeight ? this.convertRpxToPx(css.lineHeight) : 20;
353
+ const lines = [];
354
+ let currentLine = '';
355
+
356
+ for (let i = 0; i < text.length; i++) {
357
+ const char = text[i];
358
+ const testLine = currentLine + char;
359
+ const metrics = ctx.measureText(testLine);
360
+
361
+ if (metrics.width > maxWidth && currentLine !== '') {
362
+ lines.push(currentLine);
363
+ currentLine = char;
364
+
365
+ // 如果已达最大行数,添加省略号并结束
366
+ if (lines.length === lineClamp) {
367
+ if (metrics.width > maxWidth) {
368
+ // 添加省略号
369
+ let fitLine = currentLine.substring(0, currentLine.length - 1);
370
+ while (ctx.measureText(fitLine + '...').width > maxWidth && fitLine.length > 0) {
371
+ fitLine = fitLine.substring(0, fitLine.length - 1);
372
+ }
373
+ lines[lines.length - 1] = fitLine + '...';
374
+ }
375
+ break;
376
+ }
377
+ } else {
378
+ currentLine = testLine;
379
+ }
380
+
381
+ // 处理最后一行
382
+ if (i === text.length - 1 && lines.length < lineClamp) {
383
+ lines.push(currentLine);
384
+ }
385
+ }
386
+
387
+ // 绘制每一行
388
+ for (let i = 0; i < lines.length; i++) {
389
+ // 修复:正确计算文本垂直位置
390
+ const textBaseLine = css.fontSize ? this.convertRpxToPx(css.fontSize) / 2 : 10;
391
+ ctx.fillText(lines[i], x, y + (i * lineHeight) + textBaseLine);
392
+ }
393
+ },
394
+
395
+ /**
396
+ * 生成二维码图片
397
+ * @description 根据文本内容生成二维码图片URL
398
+ * @param {String} text 二维码内容
399
+ * @param {Number} width 二维码宽度
400
+ * @param {Number} height 二维码高度
401
+ * @returns {Promise<String>} 二维码图片URL
402
+ * @author jry ijry@qq.com
403
+ */
404
+ generateQRCode(text, width, height) {
405
+ return new Promise((resolve) => {
406
+ // 为每个二维码生成唯一标识
407
+ const qrCodeKey = `${text}_${width}_${height}`;
408
+
409
+ // 检查是否已经生成过该二维码
410
+ if (this.qrCodeMap.has(qrCodeKey)) {
411
+ resolve(this.qrCodeMap.get(qrCodeKey));
412
+ return;
413
+ }
414
+
415
+ // 使用 u-qrcode 组件生成二维码
416
+ try {
417
+ // 设置二维码参数
418
+ this.qrCodeValue = text;
419
+ this.qrCodeSize = Math.max(width, height);
420
+ this.qrCodeShow = true;
421
+
422
+ // 等待DOM更新
423
+ this.$nextTick(() => {
424
+ // 获取二维码组件实例并导出图片
425
+ if (this.$refs.qrCode) {
426
+ // 延迟一点时间确保二维码渲染完成
427
+ setTimeout(() => {
428
+ // 调用 u-qrcode 的 toTempFilePath 方法导出图片
429
+ this.$refs.qrCode.toTempFilePath({
430
+ success: (res) => {
431
+ // 缓存二维码图片路径
432
+ this.qrCodeMap.set(qrCodeKey, res.tempFilePath);
433
+ this.qrCodeShow = false;
434
+ resolve(res.tempFilePath);
435
+ },
436
+ fail: (err) => {
437
+ console.error('二维码生成失败:', err);
438
+ this.qrCodeShow = false;
439
+ }
440
+ });
441
+ }, 300);
442
+ } else {
443
+ // 如果没有 u-qrcode 组件,返回占位符
444
+ this.qrCodeShow = false;
445
+ }
446
+ });
447
+ } catch (error) {
448
+ console.error('生成二维码出错:', error);
449
+ this.qrCodeShow = false;
450
+ }
451
+ });
452
+ },
453
+
454
+ /**
455
+ * 将rpx单位转换为px
456
+ * @description 根据屏幕密度将rpx单位转换为px单位
457
+ * @param {String|Number} rpxValue rpx值
458
+ * @returns {Number} 转换后的px值
459
+ * @author jry ijry@qq.com
460
+ */
461
+ convertRpxToPx(rpxValue) {
462
+ if (typeof rpxValue === 'number') return rpxValue;
463
+
464
+ // 使用uni-app自带的uni.rpx2px方法
465
+ if (typeof rpxValue === 'string' && rpxValue.endsWith('rpx')) {
466
+ const value = parseFloat(rpxValue);
467
+ return uni.rpx2px(value);
468
+ }
469
+
470
+ return parseFloat(rpxValue) || 0;
471
+ },
472
+
473
+ /**
474
+ * 绘制渐变背景
475
+ * @description 绘制线性渐变或径向渐变背景
476
+ * @param {Object} ctx canvas上下文
477
+ * @param {Object} css 样式配置
478
+ * @param {Number} left 左边距
479
+ * @param {Number} top 上边距
480
+ * @param {Number} width 宽度
481
+ * @param {Number} height 高度
482
+ * @author jry ijry@qq.com
483
+ */
484
+ drawGradientBackground(ctx, css, left, top, width, height) {
485
+ const background = css.background;
486
+ let gradient = null;
487
+
488
+ // 处理线性渐变
489
+ if (background.includes('linear-gradient')) {
490
+ // 解析线性渐变角度和颜色
491
+ const angleMatch = background.match(/linear-gradient\((\d+)deg/);
492
+ const angle = angleMatch ? parseInt(angleMatch[1]) : 135;
493
+
494
+ // 根据角度计算渐变起点和终点
495
+ let startX = left, startY = top, endX = left + width, endY = top + height;
496
+
497
+ // 简化的角度处理(支持常见角度)
498
+ if (angle === 0) {
499
+ startX = left;
500
+ startY = top + height;
501
+ endX = left;
502
+ endY = top;
503
+ } else if (angle === 90) {
504
+ startX = left;
505
+ startY = top;
506
+ endX = left + width;
507
+ endY = top;
508
+ } else if (angle === 180) {
509
+ startX = left;
510
+ startY = top;
511
+ endX = left;
512
+ endY = top + height;
513
+ } else if (angle === 270) {
514
+ startX = left + width;
515
+ startY = top;
516
+ endX = left;
517
+ endY = top;
518
+ }
519
+
520
+ gradient = ctx.createLinearGradient(startX, startY, endX, endY);
521
+
522
+ // 解析颜色值
523
+ const colorMatches = background.match(/#[0-9a-fA-F]+|rgba?\([^)]+\)/g);
524
+ if (colorMatches && colorMatches.length >= 2) {
525
+ // 添加渐变色点
526
+ colorMatches.forEach((color, index) => {
527
+ const stop = index / (colorMatches.length - 1);
528
+ gradient.addColorStop(stop, color);
529
+ });
530
+ }
531
+ }
532
+ // 处理径向渐变
533
+ else if (background.includes('radial-gradient')) {
534
+ // 径向渐变从中心开始
535
+ const centerX = left + width / 2;
536
+ const centerY = top + height / 2;
537
+ const radius = Math.min(width, height) / 2;
538
+
539
+ gradient = ctx.createRadialGradient(centerX, centerY, 0, centerX, centerY, radius);
540
+
541
+ // 解析颜色值
542
+ const colorMatches = background.match(/#[0-9a-fA-F]+|rgba?\([^)]+\)/g);
543
+ if (colorMatches && colorMatches.length >= 2) {
544
+ // 添加渐变色点
545
+ colorMatches.forEach((color, index) => {
546
+ const stop = index / (colorMatches.length - 1);
547
+ gradient.addColorStop(stop, color);
548
+ });
549
+ }
550
+ }
551
+
552
+ if (gradient) {
553
+ ctx.setFillStyle(gradient);
554
+ // 处理圆角
555
+ if (css.radius) {
556
+ const radius = this.convertRpxToPx(css.radius);
557
+ this.drawRoundRect(ctx, left, top, width, height, radius, gradient);
558
+ } else {
559
+ ctx.fillRect(left, top, width, height);
560
+ }
561
+ }
562
+ },
563
+
564
+ /**
565
+ * 将dataURL转换为Blob
566
+ * @description H5环境下将base64格式的dataURL转换为Blob对象
567
+ * @param {String} dataURL base64格式的图片数据
568
+ * @returns {Blob} Blob对象
569
+ * @author jry ijry@qq.com
570
+ */
571
+ dataURLToBlob(dataURL) {
572
+ // 检查是否为H5环境且是base64数据
573
+ // #ifdef H5
574
+ if (dataURL && dataURL.startsWith('data:image')) {
575
+ const parts = dataURL.split(';base64,');
576
+ const contentType = parts[0].split(':')[1];
577
+ const raw = window.atob(parts[1]);
578
+ const rawLength = raw.length;
579
+ const uInt8Array = new Uint8Array(rawLength);
580
+
581
+ for (let i = 0; i < rawLength; ++i) {
582
+ uInt8Array[i] = raw.charCodeAt(i);
583
+ }
584
+
585
+ return new Blob([uInt8Array], { type: contentType });
586
+ }
587
+ // #endif
588
+
589
+ return null;
590
+ },
591
+ }
592
+ }
593
+ </script>
594
+
595
+ <style lang="scss" scoped>
596
+ .up-poster {
597
+ position: relative;
598
+
599
+ &__canvas {
600
+ position: relative;
601
+ overflow: hidden;
602
+ }
603
+
604
+ &__hidden-canvas {
605
+ position: fixed;
606
+ top: -10000px;
607
+ left: -10000px;
608
+ z-index: -1;
609
+ }
610
+
611
+ &__hidden-qrcode {
612
+ position: fixed;
613
+ top: -10000px;
614
+ left: -10000px;
615
+ z-index: -1;
616
+
617
+ &--hidden {
618
+ display: none;
619
+ }
620
+ }
621
+ }
622
+ </style>
@@ -260,7 +260,7 @@ export default {
260
260
  url: this.result
261
261
  }, e)
262
262
  },
263
- async longpress() {
263
+ async toTempFilePath({success, fail}) {
264
264
  if (this.context) {
265
265
  this.ctx.toTempFilePath(
266
266
  0,
@@ -272,14 +272,15 @@ export default {
272
272
  "",
273
273
  1,
274
274
  res => {
275
- this.$emit('longpressCallback', res.tempFilePath)
275
+ success(res)
276
276
  }
277
277
  );
278
278
  }
279
279
  else {
280
-
281
280
  // #ifdef MP-TOUTIAO || H5
282
- this.$emit('longpressCallback', this.ctx.canvas.toDataURL("image/png", 1));
281
+ success({
282
+ tempFilePath: this.ctx.canvas.toDataURL("image/png", 1)
283
+ })
283
284
  // #endif
284
285
 
285
286
  // #ifdef APP-PLUS
@@ -287,10 +288,9 @@ export default {
287
288
  {
288
289
  canvasId: this.cid,
289
290
  success :res => {
290
- this.$emit('longpressCallback', res.tempFilePath)
291
+ success(res)
291
292
  },
292
- fail: err =>{
293
- }
293
+ fail: fail
294
294
  },
295
295
  this)
296
296
  // #endif
@@ -301,16 +301,22 @@ export default {
301
301
  {
302
302
  canvas,
303
303
  success :res => {
304
- this.$emit('longpressCallback', res.tempFilePath)
304
+ success(res)
305
305
  },
306
- fail: err =>{
307
- }
306
+ fail: fail
308
307
  },
309
308
  this)
310
309
  // #endif
311
-
312
310
  }
313
-
311
+ },
312
+ async longpress() {
313
+ this.toTempFilePath({
314
+ success: res => {
315
+ this.$emit('longpressCallback', res.tempFilePath)
316
+ },
317
+ fail: err => {
318
+ }
319
+ })
314
320
  },
315
321
 
316
322
  /**
@@ -1,138 +1,156 @@
1
1
  import { defineMixin } from '../../libs/vue'
2
2
  import defProps from '../../libs/config/props.js'
3
+
3
4
  export const props = defineMixin({
4
- props: {
5
- // 搜索框形状,round-圆形,square-方形
6
- shape: {
7
- type: String,
8
- default: () => defProps.search.shape
9
- },
10
- // 搜索框背景色,默认值#f2f2f2
11
- bgColor: {
12
- type: String,
13
- default: () => defProps.search.bgColor
14
- },
15
- // 占位提示文字
16
- placeholder: {
17
- type: String,
18
- default: () => defProps.search.placeholder
19
- },
20
- // 是否启用清除控件
21
- clearabled: {
22
- type: Boolean,
23
- default: () => defProps.search.clearabled
24
- },
25
- // 是否自动聚焦
26
- focus: {
27
- type: Boolean,
28
- default: () => defProps.search.focus
29
- },
30
- // 是否在搜索框右侧显示取消按钮
31
- showAction: {
32
- type: Boolean,
33
- default: () => defProps.search.showAction
34
- },
35
- // 右边控件的样式
36
- actionStyle: {
37
- type: Object,
38
- default: () => defProps.search.actionStyle
39
- },
40
- // 取消按钮文字
41
- actionText: {
42
- type: String,
43
- default: () => defProps.search.actionText
44
- },
45
- // 输入框内容对齐方式,可选值为 left|center|right
46
- inputAlign: {
47
- type: String,
48
- default: () => defProps.search.inputAlign
49
- },
50
- // input输入框的样式,可以定义文字颜色,大小等,对象形式
51
- inputStyle: {
52
- type: Object,
53
- default: () => defProps.search.inputStyle
54
- },
55
- // 是否启用输入框
56
- disabled: {
57
- type: Boolean,
58
- default: () => defProps.search.disabled
59
- },
60
- // 边框颜色
61
- borderColor: {
62
- type: String,
63
- default: () => defProps.search.borderColor
64
- },
65
- // 搜索图标的颜色,默认同输入框字体颜色
66
- searchIconColor: {
67
- type: String,
68
- default: () => defProps.search.searchIconColor
69
- },
70
- // 输入框字体颜色
71
- color: {
72
- type: String,
73
- default: () => defProps.search.color
74
- },
75
- // placeholder的颜色
76
- placeholderColor: {
77
- type: String,
78
- default: () => defProps.search.placeholderColor
79
- },
80
- // 左边输入框的图标,可以为uView图标名称或图片路径
81
- searchIcon: {
82
- type: String,
83
- default: () => defProps.search.searchIcon
84
- },
85
- searchIconSize: {
86
- type: [Number, String],
87
- default: () => defProps.search.searchIconSize
88
- },
89
- // 组件与其他上下左右元素之间的距离,带单位的字符串形式,如"30px"、"30px 20px"等写法
90
- margin: {
91
- type: String,
92
- default: () => defProps.search.margin
93
- },
94
- // 开启showAction时,是否在input获取焦点时才显示
95
- animation: {
96
- type: Boolean,
97
- default: () => defProps.search.animation
98
- },
99
- // 输入框的初始化内容
100
- modelValue: {
101
- type: String,
102
- default: () => defProps.search.value
103
- },
5
+ props: {
6
+ // #ifdef VUE3
7
+ // 绑定的值
8
+ modelValue: {
9
+ type: [String, Number],
10
+ default: () => defProps.search.value
11
+ },
12
+ // #endif
13
+ // #ifdef VUE2
14
+ // 绑定的值
104
15
  value: {
105
- type: String,
106
- default: () => defProps.search.value
107
- },
108
- // 输入框最大能输入的长度,-1为不限制长度(来自uniapp文档)
109
- maxlength: {
110
- type: [String, Number],
111
- default: () => defProps.search.maxlength
112
- },
113
- // 搜索框高度,单位px
114
- height: {
115
- type: [String, Number],
116
- default: () => defProps.search.height
117
- },
118
- // 搜索框左侧文本
119
- label: {
120
- type: [String, Number, null],
121
- default: () => defProps.search.label
122
- },
123
- // 键盘弹起时,是否自动上推页面
124
- adjustPosition: {
125
- type: Boolean,
126
- default: () => true
127
- },
128
- // 键盘收起时,是否自动失去焦点
129
- autoBlur: {
130
- type: Boolean,
131
- default: () => false
132
- },
133
- iconPosition: {
134
- type: String,
135
- default: () => defProps.search.iconPosition
136
- }
137
- }
138
- })
16
+ type: [String, Number],
17
+ default: () => defProps.search.value
18
+ },
19
+ // #endif
20
+ // 搜索框形状,round-圆形,square-方形
21
+ shape: {
22
+ type: String,
23
+ default: () => defProps.search.shape
24
+ },
25
+ // 搜索框背景色
26
+ bgColor: {
27
+ type: String,
28
+ default: () => defProps.search.bgColor
29
+ },
30
+ // 占位提示文字
31
+ placeholder: {
32
+ type: String,
33
+ default: () => defProps.search.placeholder
34
+ },
35
+ // 是否启用清除控件
36
+ clearabled: {
37
+ type: Boolean,
38
+ default: () => defProps.search.clearabled
39
+ },
40
+ // 是否仅聚焦时显示清除控件
41
+ onlyClearableOnFocused: {
42
+ type: Boolean,
43
+ default: true
44
+ },
45
+ // 是否自动聚焦
46
+ focus: {
47
+ type: Boolean,
48
+ default: () => defProps.search.focus
49
+ },
50
+ // 是否在搜索框右侧显示取消按钮
51
+ showAction: {
52
+ type: Boolean,
53
+ default: () => defProps.search.showAction
54
+ },
55
+ // 右侧取消按钮文字
56
+ actionText: {
57
+ type: String,
58
+ default: () => defProps.search.actionText
59
+ },
60
+ // 搜索框左侧文本
61
+ label: {
62
+ type: [String, Number, null],
63
+ default: () => defProps.search.label
64
+ },
65
+ // 输入框内容对齐方式,可选值为:left|center|right
66
+ inputAlign: {
67
+ type: String,
68
+ default: () => defProps.search.inputAlign
69
+ },
70
+ // 是否启用输入框
71
+ disabled: {
72
+ type: Boolean,
73
+ default: () => defProps.search.disabled
74
+ },
75
+ // 开启showAction时,是否在input获取焦点时才显示
76
+ animation: {
77
+ type: Boolean,
78
+ default: () => defProps.search.animation
79
+ },
80
+ // 边框颜色,只要配置了颜色,才会有边框
81
+ borderColor: {
82
+ type: String,
83
+ default: () => defProps.search.borderColor
84
+ },
85
+ // 搜索图标的颜色,默认同输入框字体颜色
86
+ searchIconColor: {
87
+ type: String,
88
+ default: () => defProps.search.searchIconColor
89
+ },
90
+ // 搜索图标的大小
91
+ searchIconSize: {
92
+ type: [Number, String],
93
+ default: () => defProps.search.searchIconSize
94
+ },
95
+ // 输入框字体颜色
96
+ color: {
97
+ type: String,
98
+ default: () => defProps.search.color
99
+ },
100
+ // placeholder的颜色
101
+ placeholderColor: {
102
+ type: String,
103
+ default: () => defProps.search.placeholderColor
104
+ },
105
+ // 左边输入框的图标,可以为uView图标名称或图片路径
106
+ searchIcon: {
107
+ type: String,
108
+ default: () => defProps.search.searchIcon
109
+ },
110
+ // 组件与其他上下左右元素之间的距离,带单位的字符串形式,如"30px"
111
+ margin: {
112
+ type: String,
113
+ default: () => defProps.search.margin
114
+ },
115
+ // 应该是uView-plus版本新增的,用于控制搜索图标的插槽位置
116
+ iconPosition: {
117
+ type: String,
118
+ default: () => defProps.search.iconPosition
119
+ },
120
+ // 输入框最大能输入的长度,-1为不限制长度
121
+ maxlength: {
122
+ type: [String, Number],
123
+ default: () => defProps.search.maxlength
124
+ },
125
+ // 输入框高度,单位px
126
+ height: {
127
+ type: [String, Number],
128
+ default: () => defProps.search.height
129
+ },
130
+ // 键盘弹起时,是否自动上推页面
131
+ adjustPosition: {
132
+ type: Boolean,
133
+ default: () => defProps.search.adjustPosition
134
+ },
135
+ // 键盘收起时,是否自动失去焦点
136
+ autoBlur: {
137
+ type: Boolean,
138
+ default: () => defProps.search.autoBlur
139
+ },
140
+ // 输入框的样式,对象形式
141
+ inputStyle: {
142
+ type: Object,
143
+ default: () => defProps.search.inputStyle
144
+ },
145
+ // 右侧控件的样式,对象形式
146
+ actionStyle: {
147
+ type: Object,
148
+ default: () => defProps.search.actionStyle
149
+ },
150
+ // 自定义样式,对象形式
151
+ customStyle: {
152
+ type: Object,
153
+ default: () => defProps.search.customStyle
154
+ }
155
+ }
156
+ })
@@ -55,7 +55,7 @@
55
55
  />
56
56
  <view
57
57
  class="u-search__content__icon u-search__content__close"
58
- v-if="keyword && clearabled && focused"
58
+ v-if="isShowClear"
59
59
  @click="clear"
60
60
  >
61
61
  <up-icon
@@ -111,6 +111,7 @@
111
111
  * @property {String | Number} label 搜索框左边显示内容
112
112
  * @property {Boolean} adjustPosition 键盘弹起时,是否自动上推页面
113
113
  * @property {Boolean} autoBlur 键盘收起时,是否自动失去焦点
114
+ * @property {Boolean} onlyClearableOnFocused 是否仅在聚焦时显示清除控件(默认 true )
114
115
  * @property {Object} customStyle 定义需要用到的外部样式
115
116
  *
116
117
  * @event {Function} change 输入框内容发生变化时触发
@@ -125,7 +126,6 @@
125
126
  data() {
126
127
  return {
127
128
  keyword: '',
128
- showClear: false, // 是否显示右边的清除图标
129
129
  show: false,
130
130
  // 标记input当前状态是否处于聚焦中,如果是,才会显示右侧的清除控件
131
131
  focused: this.focus
@@ -165,6 +165,18 @@
165
165
  computed: {
166
166
  showActionBtn() {
167
167
  return !this.animation && this.showAction
168
+ },
169
+ // 是否显示清除控件
170
+ isShowClear() {
171
+ const { clearabled, focused, keyword, onlyClearableOnFocused } = this;
172
+ if (!clearabled) {
173
+ return false;
174
+ }
175
+ if (onlyClearableOnFocused) {
176
+ return !!focused && keyword !== "";
177
+ } else {
178
+ return keyword !== "";
179
+ }
168
180
  }
169
181
  },
170
182
  emits: ['clear', 'search', 'custom', 'focus', 'blur', 'click', 'clickIcon', 'update:modelValue', 'change'],
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "id": "uview-plus",
3
3
  "name": "uview-plus",
4
4
  "displayName": "零云®uview-plus3.0重磅发布,全面的Vue3鸿蒙跨端移动组件库,组件丰富维护更新稳定。",
5
- "version": "3.5.5",
5
+ "version": "3.5.10",
6
6
  "description": "零云®uview-plus已兼容vue3支持多语言,100+全面的组件和便捷的工具会让您信手拈来。近期新增拖动排序、条码、图片裁剪、下拉刷新、虚拟列表、签名、Markdown等。",
7
7
  "keywords": [
8
8
  "uview",