@puresnake/snake-ui 0.0.0-stage → 0.0.1

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 (279) hide show
  1. package/LICENSE +21 -0
  2. package/changelog.md +1 -0
  3. package/components/snake-activity-list/snake-activity-list.vue +365 -0
  4. package/components/snake-activity-list/types.ts +29 -0
  5. package/components/snake-auxiliary-segmentation/snake-auxiliary-segmentation.vue +44 -0
  6. package/components/snake-auxiliary-segmentation/types.ts +5 -0
  7. package/components/snake-button/snake-button.vue +357 -0
  8. package/components/snake-button/types.ts +103 -0
  9. package/components/snake-button-sort/snake-button-sort.vue +72 -0
  10. package/components/snake-button-sort/types.ts +22 -0
  11. package/components/snake-calendar/snake-calendar.vue +998 -0
  12. package/components/snake-calendar/types.ts +189 -0
  13. package/components/snake-cell-group/snake-cell-group.vue +55 -0
  14. package/components/snake-cell-group/types.ts +19 -0
  15. package/components/snake-cell-item/snake-cell-item.vue +159 -0
  16. package/components/snake-cell-item/types.ts +66 -0
  17. package/components/snake-checkbox/snake-checkbox.vue +264 -0
  18. package/components/snake-checkbox/types.ts +70 -0
  19. package/components/snake-checkbox-group/snake-checkbox-group.vue +154 -0
  20. package/components/snake-checkbox-group/types.ts +52 -0
  21. package/components/snake-cms/blocks/v2/cms-v2-carousel.vue +87 -0
  22. package/components/snake-cms/blocks/v2/cms-v2-coupon.vue +25 -0
  23. package/components/snake-cms/blocks/v2/cms-v2-custom.vue +12 -0
  24. package/components/snake-cms/blocks/v2/cms-v2-divider.vue +33 -0
  25. package/components/snake-cms/blocks/v2/cms-v2-floatbutton.vue +28 -0
  26. package/components/snake-cms/blocks/v2/cms-v2-goods-list.vue +150 -0
  27. package/components/snake-cms/blocks/v2/cms-v2-hotzone.vue +41 -0
  28. package/components/snake-cms/blocks/v2/cms-v2-images.vue +41 -0
  29. package/components/snake-cms/blocks/v2/cms-v2-magiccube.vue +93 -0
  30. package/components/snake-cms/blocks/v2/cms-v2-notice.vue +80 -0
  31. package/components/snake-cms/blocks/v2/cms-v2-popup.vue +46 -0
  32. package/components/snake-cms/blocks/v2/cms-v2-richtext.vue +18 -0
  33. package/components/snake-cms/blocks/v2/cms-v2-search.vue +115 -0
  34. package/components/snake-cms/blocks/v2/cms-v2-video.vue +25 -0
  35. package/components/snake-cms/blocks/v2/shared.ts +84 -0
  36. package/components/snake-cms/snake-cms.vue +409 -0
  37. package/components/snake-cms/types.ts +50 -0
  38. package/components/snake-commodity-search/snake-commodity-search.vue +234 -0
  39. package/components/snake-commodity-search/types.ts +11 -0
  40. package/components/snake-config-provider/snake-config-provider.vue +61 -0
  41. package/components/snake-config-provider/types.ts +22 -0
  42. package/components/snake-count-down/snake-count-down.vue +231 -0
  43. package/components/snake-count-down/types.ts +103 -0
  44. package/components/snake-coupon/snake-coupon.vue +209 -0
  45. package/components/snake-coupon/types.ts +21 -0
  46. package/components/snake-custom-module/snake-custom-module.vue +25 -0
  47. package/components/snake-custom-module/types.ts +11 -0
  48. package/components/snake-drop-menu/snake-drop-menu.vue +123 -0
  49. package/components/snake-drop-menu/types.ts +95 -0
  50. package/components/snake-drop-menu-item/snake-drop-menu-item.vue +181 -0
  51. package/components/snake-drop-menu-item/types.ts +48 -0
  52. package/components/snake-empty/snake-empty.vue +100 -0
  53. package/components/snake-empty/types.ts +48 -0
  54. package/components/snake-filter-sorts/filter-page.vue +695 -0
  55. package/components/snake-filter-sorts/snake-filter-sorts.vue +185 -0
  56. package/components/snake-filter-sorts/types.ts +57 -0
  57. package/components/snake-floating-bubble/snake-floating-bubble.vue +157 -0
  58. package/components/snake-floating-bubble/types.ts +43 -0
  59. package/components/snake-follow/snake-follow.vue +18 -0
  60. package/components/snake-follow/types.ts +2 -0
  61. package/components/snake-form/snake-form.vue +124 -0
  62. package/components/snake-form/types.ts +96 -0
  63. package/components/snake-form-item/snake-form-item.vue +331 -0
  64. package/components/snake-form-item/types.ts +70 -0
  65. package/components/snake-goods-list/snake-goods-list.vue +792 -0
  66. package/components/snake-goods-list/types.ts +55 -0
  67. package/components/snake-graphic-navigation/snake-graphic-navigation.vue +198 -0
  68. package/components/snake-graphic-navigation/types.ts +43 -0
  69. package/components/snake-icon/icon-names.ts +222 -0
  70. package/components/snake-icon/snake-icon.vue +220 -0
  71. package/components/snake-icon/types.ts +45 -0
  72. package/components/snake-image/snake-image.vue +230 -0
  73. package/components/snake-image/types.ts +70 -0
  74. package/components/snake-images/snake-images.vue +80 -0
  75. package/components/snake-images/types.ts +5 -0
  76. package/components/snake-index-anchor/snake-index-anchor.vue +83 -0
  77. package/components/snake-index-anchor/types.ts +14 -0
  78. package/components/snake-index-list/anchor-registry.ts +80 -0
  79. package/components/snake-index-list/snake-index-list.vue +259 -0
  80. package/components/snake-index-list/types.ts +115 -0
  81. package/components/snake-index-list-panel/snake-index-list-panel.vue +277 -0
  82. package/components/snake-index-list-panel/types.ts +10 -0
  83. package/components/snake-input/snake-input.vue +225 -0
  84. package/components/snake-input/types.ts +99 -0
  85. package/components/snake-jump-applet/snake-jump-applet.vue +99 -0
  86. package/components/snake-jump-applet/types.ts +17 -0
  87. package/components/snake-line/snake-line.vue +42 -0
  88. package/components/snake-line/types.ts +30 -0
  89. package/components/snake-line-progress/snake-line-progress.vue +105 -0
  90. package/components/snake-line-progress/types.ts +26 -0
  91. package/components/snake-link/snake-link.vue +74 -0
  92. package/components/snake-link/types.ts +30 -0
  93. package/components/snake-list-switching/components/tree-select/index.vue +156 -0
  94. package/components/snake-list-switching/snake-list-switching.vue +1285 -0
  95. package/components/snake-list-switching/types.ts +11 -0
  96. package/components/snake-loading/snake-loading.vue +241 -0
  97. package/components/snake-loading/types.ts +34 -0
  98. package/components/snake-loadmore/snake-loadmore.vue +103 -0
  99. package/components/snake-loadmore/types.ts +56 -0
  100. package/components/snake-magic-cube/snake-magic-cube.vue +622 -0
  101. package/components/snake-magic-cube/types.ts +5 -0
  102. package/components/snake-modal/snake-modal.vue +434 -0
  103. package/components/snake-modal/types.ts +71 -0
  104. package/components/snake-navbar/snake-navbar.vue +194 -0
  105. package/components/snake-navbar/types.ts +54 -0
  106. package/components/snake-no-network/snake-no-network.vue +125 -0
  107. package/components/snake-no-network/types.ts +27 -0
  108. package/components/snake-notice/snake-notice.vue +44 -0
  109. package/components/snake-notice/types.ts +5 -0
  110. package/components/snake-notice-bar/snake-notice-bar.vue +336 -0
  111. package/components/snake-notice-bar/types.ts +82 -0
  112. package/components/snake-overlay/snake-overlay.vue +73 -0
  113. package/components/snake-overlay/types.ts +35 -0
  114. package/components/snake-page-popup/snake-page-popup.vue +146 -0
  115. package/components/snake-page-popup/types.ts +28 -0
  116. package/components/snake-parse/audio/audio.vue +286 -0
  117. package/components/snake-parse/audio/context.js +11 -0
  118. package/components/snake-parse/audio/index.js +34 -0
  119. package/components/snake-parse/node/node.vue +830 -0
  120. package/components/snake-parse/parser.js +1480 -0
  121. package/components/snake-parse/snake-parse.vue +548 -0
  122. package/components/snake-parse/static/app-plus/snake-parse/js/handler.js +109 -0
  123. package/components/snake-parse/static/app-plus/snake-parse/js/uni.webview.js +0 -0
  124. package/components/snake-parse/static/app-plus/snake-parse/js/uni.webview.min.js +1 -0
  125. package/components/snake-parse/static/app-plus/snake-parse/local.html +3 -0
  126. package/components/snake-parse/style/index.js +132 -0
  127. package/components/snake-parse/style/parser.js +175 -0
  128. package/components/snake-parse/types.ts +49 -0
  129. package/components/snake-picture-ads/snake-picture-ads.vue +292 -0
  130. package/components/snake-picture-ads/types.ts +5 -0
  131. package/components/snake-popup/snake-popup.vue +348 -0
  132. package/components/snake-popup/types.ts +88 -0
  133. package/components/snake-qr-code/qrcode.ts +1214 -0
  134. package/components/snake-qr-code/snake-qr-code.vue +408 -0
  135. package/components/snake-qr-code/types.ts +78 -0
  136. package/components/snake-radio/snake-radio.vue +271 -0
  137. package/components/snake-radio/types.ts +64 -0
  138. package/components/snake-radio-group/snake-radio-group.vue +98 -0
  139. package/components/snake-radio-group/types.ts +48 -0
  140. package/components/snake-read-more/snake-read-more.vue +140 -0
  141. package/components/snake-read-more/types.ts +53 -0
  142. package/components/snake-rich-text/snake-rich-text.vue +24 -0
  143. package/components/snake-rich-text/types.ts +5 -0
  144. package/components/snake-root-portal/snake-root-portal.vue +92 -0
  145. package/components/snake-root-portal/types.ts +9 -0
  146. package/components/snake-search/snake-search.vue +202 -0
  147. package/components/snake-search/types.ts +84 -0
  148. package/components/snake-select/snake-select.vue +371 -0
  149. package/components/snake-select/types.ts +75 -0
  150. package/components/snake-skeleton/snake-skeleton.vue +104 -0
  151. package/components/snake-skeleton/types.ts +32 -0
  152. package/components/snake-skeleton-item/snake-skeleton-item.vue +90 -0
  153. package/components/snake-skeleton-item/types.ts +30 -0
  154. package/components/snake-slider/snake-slider.vue +249 -0
  155. package/components/snake-slider/types.ts +59 -0
  156. package/components/snake-sticky/snake-sticky.vue +178 -0
  157. package/components/snake-sticky/types.ts +48 -0
  158. package/components/snake-subsection/snake-subsection.vue +188 -0
  159. package/components/snake-subsection/types.ts +54 -0
  160. package/components/snake-swiper/snake-swiper.vue +229 -0
  161. package/components/snake-swiper/types.ts +79 -0
  162. package/components/snake-switch/snake-switch.vue +100 -0
  163. package/components/snake-switch/types.ts +41 -0
  164. package/components/snake-tabbar/snake-tabbar.vue +306 -0
  165. package/components/snake-tabbar/types.ts +93 -0
  166. package/components/snake-tabs/snake-tabs.vue +305 -0
  167. package/components/snake-tabs/types.ts +79 -0
  168. package/components/snake-text/snake-text.vue +292 -0
  169. package/components/snake-text/types.ts +100 -0
  170. package/components/snake-textarea/snake-textarea.vue +171 -0
  171. package/components/snake-textarea/types.ts +79 -0
  172. package/components/snake-toast/snake-toast.vue +330 -0
  173. package/components/snake-toast/types.ts +55 -0
  174. package/components/snake-tooltip/position.ts +33 -0
  175. package/components/snake-tooltip/snake-tooltip.vue +339 -0
  176. package/components/snake-tooltip/types.ts +80 -0
  177. package/components/snake-transition/snake-transition.vue +315 -0
  178. package/components/snake-transition/types.ts +65 -0
  179. package/components/snake-upload/snake-upload.vue +1801 -0
  180. package/components/snake-upload/types.ts +256 -0
  181. package/components/snake-videos/snake-videos.vue +122 -0
  182. package/components/snake-videos/types.ts +7 -0
  183. package/iconfont.css +881 -0
  184. package/index.d.ts +7 -0
  185. package/index.scss +26 -0
  186. package/index.ts +94 -0
  187. package/libs/cms/blocks.ts +103 -0
  188. package/libs/cms/config.ts +25 -0
  189. package/libs/cms/index.ts +7 -0
  190. package/libs/cms/normalize.ts +135 -0
  191. package/libs/cms/resolve.ts +12 -0
  192. package/libs/cms/types.ts +164 -0
  193. package/libs/cms/use-commerce.ts +385 -0
  194. package/libs/cms/v2.ts +193 -0
  195. package/libs/config/index.ts +4 -0
  196. package/libs/config/modal.ts +93 -0
  197. package/libs/config/state.ts +33 -0
  198. package/libs/config/theme.ts +351 -0
  199. package/libs/config/toast.ts +71 -0
  200. package/libs/config/types.ts +135 -0
  201. package/libs/config/zIndex.ts +44 -0
  202. package/libs/css/color.scss +105 -0
  203. package/libs/css/common.scss +171 -0
  204. package/libs/css/style.h5.scss +7 -0
  205. package/libs/css/style.mp.scss +7 -0
  206. package/libs/css/style.theme.scss +70 -0
  207. package/libs/css/style.vue.scss +140 -0
  208. package/libs/form/async-validator.min.d.ts +75 -0
  209. package/libs/form/async-validator.min.js +3 -0
  210. package/libs/form/index.ts +3 -0
  211. package/libs/form/path.ts +40 -0
  212. package/libs/form/types.ts +51 -0
  213. package/libs/form/validate.ts +149 -0
  214. package/libs/foundation.ts +96 -0
  215. package/libs/function/$parent.ts +33 -0
  216. package/libs/function/clipboard.ts +13 -0
  217. package/libs/function/color.ts +55 -0
  218. package/libs/function/debounce.ts +34 -0
  219. package/libs/function/deepClone.ts +30 -0
  220. package/libs/function/deepMerge.ts +25 -0
  221. package/libs/function/emitter.ts +30 -0
  222. package/libs/function/format.ts +27 -0
  223. package/libs/function/getParent.ts +53 -0
  224. package/libs/function/getRect.ts +29 -0
  225. package/libs/function/guid.ts +11 -0
  226. package/libs/function/index.ts +31 -0
  227. package/libs/function/queryParams.ts +73 -0
  228. package/libs/function/random.ts +6 -0
  229. package/libs/function/randomArray.ts +14 -0
  230. package/libs/function/route.ts +155 -0
  231. package/libs/function/sleep.ts +7 -0
  232. package/libs/function/style.ts +58 -0
  233. package/libs/function/styleUtils.ts +83 -0
  234. package/libs/function/system.ts +14 -0
  235. package/libs/function/test.ts +202 -0
  236. package/libs/function/throttle.ts +36 -0
  237. package/libs/function/timeFormat.ts +27 -0
  238. package/libs/function/timeFrom.ts +27 -0
  239. package/libs/function/toast.ts +10 -0
  240. package/libs/function/trim.ts +11 -0
  241. package/libs/function/type2icon.ts +11 -0
  242. package/libs/function/unit.ts +45 -0
  243. package/libs/hooks/index.ts +11 -0
  244. package/libs/hooks/useChildren.ts +125 -0
  245. package/libs/hooks/useColor.ts +5 -0
  246. package/libs/hooks/useDebounce.ts +5 -0
  247. package/libs/hooks/useLocale.ts +13 -0
  248. package/libs/hooks/useModal.ts +131 -0
  249. package/libs/hooks/useParent.ts +62 -0
  250. package/libs/hooks/useRect.ts +44 -0
  251. package/libs/hooks/useRouter.ts +5 -0
  252. package/libs/hooks/useTheme.ts +31 -0
  253. package/libs/hooks/useThrottle.ts +5 -0
  254. package/libs/hooks/useToast.ts +116 -0
  255. package/libs/index.ts +18 -0
  256. package/libs/request/auto-http.ts +1 -0
  257. package/libs/request/index.ts +343 -0
  258. package/libs/runtime/accessors.ts +55 -0
  259. package/libs/runtime/context.ts +40 -0
  260. package/libs/runtime/index.ts +18 -0
  261. package/libs/runtime/types.ts +49 -0
  262. package/libs/util/calendar.ts +6 -0
  263. package/locale/index.ts +130 -0
  264. package/locale/lang/en-US.ts +67 -0
  265. package/locale/lang/zh-CN.ts +67 -0
  266. package/package.json +130 -5
  267. package/plugins/index.ts +1 -0
  268. package/plugins/root/README.md +86 -0
  269. package/plugins/root/index.ts +123 -0
  270. package/plugins/root/page.ts +77 -0
  271. package/plugins/root/root.ts +53 -0
  272. package/plugins/root/utils.ts +137 -0
  273. package/readme.md +79 -0
  274. package/theme.scss +118 -0
  275. package/types/components.d.ts +236 -0
  276. package/types/global.d.ts +21 -0
  277. package/types/index.d.ts +6 -0
  278. package/types/uni-app.d.ts +16 -0
  279. package/README.md +0 -3
@@ -0,0 +1,79 @@
1
+ import type { UnitValue } from '../../libs/function/unit';
2
+ import type { StyleValue } from '../../types/global';
3
+ import type { FormSize } from '../snake-form/types';
4
+ /** Textarea 组件的公开属性。 */
5
+ export interface TextareaProps {
6
+ /** 双向绑定的当前值。 */
7
+ modelValue?: string | number;
8
+ /** 输入为空时的占位文本。 */
9
+ placeholder?: string;
10
+ /** 占位文本样式。 */
11
+ placeholderStyle?: string;
12
+ /** 允许输入的最大字符数。 */
13
+ maxlength?: number;
14
+ /** 组件高度。 */
15
+ height?: UnitValue;
16
+ /** auto height 配置。 */
17
+ autoHeight?: boolean;
18
+ /** 是否使用固定定位。 */
19
+ fixed?: boolean;
20
+ /** 数量或徽标内容。 */
21
+ count?: boolean;
22
+ /** 是否禁用交互。 */
23
+ disabled?: boolean;
24
+ /** 是否为只读状态。 */
25
+ readonly?: boolean;
26
+ /** 组件尺寸。 */
27
+ size?: FormSize;
28
+ /** 边框展示模式。 */
29
+ border?: 'none' | 'surround' | 'bottom';
30
+ /** 内容颜色。 */
31
+ color?: string;
32
+ /** 占位文本颜色。 */
33
+ placeholderColor?: string;
34
+ /** 文字尺寸,数值按 rpx 处理。 */
35
+ fontSize?: UnitValue;
36
+ /** 是否自动获取焦点。 */
37
+ focus?: boolean;
38
+ /** 输入框光标位置。 */
39
+ cursor?: number;
40
+ /** 文本选择区域的起始位置。 */
41
+ selectionStart?: number;
42
+ /** 文本选择区域的结束位置。 */
43
+ selectionEnd?: number;
44
+ /** 键盘右下角确认按钮类型。 */
45
+ confirmType?: string;
46
+ /** 确认输入后是否保持键盘弹出。 */
47
+ confirmHold?: boolean;
48
+ /** 键盘弹起时是否自动调整页面位置。 */
49
+ adjustPosition?: boolean;
50
+ /** 点击页面时是否保持键盘弹出。 */
51
+ holdKeyboard?: boolean;
52
+ /** 光标与键盘的距离,单位 px。 */
53
+ cursorSpacing?: number;
54
+ /** show confirm bar 配置。 */
55
+ showConfirmBar?: boolean;
56
+ /** 根节点自定义类名。 */
57
+ customClass?: string;
58
+ /** 根节点自定义样式。 */
59
+ customStyle?: StyleValue;
60
+ }
61
+ /** Textarea 组件的事件契约。 */
62
+ export type TextareaEmits = {
63
+ /** update:modelValue 事件携带的参数。 */
64
+ 'update:modelValue': [value: string];
65
+ /** input 事件携带的参数。 */
66
+ input: [value: string];
67
+ /** change 事件携带的参数。 */
68
+ change: [value: string];
69
+ /** focus 事件携带的参数。 */
70
+ focus: [event: unknown];
71
+ /** blur 事件携带的参数。 */
72
+ blur: [event: unknown];
73
+ /** confirm 事件携带的参数。 */
74
+ confirm: [value: string, event: unknown];
75
+ /** linechange 事件携带的参数。 */
76
+ linechange: [event: unknown];
77
+ /** keyboardheightchange 事件携带的参数。 */
78
+ keyboardheightchange: [event: unknown];
79
+ };
@@ -0,0 +1,330 @@
1
+ <template>
2
+ <view
3
+ class="snake-toast"
4
+ :class="[
5
+ isShow ? 'snake-show' : '',
6
+ 'snake-type-' + (tmpConfig.type || 'default'),
7
+ 'snake-position-' + tmpConfig.position,
8
+ customClass
9
+ ]"
10
+ :style="toStyle({ zIndex: uZIndex }, customStyle as string | Record<string, any>)"
11
+ >
12
+ <view class="snake-toast__icon-wrap">
13
+ <!-- loading 类型走独立的加载动画组件 -->
14
+ <snake-loading
15
+ v-if="tmpConfig.loading"
16
+ type="circular"
17
+ color="currentColor"
18
+ custom-style="margin-right: 16rpx;"
19
+ ></snake-loading>
20
+ <!-- 其它类型仍然使用图标 -->
21
+ <snake-icon
22
+ v-else-if="tmpConfig.icon && iconName"
23
+ :name="iconName"
24
+ :size="20"
25
+ color="currentColor"
26
+ custom-style="margin-right: 10rpx;"
27
+ ></snake-icon>
28
+ </view>
29
+ <text class="snake-toast__text">{{ tmpConfig.title }}</text>
30
+ </view>
31
+ </template>
32
+
33
+ <script setup lang="ts">
34
+ /**
35
+ * @component Toast
36
+ * @description 消息提示,支持声明式 ref 调用与函数式 useToast() 调用,用于成功、错误、警告、加载等轻提示。
37
+ * @see /components/toast
38
+ */
39
+
40
+ import { computed, onBeforeUnmount, onMounted, ref } from 'vue';
41
+ import { onPageHide, onPageShow } from '@dcloudio/uni-app';
42
+ import zIndex from '../../libs/config/zIndex';
43
+ import { toStyle } from '../../libs/function/style';
44
+ import { deepMerge } from '../../libs/function/deepMerge';
45
+ import { type2icon } from '../../libs/function/type2icon';
46
+ import { route } from '../../libs/function/route';
47
+ import { emitter } from '../../libs/function/emitter';
48
+ import SnakeLoading from '../snake-loading/snake-loading.vue';
49
+ import Icon from '../snake-icon/snake-icon.vue';
50
+ import { toastProps } from './types';
51
+ import type { ToastExpose } from './types';
52
+ import {
53
+ SNAKE_TOAST_EVENT_HIDE,
54
+ SNAKE_TOAST_EVENT_SHOW,
55
+ SNAKE_TOAST_GLOBAL_EVENT_HIDE,
56
+ SNAKE_TOAST_GLOBAL_EVENT_SHOW,
57
+ getEventWithCurrentPage,
58
+ type ToastPayload
59
+ } from '../../libs/config/toast';
60
+
61
+ defineOptions({ name: 'Toast', options: { virtualHost: true, styleIsolation: 'shared' } });
62
+
63
+ const props = defineProps(toastProps);
64
+
65
+ // 是否已经初始化事件监听
66
+ const isInit = ref(false);
67
+ // 是否显示 toast
68
+ const isShow = ref(false);
69
+ // 定时器
70
+ let timer: ReturnType<typeof setTimeout> | null = null;
71
+
72
+ // 内置配置
73
+ const config = computed(() => ({
74
+ zIndex: props.zIndex,
75
+ type: props.type,
76
+ duration: props.duration,
77
+ icon: props.icon,
78
+ position: props.position,
79
+ callback: props.callback,
80
+ back: props.back,
81
+ isTab: props.isTab,
82
+ url: props.url,
83
+ params: props.params,
84
+ loading: props.loading,
85
+ title: ''
86
+ }));
87
+
88
+ // 合并后的临时配置
89
+ const tmpConfig = ref<Record<string, any>>({ ...config.value });
90
+
91
+ /**
92
+ * 只有不为空,并且 type 为 error|warning|success|info 时,才显示图标
93
+ */
94
+ const iconName = computed(() => {
95
+ if (['error', 'warning', 'success', 'info'].indexOf(tmpConfig.value.type) >= 0 && tmpConfig.value.icon) {
96
+ return type2icon(tmpConfig.value.type);
97
+ }
98
+ return '';
99
+ });
100
+
101
+ // 显示时的层级
102
+ const uZIndex = computed(() => props.zIndex || zIndex.toast);
103
+
104
+ /**
105
+ * 显示 toast,由父组件通过 ref.show(options) 形式调用
106
+ * @description 当 duration 为 0 或不传时,表示不自动关闭,需要手动调用 hide/close 方法关闭
107
+ */
108
+ function show(options: Record<string, any>) {
109
+ // 不将结果合并到 config 变量,避免多次调用 toast 时前后的配置造成混乱
110
+ tmpConfig.value = deepMerge(config.value, options);
111
+ if (timer) {
112
+ clearTimeout(timer);
113
+ timer = null;
114
+ }
115
+ isShow.value = true;
116
+ // duration 为 0、undefined 或小于等于 0 时,表示不自动关闭,需要手动调用 hide/close
117
+ if (tmpConfig.value.duration > 0) {
118
+ timer = setTimeout(() => {
119
+ isShow.value = false;
120
+ clearTimeout(timer!);
121
+ timer = null;
122
+ if (typeof tmpConfig.value.callback === 'function') {
123
+ tmpConfig.value.callback();
124
+ }
125
+ timeEnd();
126
+ }, tmpConfig.value.duration);
127
+ }
128
+ }
129
+
130
+ /**
131
+ * 隐藏 toast,由父组件通过 ref.hide() 形式调用
132
+ */
133
+ function hide() {
134
+ isShow.value = false;
135
+ if (timer) {
136
+ clearTimeout(timer);
137
+ timer = null;
138
+ }
139
+ }
140
+
141
+ /**
142
+ * 倒计时结束后,进行跳转等操作
143
+ */
144
+ function timeEnd() {
145
+ if (tmpConfig.value.url) {
146
+ const url = tmpConfig.value.url.startsWith('/') ? tmpConfig.value.url : '/' + tmpConfig.value.url;
147
+ if (tmpConfig.value.isTab) {
148
+ uni.switchTab({ url });
149
+ } else {
150
+ route({ type: 'navigateTo', url, params: tmpConfig.value.params });
151
+ }
152
+ } else if (tmpConfig.value.back) {
153
+ route({ type: 'back' });
154
+ }
155
+ }
156
+
157
+ /**
158
+ * 函数式调用支持:
159
+ * - useToast() 内部通过 emitter 派发「全局」事件,仅由 App 根部的 <snake-toast global /> 承接
160
+ * - 页面级 <snake-toast page /> 监听「页面级」事件
161
+ * - 不影响原有 ref.show()/ref.hide() 使用方式
162
+ */
163
+ function onServiceShow(payload: ToastPayload) {
164
+ show(payload || {});
165
+ }
166
+
167
+ function onServiceHide() {
168
+ hide();
169
+ }
170
+
171
+ // 是否为 App 根部的“全局 toast”
172
+ const isGlobal = computed(() => !!props.global);
173
+ // 是否为页面级 toast
174
+ const isPage = computed(() => !!props.page);
175
+
176
+ // 显示事件
177
+ const showEvent = computed(() =>
178
+ isGlobal.value
179
+ ? SNAKE_TOAST_GLOBAL_EVENT_SHOW
180
+ : isPage.value
181
+ ? getEventWithCurrentPage(SNAKE_TOAST_EVENT_SHOW, props.page)
182
+ : ''
183
+ );
184
+
185
+ // 隐藏事件
186
+ const hideEvent = computed(() =>
187
+ isGlobal.value
188
+ ? SNAKE_TOAST_GLOBAL_EVENT_HIDE
189
+ : isPage.value
190
+ ? getEventWithCurrentPage(SNAKE_TOAST_EVENT_HIDE, props.page)
191
+ : ''
192
+ );
193
+
194
+ // 开始监听事件
195
+ function startListeners() {
196
+ if (isInit.value) {
197
+ return;
198
+ }
199
+ isInit.value = true;
200
+ if (showEvent.value) {
201
+ emitter.on(showEvent.value, onServiceShow);
202
+ }
203
+ if (hideEvent.value) {
204
+ emitter.on(hideEvent.value, onServiceHide);
205
+ }
206
+ }
207
+
208
+ // 停止监听事件
209
+ function stopListeners() {
210
+ if (!isInit.value) {
211
+ return;
212
+ }
213
+ isInit.value = false;
214
+ if (showEvent.value) {
215
+ emitter.off(showEvent.value, onServiceShow);
216
+ }
217
+ if (hideEvent.value) {
218
+ emitter.off(hideEvent.value, onServiceHide);
219
+ }
220
+ }
221
+
222
+ onPageShow(() => {
223
+ startListeners();
224
+ });
225
+
226
+ onPageHide(() => {
227
+ stopListeners();
228
+ });
229
+
230
+ onMounted(() => {
231
+ startListeners();
232
+ });
233
+
234
+ onBeforeUnmount(() => {
235
+ stopListeners();
236
+ });
237
+
238
+ defineExpose<ToastExpose>({
239
+ show,
240
+ hide,
241
+ close: hide
242
+ });
243
+ </script>
244
+
245
+ <style scoped lang="scss">
246
+ .snake-toast {
247
+ position: fixed;
248
+ display: flex;
249
+ align-items: center;
250
+ justify-content: center;
251
+ padding: 30rpx 40rpx;
252
+ font-size: 28rpx;
253
+ text-align: center;
254
+ color: var(--snake-color-white, #ffffff);
255
+ background: var(--snake-color-text, #303133);
256
+ border-radius: 8rpx;
257
+ opacity: 0;
258
+ pointer-events: none;
259
+ transition: opacity 0.3s;
260
+ }
261
+
262
+ .snake-toast.snake-show {
263
+ opacity: 1;
264
+ }
265
+
266
+ .snake-toast__icon-wrap {
267
+ display: flex;
268
+ align-items: center;
269
+ }
270
+
271
+ .snake-toast__text {
272
+ word-break: break-all;
273
+ }
274
+
275
+ .snake-position-center {
276
+ left: 50%;
277
+ top: 50%;
278
+ transform: translate(-50%, -50%);
279
+ /* #ifndef APP-NVUE */
280
+ max-width: 70%;
281
+ /* #endif */
282
+ }
283
+
284
+ .snake-position-top {
285
+ left: 50%;
286
+ top: 20%;
287
+ transform: translate(-50%, -50%);
288
+ }
289
+
290
+ .snake-position-bottom {
291
+ left: 50%;
292
+ bottom: 20%;
293
+ transform: translate(-50%, -50%);
294
+ }
295
+
296
+ .snake-type-primary {
297
+ color: var(--snake-color-primary, #06d290);
298
+ background-color: var(--snake-color-primary-light, rgba(6, 210, 144, 0.1));
299
+ border: 1px solid var(--snake-color-primary-light, rgba(6, 210, 144, 0.1));
300
+ }
301
+
302
+ .snake-type-success {
303
+ color: var(--snake-color-success, #06d290);
304
+ background-color: var(--snake-color-success-light, rgba(6, 210, 144, 0.1));
305
+ border: 1px solid var(--snake-color-success-light, rgba(6, 210, 144, 0.1));
306
+ }
307
+
308
+ .snake-type-error {
309
+ color: var(--snake-color-error, #fa3534);
310
+ background-color: var(--snake-color-error-light, #fef0f0);
311
+ border: 1px solid var(--snake-color-error-light, #fef0f0);
312
+ }
313
+
314
+ .snake-type-warning {
315
+ color: var(--snake-color-warning, #ff9900);
316
+ background-color: var(--snake-color-warning-light, #fdf6ec);
317
+ border: 1px solid var(--snake-color-warning-light, #fdf6ec);
318
+ }
319
+
320
+ .snake-type-info {
321
+ color: var(--snake-color-info, #909399);
322
+ background-color: var(--snake-color-info-light, #f4f4f5);
323
+ border: 1px solid var(--snake-color-info-light, #f4f4f5);
324
+ }
325
+
326
+ .snake-type-default {
327
+ color: var(--snake-color-white, #ffffff);
328
+ background-color: var(--snake-color-text, #303133);
329
+ }
330
+ </style>
@@ -0,0 +1,55 @@
1
+ import type { ExtractPropTypes, PropType } from 'vue';
2
+ import zIndex from '../../libs/config/zIndex';
3
+
4
+ /** snake-toast 支持的提示类型。 */
5
+ export type ToastType = 'success' | 'error' | 'warning' | 'info' | 'primary' | 'default' | '';
6
+
7
+ /** snake-toast 支持的显示位置。 */
8
+ export type ToastPosition = 'center' | 'top' | 'bottom';
9
+
10
+ /** toastProps 运行时属性及默认值。 */
11
+ export const toastProps = {
12
+ /** 根节点自定义样式。 */
13
+ customStyle: { type: [String, Object, Array] as PropType<string | Record<string, any> | unknown[]>, default: () => ({}) },
14
+ /** 根节点自定义类名。 */
15
+ customClass: { type: String, default: '' },
16
+ /** 层级 z-index。 */
17
+ zIndex: { type: [Number, String] as PropType<number | string>, default: zIndex.toast },
18
+ /** 提示类型,success/warning/error/info 等。 */
19
+ type: { type: String as PropType<ToastType>, default: '' },
20
+ /** 显示时长,单位 ms。设为 0 表示不自动关闭,需手动调用 hide/close。 */
21
+ duration: { type: Number, default: 2000 },
22
+ /** 是否显示图标。 */
23
+ icon: { type: Boolean, default: true },
24
+ /** 显示位置,center/top/bottom。 */
25
+ position: { type: String as PropType<ToastPosition>, default: 'center' },
26
+ /** 关闭时的回调函数。 */
27
+ callback: { type: Function as unknown as PropType<(() => void) | null>, default: null },
28
+ /** 是否返回上一页。 */
29
+ back: { type: Boolean, default: false },
30
+ /** 是否为 tab 页面跳转。 */
31
+ isTab: { type: Boolean, default: false },
32
+ /** 跳转的 url。 */
33
+ url: { type: String, default: '' },
34
+ /** 跳转参数对象。 */
35
+ params: { type: Object as PropType<Record<string, any>>, default: () => ({}) },
36
+ /** 是否作为全局根部 toast(通常放在 App.vue 中,给 useToast() 使用)。 */
37
+ global: { type: Boolean, default: false },
38
+ /** 是否作为页面级 toast(通常放在页面中,给 useToast({ page: true }) 使用)。 */
39
+ page: { type: [Boolean, String] as PropType<boolean | string>, default: false },
40
+ /** 是否为 loading “常驻”。 */
41
+ loading: { type: Boolean, default: false }
42
+ };
43
+
44
+ /** Toast 组件公开属性。 */
45
+ export type ToastProps = ExtractPropTypes<typeof toastProps>;
46
+
47
+ /** Toast 组件通过 ref 暴露的方法。 */
48
+ export type ToastExpose = {
49
+ /** 显示 toast。 */
50
+ show: (options: Record<string, any>) => void;
51
+ /** 隐藏 toast。 */
52
+ hide: () => void;
53
+ /** 关闭 toast(hide 的别名)。 */
54
+ close: () => void;
55
+ };
@@ -0,0 +1,33 @@
1
+ /** Tooltip 定位计算所需的节点矩形。 */
2
+ export interface TooltipRect {
3
+ left: number;
4
+ top: number;
5
+ width: number;
6
+ height: number;
7
+ }
8
+
9
+ /** 箭头左侧或顶部相对提示层的像素偏移。 */
10
+ export interface TooltipArrowPosition {
11
+ x?: number;
12
+ y?: number;
13
+ }
14
+
15
+ /**
16
+ * 将箭头对准触发元素中心,并限制在提示层边缘以内。
17
+ * 面板本身用 CSS 相对触发元素定位,内容尺寸变化时会自动重新布局。
18
+ */
19
+ export function getTooltipArrowPosition(
20
+ placement: string,
21
+ target: TooltipRect,
22
+ panel: TooltipRect,
23
+ arrowSize: number
24
+ ): TooltipArrowPosition {
25
+ const vertical = placement.startsWith('top') || placement.startsWith('bottom');
26
+ const panelSize = vertical ? panel.width : panel.height;
27
+ const targetCenter = vertical ? target.left + target.width / 2 : target.top + target.height / 2;
28
+ const panelStart = vertical ? panel.left : panel.top;
29
+ const inset = arrowSize;
30
+ const max = Math.max(inset, panelSize - arrowSize - inset);
31
+ const offset = Math.min(max, Math.max(inset, targetCenter - panelStart - arrowSize / 2));
32
+ return vertical ? { x: offset } : { y: offset };
33
+ }