hy-app 0.4.10 → 0.4.11

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.
@@ -151,8 +151,8 @@ const itemStyle = computed<CSSProperties>(() => {
151
151
  /**
152
152
  * @description 点击事件
153
153
  * */
154
- const childClick = (name: string | Record<string, any>) => {
155
- emit("click", name);
154
+ const childClick = (temp: string | Record<string, any>) => {
155
+ emit("click", temp);
156
156
  };
157
157
  </script>
158
158
 
@@ -11,7 +11,7 @@
11
11
  <canvas
12
12
  class="hy-qrcode__content--canvas"
13
13
  :id="cid"
14
- :canvas-id="cid"
14
+ type="2d"
15
15
  :style="{ width: addUnit(size), height: addUnit(size) }"
16
16
  />
17
17
  <!-- #endif -->
@@ -1176,6 +1176,108 @@ let QRCode = {};
1176
1176
  }
1177
1177
  return options.foreground;
1178
1178
  };
1179
+ // 为2D Canvas添加辅助函数
1180
+ function drawIconWithBackground(canvas, ctx, options, qrCodeAlg) {
1181
+ // 在小程序中使用canvas.createImage()而不是wx.createImage()
1182
+ const img = canvas.createImage();
1183
+ img.src = options.image;
1184
+ img.onload = function() {
1185
+ var ratioImgSize = options.imageSize || 40;
1186
+ var x = Number(((options.size - ratioImgSize) / 2).toFixed(2));
1187
+ var y = Number(((options.size - ratioImgSize) / 2).toFixed(2));
1188
+
1189
+ // 绘制圆角矩形背景
1190
+ drawRoundedRect2D(ctx, x, y, ratioImgSize, ratioImgSize, 2, options.background);
1191
+
1192
+ // 绘制图标
1193
+ ctx.drawImage(img, x, y, ratioImgSize, ratioImgSize);
1194
+
1195
+ // 导出图片
1196
+ exportCanvasImage(canvas, options);
1197
+ };
1198
+
1199
+ // 添加错误处理
1200
+ img.onerror = function(e) {
1201
+ console.error('Failed to load QR code icon:', e);
1202
+ // 即使图标加载失败也要导出二维码
1203
+ exportCanvasImage(canvas, options);
1204
+ };
1205
+ }
1206
+
1207
+ function drawRoundedRect2D(ctx, x, y, width, height, r, fillColor) {
1208
+ ctx.beginPath();
1209
+ ctx.moveTo(x + r, y);
1210
+ ctx.arcTo(x + width, y, x + width, y + r, r);
1211
+ ctx.arcTo(x + width, y + height, x + width - r, y + height, r);
1212
+ ctx.arcTo(x, y + height, x, y + height - r, r);
1213
+ ctx.arcTo(x, y, x + r, y, r);
1214
+ ctx.closePath();
1215
+ ctx.fillStyle = fillColor;
1216
+ ctx.fill();
1217
+ }
1218
+
1219
+ function exportCanvasImage(canvas, options) {
1220
+ setTimeout(() => {
1221
+ wx.canvasToTempFilePath({
1222
+ canvas: canvas,
1223
+ quality: 1,
1224
+ success: function(res) {
1225
+ if (options.cbResult) {
1226
+ options.cbResult(res.tempFilePath);
1227
+ }
1228
+ },
1229
+ fail: function(res) {
1230
+ if (options.cbResult) {
1231
+ options.cbResult(res);
1232
+ }
1233
+ },
1234
+ complete: function() {
1235
+ uni.hideLoading();
1236
+ }
1237
+ }, options.context);
1238
+ }, options.text.length + 100);
1239
+ }
1240
+
1241
+ // 2D Canvas二维码绘制函数
1242
+ function drawQRCode2D(canvas, ctx, options, qrCodeAlg) {
1243
+ var count = qrCodeAlg.getModuleCount();
1244
+ var ratioSize = options.size;
1245
+
1246
+ // 清除画布
1247
+ ctx.clearRect(0, 0, ratioSize, ratioSize);
1248
+ // 设置背景色
1249
+ ctx.fillStyle = options.background;
1250
+ ctx.fillRect(0, 0, ratioSize, ratioSize);
1251
+
1252
+ //计算每个点的长宽
1253
+ var tileW = (ratioSize / count).toPrecision(4);
1254
+ var tileH = (ratioSize / count).toPrecision(4);
1255
+
1256
+ //绘制二维码
1257
+ for (var row = 0; row < count; row++) {
1258
+ for (var col = 0; col < count; col++) {
1259
+ var w = Math.ceil((col + 1) * tileW) - Math.floor(col * tileW);
1260
+ var h = Math.ceil((row + 1) * tileW) - Math.floor(row * tileW);
1261
+ var foreground = getForeGround({
1262
+ row: row,
1263
+ col: col,
1264
+ count: count,
1265
+ options: options
1266
+ });
1267
+ ctx.fillStyle = qrCodeAlg.modules[row][col] ? foreground : options.background;
1268
+ ctx.fillRect(Math.round(col * tileW), Math.round(row * tileH), w, h);
1269
+ }
1270
+ }
1271
+
1272
+ if (options.image) {
1273
+ // 绘制中间图标
1274
+ drawIconWithBackground(canvas, ctx, options, qrCodeAlg);
1275
+ } else {
1276
+ // 导出图片
1277
+ exportCanvasImage(canvas, options);
1278
+ }
1279
+ }
1280
+
1179
1281
  // 创建canvas
1180
1282
  let createCanvas = function (options) {
1181
1283
  if (options.showLoading) {
@@ -1184,6 +1286,38 @@ let QRCode = {};
1184
1286
  mask: true
1185
1287
  });
1186
1288
  }
1289
+
1290
+ // 尝试使用2D Canvas (小程序端)
1291
+ try {
1292
+ if (!options.nvueContext && typeof wx !== 'undefined' && wx.createSelectorQuery) {
1293
+ const query = wx.createSelectorQuery().in(options.context);
1294
+ query.select('#' + options.canvasId)
1295
+ .fields({ node: true, size: true })
1296
+ .exec((res) => {
1297
+ if (res[0] && res[0].node) {
1298
+ const canvas = res[0].node;
1299
+ const ctx = canvas.getContext('2d');
1300
+
1301
+ // 设置canvas尺寸
1302
+ const dpr = wx.getSystemInfoSync().pixelRatio;
1303
+ canvas.width = options.size * dpr;
1304
+ canvas.height = options.size * dpr;
1305
+ ctx.scale(dpr, dpr);
1306
+
1307
+ // 创建二维码算法实例
1308
+ var qrCodeAlg = new QRCodeAlg(options.text, options.correctLevel);
1309
+
1310
+ // 使用2D Canvas绘制
1311
+ drawQRCode2D(canvas, ctx, options, qrCodeAlg);
1312
+ return;
1313
+ }
1314
+ });
1315
+ }
1316
+ } catch (e) {
1317
+ console.warn('2D Canvas initialization failed, falling back to legacy mode:', e);
1318
+ }
1319
+
1320
+ // 回退到传统Canvas方式
1187
1321
  var ctx = "";
1188
1322
  if (options.nvueContext) {
1189
1323
  ctx = options.nvueContext;
@@ -17,10 +17,11 @@
17
17
  borderColor: borderColor,
18
18
  }"
19
19
  >
20
- <template v-if="$slots.label || label">
21
- <slot name="label">
22
- <text class="hy-search__content__label">{{ label }}</text>
23
- </slot>
20
+ <template>
21
+ <slot v-if="$slots.label" name="label"></slot>
22
+ <text v-else-if="label" class="hy-search__content__label">{{
23
+ label
24
+ }}</text>
24
25
  </template>
25
26
  <view class="hy-search__content__icon" v-if="searchIcon">
26
27
  <HyIcon
@@ -50,7 +51,10 @@
50
51
  placeholder-class="hy-search__content__input--placeholder"
51
52
  :placeholder="placeholder"
52
53
  :placeholder-style="`color: ${placeholderColor}`"
53
- class="hy-search__content__input"
54
+ :class="[
55
+ 'hy-search__content__input',
56
+ disabled && 'hy-search__content__input--disabled',
57
+ ]"
54
58
  type="text"
55
59
  :always-embed="true"
56
60
  :style="[
@@ -213,7 +217,10 @@ const props = defineProps({
213
217
  default: "",
214
218
  },
215
219
  /** 输入框左边的图标属性集合,可以为图标名称或图片路径 */
216
- searchIcon: [Boolean, Object] as PropType<HyIconProps | boolean>,
220
+ searchIcon: {
221
+ type: [Boolean, Object] as PropType<HyIconProps | boolean>,
222
+ default: { name: IconConfig.SEARCH },
223
+ },
217
224
  /** 组件与其他上下左右之间的距离,带单位的字符串形式,如"30px" */
218
225
  margin: {
219
226
  type: [String, Number],
@@ -59,6 +59,10 @@ $hy-search-close-size: 20px !default;
59
59
  color: $hy-text-color;
60
60
  background-color: $hy-background--empty;
61
61
 
62
+ @include m(disabled) {
63
+ color: $hy-text-color--disabled;
64
+ }
65
+
62
66
  @include m(placeholder) {
63
67
  font-size: 25rpx;
64
68
  color: $hy-text-color--placeholder;