hy-app 0.3.0 → 0.3.2

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.
Files changed (108) hide show
  1. package/README.md +6 -3
  2. package/common/shakeService.ts +31 -29
  3. package/components/avatar.zip +0 -0
  4. package/components/hy-action-sheet/hy-action-sheet.vue +71 -46
  5. package/components/hy-address-picker/hy-address-picker.vue +94 -83
  6. package/components/hy-avatar/hy-avatar.vue +84 -85
  7. package/components/hy-back-top/hy-back-top.vue +8 -6
  8. package/components/hy-badge/hy-badge.vue +47 -46
  9. package/components/hy-button/hy-button.vue +117 -93
  10. package/components/hy-calendar/hy-calendar.vue +168 -160
  11. package/components/hy-card/hy-card.vue +50 -43
  12. package/components/hy-card/typing.d.ts +33 -32
  13. package/components/hy-cell/hy-cell.vue +73 -51
  14. package/components/hy-check-button/hy-check-button.vue +54 -47
  15. package/components/hy-checkbox/hy-checkbox.vue +97 -105
  16. package/components/hy-code-input/hy-code-input.vue +80 -89
  17. package/components/hy-config-provider/hy-config-provider.vue +20 -21
  18. package/components/hy-count-down/hy-count-down.vue +66 -67
  19. package/components/hy-count-to/hy-count-to.vue +105 -99
  20. package/components/hy-count-to/typing.d.ts +13 -12
  21. package/components/hy-datetime-picker/hy-datetime-picker.vue +261 -253
  22. package/components/hy-datetime-picker/typing.d.ts +42 -40
  23. package/components/hy-divider/hy-divider.vue +68 -73
  24. package/components/hy-dropdown/hy-dropdown.vue +20 -19
  25. package/components/hy-dropdown-item/hy-dropdown-item.vue +66 -61
  26. package/components/hy-dropdown-item/typing.d.ts +9 -9
  27. package/components/hy-empty/hy-empty.vue +42 -42
  28. package/components/hy-flex/hy-flex.vue +99 -0
  29. package/components/hy-flex/index.scss +8 -0
  30. package/components/hy-flex/typing.d.ts +23 -0
  31. package/components/hy-float-button/hy-float-button.vue +218 -210
  32. package/components/hy-folding-panel/hy-folding-panel.vue +32 -33
  33. package/components/hy-form/hy-form.vue +264 -252
  34. package/components/hy-form/typing.d.ts +4 -0
  35. package/components/hy-form-group/hy-form-group.vue +114 -183
  36. package/components/hy-form-item/hy-form-item.vue +12 -10
  37. package/components/hy-form-item/index.scss +2 -2
  38. package/components/hy-form-item/typing.d.ts +3 -6
  39. package/components/hy-grid/hy-grid.vue +44 -43
  40. package/components/hy-icon/hy-icon.vue +61 -67
  41. package/components/hy-image/hy-image.vue +112 -88
  42. package/components/hy-image/typing.d.ts +27 -23
  43. package/components/hy-input/hy-input.vue +157 -127
  44. package/components/hy-input/typing.d.ts +53 -47
  45. package/components/hy-line/hy-line.vue +26 -26
  46. package/components/hy-line-progress/hy-line-progress.vue +42 -35
  47. package/components/hy-list/hy-list.vue +76 -85
  48. package/components/hy-loading/hy-loading.vue +26 -23
  49. package/components/hy-login/TheUserLogin.vue +1 -1
  50. package/components/hy-menu/hy-menu.vue +48 -43
  51. package/components/hy-menu/typing.d.ts +18 -17
  52. package/components/hy-modal/hy-modal.vue +39 -35
  53. package/components/hy-navbar/hy-navbar.vue +25 -25
  54. package/components/hy-navbar/typing.d.ts +24 -22
  55. package/components/hy-notice-bar/hy-notice-bar.vue +26 -27
  56. package/components/hy-notify/hy-notify.vue +53 -53
  57. package/components/hy-number-step/hy-number-step.vue +134 -146
  58. package/components/hy-number-step/typing.d.ts +35 -35
  59. package/components/hy-overlay/hy-overlay.vue +23 -21
  60. package/components/hy-pagination/hy-pagination.vue +41 -36
  61. package/components/hy-picker/hy-picker.vue +184 -154
  62. package/components/hy-picker/typing.d.ts +39 -39
  63. package/components/hy-popover/hy-popover.vue +97 -77
  64. package/components/hy-popup/hy-popup.vue +107 -98
  65. package/components/hy-price/hy-price.vue +38 -34
  66. package/components/hy-qrcode/hy-qrcode.vue +50 -51
  67. package/components/hy-radio/hy-radio.vue +101 -113
  68. package/components/hy-rate/hy-rate.vue +107 -88
  69. package/components/hy-read-more/hy-read-more.vue +64 -49
  70. package/components/hy-scroll-list/hy-scroll-list.vue +45 -48
  71. package/components/hy-search/hy-search.vue +73 -66
  72. package/components/hy-search/typing.d.ts +36 -35
  73. package/components/hy-signature/hy-signature.vue +282 -240
  74. package/components/hy-slider/hy-slider.vue +195 -153
  75. package/components/hy-slider/typing.d.ts +21 -21
  76. package/components/hy-steps/hy-steps.vue +118 -90
  77. package/components/hy-steps/index.scss +31 -21
  78. package/components/hy-submit-bar/hy-submit-bar.vue +61 -70
  79. package/components/hy-subsection/hy-subsection.vue +99 -102
  80. package/components/hy-subsection/typing.d.ts +19 -19
  81. package/components/hy-swipe-action/hy-swipe-action.vue +131 -118
  82. package/components/hy-swiper/hy-swiper.vue +85 -71
  83. package/components/hy-switch/hy-switch.vue +67 -72
  84. package/components/hy-switch/typing.d.ts +21 -19
  85. package/components/hy-tabs/hy-tabs.vue +168 -113
  86. package/components/hy-tag/hy-tag.vue +90 -86
  87. package/components/hy-tag/typing.d.ts +26 -21
  88. package/components/hy-text/hy-text.vue +119 -111
  89. package/components/hy-textarea/hy-textarea.vue +100 -93
  90. package/components/hy-textarea/typing.d.ts +36 -31
  91. package/components/hy-toast/hy-toast.vue +77 -67
  92. package/components/hy-tooltip/hy-tooltip.vue +109 -91
  93. package/components/hy-transition/hy-transition.vue +62 -66
  94. package/components/hy-upload/hy-upload.vue +294 -152
  95. package/components/hy-upload/typing.d.ts +41 -36
  96. package/components/hy-warn/hy-warn.vue +34 -27
  97. package/components/hy-waterfall/hy-waterfall.vue +83 -74
  98. package/components/hy-watermark/hy-watermark.vue +134 -115
  99. package/components/index.ts +1 -1
  100. package/composables/usePopover.ts +236 -221
  101. package/composables/useQueue.ts +53 -52
  102. package/global.d.ts +1 -0
  103. package/package.json +2 -2
  104. package/store/index.ts +9 -1
  105. package/theme.scss +5 -5
  106. package/typing/index.ts +0 -1
  107. package/typing/modules/common.d.ts +0 -2
  108. package/web-types.json +1 -1
@@ -29,7 +29,12 @@
29
29
  hover-class="hy-popup__content__close--hover"
30
30
  hover-stay-time="150"
31
31
  >
32
- <HyIcon :name="IconConfig.CLOSE" color="#909399" size="18" bold></HyIcon>
32
+ <HyIcon
33
+ :name="IconConfig.CLOSE"
34
+ color="#909399"
35
+ size="18"
36
+ bold
37
+ ></HyIcon>
33
38
  </view>
34
39
  <!-- <hy-safe-bottom v-if="safeAreaInsetBottom"></hy-safe-bottom>-->
35
40
  </view>
@@ -39,32 +44,32 @@
39
44
 
40
45
  <script lang="ts">
41
46
  export default {
42
- name: 'hy-popup',
47
+ name: "hy-popup",
43
48
  options: {
44
49
  addGlobalClass: true,
45
50
  virtualHost: true,
46
- styleIsolation: 'shared',
51
+ styleIsolation: "shared",
47
52
  },
48
- }
53
+ };
49
54
  </script>
50
55
 
51
56
  <script setup lang="ts">
52
- import { computed, ref, toRefs, watch } from 'vue'
53
- import type { CSSProperties, PropType } from 'vue'
54
- import type { IPopupEmits } from './typing'
55
- import { addUnit, getWindowInfo } from '../../utils'
56
- import { IconConfig } from '../../config'
57
+ import { computed, ref, toRefs, watch } from "vue";
58
+ import type { CSSProperties, PropType } from "vue";
59
+ import type { IPopupEmits } from "./typing";
60
+ import { addUnit, getWindowInfo } from "../../utils";
61
+ import { IconConfig } from "../../config";
57
62
 
58
63
  // 组件
59
- import HyTransition from '../hy-transition/hy-transition.vue'
60
- import HyOverlay from '../hy-overlay/hy-overlay.vue'
61
- import HyIcon from '../hy-icon/hy-icon.vue'
64
+ import HyTransition from "../hy-transition/hy-transition.vue";
65
+ import HyOverlay from "../hy-overlay/hy-overlay.vue";
66
+ import HyIcon from "../hy-icon/hy-icon.vue";
62
67
 
63
68
  /**
64
69
  * 弹出层容器,用于展示弹窗、信息提示等内容,支持上、下、左、右和中部弹出。组件只提供容器,内部内容由用户自定义。
65
70
  * @displayName hy-popup
66
71
  */
67
- defineOptions({})
72
+ defineOptions({});
68
73
 
69
74
  // const props = withDefaults(defineProps<IProps>(), defaultProps)
70
75
  const props = defineProps({
@@ -78,10 +83,13 @@ const props = defineProps({
78
83
  type: Boolean,
79
84
  default: true,
80
85
  },
81
- /** 弹出方向 */
86
+ /**
87
+ * 弹出方向
88
+ * @values left,right,top,bottom,center
89
+ * */
82
90
  mode: {
83
- type: String,
84
- default: 'bottom',
91
+ type: String as PropType<HyApp.LayoutType>,
92
+ default: "bottom",
85
93
  },
86
94
  /** 动画时长,单位ms */
87
95
  duration: {
@@ -126,7 +134,7 @@ const props = defineProps({
126
134
  * */
127
135
  closeIconPos: {
128
136
  type: String,
129
- default: 'top-right',
137
+ default: "top-right",
130
138
  },
131
139
  /** 圆角值 */
132
140
  round: [String, Number],
@@ -138,18 +146,19 @@ const props = defineProps({
138
146
  /** 背景颜色 */
139
147
  bgColor: String,
140
148
  /** 定义需要用到的外部样式 */
141
- customStyle: Object as PropType<CSSProperties>,
149
+ customStyle: {
150
+ type: Object as PropType<CSSProperties>,
151
+ default: () => {},
152
+ },
142
153
  /** 自定义外部类名 */
143
154
  customClass: String,
144
- })
145
- const { duration, show, closeOnClickOverlay, mode, zIndex, bgColor, round, customStyle, zoom } =
146
- toRefs(props)
147
- const emit = defineEmits<IPopupEmits>()
155
+ });
156
+ const emit = defineEmits<IPopupEmits>();
148
157
 
149
- const overlayDuration = ref(duration.value + 50)
158
+ const overlayDuration = ref(props.duration + 50);
150
159
 
151
160
  watch(
152
- () => show.value,
161
+ () => props.show,
153
162
  (newValue) => {
154
163
  if (newValue) {
155
164
  // #ifdef MP-WEIXIN
@@ -158,117 +167,117 @@ watch(
158
167
  // #endif
159
168
  }
160
169
  },
161
- )
170
+ );
162
171
 
163
172
  const transitionStyle = computed(() => {
164
173
  const style: CSSProperties = {
165
- zIndex: zIndex.value,
166
- position: 'fixed',
167
- display: 'flex',
168
- }
169
- if (mode.value !== 'center') {
170
- style[mode.value] = 0
174
+ zIndex: props.zIndex,
175
+ position: "fixed",
176
+ display: "flex",
177
+ };
178
+ if (props.mode !== "center") {
179
+ style[props.mode] = 0;
171
180
  }
172
- switch (mode.value) {
173
- case 'left':
174
- case 'right':
175
- style.bottom = 0
176
- style.top = 0
177
- break
178
- case 'top':
179
- case 'bottom':
180
- style.left = 0
181
- style.right = 0
182
- break
183
- case 'center':
181
+ switch (props.mode) {
182
+ case "left":
183
+ case "right":
184
+ style.bottom = 0;
185
+ style.top = 0;
186
+ break;
187
+ case "top":
188
+ case "bottom":
189
+ style.left = 0;
190
+ style.right = 0;
191
+ break;
192
+ case "center":
184
193
  Object.assign(style, {
185
- alignItems: 'center',
186
- 'justify-content': 'center',
194
+ alignItems: "center",
195
+ "justify-content": "center",
187
196
  top: 0,
188
197
  left: 0,
189
198
  right: 0,
190
199
  bottom: 0,
191
- })
192
- break
200
+ });
201
+ break;
193
202
  default:
194
- break
203
+ break;
195
204
  }
196
205
 
197
- return style
198
- })
206
+ return style;
207
+ });
199
208
  const contentStyle = computed(() => {
200
- const style: CSSProperties = {}
209
+ const style: CSSProperties = {};
201
210
  // 通过设备信息的safeAreaInsets值来判断是否需要预留顶部状态栏和底部安全局的位置
202
211
  // 不使用css方案,是因为nvue不支持css的iPhoneX安全区查询属性
203
- const { safeAreaInsets } = getWindowInfo()
204
- if (mode.value !== 'center') {
205
- style.flex = 1
212
+ const { safeAreaInsets } = getWindowInfo();
213
+ if (props.mode !== "center") {
214
+ style.flex = 1;
206
215
  }
207
216
  // 背景色,一般用于设置为transparent,去除默认的白色背景
208
- if (bgColor.value) {
209
- style.backgroundColor = bgColor.value
217
+ if (props.bgColor) {
218
+ style.backgroundColor = props.bgColor;
210
219
  }
211
- if (round.value) {
212
- const value = addUnit(round.value)
213
- switch (mode.value) {
214
- case 'top':
215
- style.borderBottomLeftRadius = value
216
- style.borderBottomRightRadius = value
217
- break
218
- case 'bottom':
219
- style.borderTopLeftRadius = value
220
- style.borderTopRightRadius = value
221
- break
222
- case 'center':
223
- style.borderRadius = value
224
- break
220
+ if (props.round) {
221
+ const value = addUnit(props.round);
222
+ switch (props.mode) {
223
+ case "top":
224
+ style.borderBottomLeftRadius = value;
225
+ style.borderBottomRightRadius = value;
226
+ break;
227
+ case "bottom":
228
+ style.borderTopLeftRadius = value;
229
+ style.borderTopRightRadius = value;
230
+ break;
231
+ case "center":
232
+ style.borderRadius = value;
233
+ break;
225
234
  default:
226
- break
235
+ break;
227
236
  }
228
237
  }
229
- return Object.assign(style, customStyle.value || {})
230
- })
238
+ return Object.assign(style, props.customStyle);
239
+ });
231
240
  const positionMode = computed(() => {
232
- if (mode.value === 'center') {
233
- return zoom.value ? 'fade-zoom' : 'fade'
241
+ if (props.mode === "center") {
242
+ return props.zoom ? "fade-zoom" : "fade";
234
243
  }
235
- if (mode.value === 'left') {
236
- return 'slide-left'
244
+ if (props.mode === "left") {
245
+ return "slide-left";
237
246
  }
238
- if (mode.value === 'right') {
239
- return 'slide-right'
247
+ if (props.mode === "right") {
248
+ return "slide-right";
240
249
  }
241
- if (mode.value === 'bottom') {
242
- return 'slide-up'
250
+ if (props.mode === "bottom") {
251
+ return "slide-up";
243
252
  }
244
- if (mode.value === 'top') {
245
- return 'slide-down'
253
+ if (props.mode === "top") {
254
+ return "slide-down";
246
255
  }
247
- })
256
+ });
248
257
 
249
258
  // 点击遮罩
250
259
  const overlayClick = () => {
251
- if (closeOnClickOverlay.value) {
252
- emit('update:show', false)
253
- emit('close')
260
+ if (props.closeOnClickOverlay) {
261
+ emit("update:show", false);
262
+ emit("close");
254
263
  }
255
- }
264
+ };
256
265
  const close = () => {
257
- emit('update:show', false)
258
- emit('close')
259
- }
266
+ emit("update:show", false);
267
+ emit("close");
268
+ };
260
269
  const afterEnter = () => {
261
- emit('open')
262
- }
270
+ emit("open");
271
+ };
263
272
  const clickHandler = () => {
264
273
  // 由于中部弹出时,其u-transition占据了整个页面相当于遮罩,此时需要发出遮罩点击事件,是否无法通过点击遮罩关闭弹窗
265
- if (mode.value === 'center') {
266
- overlayClick()
274
+ if (props.mode === "center") {
275
+ overlayClick();
267
276
  }
268
- emit('click')
269
- }
277
+ emit("click");
278
+ };
270
279
  </script>
271
280
 
272
281
  <style lang="scss" scoped>
273
- @import './index.scss';
282
+ @import "./index.scss";
274
283
  </style>
@@ -1,40 +1,43 @@
1
- <!--
2
- Description: 价格的样式
3
- -->
4
-
5
1
  <template>
6
- <text :class="['hy-price', customClass]" :style="priceStyle" @tap="handleClick">
2
+ <text
3
+ :class="['hy-price', customClass]"
4
+ :style="priceStyle"
5
+ @tap="handleClick"
6
+ >
7
7
  <text class="hy-price__prefix">{{ symbol }}</text>
8
- <text class="hy-price__text" :style="[{ 'font-size': addUnit(getPx(size) * ratio) }]">
8
+ <text
9
+ class="hy-price__text"
10
+ :style="[{ 'font-size': addUnit(getPx(size) * ratio) }]"
11
+ >
9
12
  {{ priceOne[0] }}
10
13
  </text>
11
14
  <text class="hy-price__decimal">
12
- {{ '.' + priceOne[1].slice(0, num) }}
15
+ {{ "." + priceOne[1].slice(0, num) }}
13
16
  </text>
14
17
  </text>
15
18
  </template>
16
19
 
17
20
  <script lang="ts">
18
21
  export default {
19
- name: 'hy-price',
22
+ name: "hy-price",
20
23
  options: {
21
24
  addGlobalClass: true,
22
25
  virtualHost: true,
23
- styleIsolation: 'shared',
26
+ styleIsolation: "shared",
24
27
  },
25
- }
28
+ };
26
29
  </script>
27
30
 
28
31
  <script setup lang="ts">
29
- import { computed, toRefs } from 'vue'
30
- import type { CSSProperties, PropType } from 'vue'
31
- import { addUnit, getPx } from '../../utils'
32
+ import { computed, toRefs } from "vue";
33
+ import type { CSSProperties, PropType } from "vue";
34
+ import { addUnit, getPx } from "../../utils";
32
35
 
33
36
  /**
34
37
  * 业务组件,突出金额小数点前大,小数点后小
35
38
  * @displayName hy-price
36
39
  */
37
- defineOptions({})
40
+ defineOptions({});
38
41
 
39
42
  // const props = withDefaults(defineProps<IProps>(), defaultProps)
40
43
  const props = defineProps({
@@ -43,7 +46,7 @@ const props = defineProps({
43
46
  /** 金额符号 */
44
47
  symbol: {
45
48
  type: String,
46
- default: '',
49
+ default: "",
47
50
  },
48
51
  /** 比例大小 */
49
52
  ratio: {
@@ -58,7 +61,7 @@ const props = defineProps({
58
61
  /** 字体颜色 */
59
62
  color: {
60
63
  type: String,
61
- default: '#FE3232',
64
+ default: "#FE3232",
62
65
  },
63
66
  /** 字体大小 */
64
67
  size: {
@@ -78,12 +81,13 @@ const props = defineProps({
78
81
  /** 定义需要用到的外部样式 */
79
82
  customStyle: {
80
83
  type: Object as PropType<CSSProperties>,
84
+ default: () => {},
81
85
  },
82
86
  /** 自定义外部类名 */
83
87
  customClass: String,
84
- })
85
- const { text, color, weight, size, slant, customStyle } = toRefs(props)
86
- const emit = defineEmits(['click'])
88
+ });
89
+ const { text, color, weight, size, slant, customStyle } = toRefs(props);
90
+ const emit = defineEmits(["click"]);
87
91
 
88
92
  /**
89
93
  * @description 价格整体样式
@@ -92,42 +96,42 @@ const priceStyle = computed<CSSProperties>(() => {
92
96
  const style: CSSProperties = {
93
97
  color: color.value,
94
98
  fontWeight: weight.value,
95
- fontStyle: slant.value ? 'oblique' : '',
99
+ fontStyle: slant.value ? "oblique" : "",
96
100
  fontSize: addUnit(size.value),
97
- }
101
+ };
98
102
 
99
- return Object.assign(style, customStyle.value)
100
- })
103
+ return Object.assign(style, customStyle.value);
104
+ });
101
105
 
102
106
  /**
103
107
  * @description 价格处理
104
108
  * */
105
109
  const priceOne = computed(() => {
106
- let value = ''
107
- if (typeof text.value !== 'string') {
108
- value = text.value.toString()
110
+ let value = "";
111
+ if (typeof text.value !== "string") {
112
+ value = text.value.toString();
109
113
  } else {
110
- value = text.value
114
+ value = text.value;
111
115
  }
112
116
  if (/\./g.test(value)) {
113
117
  if (Number(value)) {
114
- return value.split('.')
118
+ return value.split(".");
115
119
  } else {
116
- return ['0', '00']
120
+ return ["0", "00"];
117
121
  }
118
122
  } else {
119
- return [value, '000000']
123
+ return [value, "000000"];
120
124
  }
121
- })
125
+ });
122
126
 
123
127
  /**
124
128
  * @description 点击事件
125
129
  * */
126
130
  const handleClick = () => {
127
- emit('click', text.value)
128
- }
131
+ emit("click", text.value);
132
+ };
129
133
  </script>
130
134
 
131
135
  <style lang="scss" scoped>
132
- @import './index.scss';
136
+ @import "./index.scss";
133
137
  </style>
@@ -22,35 +22,35 @@
22
22
 
23
23
  <script lang="ts">
24
24
  export default {
25
- name: 'hy-qrcode',
25
+ name: "hy-qrcode",
26
26
  options: {
27
27
  addGlobalClass: true,
28
28
  virtualHost: true,
29
- styleIsolation: 'shared',
29
+ styleIsolation: "shared",
30
30
  },
31
- }
31
+ };
32
32
  </script>
33
33
 
34
34
  <script setup lang="ts">
35
- import { getCurrentInstance, toRefs, ref, onMounted } from 'vue'
36
- import type { IQrcodeEmits } from './typing'
37
- import QRCode from './qrcode.js'
38
- import { addUnit, error } from '../../utils'
35
+ import { getCurrentInstance, toRefs, ref, onMounted } from "vue";
36
+ import type { IQrcodeEmits } from "./typing";
37
+ import QRCode from "./qrcode.js";
38
+ import { addUnit, error } from "../../utils";
39
39
  // 组件
40
- import HyLoading from '../hy-loading/hy-loading.vue'
40
+ import HyLoading from "../hy-loading/hy-loading.vue";
41
41
 
42
42
  /**
43
43
  * 根据提供的字符串前端JS生成二维码展示
44
44
  * @displayName hy-qrcode
45
45
  */
46
- defineOptions({})
46
+ defineOptions({});
47
47
 
48
48
  // const props = withDefaults(defineProps<IProps>(), defaultProps)
49
49
  const props = defineProps({
50
50
  /** 实例ID字符串(如果有多个二维码组件必须设置不一样的cid) */
51
51
  cid: {
52
52
  type: String,
53
- default: 'hy-qrcode-canvas' + Math.random().toString(),
53
+ default: "hy-qrcode-canvas" + Math.random().toString(),
54
54
  },
55
55
  /** 二维码大小 */
56
56
  size: {
@@ -67,17 +67,17 @@ const props = defineProps({
67
67
  /** 二维码背景色 */
68
68
  background: {
69
69
  type: String,
70
- default: '#ffffff',
70
+ default: "#ffffff",
71
71
  },
72
72
  /** 二维码颜色 */
73
73
  foreground: {
74
74
  type: String,
75
- default: '#000000',
75
+ default: "#000000",
76
76
  },
77
77
  /** 定位角点颜色 */
78
78
  pdGround: {
79
79
  type: String,
80
- default: '#000000',
80
+ default: "#000000",
81
81
  },
82
82
  /** 是否是自定义组件 */
83
83
  usingComponents: {
@@ -104,36 +104,35 @@ const props = defineProps({
104
104
  /** 加载中提示语 */
105
105
  loadingText: {
106
106
  type: String,
107
- default: '二维码生成中',
107
+ default: "二维码生成中",
108
108
  },
109
109
  /** 是否预览 */
110
110
  allowPreview: {
111
111
  type: Boolean,
112
112
  default: false,
113
113
  },
114
- })
115
- const { text, allowPreview } = toRefs(props)
116
- const emit = defineEmits<IQrcodeEmits>()
114
+ });
115
+ const emit = defineEmits<IQrcodeEmits>();
117
116
 
118
- const instance = getCurrentInstance()
119
- const loading = ref(false)
120
- const qrcode = ref('')
121
- const result = ref('')
117
+ const instance = getCurrentInstance();
118
+ const loading = ref(false);
119
+ const qrcode = ref("");
120
+ const result = ref("");
122
121
 
123
122
  onMounted(() => {
124
- initQrCode()
125
- })
123
+ initQrCode();
124
+ });
126
125
 
127
126
  const initQrCode = () => {
128
- if (text.value) {
129
- loading.value = true
127
+ if (props.text) {
128
+ loading.value = true;
130
129
  qrcode.value = new QRCode({
131
130
  context: instance, // 上下文环境
132
131
  canvasId: props.cid, // canvas-id
133
132
  usingComponents: props.usingComponents, // 是否是自定义组件
134
133
  showLoading: false, // 是否显示loading
135
134
  loadingText: props.loadingText, // loading文字
136
- text: text.value, // 生成内容
135
+ text: props.text, // 生成内容
137
136
  size: props.size, // 二维码大小
138
137
  background: props.background, // 背景色
139
138
  foreground: props.foreground, // 前景色
@@ -143,67 +142,67 @@ const initQrCode = () => {
143
142
  imageSize: props.iconSize, // 二维码图标大小
144
143
  cbResult: function (res: any) {
145
144
  // 生成二维码的回调
146
- _result(res)
145
+ _result(res);
147
146
  },
148
- })
147
+ });
149
148
  } else {
150
- error('二维码内容不能为空')
149
+ error("二维码内容不能为空");
151
150
  }
152
- }
151
+ };
153
152
 
154
153
  const _result = (res: any) => {
155
- loading.value = false
156
- result.value = res
157
- emit('result', res)
158
- }
154
+ loading.value = false;
155
+ result.value = res;
156
+ emit("result", res);
157
+ };
159
158
 
160
159
  const _saveCode = () => {
161
- if (result.value != '') {
160
+ if (result.value != "") {
162
161
  uni.saveImageToPhotosAlbum({
163
162
  filePath: result.value,
164
163
  success: function () {
165
164
  uni.showToast({
166
- title: '二维码保存成功',
167
- icon: 'success',
165
+ title: "二维码保存成功",
166
+ icon: "success",
168
167
  duration: 2000,
169
- })
168
+ });
170
169
  },
171
- })
170
+ });
172
171
  }
173
- }
172
+ };
174
173
  /**
175
174
  * @description 预览
176
175
  * */
177
176
  const preview = (e: Event) => {
178
177
  // 预览图片
179
178
  // console.log(this.result)
180
- if (allowPreview.value) {
179
+ if (props.allowPreview) {
181
180
  uni.previewImage({
182
181
  urls: [result.value],
183
182
  longPressActions: {
184
- itemList: ['保存二维码图片'],
183
+ itemList: ["保存二维码图片"],
185
184
  success: function (data) {
186
185
  // console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data.index + 1) + '张图片');
187
186
  switch (data.tapIndex) {
188
187
  case 0:
189
- _saveCode()
190
- break
188
+ _saveCode();
189
+ break;
191
190
  }
192
191
  },
193
192
  fail: function (err) {
194
- console.error(err.errMsg)
193
+ console.error(err.errMsg);
195
194
  },
196
195
  },
197
- })
196
+ });
198
197
  }
199
- emit('preview', result.value, e)
200
- }
198
+ emit("preview", result.value, e);
199
+ };
201
200
 
202
201
  const onLongPress = () => {
203
- emit('longPress')
204
- }
202
+ emit("longPress");
203
+ };
205
204
  </script>
206
205
 
207
206
  <style lang="scss" scoped>
208
- @import './index.scss';
207
+ @import "./index.scss";
209
208
  </style>