hy-app 0.2.4 → 0.2.5

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.
@@ -27,15 +27,15 @@
27
27
  color: $hy-primary;
28
28
  }
29
29
 
30
- @include themeColor(primary, "", "", $hy-primary);
31
- @include themeColor(warning, "", "", $hy-warning);
32
- @include themeColor(success, "", "", $hy-success);
33
- @include themeColor(info, "", "", $hy-info);
34
- @include themeColor(error, "", "", $hy-error);
30
+ @include themeColor(primary, "", transparent, $hy-primary);
31
+ @include themeColor(warning, "", transparent, $hy-warning);
32
+ @include themeColor(success, "", transparent, $hy-success);
33
+ @include themeColor(info, "", transparent, $hy-info);
34
+ @include themeColor(error, "", transparent, $hy-error);
35
35
  @include themeColor(main, "", "", $hy-text-color);
36
36
  @include themeColor(content, "", "", $hy-text-color--grey);
37
37
  @include themeColor(tips, "", "",$hy-text-color--grey);
38
38
  @include themeColor(light, "", "", $hy-border-color-light);
39
39
 
40
40
  }
41
- }
41
+ }
@@ -16,96 +16,84 @@
16
16
 
17
17
  <script lang="ts">
18
18
  export default {
19
- name: "hy-watermark",
19
+ name: 'hy-watermark',
20
20
  options: {
21
21
  addGlobalClass: true,
22
22
  virtualHost: true,
23
- styleIsolation: "shared",
23
+ styleIsolation: 'shared',
24
24
  },
25
- };
25
+ }
26
26
  </script>
27
27
 
28
28
  <script lang="ts" setup>
29
- import {
30
- computed,
31
- onMounted,
32
- ref,
33
- watch,
34
- nextTick,
35
- type CSSProperties,
36
- toRefs,
37
- } from "vue";
38
- import { addUnit, guid } from "../../utils";
39
- import type IProps from "./typing";
40
- import defaultProps from "./props";
29
+ import { computed, onMounted, ref, watch, nextTick, type CSSProperties, toRefs } from 'vue'
30
+ import { addUnit, guid } from '../../utils'
31
+ import type IProps from './typing'
32
+ import defaultProps from './props'
41
33
 
42
- const props = withDefaults(defineProps<IProps>(), defaultProps);
43
- const { customStyle } = toRefs(props);
34
+ const props = withDefaults(defineProps<IProps>(), defaultProps)
35
+ const { customStyle } = toRefs(props)
44
36
 
45
37
  watch(
46
38
  () => props,
47
39
  () => {
48
- doReset();
40
+ doReset()
49
41
  },
50
42
  { deep: true },
51
- );
43
+ )
52
44
 
53
- const canvasId = ref<string>(`watermark--${guid()}`); // canvas 组件的唯一标识符
54
- const waterMarkUrl = ref<string>(""); // canvas生成base64水印
45
+ const canvasId = ref<string>(`watermark--${guid()}`) // canvas 组件的唯一标识符
46
+ const waterMarkUrl = ref<string>('') // canvas生成base64水印
55
47
  const canvasOffScreenable = ref<boolean>(
56
- uni.canIUse("createOffscreenCanvas") && Boolean(uni.createOffscreenCanvas),
57
- ); // 是否可以使用离屏canvas
58
- const pixelRatio = ref<number>(uni.getSystemInfoSync().pixelRatio); // 像素比
59
- const canvasHeight = ref<number>(
60
- (props.height + props.gutterY) * pixelRatio.value,
61
- ); // canvas画布高度
62
- const canvasWidth = ref<number>(
63
- (props.width + props.gutterX) * pixelRatio.value,
64
- ); // canvas画布宽度
65
- const showCanvas = ref<boolean>(true); // 是否展示canvas
48
+ uni.canIUse('createOffscreenCanvas') && Boolean(uni.createOffscreenCanvas),
49
+ ) // 是否可以使用离屏canvas
50
+ const pixelRatio = ref<number>(uni.getSystemInfoSync().pixelRatio) // 像素比
51
+ const canvasHeight = ref<number>((props.height + props.gutterY) * pixelRatio.value) // canvas画布高度
52
+ const canvasWidth = ref<number>((props.width + props.gutterX) * pixelRatio.value) // canvas画布宽度
53
+ const showCanvas = ref<boolean>(true) // 是否展示canvas
66
54
 
67
55
  /**
68
- * 水印css类
56
+ * @description 水印css类
69
57
  */
70
58
  const rootClass = computed(() => {
71
- let classes: string = "hy-watermark";
59
+ const classes: string[] = ['hy-watermark']
72
60
  if (props.fullScreen) {
73
- classes = `${classes} is-fullscreen`;
61
+ classes.push('is-fullscreen')
74
62
  }
75
- return `${classes}`;
76
- });
63
+ return classes
64
+ })
77
65
 
78
66
  /**
79
- * 水印样式
67
+ * @description 水印样式
80
68
  */
81
69
  const rootStyle = computed(() => {
82
70
  const style: CSSProperties = {
83
71
  opacity: props.opacity,
84
72
  backgroundSize: addUnit(props.width + props.gutterX),
85
- };
73
+ }
86
74
  if (waterMarkUrl.value) {
87
- style["backgroundImage"] = `url('${waterMarkUrl.value}')`;
75
+ style['backgroundImage'] = `url('${waterMarkUrl.value}')`
88
76
  }
89
- return Object.assign(style, customStyle.value);
90
- });
77
+ return Object.assign(style, customStyle.value)
78
+ })
91
79
 
92
80
  onMounted(() => {
93
- doInit();
94
- });
81
+ doInit()
82
+ })
95
83
 
96
84
  function doReset() {
97
- showCanvas.value = true;
98
- canvasHeight.value = (props.height + props.gutterY) * pixelRatio.value;
99
- canvasWidth.value = (props.width + props.gutterX) * pixelRatio.value;
85
+ showCanvas.value = true
86
+ canvasHeight.value = (props.height + props.gutterY) * pixelRatio.value
87
+ canvasWidth.value = (props.width + props.gutterX) * pixelRatio.value
100
88
  nextTick(() => {
101
- doInit();
102
- });
89
+ doInit()
90
+ })
103
91
  }
104
92
 
105
93
  function doInit() {
106
94
  // #ifdef H5
107
95
  // h5使用document.createElement创建canvas,不用展示canvas标签
108
- showCanvas.value = false;
96
+ showCanvas.value = false
109
97
  // #endif
110
98
  const {
111
99
  width,
@@ -122,7 +110,7 @@ function doInit() {
122
110
  image,
123
111
  imageHeight,
124
112
  imageWidth,
125
- } = props;
113
+ } = props
126
114
 
127
115
  // 创建水印
128
116
  createWaterMark(
@@ -140,7 +128,7 @@ function doInit() {
140
128
  image,
141
129
  imageHeight,
142
130
  imageWidth,
143
- );
131
+ )
144
132
  }
145
133
 
146
134
  /**
@@ -176,11 +164,11 @@ function createWaterMark(
176
164
  imageHeight: number,
177
165
  imageWidth: number,
178
166
  ) {
179
- const canvasHeight = (height + gutterY) * pixelRatio.value;
180
- const canvasWidth = (width + gutterX) * pixelRatio.value;
181
- const contentWidth = width * pixelRatio.value;
182
- const contentHeight = height * pixelRatio.value;
183
- const fontSize = size * pixelRatio.value;
167
+ const canvasHeight = (height + gutterY) * pixelRatio.value
168
+ const canvasWidth = (width + gutterX) * pixelRatio.value
169
+ const contentWidth = width * pixelRatio.value
170
+ const contentHeight = height * pixelRatio.value
171
+ const fontSize = size * pixelRatio.value
184
172
  // #ifndef H5
185
173
  if (canvasOffScreenable.value) {
186
174
  createOffscreenCanvas(
@@ -198,7 +186,7 @@ function createWaterMark(
198
186
  image,
199
187
  imageHeight,
200
188
  imageWidth,
201
- );
189
+ )
202
190
  } else {
203
191
  createCanvas(
204
192
  canvasHeight,
@@ -210,7 +198,7 @@ function createWaterMark(
210
198
  image,
211
199
  imageHeight,
212
200
  imageWidth,
213
- );
201
+ )
214
202
  }
215
203
  // #endif
216
204
  // #ifdef H5
@@ -229,7 +217,7 @@ function createWaterMark(
229
217
  image,
230
218
  imageHeight,
231
219
  imageWidth,
232
- );
220
+ )
233
221
  // #endif
234
222
  }
235
223
 
@@ -270,12 +258,12 @@ function createOffscreenCanvas(
270
258
  const canvas: any = uni.createOffscreenCanvas({
271
259
  height: canvasHeight,
272
260
  width: canvasWidth,
273
- type: "2d",
274
- });
275
- const ctx: any = canvas.getContext("2d");
261
+ type: '2d',
262
+ })
263
+ const ctx: any = canvas.getContext('2d')
276
264
  if (ctx) {
277
265
  if (image) {
278
- const img = canvas.createImage() as HTMLImageElement;
266
+ const img = canvas.createImage() as HTMLImageElement
279
267
  drawImageOffScreen(
280
268
  ctx,
281
269
  img,
@@ -286,7 +274,7 @@ function createOffscreenCanvas(
286
274
  contentWidth,
287
275
  contentHeight,
288
276
  canvas,
289
- );
277
+ )
290
278
  } else {
291
279
  drawTextOffScreen(
292
280
  ctx,
@@ -300,10 +288,10 @@ function createOffscreenCanvas(
300
288
  fontWeight,
301
289
  color,
302
290
  canvas,
303
- );
291
+ )
304
292
  }
305
293
  } else {
306
- console.error("无法获取canvas上下文,请确认当前环境是否支持canvas");
294
+ console.error('无法获取canvas上下文,请确认当前环境是否支持canvas')
307
295
  }
308
296
  }
309
297
 
@@ -331,23 +319,15 @@ function createCanvas(
331
319
  imageHeight: number,
332
320
  imageWidth: number,
333
321
  ) {
334
- const ctx = uni.createCanvasContext(canvasId.value);
322
+ const ctx = uni.createCanvasContext(canvasId.value)
335
323
  if (ctx) {
336
324
  if (image) {
337
- drawImageOnScreen(
338
- ctx,
339
- image,
340
- imageHeight,
341
- imageWidth,
342
- rotate,
343
- contentWidth,
344
- contentHeight,
345
- );
325
+ drawImageOnScreen(ctx, image, imageHeight, imageWidth, rotate, contentWidth, contentHeight)
346
326
  } else {
347
- drawTextOnScreen(ctx, content, contentWidth, rotate, fontSize, color);
327
+ drawTextOnScreen(ctx, content, contentWidth, rotate, fontSize, color)
348
328
  }
349
329
  } else {
350
- console.error("无法获取canvas上下文,请确认当前环境是否支持canvas");
330
+ console.error('无法获取canvas上下文,请确认当前环境是否支持canvas')
351
331
  }
352
332
  }
353
333
 
@@ -381,13 +361,13 @@ function createH5Canvas(
381
361
  imageHeight: number,
382
362
  imageWidth: number,
383
363
  ) {
384
- const canvas = document.createElement("canvas");
385
- const ctx = canvas.getContext("2d");
386
- canvas.setAttribute("width", `${canvasWidth}px`);
387
- canvas.setAttribute("height", `${canvasHeight}px`);
364
+ const canvas = document.createElement('canvas')
365
+ const ctx = canvas.getContext('2d')
366
+ canvas.setAttribute('width', `${canvasWidth}px`)
367
+ canvas.setAttribute('height', `${canvasHeight}px`)
388
368
  if (ctx) {
389
369
  if (image) {
390
- const img = new Image();
370
+ const img = new Image()
391
371
  drawImageOffScreen(
392
372
  ctx,
393
373
  img,
@@ -398,7 +378,7 @@ function createH5Canvas(
398
378
  contentWidth,
399
379
  contentHeight,
400
380
  canvas,
401
- );
381
+ )
402
382
  } else {
403
383
  drawTextOffScreen(
404
384
  ctx,
@@ -412,10 +392,10 @@ function createH5Canvas(
412
392
  fontWeight,
413
393
  color,
414
394
  canvas,
415
- );
395
+ )
416
396
  }
417
397
  } else {
418
- console.error("无法获取canvas上下文,请确认当前环境是否支持canvas");
398
+ console.error('无法获取canvas上下文,请确认当前环境是否支持canvas')
419
399
  }
420
400
  }
421
401
 
@@ -446,15 +426,15 @@ function drawTextOffScreen(
446
426
  color: string,
447
427
  canvas: HTMLCanvasElement,
448
428
  ) {
449
- ctx.textBaseline = "middle";
450
- ctx.textAlign = "center";
451
- ctx.translate(contentWidth / 2, contentWidth / 2);
452
- ctx.rotate((Math.PI / 180) * rotate);
453
- ctx.font = `${fontStyle} normal ${fontWeight} ${fontSize}px/${contentHeight}px ${fontFamily}`;
454
- ctx.fillStyle = color;
455
- ctx.fillText(content, 0, 0);
456
- ctx.restore();
457
- waterMarkUrl.value = canvas.toDataURL();
429
+ ctx.textBaseline = 'middle'
430
+ ctx.textAlign = 'center'
431
+ ctx.translate(contentWidth / 2, contentWidth / 2)
432
+ ctx.rotate((Math.PI / 180) * rotate)
433
+ ctx.font = `${fontStyle} normal ${fontWeight} ${fontSize}px/${contentHeight}px ${fontFamily}`
434
+ ctx.fillStyle = color
435
+ ctx.fillText(content, 0, 0)
436
+ ctx.restore()
437
+ waterMarkUrl.value = canvas.toDataURL()
458
438
  }
459
439
 
460
440
  /**
@@ -474,32 +454,32 @@ function drawTextOnScreen(
474
454
  fontSize: number,
475
455
  color: string,
476
456
  ) {
477
- ctx.setTextBaseline("middle");
478
- ctx.setTextAlign("center");
479
- ctx.translate(contentWidth / 2, contentWidth / 2);
480
- ctx.rotate((Math.PI / 180) * rotate);
481
- ctx.setFillStyle(color);
482
- ctx.setFontSize(fontSize);
483
- ctx.fillText(content, 0, 0);
484
- ctx.restore();
485
- ctx.draw();
457
+ ctx.setTextBaseline('middle')
458
+ ctx.setTextAlign('center')
459
+ ctx.translate(contentWidth / 2, contentWidth / 2)
460
+ ctx.rotate((Math.PI / 180) * rotate)
461
+ ctx.setFillStyle(color)
462
+ ctx.setFontSize(fontSize)
463
+ ctx.fillText(content, 0, 0)
464
+ ctx.restore()
465
+ ctx.draw()
486
466
  // #ifdef MP-DINGTALK
487
467
  // 钉钉小程序的canvasToTempFilePath接口与其他平台不一样
488
- (ctx as any).toTempFilePath({
468
+ ;(ctx as any).toTempFilePath({
489
469
  success(res: any) {
490
- showCanvas.value = false;
491
- waterMarkUrl.value = res.filePath;
470
+ showCanvas.value = false
471
+ waterMarkUrl.value = res.filePath
492
472
  },
493
- });
473
+ })
494
474
  // #endif
495
475
  // #ifndef MP-DINGTALK
496
476
  uni.canvasToTempFilePath({
497
477
  canvasId: canvasId.value,
498
478
  success: (res) => {
499
- showCanvas.value = false;
500
- waterMarkUrl.value = res.tempFilePath;
479
+ showCanvas.value = false
480
+ waterMarkUrl.value = res.tempFilePath
501
481
  },
502
- });
482
+ })
503
483
  // #endif
504
484
  }
505
485
 
@@ -526,12 +506,12 @@ async function drawImageOffScreen(
526
506
  contentHeight: number,
527
507
  canvas: HTMLCanvasElement,
528
508
  ) {
529
- ctx.translate(contentWidth / 2, contentHeight / 2);
530
- ctx.rotate((Math.PI / 180) * Number(rotate));
531
- img.crossOrigin = "anonymous";
532
- img.referrerPolicy = "no-referrer";
509
+ ctx.translate(contentWidth / 2, contentHeight / 2)
510
+ ctx.rotate((Math.PI / 180) * Number(rotate))
511
+ img.crossOrigin = 'anonymous'
512
+ img.referrerPolicy = 'no-referrer'
533
513
 
534
- img.src = image;
514
+ img.src = image
535
515
  img.onload = () => {
536
516
  ctx.drawImage(
537
517
  img,
@@ -539,10 +519,10 @@ async function drawImageOffScreen(
539
519
  (-imageHeight * pixelRatio.value) / 2,
540
520
  imageWidth * pixelRatio.value,
541
521
  imageHeight * pixelRatio.value,
542
- );
543
- ctx.restore();
544
- waterMarkUrl.value = canvas.toDataURL();
545
- };
522
+ )
523
+ ctx.restore()
524
+ waterMarkUrl.value = canvas.toDataURL()
525
+ }
546
526
  }
547
527
 
548
528
  /**
@@ -564,8 +544,8 @@ function drawImageOnScreen(
564
544
  contentWidth: number,
565
545
  contentHeight: number,
566
546
  ) {
567
- ctx.translate(contentWidth / 2, contentHeight / 2);
568
- ctx.rotate((Math.PI / 180) * Number(rotate));
547
+ ctx.translate(contentWidth / 2, contentHeight / 2)
548
+ ctx.rotate((Math.PI / 180) * Number(rotate))
569
549
 
570
550
  ctx.drawImage(
571
551
  image,
@@ -573,31 +553,31 @@ function drawImageOnScreen(
573
553
  (-imageHeight * pixelRatio.value) / 2,
574
554
  imageWidth * pixelRatio.value,
575
555
  imageHeight * pixelRatio.value,
576
- );
577
- ctx.restore();
556
+ )
557
+ ctx.restore()
578
558
  ctx.draw(false, () => {
579
559
  // #ifdef MP-DINGTALK
580
560
  // 钉钉小程序的canvasToTempFilePath接口与其他平台不一样
581
- (ctx as any).toTempFilePath({
561
+ ;(ctx as any).toTempFilePath({
582
562
  success(res: any) {
583
- showCanvas.value = false;
584
- waterMarkUrl.value = res.filePath;
563
+ showCanvas.value = false
564
+ waterMarkUrl.value = res.filePath
585
565
  },
586
- });
566
+ })
587
567
  // #endif
588
568
  // #ifndef MP-DINGTALK
589
569
  uni.canvasToTempFilePath({
590
570
  canvasId: canvasId.value,
591
571
  success: (res) => {
592
- showCanvas.value = false;
593
- waterMarkUrl.value = res.tempFilePath;
572
+ showCanvas.value = false
573
+ waterMarkUrl.value = res.tempFilePath
594
574
  },
595
- });
575
+ })
596
576
  // #endif
597
- });
577
+ })
598
578
  }
599
579
  </script>
600
580
 
601
581
  <style lang="scss" scoped>
602
- @import "./index.scss";
582
+ @import './index.scss';
603
583
  </style>
@@ -11,5 +11,7 @@
11
11
  bottom: 0;
12
12
  pointer-events: none;
13
13
  background-repeat: repeat;
14
-
15
- }
14
+ @include is(fullscreen) {
15
+ position: fixed;
16
+ }
17
+ }
package/index.scss CHANGED
@@ -1,3 +1,3 @@
1
1
  @use "./libs/css/common.scss";
2
2
  @use "./libs/css/vars.css";
3
- //@use "./libs/css/mixin.scss" as HyMixin;
3
+ //@use "./libs/css/mixin.scss";
@@ -22,4 +22,12 @@
22
22
  height: 100vh;
23
23
  /* #endif */
24
24
  overflow: auto;
25
- }
25
+ }
26
+
27
+ /* 解决滚动时候出现滚动条 */
28
+ ::-webkit-scrollbar{
29
+ width: 0;
30
+ height: 0;
31
+ color: transparent;
32
+ display:none;
33
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "hy-app",
3
- "version": "0.2.4",
4
- "description": "新增组件:分页、签名面板、水印、验证码输入、侧边菜单栏",
3
+ "version": "0.2.5",
4
+ "description": "修复在微信小程序线上bug",
5
5
  "main": "./index.ts",
6
6
  "private": false,
7
7
  "scripts": {},
package/theme.scss CHANGED
@@ -43,27 +43,16 @@ $hy-background--2: var(--hy-background--2, #ffffff) !default; // 弹窗背景色
43
43
  $hy-background--3: var(--hy-background--3, #646566) !default; // 弹窗背景色
44
44
  $hy-background--container: var(--hy-background--container, #ffffff) !default; // 容器背景色
45
45
  $hy-background--disabled: var(--hy-background--disabled, #F5F5F5); // 禁用背景色
46
- $hy-background--track: var(--hy-background--track, #F6F6F6) !default;
46
+ $hy-background--track: var(--hy-background--track, #F6F6F6) !default; // 轨道背景色
47
47
  $hy-background--empty: var(--hy-background--empty, #F3F3F3) !default; // 搜索背景色
48
48
  $hy-background--hover: var(--hy-background--hover, rgba(0,0,0,0.1)) !default; // 点击状态
49
49
  $hy-light-background-mask: var(--hy-light-background-mask, rgba(0, 0, 0, 0.5)); //遮罩颜色
50
- $hy-background--active: var(--hy-background--active, #131313); // 选中状态值
50
+ $hy-background--active: var(--hy-background--active, #131313); // 选中背景色
51
51
 
52
52
  /* 文字尺寸 */
53
- $hy-font-size-sm: 12px;
54
- $hy-font-size-base: 16px;
55
- $hy-font-size-lg: 20px;
56
-
57
- /* 文章场景相关 */
58
- $hy-color-title: #2c405a; // 文章标题颜色
59
- $hy-weight-title: 700;
60
- $hy-font-size-title: 44rpx;
61
- $hy-color-subtitle: #555555; // 二级标题颜色
62
- $hy-font-size-subtitle: 38rpx;
63
- $hy-color-paragraph: #3f536e; // 文章段落颜色
64
- $hy-font-size-paragraph: 32rpx;
65
- $hy-color-hint: #999; // 提示文字
66
- $hy-font-size-hint: 26rpx;
53
+ $hy-font-size-sm: 24rpx; // 提示文字大小
54
+ $hy-font-size-base: 32rpx; // 基本文字大小
55
+ $hy-font-size-lg: 40rpx; // 标题文字大小
67
56
 
68
57
 
69
58
  /* 边框颜色 */
@@ -98,4 +87,4 @@ $hy-border-margin-padding-sm: var(--hy-border-margin-padding-sm, 10rpx) !default
98
87
  $hy-border-margin-padding-base: var(--hy-border-margin-padding-base, 20rpx) !default;
99
88
  $hy-border-margin-padding-lg: var(--hy-border-margin-padding-lg, 30rpx) !default;
100
89
  /* 底部线条 */
101
- $hy-border-line: var(--hy-border-line, 1rpx solid #c2c2c4) !default;
90
+ $hy-border-line: var(--hy-border-line, 1px solid #c2c2c4) !default;