hy-app 0.6.4 → 0.6.6

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 (106) hide show
  1. package/attributes.json +1 -1
  2. package/components/hy-address-picker/hy-address-picker.vue +249 -249
  3. package/components/hy-address-picker/props.ts +103 -103
  4. package/components/hy-button/hy-button.vue +320 -289
  5. package/components/hy-button/props.ts +143 -143
  6. package/components/hy-button/typing.d.ts +43 -35
  7. package/components/hy-calendar/header.vue +58 -58
  8. package/components/hy-calendar/hy-calendar.vue +8 -6
  9. package/components/hy-calendar/month.vue +402 -402
  10. package/components/hy-calendar/props.ts +169 -169
  11. package/components/hy-calendar/typing.d.ts +47 -45
  12. package/components/hy-cell-item/hy-cell-item.vue +161 -161
  13. package/components/hy-cell-item/props.ts +59 -59
  14. package/components/hy-check-button/hy-check-button.vue +135 -135
  15. package/components/hy-code-input/hy-code-input.vue +231 -231
  16. package/components/hy-code-input/props.ts +90 -90
  17. package/components/hy-config-provider/hy-config-provider.vue +53 -53
  18. package/components/hy-config-provider/props.ts +30 -30
  19. package/components/hy-coupon/hy-coupon.vue +183 -183
  20. package/components/hy-coupon/props.ts +108 -108
  21. package/components/hy-datetime-picker/hy-datetime-picker.vue +41 -55
  22. package/components/hy-datetime-picker/props.ts +144 -144
  23. package/components/hy-datetime-picker/typing.d.ts +2 -0
  24. package/components/hy-divider/props.ts +83 -83
  25. package/components/hy-empty/icon.ts +72 -72
  26. package/components/hy-folding-panel/hy-folding-panel-group.vue +162 -162
  27. package/components/hy-form/hy-form.vue +220 -220
  28. package/components/hy-icon/hy-icon.vue +112 -112
  29. package/components/hy-index-bar/hy-index-bar.vue +185 -185
  30. package/components/hy-index-bar/index.scss +64 -64
  31. package/components/hy-index-bar/props.ts +94 -94
  32. package/components/hy-index-bar/typing.d.ts +36 -36
  33. package/components/hy-input/hy-input.vue +333 -333
  34. package/components/hy-input/props.ts +186 -186
  35. package/components/hy-modal/hy-modal.vue +211 -211
  36. package/components/hy-modal/props.ts +94 -94
  37. package/components/hy-modal/typing.d.ts +16 -16
  38. package/components/hy-notice-bar/hy-row-notice.vue +121 -121
  39. package/components/hy-notify/hy-notify.vue +174 -174
  40. package/components/hy-number-step/hy-number-step.vue +367 -367
  41. package/components/hy-overlay/hy-overlay.vue +61 -61
  42. package/components/hy-overlay/props.ts +38 -38
  43. package/components/hy-pagination/hy-pagination.vue +136 -136
  44. package/components/hy-pagination/props.ts +58 -58
  45. package/components/hy-parse/hy-parse.vue +550 -550
  46. package/components/hy-parse/node/node.vue +781 -781
  47. package/components/hy-parse/parser.js +1455 -1455
  48. package/components/hy-parse/props.ts +19 -19
  49. package/components/hy-parse/typing.d.ts +68 -68
  50. package/components/hy-picker/hy-picker.vue +435 -435
  51. package/components/hy-picker/props.ts +122 -122
  52. package/components/hy-picker/typing.d.ts +38 -38
  53. package/components/hy-qrcode/props.ts +72 -72
  54. package/components/hy-qrcode/qrcode.js.bak +1433 -1433
  55. package/components/hy-radio/props.ts +97 -97
  56. package/components/hy-read-more/props.ts +48 -48
  57. package/components/hy-search/props.ts +133 -133
  58. package/components/hy-signature/canvasHelper.ts +51 -51
  59. package/components/hy-signature/props.ts +121 -121
  60. package/components/hy-skeleton/hy-skeleton.vue +142 -142
  61. package/components/hy-skeleton/props.ts +46 -46
  62. package/components/hy-skeleton/typing.d.ts +31 -31
  63. package/components/hy-steps/hy-steps.vue +275 -275
  64. package/components/hy-steps/typing.d.ts +25 -25
  65. package/components/hy-swiper/hy-swiper.vue +3 -3
  66. package/components/hy-swiper/index.scss +5 -5
  67. package/components/hy-swiper/props.ts +0 -1
  68. package/components/hy-table/hy-table.vue +630 -630
  69. package/components/hy-table/props.ts +62 -62
  70. package/components/hy-table/typing.d.ts +29 -29
  71. package/components/hy-tabs/hy-tabs.vue +336 -335
  72. package/components/hy-tabs/props.ts +84 -77
  73. package/components/hy-tag/hy-tag.vue +173 -173
  74. package/components/hy-tag/props.ts +89 -89
  75. package/components/hy-text/hy-text.vue +237 -237
  76. package/components/hy-text/props.ts +115 -115
  77. package/components/hy-textarea/hy-textarea.vue +198 -198
  78. package/components/hy-toast/hy-toast.vue +200 -200
  79. package/components/hy-toast/props.ts +3 -3
  80. package/components/hy-transition/hy-transition.vue +157 -157
  81. package/components/hy-transition/props.ts +32 -32
  82. package/components/hy-upload/hy-upload.vue +384 -384
  83. package/components/hy-watermark/hy-watermark.vue +1058 -1058
  84. package/components/hy-watermark/props.ts +109 -109
  85. package/global.d.ts +94 -94
  86. package/libs/api/http.ts +119 -119
  87. package/libs/composables/index.ts +8 -8
  88. package/libs/composables/useMessage.ts +149 -149
  89. package/libs/composables/useToast.ts +45 -45
  90. package/libs/composables/useTranslate.ts +10 -10
  91. package/libs/css/_config.scss +5 -5
  92. package/libs/index.ts +8 -8
  93. package/libs/locale/index.ts +32 -32
  94. package/libs/locale/lang/en-US.ts +84 -84
  95. package/libs/locale/lang/zh-CN.ts +87 -87
  96. package/libs/typing/index.ts +2 -2
  97. package/libs/typing/modules/common.d.ts +139 -139
  98. package/libs/typing/modules/form.ts +176 -176
  99. package/libs/typing/modules/http.d.ts +19 -19
  100. package/libs/typing/modules/index.d.ts +12 -12
  101. package/libs/utils/inside.ts +340 -340
  102. package/libs/utils/inspect.ts +140 -140
  103. package/libs/utils/utils.ts +525 -525
  104. package/package.json +81 -81
  105. package/tags.json +1 -1
  106. package/web-types.json +1 -1
@@ -1,121 +1,121 @@
1
- <template>
2
- <view class="hy-notice" @tap="clickHandler">
3
- <slot name="icon">
4
- <view class="hy-notice__left-icon" v-if="icon">
5
- <hy-icon :name="icon" :color="color" size="19"></hy-icon>
6
- </view>
7
- </slot>
8
- <view class="hy-notice__content" ref="hy-notice__content">
9
- <view
10
- ref="hy-notice__content--text"
11
- class="hy-notice__content--text"
12
- :style="animationStyle"
13
- >
14
- <text v-for="(item, index) in innerText" :key="index" :style="textStyle">{{
15
- item
16
- }}</text>
17
- </view>
18
- </view>
19
- <view class="hy-notice__right-icon" v-if="['link', 'closable'].includes(mode)">
20
- <hy-icon
21
- v-if="mode === 'link'"
22
- :name="IconConfig.RIGHT"
23
- :size="17"
24
- :color="color"
25
- ></hy-icon>
26
- <hy-icon
27
- v-if="mode === 'closable'"
28
- @click="close"
29
- :name="IconConfig.CLOSE"
30
- :size="16"
31
- :color="color"
32
- ></hy-icon>
33
- </view>
34
- </view>
35
- </template>
36
-
37
- <script setup lang="ts">
38
- import { ref, watch, toRefs, computed, type CSSProperties, getCurrentInstance } from 'vue'
39
- import noticeBarProps from './props'
40
- import { addUnit, getRect, sleep, IconConfig } from '../../libs'
41
- // 组件
42
- import HyIcon from '../hy-icon/hy-icon.vue'
43
-
44
- const props = defineProps(noticeBarProps)
45
- const { text, speed, fontSize, color } = toRefs(props)
46
- const emit = defineEmits(['click', 'close'])
47
-
48
- const instance = getCurrentInstance()
49
- const animationDuration = ref<string>('0') // 动画执行时间
50
- const animationPlayState = ref<string>('paused') // 动画的开始和结束执行
51
- const initValue = ref<string>('')
52
-
53
- watch(
54
- () => text.value,
55
- async (newValue) => {
56
- initValue.value = Array.isArray(newValue) ? newValue.join('') : newValue
57
- let boxWidth = 0,
58
- textWidth = 0
59
- // 进行一定的延时
60
- await sleep()
61
- // 查询盒子和文字的宽度
62
- textWidth = (await getRect('.hy-notice__content--text', false, instance)).width
63
- boxWidth = (await getRect('.hy-notice__content', false, instance)).width
64
- // 根据t=s/v(时间=路程/速度),这里为何不需要加上#u-notice-box的宽度,因为中设置了.u-notice-content样式中设置了padding-left: 100%
65
- // 恰巧计算出来的结果中已经包含了#u-notice-box的宽度
66
- animationDuration.value = `${textWidth / speed.value}s`
67
- // 这里必须这样开始动画,否则在APP上动画速度不会改变
68
- animationPlayState.value = 'paused'
69
- await sleep(10)
70
- animationPlayState.value = 'running'
71
- },
72
- { immediate: true }
73
- )
74
-
75
- /**
76
- * @description 文字内容的样式
77
- * */
78
- const textStyle = computed<CSSProperties>(() => {
79
- let style: CSSProperties = {}
80
- style.whiteSpace = 'nowrap !important'
81
- style.color = color.value
82
- style.fontSize = addUnit(fontSize.value)
83
- return style
84
- })
85
- /**
86
- * @description 动画的样式
87
- * */
88
- const animationStyle = computed<CSSProperties>(() => {
89
- let style: CSSProperties = {}
90
- style.animationDuration = animationDuration.value
91
- style.animationPlayState = animationPlayState.value
92
- return style
93
- })
94
- // 内部对用户传入的数据进一步分割,放到多个text标签循环,否则如果用户传入的字符串很长(100个字符以上)
95
- // 放在一个text标签中进行滚动,在低端安卓机上,动画可能会出现抖动现象,需要分割到多个text中可解决此问题
96
- const innerText = computed(() => {
97
- let result = [],
98
- // 每组text标签的字符长度
99
- len = 20
100
- const textArr = initValue.value.split('')
101
- for (let i = 0; i < textArr.length; i += len) {
102
- // 对拆分的后的text进行slice分割,得到的为数组再进行join拼接为字符串
103
- result.push(textArr.slice(i, i + len).join(''))
104
- }
105
- return result
106
- })
107
-
108
- // 点击通告栏
109
- const clickHandler = (index: number) => {
110
- emit('click', index)
111
- }
112
-
113
- // 点击关闭按钮
114
- const close = () => {
115
- emit('close')
116
- }
117
- </script>
118
-
119
- <style lang="scss" scoped>
120
- @import './index.scss';
121
- </style>
1
+ <template>
2
+ <view class="hy-notice" @tap="clickHandler">
3
+ <slot name="icon">
4
+ <view class="hy-notice__left-icon" v-if="icon">
5
+ <hy-icon :name="icon" :color="color" size="19"></hy-icon>
6
+ </view>
7
+ </slot>
8
+ <view class="hy-notice__content" ref="hy-notice__content">
9
+ <view
10
+ ref="hy-notice__content--text"
11
+ class="hy-notice__content--text"
12
+ :style="animationStyle"
13
+ >
14
+ <text v-for="(item, index) in innerText" :key="index" :style="textStyle">{{
15
+ item
16
+ }}</text>
17
+ </view>
18
+ </view>
19
+ <view class="hy-notice__right-icon" v-if="['link', 'closable'].includes(mode)">
20
+ <hy-icon
21
+ v-if="mode === 'link'"
22
+ :name="IconConfig.RIGHT"
23
+ :size="17"
24
+ :color="color"
25
+ ></hy-icon>
26
+ <hy-icon
27
+ v-if="mode === 'closable'"
28
+ @click="close"
29
+ :name="IconConfig.CLOSE"
30
+ :size="16"
31
+ :color="color"
32
+ ></hy-icon>
33
+ </view>
34
+ </view>
35
+ </template>
36
+
37
+ <script setup lang="ts">
38
+ import { ref, watch, toRefs, computed, type CSSProperties, getCurrentInstance } from 'vue'
39
+ import noticeBarProps from './props'
40
+ import { addUnit, getRect, sleep, IconConfig } from '../../libs'
41
+ // 组件
42
+ import HyIcon from '../hy-icon/hy-icon.vue'
43
+
44
+ const props = defineProps(noticeBarProps)
45
+ const { text, speed, fontSize, color } = toRefs(props)
46
+ const emit = defineEmits(['click', 'close'])
47
+
48
+ const instance = getCurrentInstance()
49
+ const animationDuration = ref<string>('0') // 动画执行时间
50
+ const animationPlayState = ref<string>('paused') // 动画的开始和结束执行
51
+ const initValue = ref<string>('')
52
+
53
+ watch(
54
+ () => text.value,
55
+ async (newValue) => {
56
+ initValue.value = Array.isArray(newValue) ? newValue.join('') : newValue
57
+ let boxWidth = 0,
58
+ textWidth = 0
59
+ // 进行一定的延时
60
+ await sleep()
61
+ // 查询盒子和文字的宽度
62
+ textWidth = (await getRect('.hy-notice__content--text', false, instance)).width
63
+ boxWidth = (await getRect('.hy-notice__content', false, instance)).width
64
+ // 根据t=s/v(时间=路程/速度),这里为何不需要加上#u-notice-box的宽度,因为中设置了.u-notice-content样式中设置了padding-left: 100%
65
+ // 恰巧计算出来的结果中已经包含了#u-notice-box的宽度
66
+ animationDuration.value = `${textWidth / speed.value}s`
67
+ // 这里必须这样开始动画,否则在APP上动画速度不会改变
68
+ animationPlayState.value = 'paused'
69
+ await sleep(10)
70
+ animationPlayState.value = 'running'
71
+ },
72
+ { immediate: true }
73
+ )
74
+
75
+ /**
76
+ * @description 文字内容的样式
77
+ * */
78
+ const textStyle = computed<CSSProperties>(() => {
79
+ let style: CSSProperties = {}
80
+ style.whiteSpace = 'nowrap !important'
81
+ style.color = color.value
82
+ style.fontSize = addUnit(fontSize.value)
83
+ return style
84
+ })
85
+ /**
86
+ * @description 动画的样式
87
+ * */
88
+ const animationStyle = computed<CSSProperties>(() => {
89
+ let style: CSSProperties = {}
90
+ style.animationDuration = animationDuration.value
91
+ style.animationPlayState = animationPlayState.value
92
+ return style
93
+ })
94
+ // 内部对用户传入的数据进一步分割,放到多个text标签循环,否则如果用户传入的字符串很长(100个字符以上)
95
+ // 放在一个text标签中进行滚动,在低端安卓机上,动画可能会出现抖动现象,需要分割到多个text中可解决此问题
96
+ const innerText = computed(() => {
97
+ let result = [],
98
+ // 每组text标签的字符长度
99
+ len = 20
100
+ const textArr = initValue.value.split('')
101
+ for (let i = 0; i < textArr.length; i += len) {
102
+ // 对拆分的后的text进行slice分割,得到的为数组再进行join拼接为字符串
103
+ result.push(textArr.slice(i, i + len).join(''))
104
+ }
105
+ return result
106
+ })
107
+
108
+ // 点击通告栏
109
+ const clickHandler = (index: number) => {
110
+ emit('click', index)
111
+ }
112
+
113
+ // 点击关闭按钮
114
+ const close = () => {
115
+ emit('close')
116
+ }
117
+ </script>
118
+
119
+ <style lang="scss" scoped>
120
+ @import './index.scss';
121
+ </style>
@@ -1,174 +1,174 @@
1
- <template>
2
- <hy-transition mode="slide-down" :customStyle="containerStyle" :show="open">
3
- <view
4
- :class="['hy-notify', `hy-notify--${tmpConfig?.type}`, customClass]"
5
- :style="[backgroundColor, customStyle]"
6
- >
7
- <hy-status-bar v-if="tmpConfig?.safeAreaInsetTop"></hy-status-bar>
8
- <view class="hy-notify__wrapper">
9
- <template v-if="['success', 'warning', 'error'].includes(tmpConfig.type)">
10
- <slot v-if="$slots.icon" name="icon"></slot>
11
- <hy-icon
12
- v-else
13
- :name="tmpConfig?.icon || icon"
14
- :color="tmpConfig?.color"
15
- :size="tmpConfig.fontSize"
16
- :customStyle="{ marginRight: '4px' }"
17
- ></hy-icon>
18
- </template>
19
- <text
20
- class="hy-notify__wrapper--text"
21
- :style="{
22
- fontSize: addUnit(tmpConfig?.fontSize),
23
- color: tmpConfig?.color
24
- }"
25
- >
26
- {{ tmpConfig?.message }}
27
- </text>
28
- </view>
29
- </view>
30
- </hy-transition>
31
- </template>
32
-
33
- <script lang="ts">
34
- export default {
35
- name: 'hy-notify',
36
- options: {
37
- addGlobalClass: true,
38
- virtualHost: true,
39
- styleIsolation: 'shared'
40
- }
41
- }
42
- </script>
43
-
44
- <script setup lang="ts">
45
- import type HyNotifyProps from './typing'
46
- import { computed, ref } from 'vue'
47
- import type { CSSProperties } from 'vue'
48
- import { addUnit, IconConfig } from '../../libs'
49
- import notifyProps from './props'
50
- // 组件
51
- import HyTransition from '../hy-transition/hy-transition.vue'
52
- import HyStatusBar from '../hy-status-bar/hy-status-bar.vue'
53
- import HyIcon from '../hy-icon/hy-icon.vue'
54
-
55
- /**
56
- * 一般用于页面顶部向下滑出一个提示,尔后自动收起的场景。
57
- * @displayName hy-notify
58
- */
59
- defineOptions({})
60
-
61
- const props = defineProps(notifyProps)
62
-
63
- const config = ref<HyNotifyProps>({
64
- // 到顶部的距离
65
- top: props.top,
66
- // type主题,primary,success,warning,error
67
- type: props.type,
68
- // 字体颜色
69
- color: props.color,
70
- // 背景颜色
71
- bgColor: props.bgColor,
72
- // 展示的文字内容
73
- message: props.message,
74
- // 展示时长,为0时不消失,单位ms
75
- duration: props.duration,
76
- // 字体大小
77
- fontSize: props.fontSize,
78
- // 是否留出顶部安全距离(状态栏高度)
79
- safeAreaInsetTop: props.safeAreaInsetTop
80
- })
81
- const tmpConfig = ref<HyNotifyProps>({})
82
- const open = ref(false)
83
- let timer: ReturnType<typeof setTimeout>
84
-
85
- /**
86
- * @description 容器样式
87
- * */
88
- const containerStyle = computed(() => {
89
- let top = 0
90
- if (tmpConfig.value.top === 0) {
91
- // #ifdef H5
92
- // H5端,导航栏为普通元素,需要将组件移动到导航栏的下边沿
93
- // H5的导航栏高度为44px
94
- top = 44
95
- // #endif
96
- }
97
- const style: CSSProperties = {
98
- top: addUnit(tmpConfig.value.top === 0 ? top : tmpConfig.value.top),
99
- // 因为组件底层为hy-transition组件,必须将其设置为fixed定位
100
- // 让其出现在导航栏底部
101
- position: 'fixed',
102
- left: 0,
103
- right: 0,
104
- zIndex: 888
105
- }
106
- return style
107
- })
108
- /**
109
- * @description 组件背景颜色
110
- */
111
- const backgroundColor = computed(() => {
112
- const style: CSSProperties = {}
113
- if (tmpConfig.value.bgColor) {
114
- style.backgroundColor = tmpConfig.value.bgColor
115
- }
116
- return style
117
- })
118
-
119
- /**
120
- * @description 默认主题下的图标
121
- * */
122
- const icon = computed(() => {
123
- switch (tmpConfig.value.type) {
124
- case 'success':
125
- return IconConfig.SUCCESS
126
- case 'error':
127
- return IconConfig.CLOSE_CIRCLE
128
- case 'warning':
129
- return IconConfig.NOTICE_CIRCLE
130
- default:
131
- return ''
132
- }
133
- })
134
-
135
- const show = (options: HyNotifyProps) => {
136
- // 不将结果合并到this.config变量,避免多次调用hy-toast,前后的配置造成混乱
137
- tmpConfig.value = Object.assign(config.value, options)
138
- // 任何定时器初始化之前,都要执行清除操作,否则可能会造成混乱
139
- clearTimer()
140
- open.value = true
141
- if (tmpConfig.value.duration && tmpConfig.value.duration! > 0) {
142
- timer = setTimeout(() => {
143
- open.value = false
144
- // 倒计时结束,清除定时器,隐藏toast组件
145
- clearTimer()
146
- // 判断是否存在callback方法,如果存在就执行
147
- typeof tmpConfig.value.complete === 'function' && tmpConfig.value.complete()
148
- }, tmpConfig.value.duration)
149
- }
150
- }
151
- /**
152
- * @description 关闭notify
153
- * */
154
- const close = () => {
155
- clearTimer()
156
- }
157
- /**
158
- * @description 清除定时任务
159
- * */
160
- const clearTimer = () => {
161
- open.value = false
162
- // 清除定时器
163
- clearTimeout(timer)
164
- }
165
-
166
- defineExpose({
167
- show,
168
- close
169
- })
170
- </script>
171
-
172
- <style scoped lang="scss">
173
- @import './index.scss';
174
- </style>
1
+ <template>
2
+ <hy-transition mode="slide-down" :customStyle="containerStyle" :show="open">
3
+ <view
4
+ :class="['hy-notify', `hy-notify--${tmpConfig?.type}`, customClass]"
5
+ :style="[backgroundColor, customStyle]"
6
+ >
7
+ <hy-status-bar v-if="tmpConfig?.safeAreaInsetTop"></hy-status-bar>
8
+ <view class="hy-notify__wrapper">
9
+ <template v-if="['success', 'warning', 'error'].includes(tmpConfig.type)">
10
+ <slot v-if="$slots.icon" name="icon"></slot>
11
+ <hy-icon
12
+ v-else
13
+ :name="tmpConfig?.icon || icon"
14
+ :color="tmpConfig?.color"
15
+ :size="tmpConfig.fontSize"
16
+ :customStyle="{ marginRight: '4px' }"
17
+ ></hy-icon>
18
+ </template>
19
+ <text
20
+ class="hy-notify__wrapper--text"
21
+ :style="{
22
+ fontSize: addUnit(tmpConfig?.fontSize),
23
+ color: tmpConfig?.color
24
+ }"
25
+ >
26
+ {{ tmpConfig?.message }}
27
+ </text>
28
+ </view>
29
+ </view>
30
+ </hy-transition>
31
+ </template>
32
+
33
+ <script lang="ts">
34
+ export default {
35
+ name: 'hy-notify',
36
+ options: {
37
+ addGlobalClass: true,
38
+ virtualHost: true,
39
+ styleIsolation: 'shared'
40
+ }
41
+ }
42
+ </script>
43
+
44
+ <script setup lang="ts">
45
+ import type HyNotifyProps from './typing'
46
+ import { computed, ref } from 'vue'
47
+ import type { CSSProperties } from 'vue'
48
+ import { addUnit, IconConfig } from '../../libs'
49
+ import notifyProps from './props'
50
+ // 组件
51
+ import HyTransition from '../hy-transition/hy-transition.vue'
52
+ import HyStatusBar from '../hy-status-bar/hy-status-bar.vue'
53
+ import HyIcon from '../hy-icon/hy-icon.vue'
54
+
55
+ /**
56
+ * 一般用于页面顶部向下滑出一个提示,尔后自动收起的场景。
57
+ * @displayName hy-notify
58
+ */
59
+ defineOptions({})
60
+
61
+ const props = defineProps(notifyProps)
62
+
63
+ const config = ref<HyNotifyProps>({
64
+ // 到顶部的距离
65
+ top: props.top,
66
+ // type主题,primary,success,warning,error
67
+ type: props.type,
68
+ // 字体颜色
69
+ color: props.color,
70
+ // 背景颜色
71
+ bgColor: props.bgColor,
72
+ // 展示的文字内容
73
+ message: props.message,
74
+ // 展示时长,为0时不消失,单位ms
75
+ duration: props.duration,
76
+ // 字体大小
77
+ fontSize: props.fontSize,
78
+ // 是否留出顶部安全距离(状态栏高度)
79
+ safeAreaInsetTop: props.safeAreaInsetTop
80
+ })
81
+ const tmpConfig = ref<HyNotifyProps>({})
82
+ const open = ref(false)
83
+ let timer: ReturnType<typeof setTimeout>
84
+
85
+ /**
86
+ * @description 容器样式
87
+ * */
88
+ const containerStyle = computed(() => {
89
+ let top = 0
90
+ if (tmpConfig.value.top === 0) {
91
+ // #ifdef H5
92
+ // H5端,导航栏为普通元素,需要将组件移动到导航栏的下边沿
93
+ // H5的导航栏高度为44px
94
+ top = 44
95
+ // #endif
96
+ }
97
+ const style: CSSProperties = {
98
+ top: addUnit(tmpConfig.value.top === 0 ? top : tmpConfig.value.top),
99
+ // 因为组件底层为hy-transition组件,必须将其设置为fixed定位
100
+ // 让其出现在导航栏底部
101
+ position: 'fixed',
102
+ left: 0,
103
+ right: 0,
104
+ zIndex: 888
105
+ }
106
+ return style
107
+ })
108
+ /**
109
+ * @description 组件背景颜色
110
+ */
111
+ const backgroundColor = computed(() => {
112
+ const style: CSSProperties = {}
113
+ if (tmpConfig.value.bgColor) {
114
+ style.backgroundColor = tmpConfig.value.bgColor
115
+ }
116
+ return style
117
+ })
118
+
119
+ /**
120
+ * @description 默认主题下的图标
121
+ * */
122
+ const icon = computed(() => {
123
+ switch (tmpConfig.value.type) {
124
+ case 'success':
125
+ return IconConfig.SUCCESS
126
+ case 'error':
127
+ return IconConfig.CLOSE_CIRCLE
128
+ case 'warning':
129
+ return IconConfig.NOTICE_CIRCLE
130
+ default:
131
+ return ''
132
+ }
133
+ })
134
+
135
+ const show = (options: HyNotifyProps) => {
136
+ // 不将结果合并到this.config变量,避免多次调用hy-toast,前后的配置造成混乱
137
+ tmpConfig.value = Object.assign(config.value, options)
138
+ // 任何定时器初始化之前,都要执行清除操作,否则可能会造成混乱
139
+ clearTimer()
140
+ open.value = true
141
+ if (tmpConfig.value.duration && tmpConfig.value.duration! > 0) {
142
+ timer = setTimeout(() => {
143
+ open.value = false
144
+ // 倒计时结束,清除定时器,隐藏toast组件
145
+ clearTimer()
146
+ // 判断是否存在callback方法,如果存在就执行
147
+ typeof tmpConfig.value.complete === 'function' && tmpConfig.value.complete()
148
+ }, tmpConfig.value.duration)
149
+ }
150
+ }
151
+ /**
152
+ * @description 关闭notify
153
+ * */
154
+ const close = () => {
155
+ clearTimer()
156
+ }
157
+ /**
158
+ * @description 清除定时任务
159
+ * */
160
+ const clearTimer = () => {
161
+ open.value = false
162
+ // 清除定时器
163
+ clearTimeout(timer)
164
+ }
165
+
166
+ defineExpose({
167
+ show,
168
+ close
169
+ })
170
+ </script>
171
+
172
+ <style scoped lang="scss">
173
+ @import './index.scss';
174
+ </style>