hy-app 0.4.13 → 0.5.0

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 (211) hide show
  1. package/components/hy-action-sheet/hy-action-sheet.vue +155 -238
  2. package/components/hy-action-sheet/props.ts +68 -15
  3. package/components/hy-action-sheet/typing.d.ts +115 -115
  4. package/components/hy-address-picker/hy-address-picker.vue +185 -289
  5. package/components/hy-address-picker/props.ts +97 -21
  6. package/components/hy-address-picker/typing.d.ts +90 -89
  7. package/components/hy-avatar/hy-avatar.vue +121 -204
  8. package/components/hy-avatar/props.ts +76 -18
  9. package/components/hy-avatar/typing.d.ts +63 -62
  10. package/components/hy-back-top/hy-back-top.vue +65 -120
  11. package/components/hy-back-top/props.ts +57 -16
  12. package/components/hy-back-top/typing.d.ts +43 -42
  13. package/components/hy-badge/hy-badge.vue +66 -138
  14. package/components/hy-badge/props.ts +73 -17
  15. package/components/hy-badge/typing.d.ts +59 -58
  16. package/components/hy-button/hy-button.vue +226 -375
  17. package/components/hy-button/props.ts +129 -158
  18. package/components/hy-calendar/header.vue +48 -64
  19. package/components/hy-calendar/hy-calendar.vue +274 -438
  20. package/components/hy-calendar/month.vue +508 -516
  21. package/components/hy-calendar/props.ts +157 -35
  22. package/components/hy-calendar/typing.d.ts +129 -128
  23. package/components/hy-card/hy-card.vue +118 -240
  24. package/components/hy-card/index.scss +1 -2
  25. package/components/hy-card/props.ts +122 -27
  26. package/components/hy-card/typing.d.ts +119 -118
  27. package/components/hy-cell/hy-cell.vue +176 -258
  28. package/components/hy-cell/props.ts +71 -17
  29. package/components/hy-cell/typing.d.ts +87 -86
  30. package/components/hy-check-button/hy-check-button.vue +69 -139
  31. package/components/hy-check-button/props.ts +72 -18
  32. package/components/hy-check-button/typing.d.ts +74 -73
  33. package/components/hy-checkbox/hy-checkbox.vue +170 -263
  34. package/components/hy-checkbox/props.ts +94 -24
  35. package/components/hy-checkbox/typing.d.ts +72 -72
  36. package/components/hy-checkbox-group/hy-checkbox-group.vue +25 -100
  37. package/components/hy-checkbox-group/props.ts +80 -0
  38. package/components/hy-checkbox-group/typing.d.ts +65 -65
  39. package/components/hy-checkbox-item/hy-checkbox-item.vue +140 -177
  40. package/components/hy-checkbox-item/props.ts +24 -0
  41. package/components/hy-checkbox-item/typing.d.ts +4 -3
  42. package/components/hy-code-input/hy-code-input.vue +179 -262
  43. package/components/hy-code-input/props.ts +84 -18
  44. package/components/hy-code-input/typing.d.ts +71 -71
  45. package/components/hy-config-provider/hy-config-provider.vue +28 -50
  46. package/components/hy-config-provider/props.ts +26 -11
  47. package/components/hy-config-provider/typing.d.ts +20 -20
  48. package/components/hy-count-down/hy-count-down.vue +103 -131
  49. package/components/hy-count-down/props.ts +30 -8
  50. package/components/hy-count-down/typing.d.ts +25 -25
  51. package/components/hy-count-to/hy-count-to.vue +148 -213
  52. package/components/hy-count-to/props.ts +60 -15
  53. package/components/hy-count-to/typing.d.ts +46 -46
  54. package/components/hy-coupon/README.md +133 -0
  55. package/components/hy-coupon/hy-coupon.vue +180 -0
  56. package/components/hy-coupon/index.scss +553 -0
  57. package/components/hy-coupon/props.ts +129 -0
  58. package/components/hy-coupon/typing.d.ts +146 -0
  59. package/components/hy-datetime-picker/hy-datetime-picker.vue +415 -580
  60. package/components/hy-datetime-picker/props.ts +142 -32
  61. package/components/hy-datetime-picker/typing.d.ts +132 -132
  62. package/components/hy-divider/hy-divider.vue +90 -169
  63. package/components/hy-divider/props.ts +78 -19
  64. package/components/hy-divider/typing.d.ts +60 -60
  65. package/components/hy-dropdown/hy-dropdown.vue +37 -71
  66. package/components/hy-dropdown/props.ts +38 -15
  67. package/components/hy-dropdown/typing.d.ts +44 -44
  68. package/components/hy-dropdown-item/hy-dropdown-item.vue +141 -173
  69. package/components/hy-dropdown-item/props.ts +19 -8
  70. package/components/hy-empty/hy-empty.vue +75 -129
  71. package/components/hy-empty/props.ts +57 -15
  72. package/components/hy-empty/typing.d.ts +84 -84
  73. package/components/hy-flex/hy-flex.vue +33 -88
  74. package/components/hy-flex/props.ts +58 -0
  75. package/components/hy-flex/typing.d.ts +14 -16
  76. package/components/hy-float-button/hy-float-button.vue +289 -406
  77. package/components/hy-float-button/props.ts +109 -25
  78. package/components/hy-folding-panel/hy-folding-panel.vue +86 -374
  79. package/components/hy-folding-panel/props.ts +40 -15
  80. package/components/hy-folding-panel/typing.d.ts +52 -63
  81. package/components/hy-folding-panel-item/hy-folding-panel-item.vue +186 -228
  82. package/components/hy-folding-panel-item/index.scss +87 -0
  83. package/components/hy-folding-panel-item/props.ts +81 -0
  84. package/components/hy-folding-panel-item/typing.d.ts +23 -0
  85. package/components/hy-form/hy-form.vue +172 -212
  86. package/components/hy-form/props.ts +37 -0
  87. package/components/hy-form/typing.d.ts +68 -61
  88. package/components/hy-form-group/typing.d.ts +74 -74
  89. package/components/hy-form-item/hy-form-item.vue +100 -129
  90. package/components/hy-form-item/props.ts +25 -0
  91. package/components/hy-form-item/typing.d.ts +40 -37
  92. package/components/hy-grid/hy-grid.vue +76 -132
  93. package/components/hy-grid/props.ts +58 -16
  94. package/components/hy-grid/typing.d.ts +66 -66
  95. package/components/hy-icon/hy-icon.vue +84 -161
  96. package/components/hy-icon/props.ts +76 -22
  97. package/components/hy-icon/typing.d.ts +83 -82
  98. package/components/hy-image/hy-image.vue +142 -272
  99. package/components/hy-image/props.ts +105 -23
  100. package/components/hy-image/typing.d.ts +84 -87
  101. package/components/hy-input/hy-input.vue +230 -421
  102. package/components/hy-input/props.ts +183 -35
  103. package/components/hy-input/typing.d.ts +169 -169
  104. package/components/hy-line/hy-line.vue +34 -72
  105. package/components/hy-line/props.ts +41 -10
  106. package/components/hy-line/typing.d.ts +29 -29
  107. package/components/hy-line-progress/hy-line-progress.vue +66 -101
  108. package/components/hy-line-progress/props.ts +31 -10
  109. package/components/hy-line-progress/typing.d.ts +29 -29
  110. package/components/hy-list/hy-list.vue +151 -220
  111. package/components/hy-list/props.ts +67 -16
  112. package/components/hy-list/typing.d.ts +52 -52
  113. package/components/hy-loading/hy-loading.vue +63 -119
  114. package/components/hy-loading/props.ts +63 -15
  115. package/components/hy-loading/typing.d.ts +49 -49
  116. package/components/hy-menu/hy-menu.vue +124 -166
  117. package/components/hy-menu/props.ts +42 -10
  118. package/components/hy-menu/typing.d.ts +60 -60
  119. package/components/hy-modal/hy-modal.vue +127 -218
  120. package/components/hy-modal/props.ts +89 -24
  121. package/components/hy-navbar/hy-navbar.vue +104 -177
  122. package/components/hy-navbar/props.ts +76 -22
  123. package/components/hy-navbar/typing.d.ts +81 -81
  124. package/components/hy-notice-bar/hy-notice-bar.vue +67 -144
  125. package/components/hy-notice-bar/props.ts +80 -19
  126. package/components/hy-notice-bar/typing.d.ts +62 -62
  127. package/components/hy-notify/hy-notify.vue +128 -177
  128. package/components/hy-notify/props.ts +49 -12
  129. package/components/hy-notify/typing.d.ts +45 -41
  130. package/components/hy-number-step/hy-number-step.vue +281 -394
  131. package/components/hy-number-step/props.ts +110 -27
  132. package/components/hy-number-step/typing.d.ts +120 -120
  133. package/components/hy-overlay/hy-overlay.vue +39 -66
  134. package/components/hy-overlay/props.ts +31 -8
  135. package/components/hy-pagination/hy-pagination.vue +100 -155
  136. package/components/hy-pagination/props.ts +53 -13
  137. package/components/hy-picker/hy-picker.vue +309 -430
  138. package/components/hy-picker/index.scss +8 -12
  139. package/components/hy-picker/props.ts +110 -26
  140. package/components/hy-popover/hy-popover.vue +190 -252
  141. package/components/hy-popover/props.ts +48 -10
  142. package/components/hy-popup/hy-popup.vue +162 -248
  143. package/components/hy-popup/props.ts +82 -18
  144. package/components/hy-price/hy-price.vue +45 -104
  145. package/components/hy-price/props.ts +52 -12
  146. package/components/hy-price/typing.d.ts +41 -36
  147. package/components/hy-qrcode/hy-qrcode.vue +115 -185
  148. package/components/hy-qrcode/props.ts +68 -18
  149. package/components/hy-qrcode/typing.d.ts +67 -66
  150. package/components/hy-radio/hy-radio.vue +161 -259
  151. package/components/hy-radio/props.ts +95 -25
  152. package/components/hy-radio/typing.d.ts +85 -84
  153. package/components/hy-rate/hy-rate.vue +185 -270
  154. package/components/hy-rate/props.ts +76 -18
  155. package/components/hy-rate/typing.d.ts +61 -60
  156. package/components/hy-read-more/hy-read-more.vue +93 -136
  157. package/components/hy-read-more/props.ts +43 -13
  158. package/components/hy-scroll-list/hy-scroll-list.vue +81 -102
  159. package/components/hy-scroll-list/props.ts +22 -11
  160. package/components/hy-search/hy-search.vue +155 -284
  161. package/components/hy-search/props.ts +130 -25
  162. package/components/hy-signature/hy-signature.vue +491 -635
  163. package/components/hy-signature/props.ts +115 -26
  164. package/components/hy-signature/typing.d.ts +138 -138
  165. package/components/hy-slider/hy-slider.vue +388 -477
  166. package/components/hy-slider/props.ts +75 -19
  167. package/components/hy-steps/hy-steps.vue +212 -279
  168. package/components/hy-steps/props.ts +47 -13
  169. package/components/hy-submit-bar/hy-submit-bar.vue +137 -222
  170. package/components/hy-submit-bar/props.ts +89 -20
  171. package/components/hy-submit-bar/typing.d.ts +86 -85
  172. package/components/hy-subsection/hy-subsection.vue +132 -185
  173. package/components/hy-subsection/props.ts +50 -17
  174. package/components/hy-subsection/typing.d.ts +52 -52
  175. package/components/hy-swipe-action/hy-swipe-action.vue +228 -283
  176. package/components/hy-swipe-action/props.ts +43 -18
  177. package/components/hy-swipe-action/typing.d.ts +46 -46
  178. package/components/hy-swiper/hy-swiper.vue +159 -286
  179. package/components/hy-swiper/props.ts +126 -28
  180. package/components/hy-swiper/typing.d.ts +115 -115
  181. package/components/hy-switch/hy-switch.vue +112 -176
  182. package/components/hy-switch/props.ts +60 -15
  183. package/components/hy-switch/typing.d.ts +63 -63
  184. package/components/hy-tabBar/hy-tabBar.vue +64 -60
  185. package/components/hy-tabs/hy-tabs.vue +277 -380
  186. package/components/hy-tabs/props.ts +75 -18
  187. package/components/hy-tag/hy-tag.vue +111 -204
  188. package/components/hy-tag/props.ts +81 -19
  189. package/components/hy-text/hy-text.vue +200 -322
  190. package/components/hy-text/props.ts +107 -28
  191. package/components/hy-textarea/hy-textarea.vue +147 -256
  192. package/components/hy-textarea/props.ts +112 -25
  193. package/components/hy-textarea/typing.d.ts +42 -42
  194. package/components/hy-toast/hy-toast.vue +135 -143
  195. package/components/hy-tooltip/hy-tooltip.vue +220 -306
  196. package/components/hy-tooltip/props.ts +79 -15
  197. package/components/hy-transition/hy-transition.vue +111 -138
  198. package/components/hy-transition/props.ts +30 -8
  199. package/components/hy-upload/hy-upload.vue +320 -469
  200. package/components/hy-upload/props.ts +130 -27
  201. package/components/hy-warn/hy-warn.vue +80 -129
  202. package/components/hy-warn/props.ts +47 -12
  203. package/components/hy-waterfall/hy-waterfall.vue +139 -163
  204. package/components/hy-waterfall/props.ts +19 -7
  205. package/components/hy-watermark/hy-watermark.vue +762 -870
  206. package/components/hy-watermark/props.ts +103 -22
  207. package/global.d.ts +2 -0
  208. package/libs/css/theme.scss +3 -3
  209. package/package.json +2 -2
  210. package/web-types.json +1 -1
  211. package/components/hy-folding-panel/index.scss +0 -9
@@ -1,26 +1,113 @@
1
- import type IProps from "./typing";
2
- const defaultProps: IProps = {
3
- modelValue: "",
4
- placeholder: "",
5
- placeholderClass: "textarea-placeholder",
6
- height: 70,
7
- confirmType: "done",
8
- disabled: false,
9
- count: false,
10
- focus: false,
11
- autoHeight: false,
12
- fixed: false,
13
- cursorSpacing: 0,
14
- cursor: "",
15
- showConfirmBar: true,
16
- selectionStart: -1,
17
- selectionEnd: -1,
18
- adjustPosition: true,
19
- disableDefaultPadding: false,
20
- holdKeyboard: false,
21
- maxlength: 140,
22
- border: "surround",
23
- formatter: null,
24
- };
1
+ import type { CSSProperties, PropType } from 'vue'
25
2
 
26
- export default defaultProps;
3
+ const textareaProps = {
4
+ /** 输入框的内容 */
5
+ modelValue: {
6
+ type: String,
7
+ default: ''
8
+ },
9
+ /** 输入框为空时占位符 */
10
+ placeholder: String,
11
+ /** 指定placeholder的样式类,注意页面或组件的style中写了scoped时,需要在类名前写/deep/ */
12
+ placeholderClass: {
13
+ type: String,
14
+ default: 'textarea-placeholder'
15
+ },
16
+ /** 指定placeholder的样式,对象形式 */
17
+ placeholderStyle: Object as PropType<CSSProperties>,
18
+ /** 输入框高度 */
19
+ height: {
20
+ type: [String, Number],
21
+ default: 70
22
+ },
23
+ /** 设置键盘右下角按钮的文字,仅微信小程序,App-vue和H5有效 */
24
+ confirmType: {
25
+ type: String,
26
+ default: 'done'
27
+ },
28
+ /** 是否禁用 */
29
+ disabled: {
30
+ type: Boolean,
31
+ default: false
32
+ },
33
+ /** 是否显示统计字数 */
34
+ count: {
35
+ type: Boolean,
36
+ default: false
37
+ },
38
+ /** 是否自动获取焦点,nvue不支持,H5取决于浏览器的实现 */
39
+ focus: {
40
+ type: Boolean,
41
+ default: false
42
+ },
43
+ /** 是否自动增加高度 */
44
+ autoHeight: {
45
+ type: Boolean,
46
+ default: false
47
+ },
48
+ /** 如果textarea是在一个position:fixed的区域,需要显示指定属性fixed为true */
49
+ fixed: {
50
+ type: Boolean,
51
+ default: false
52
+ },
53
+ /** 指定光标与键盘的距离 */
54
+ cursorSpacing: {
55
+ type: Number,
56
+ default: 0
57
+ },
58
+ /** 指定focus时的光标位置 */
59
+ cursor: [String, Number],
60
+ /** 是否显示键盘上方带有”完成“按钮那一栏 */
61
+ showConfirmBar: {
62
+ type: Boolean,
63
+ default: true
64
+ },
65
+ /** 光标起始位置,自动聚焦时有效,需与selection-end搭配使用, */
66
+ selectionStart: {
67
+ type: Number,
68
+ default: -1
69
+ },
70
+ /** 光标结束位置,自动聚焦时有效,需与selection-start搭配使用 */
71
+ selectionEnd: {
72
+ type: Number,
73
+ default: -1
74
+ },
75
+ /** 键盘弹起时,是否自动上推页面 */
76
+ adjustPosition: {
77
+ type: Boolean,
78
+ default: true
79
+ },
80
+ /** 是否去掉 iOS 下的默认内边距,只微信小程序有效 */
81
+ disableDefaultPadding: {
82
+ type: Boolean,
83
+ default: false
84
+ },
85
+ /** focus时,点击页面的时候不收起键盘,只微信小程序有效 */
86
+ holdKeyboard: {
87
+ type: Boolean,
88
+ default: false
89
+ },
90
+ /** 最大输入长度,设置为 -1 的时候不限制最大长度 */
91
+ maxlength: {
92
+ type: Number,
93
+ default: 140
94
+ },
95
+ /**
96
+ * 边框类型
97
+ * @values surround,none,bottom
98
+ * */
99
+ border: {
100
+ type: String,
101
+ default: 'surround'
102
+ },
103
+ /** 内容式化函数 */
104
+ formatter: Function,
105
+ /** 定义需要用到的外部样式 */
106
+ customStyle: {
107
+ type: Object as PropType<CSSProperties>
108
+ },
109
+ /** 自定义外部类名 */
110
+ customClass: String
111
+ }
112
+
113
+ export default textareaProps
@@ -1,49 +1,49 @@
1
- import type { CSSProperties } from "vue";
1
+ import type { CSSProperties } from 'vue'
2
2
  import type {
3
- InputOnBlurEvent,
4
- InputOnConfirmEvent,
5
- InputOnFocusEvent,
6
- } from "@uni-helper/uni-types";
3
+ InputOnBlurEvent,
4
+ InputOnConfirmEvent,
5
+ InputOnFocusEvent
6
+ } from '@uni-helper/uni-types'
7
7
 
8
8
  export default interface HyTextareaProps {
9
- modelValue: string;
10
- placeholder?: string | null;
11
- placeholderClass?: string;
12
- placeholderStyle?: CSSProperties;
13
- height?: number;
14
- confirmType?: "done" | "send" | "search" | "next" | "go";
15
- disabled?: boolean;
16
- count?: boolean;
17
- focus?: boolean;
18
- autoHeight?: boolean;
19
- fixed?: boolean;
20
- cursorSpacing?: number;
21
- cursor?: string;
22
- showConfirmBar?: boolean;
23
- selectionStart?: number;
24
- selectionEnd?: number;
25
- adjustPosition?: boolean;
26
- disableDefaultPadding?: boolean;
27
- holdKeyboard?: boolean;
28
- maxlength?: number;
29
- border?: HyApp.BorderType;
30
- formatter?: ((value: string) => string) | null;
31
- customStyle?: CSSProperties;
9
+ modelValue: string
10
+ placeholder?: string | null
11
+ placeholderClass?: string
12
+ placeholderStyle?: CSSProperties
13
+ height?: number
14
+ confirmType?: 'done' | 'send' | 'search' | 'next' | 'go'
15
+ disabled?: boolean
16
+ count?: boolean
17
+ focus?: boolean
18
+ autoHeight?: boolean
19
+ fixed?: boolean
20
+ cursorSpacing?: number
21
+ cursor?: string
22
+ showConfirmBar?: boolean
23
+ selectionStart?: number
24
+ selectionEnd?: number
25
+ adjustPosition?: boolean
26
+ disableDefaultPadding?: boolean
27
+ holdKeyboard?: boolean
28
+ maxlength?: number
29
+ border?: HyApp.BorderType
30
+ formatter?: ((value: string) => string) | null
31
+ customStyle?: CSSProperties
32
32
  }
33
33
 
34
34
  export interface ITextareaEmits {
35
- /** 输入框失去焦点时触发 */
36
- (e: "blur", event: InputOnBlurEvent): void;
37
- /** 输入框聚焦时触发 */
38
- (e: "focus", event: InputOnFocusEvent): void;
39
- /** 当键盘输入时,触发 input 事件 */
40
- (e: "change", value: string): void;
41
- /** 点击完成时, 触发 confirm 事件 */
42
- (e: "confirm", event: InputOnConfirmEvent): void;
43
- /** 输入框行数变化时调用 */
44
- (e: "lineChange", event: any): void;
45
- /** 当键盘输入时,触发 input 事件 */
46
- (e: "update:modelValue", value: string): void;
47
- /** 键盘高度发生变化的时候触发此事件 */
48
- (e: "keyboardheightchange", event: InputOnKeyboardheightchangeEvent): void;
35
+ /** 输入框失去焦点时触发 */
36
+ (e: 'blur', event: InputOnBlurEvent): void
37
+ /** 输入框聚焦时触发 */
38
+ (e: 'focus', event: InputOnFocusEvent): void
39
+ /** 当键盘输入时,触发 input 事件 */
40
+ (e: 'change', value: string): void
41
+ /** 点击完成时, 触发 confirm 事件 */
42
+ (e: 'confirm', event: InputOnConfirmEvent): void
43
+ /** 输入框行数变化时调用 */
44
+ (e: 'lineChange', event: any): void
45
+ /** 当键盘输入时,触发 input 事件 */
46
+ (e: 'update:modelValue', value: string): void
47
+ /** 键盘高度发生变化的时候触发此事件 */
48
+ (e: 'keyboardheightchange', event: InputOnKeyboardheightchangeEvent): void
49
49
  }
@@ -1,198 +1,190 @@
1
1
  <template>
2
- <HyOverlay
3
- :show="isShow"
4
- :zIndex="tmpConfig.overlay ? 10070 : -1"
5
- :custom-style="overlayStyle"
6
- >
7
- <view :style="[contentStyle]" :class="contentClass">
8
- <HyLoading
9
- v-if="tmpConfig.loading"
10
- :mode="tmpConfig.loadMode || 'circle'"
11
- :color="loadingIconColor"
12
- inactiveColor="#F0E6EF"
13
- size="25"
14
- :customStyle="{ marginBottom: '20px' }"
15
- ></HyLoading>
16
- <view
17
- v-else-if="iconNameCom"
18
- :class="[
19
- 'hy-toast__content--icon',
20
- `hy-toast__content--icon__${tmpConfig.type}`,
21
- ]"
22
- >
23
- <HyIcon :name="iconNameCom" size="17" color="#FFFFFF"></HyIcon>
24
- </view>
25
- <text
26
- :class="[
27
- 'hy-toast__content--text',
28
- !tmpConfig.icon ? `hy-toast__content--text__${tmpConfig.type}` : '',
29
- ]"
30
- >
31
- {{ tmpConfig.message }}
32
- </text>
33
- </view>
34
- </HyOverlay>
2
+ <HyOverlay :show="isShow" :zIndex="tmpConfig.overlay ? 10070 : -1" :custom-style="overlayStyle">
3
+ <view :style="[contentStyle]" :class="contentClass">
4
+ <hy-loading
5
+ v-if="tmpConfig.loading"
6
+ :mode="tmpConfig.loadMode || 'circle'"
7
+ :color="loadingIconColor"
8
+ inactiveColor="#F0E6EF"
9
+ size="25"
10
+ :customStyle="{ marginBottom: '20px' }"
11
+ ></hy-loading>
12
+ <view
13
+ v-else-if="iconNameCom"
14
+ :class="['hy-toast__content--icon', `hy-toast__content--icon__${tmpConfig.type}`]"
15
+ >
16
+ <hy-icon :name="iconNameCom" size="17" color="#FFFFFF"></hy-icon>
17
+ </view>
18
+ <text
19
+ :class="[
20
+ 'hy-toast__content--text',
21
+ !tmpConfig.icon ? `hy-toast__content--text__${tmpConfig.type}` : ''
22
+ ]"
23
+ >
24
+ {{ tmpConfig.message }}
25
+ </text>
26
+ </view>
27
+ </HyOverlay>
35
28
  </template>
36
29
 
37
30
  <script lang="ts">
38
31
  export default {
39
- name: "hy-toast",
40
- options: {
41
- addGlobalClass: true,
42
- virtualHost: true,
43
- styleIsolation: "shared",
44
- },
45
- };
32
+ name: 'hy-toast',
33
+ options: {
34
+ addGlobalClass: true,
35
+ virtualHost: true,
36
+ styleIsolation: 'shared'
37
+ }
38
+ }
46
39
  </script>
47
40
 
48
41
  <script setup lang="ts">
49
- import { computed, onMounted, onUnmounted, reactive, ref } from "vue";
50
- import type { CSSProperties } from "vue";
51
- import type ToastOptions from "./typing";
52
- import { ColorConfig, iconName, getWindowInfo, hexToRgb } from "../../libs";
42
+ import { computed, onMounted, onUnmounted, reactive, ref } from 'vue'
43
+ import type { CSSProperties } from 'vue'
44
+ import type ToastOptions from './typing'
45
+ import { ColorConfig, iconName, getWindowInfo, hexToRgb } from '../../libs'
53
46
  // 组件
54
- import HyOverlay from "../hy-overlay/hy-overlay.vue";
55
- import HyIcon from "../hy-icon/hy-icon.vue";
56
- import HyLoading from "../hy-loading/hy-loading.vue";
47
+ import HyOverlay from '../hy-overlay/hy-overlay.vue'
48
+ import HyIcon from '../hy-icon/hy-icon.vue'
49
+ import HyLoading from '../hy-loading/hy-loading.vue'
57
50
 
58
51
  /**
59
52
  * Toast 组件主要用于消息通知、加载提示、操作结果提示等醒目提示效果,我们为其提供了多种丰富的API。
60
53
  * @displayName hy-toast
61
54
  */
62
- defineOptions({});
55
+ defineOptions({})
63
56
 
64
- const isShow = ref(false);
65
- const tmpConfig = ref<ToastOptions>({});
57
+ const isShow = ref(false)
58
+ const tmpConfig = ref<ToastOptions>({})
66
59
  const config: ToastOptions = reactive({
67
- message: "",
68
- type: "",
69
- duration: 2000,
70
- icon: false,
71
- position: "center",
72
- complete: null,
73
- overlay: true,
74
- loading: false,
75
- });
76
- let timer: any = null;
60
+ message: '',
61
+ type: '',
62
+ duration: 2000,
63
+ icon: false,
64
+ position: 'center',
65
+ complete: null,
66
+ overlay: true,
67
+ loading: false
68
+ })
69
+ let timer: any = null
77
70
 
78
71
  const isThemeType = (type: string): boolean =>
79
- ["error", "warning", "success", "primary", "info"].includes(type);
72
+ ['error', 'warning', 'success', 'primary', 'info'].includes(type)
80
73
 
81
74
  const overlayStyle = computed(() => {
82
- const style: CSSProperties = {
83
- justifyContent: "center",
84
- alignItems: "center",
85
- display: "flex",
86
- };
87
- // 将遮罩设置为100%透明度,避免出现灰色背景
88
- style.backgroundColor = "rgba(0, 0, 0, 0)";
89
- return style;
90
- });
75
+ const style: CSSProperties = {
76
+ justifyContent: 'center',
77
+ alignItems: 'center',
78
+ display: 'flex'
79
+ }
80
+ // 将遮罩设置为100%透明度,避免出现灰色背景
81
+ style.backgroundColor = 'rgba(0, 0, 0, 0)'
82
+ return style
83
+ })
91
84
 
92
85
  const iconNameCom = computed(() => {
93
- // 只有不为none,并且type为error|warning|succes|info时候,才显示图标
94
- if (!tmpConfig.value.icon || !tmpConfig.value.type) {
95
- return "";
96
- }
97
- if (tmpConfig.value.icon === true) {
98
- if (isThemeType(tmpConfig.value.type)) {
99
- return iconName(tmpConfig.value.type);
86
+ // 只有不为none,并且type为error|warning|succes|info时候,才显示图标
87
+ if (!tmpConfig.value.icon || !tmpConfig.value.type) {
88
+ return ''
89
+ }
90
+ if (tmpConfig.value.icon === true) {
91
+ if (isThemeType(tmpConfig.value.type)) {
92
+ return iconName(tmpConfig.value.type)
93
+ } else {
94
+ return ''
95
+ }
100
96
  } else {
101
- return "";
97
+ return tmpConfig.value.icon
102
98
  }
103
- } else {
104
- return tmpConfig.value.icon;
105
- }
106
- });
99
+ })
107
100
 
108
101
  /**
109
102
  * @description 内容盒子的样式
110
103
  * */
111
104
  const contentStyle = computed(() => {
112
- const windowHeight = getWindowInfo().windowHeight,
113
- style: CSSProperties = {};
114
- let value = 0;
115
- // 根据top和bottom,对Y轴进行窗体高度的百分比偏移
116
- if (tmpConfig.value.position === "top") {
117
- value = -windowHeight * 0.25;
118
- } else if (tmpConfig.value.position === "bottom") {
119
- value = windowHeight * 0.25;
120
- }
121
- style.transform = `translateY(${value}px)`;
122
- return style;
123
- });
105
+ const windowHeight = getWindowInfo().windowHeight,
106
+ style: CSSProperties = {}
107
+ let value = 0
108
+ // 根据top和bottom,对Y轴进行窗体高度的百分比偏移
109
+ if (tmpConfig.value.position === 'top') {
110
+ value = -windowHeight * 0.25
111
+ } else if (tmpConfig.value.position === 'bottom') {
112
+ value = windowHeight * 0.25
113
+ }
114
+ style.transform = `translateY(${value}px)`
115
+ return style
116
+ })
124
117
 
125
118
  const contentClass = computed(() => {
126
- return [
127
- "hy-toast__content",
128
- "hy-toast__" + tmpConfig.value.type,
129
- tmpConfig.value.loading && "hy-toast__content--loading",
130
- ];
131
- });
119
+ return [
120
+ 'hy-toast__content',
121
+ 'hy-toast__' + tmpConfig.value.type,
122
+ tmpConfig.value.loading && 'hy-toast__content--loading'
123
+ ]
124
+ })
132
125
 
133
126
  const loadingIconColor = computed(() => {
134
- let colorTmp = "rgb(255, 255, 255)";
135
- if (isThemeType(tmpConfig.value.type!)) {
136
- // loading-icon组件内部会对color参数进行一个透明度处理,该方法要求传入的颜色值
137
- // 必须为rgb格式的,所以这里做一个处理
138
- colorTmp = hexToRgb(ColorConfig[tmpConfig.value.type!]) as string;
139
- }
140
- return colorTmp;
141
- });
127
+ let colorTmp = 'rgb(255, 255, 255)'
128
+ if (isThemeType(tmpConfig.value.type!)) {
129
+ // loading-icon组件内部会对color参数进行一个透明度处理,该方法要求传入的颜色值
130
+ // 必须为rgb格式的,所以这里做一个处理
131
+ colorTmp = hexToRgb(ColorConfig[tmpConfig.value.type!]) as string
132
+ }
133
+ return colorTmp
134
+ })
142
135
 
143
136
  onMounted(() => {
144
- // 监听全局事件
145
- uni.$on("__hy_toast_open__", show);
146
- uni.$on("__hy_toast_close__", hide);
147
- });
137
+ // 监听全局事件
138
+ uni.$on('__hy_toast_open__', show)
139
+ uni.$on('__hy_toast_close__', hide)
140
+ })
148
141
 
149
142
  onUnmounted(() => {
150
- uni.$off("__hy_toast_open__", show);
151
- uni.$off("__hy_toast_close__", hide);
152
- });
143
+ uni.$off('__hy_toast_open__', show)
144
+ uni.$off('__hy_toast_close__', hide)
145
+ })
153
146
 
154
147
  /**
155
148
  * @description 显示toast组件,由父组件通过xxx.show(options)形式调用
156
149
  * */
157
150
  const show = (options: ToastOptions) => {
158
- // 不将结果合并到this.config变量,避免多次调用u-toast,前后的配置造成混乱
159
- tmpConfig.value = Object.assign(config, options);
160
- // 清除定时器
161
- clearTimer();
162
- isShow.value = true;
163
- // -1时不自动关闭
164
- if (tmpConfig.value.duration !== -1 && !tmpConfig.value.loading) {
165
- timer = setTimeout(() => {
166
- // 倒计时结束,清除定时器,隐藏toast组件
167
- clearTimer();
168
- // 判断是否存在callback方法,如果存在就执行
169
- typeof tmpConfig.value.complete === "function" &&
170
- tmpConfig.value.complete();
171
- }, tmpConfig.value.duration);
172
- }
173
- };
151
+ // 不将结果合并到this.config变量,避免多次调用u-toast,前后的配置造成混乱
152
+ tmpConfig.value = Object.assign(config, options)
153
+ // 清除定时器
154
+ clearTimer()
155
+ isShow.value = true
156
+ // -1时不自动关闭
157
+ if (tmpConfig.value.duration !== -1 && !tmpConfig.value.loading) {
158
+ timer = setTimeout(() => {
159
+ // 倒计时结束,清除定时器,隐藏toast组件
160
+ clearTimer()
161
+ // 判断是否存在callback方法,如果存在就执行
162
+ typeof tmpConfig.value.complete === 'function' && tmpConfig.value.complete()
163
+ }, tmpConfig.value.duration)
164
+ }
165
+ }
174
166
 
175
167
  // 隐藏toast组件,由父组件通过this.$refs.xxx.hide()形式调用
176
168
  const hide = () => {
177
- config.loading = false;
178
- clearTimer();
179
- };
169
+ config.loading = false
170
+ clearTimer()
171
+ }
180
172
  /**
181
173
  * @description 清除定时任务
182
174
  * */
183
175
  const clearTimer = () => {
184
- isShow.value = false;
185
- // 清除定时器
186
- clearTimeout(timer);
187
- timer = null;
188
- };
176
+ isShow.value = false
177
+ // 清除定时器
178
+ clearTimeout(timer)
179
+ timer = null
180
+ }
189
181
 
190
182
  defineExpose({
191
- show,
192
- hide,
193
- });
183
+ show,
184
+ hide
185
+ })
194
186
  </script>
195
187
 
196
188
  <style scoped lang="scss">
197
- @import "./index.scss";
189
+ @import './index.scss';
198
190
  </style>