@puresnake/snake-ui 0.0.0-stage → 0.0.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 (279) hide show
  1. package/LICENSE +21 -0
  2. package/changelog.md +83 -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 +134 -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,277 @@
1
+ <template>
2
+ <view class="snake-index-list-panel" :class="customClass" :style="customStyle">
3
+ <scroll-view
4
+ class="snake-index-list-panel__content"
5
+ scroll-y
6
+ :scroll-top="innerScrollTop"
7
+ :scroll-into-view="scrollIntoView"
8
+ @scroll="onScroll"
9
+ >
10
+ <slot />
11
+ </scroll-view>
12
+ <view
13
+ v-if="indexList.length"
14
+ class="snake-index-list-panel__rail"
15
+ :style="[{ zIndex: props.zIndex }, railStyle]"
16
+ aria-label="索引导航"
17
+ @touchstart.stop.prevent="touchSelect"
18
+ @touchmove.stop.prevent="touchSelect"
19
+ @touchend.stop.prevent="touching = false"
20
+ @touchcancel.stop.prevent="touching = false"
21
+ >
22
+ <view
23
+ v-for="(item, index) in indexList"
24
+ :key="`${item}-${index}`"
25
+ class="snake-index-list-panel__key"
26
+ :class="{ 'is-active': activeIndex === index }"
27
+ :style="{ color: activeIndex === index ? activeColor : inactiveColor }"
28
+ @click="scrollTo(index)"
29
+ >
30
+ {{ item }}
31
+ </view>
32
+ </view>
33
+ <view v-if="indexList.length" class="snake-index-list-panel__bubble" :class="{ 'is-visible': touching }">
34
+ {{ activeIndex >= 0 ? indexList[activeIndex] : '' }}
35
+ </view>
36
+ </view>
37
+ </template>
38
+
39
+ <script setup lang="ts">
40
+ /**
41
+ * @component IndexListPanel
42
+ * @description 用于弹窗和定高区域的索引列表,自身管理内部 scroll-view,不依赖页面滚动位置。
43
+ * @see /components/index-list-panel
44
+ */
45
+
46
+ import { getCurrentInstance, nextTick, onMounted, provide, ref, toRef, watch, type CSSProperties } from 'vue';
47
+ import zIndex from '../../libs/config/zIndex';
48
+ import { addUnit } from '../../libs/function/unit';
49
+ import { createAnchorRegistry } from '../snake-index-list/anchor-registry';
50
+ import { indexFromTouch, offsetTopPx, resolveIndex, indexListKey } from '../snake-index-list/types';
51
+ import type { IndexValue } from '../snake-index-list/types';
52
+ import type { IndexListPanelEmits, IndexListPanelProps } from './types';
53
+
54
+ defineOptions({ name: 'IndexListPanel', options: { virtualHost: true, styleIsolation: 'shared' } });
55
+
56
+ const props = withDefaults(defineProps<IndexListPanelProps>(), {
57
+ indexList: () => [],
58
+ scrollTop: 0,
59
+ zIndex: zIndex.indexListSticky,
60
+ sticky: true,
61
+ offsetTop: 0,
62
+ activeColor: 'var(--snake-color-primary, #06D290)',
63
+ inactiveColor: 'var(--snake-color-text-muted, #909399)',
64
+ railStyle: '',
65
+ customClass: '',
66
+ customStyle: ''
67
+ });
68
+ const emit = defineEmits<IndexListPanelEmits>();
69
+ const instance = getCurrentInstance();
70
+ const activeIndex = ref(props.indexList.length ? 0 : -1);
71
+ const scrollIntoView = ref('');
72
+ // Keep the command value separate from the position reported by scroll-view.
73
+ // Binding the live scroll position back to `scroll-top` makes every scroll event
74
+ // trigger another native scroll/layout pass, which is especially noticeable on
75
+ // long lists and while dragging the index rail.
76
+ const innerScrollTop = ref(Number(props.scrollTop) || 0);
77
+ const currentScrollTop = ref(Number(props.scrollTop) || 0);
78
+ const railTop = ref(0);
79
+ const railHeight = ref(0);
80
+ const anchorOffsets = ref<number[]>([]);
81
+ // 锚点位置由锚点组件自测回报(微信端父级查询跨不过自定义组件边界)。
82
+ const registry = createAnchorRegistry();
83
+ const touching = ref(false);
84
+ let updating = false;
85
+ let scrollIntoViewTimer: ReturnType<typeof setTimeout> | undefined;
86
+ const anchorId = (value: IndexValue) => `snake-index-panel-anchor-${String(value).replace(/[^a-zA-Z0-9_-]/g, '-')}`;
87
+
88
+ function setActive(index: number, selected = false) {
89
+ if (!props.indexList.length || index < 0 || index >= props.indexList.length) return;
90
+ if (index !== activeIndex.value) {
91
+ activeIndex.value = index;
92
+ emit('change', { index, value: props.indexList[index] });
93
+ }
94
+ if (selected) emit('select', props.indexList[index]);
95
+ }
96
+
97
+ function scrollTo(indexOrValue: number | IndexValue) {
98
+ const index = resolveIndex(indexOrValue, props.indexList);
99
+ if (index < 0) return;
100
+ setActive(index, true);
101
+ const offset = anchorOffsets.value[index];
102
+ if (index < anchorOffsets.value.length && Number.isFinite(offset)) {
103
+ const nextScrollTop = Math.max(0, offset);
104
+ currentScrollTop.value = nextScrollTop;
105
+ innerScrollTop.value = nextScrollTop;
106
+ scrollIntoView.value = '';
107
+ if (scrollIntoViewTimer) clearTimeout(scrollIntoViewTimer);
108
+ return;
109
+ }
110
+ scrollIntoView.value = '';
111
+ if (scrollIntoViewTimer) clearTimeout(scrollIntoViewTimer);
112
+ scrollIntoViewTimer = setTimeout(() => (scrollIntoView.value = anchorId(props.indexList[index])), 0);
113
+ }
114
+
115
+ function touchSelect(event: any) {
116
+ touching.value = true;
117
+ const y = Number(event.touches?.[0]?.clientY ?? event.changedTouches?.[0]?.clientY);
118
+ const index = indexFromTouch(y, railTop.value, railHeight.value, props.indexList.length);
119
+ if (index >= 0) scrollTo(index);
120
+ }
121
+
122
+ function onScroll(event: any) {
123
+ currentScrollTop.value = Number(event.detail?.scrollTop) || 0;
124
+ if (!anchorOffsets.value.length) void update();
125
+ const target = currentScrollTop.value + offsetTopPx(props.offsetTop) + 1;
126
+ let low = 0;
127
+ let high = anchorOffsets.value.length - 1;
128
+ let index = 0;
129
+ while (low <= high) {
130
+ const middle = (low + high) >> 1;
131
+ if (anchorOffsets.value[middle] <= target) {
132
+ index = middle;
133
+ low = middle + 1;
134
+ } else {
135
+ high = middle - 1;
136
+ }
137
+ }
138
+ if (anchorOffsets.value.length) setActive(index);
139
+ }
140
+
141
+ async function update() {
142
+ if (typeof uni === 'undefined' || updating) return;
143
+ updating = true;
144
+ try {
145
+ await nextTick();
146
+ const contentTop = await new Promise<number>(resolve => {
147
+ const query = uni.createSelectorQuery().in(instance?.proxy as any);
148
+ query.select('.snake-index-list-panel__content').boundingClientRect();
149
+ query.select('.snake-index-list-panel__rail').boundingClientRect();
150
+ query.exec((results: any[]) => {
151
+ const content = results?.[0];
152
+ const rail = results?.[1];
153
+ if (rail) {
154
+ railTop.value = Number(rail.top) || 0;
155
+ railHeight.value = Number(rail.height) || 0;
156
+ }
157
+ resolve(content ? Number(content.top) || 0 : 0);
158
+ });
159
+ });
160
+ await registry.collect();
161
+ anchorOffsets.value = props.indexList.map(value => {
162
+ const rect = registry.rects.get(value);
163
+ // 未回报的锚点以 Infinity 占位,scrollTo 自动退回 scroll-into-view。
164
+ return rect ? rect.top - contentTop + currentScrollTop.value : Number.POSITIVE_INFINITY;
165
+ });
166
+ activeIndex.value = props.indexList.length ? Math.max(0, activeIndex.value) : -1;
167
+ } finally {
168
+ updating = false;
169
+ }
170
+ }
171
+
172
+ function indexOfAnchor(value: IndexValue) {
173
+ return props.indexList.indexOf(value);
174
+ }
175
+
176
+ function anchorStyle(value: IndexValue): CSSProperties {
177
+ const index = indexOfAnchor(value);
178
+ return {
179
+ color: index === activeIndex.value ? props.activeColor : undefined
180
+ };
181
+ }
182
+
183
+ function wrapperStyle(): CSSProperties {
184
+ if (!props.sticky) return {};
185
+ return {
186
+ position: 'sticky',
187
+ top: addUnit(props.offsetTop, 'rpx'),
188
+ zIndex: props.zIndex
189
+ };
190
+ }
191
+
192
+ provide(indexListKey, {
193
+ activeIndex,
194
+ sticky: toRef(props, 'sticky'),
195
+ offsetTop: toRef(props, 'offsetTop'),
196
+ zIndex: toRef(props, 'zIndex'),
197
+ anchorId,
198
+ anchorStyle,
199
+ wrapperStyle,
200
+ isActive: value => indexOfAnchor(value) === activeIndex.value,
201
+ measureToken: registry.measureToken,
202
+ registerAnchor: registry.registerAnchor,
203
+ unregisterAnchor: registry.unregisterAnchor,
204
+ reportAnchor: registry.reportAnchor
205
+ });
206
+
207
+ watch(
208
+ () => props.scrollTop,
209
+ value => {
210
+ const nextScrollTop = Number(value) || 0;
211
+ currentScrollTop.value = nextScrollTop;
212
+ innerScrollTop.value = nextScrollTop;
213
+ }
214
+ );
215
+ watch(
216
+ () => props.indexList,
217
+ () => void update(),
218
+ { deep: true }
219
+ );
220
+ onMounted(() => void update());
221
+ defineExpose({ scrollTo, update });
222
+ </script>
223
+
224
+ <style scoped>
225
+ .snake-index-list-panel {
226
+ position: relative;
227
+ height: 100%;
228
+ min-height: 400rpx;
229
+ }
230
+ .snake-index-list-panel__content {
231
+ height: 100%;
232
+ }
233
+ .snake-index-list-panel__rail {
234
+ position: absolute;
235
+ top: 50%;
236
+ right: 10rpx;
237
+ display: flex;
238
+ flex-direction: column;
239
+ padding: 8rpx 0;
240
+ border-radius: 999px;
241
+ background: rgba(255, 255, 255, 0.86);
242
+ transform: translateY(-50%);
243
+ user-select: none;
244
+ }
245
+ .snake-index-list-panel__key {
246
+ display: flex;
247
+ min-width: 44rpx;
248
+ min-height: 34rpx;
249
+ align-items: center;
250
+ justify-content: center;
251
+ border-radius: 50%;
252
+ font-size: 20rpx;
253
+ line-height: 34rpx;
254
+ }
255
+ .snake-index-list-panel__key.is-active {
256
+ font-weight: 700;
257
+ background: var(--snake-color-primary-light, rgba(6, 210, 144, 0.1));
258
+ }
259
+ .snake-index-list-panel__bubble {
260
+ position: absolute;
261
+ top: 50%;
262
+ left: 50%;
263
+ display: none;
264
+ width: 96rpx;
265
+ height: 96rpx;
266
+ align-items: center;
267
+ justify-content: center;
268
+ border-radius: 16rpx;
269
+ color: #fff;
270
+ font-size: 42rpx;
271
+ background: rgba(0, 0, 0, 0.58);
272
+ transform: translate(-50%, -50%);
273
+ }
274
+ .snake-index-list-panel__bubble.is-visible {
275
+ display: flex;
276
+ }
277
+ </style>
@@ -0,0 +1,10 @@
1
+ import type { IndexListEmits, IndexListExpose, IndexListProps } from '../snake-index-list/types';
2
+
3
+ /** IndexListPanel 组件的公开属性。 */
4
+ export interface IndexListPanelProps extends IndexListProps {}
5
+
6
+ /** IndexListPanel 组件的事件契约。 */
7
+ export type IndexListPanelEmits = IndexListEmits;
8
+
9
+ /** IndexListPanel 组件实例公开的方法。 */
10
+ export type IndexListPanelExpose = IndexListExpose;
@@ -0,0 +1,225 @@
1
+ <template>
2
+ <view class="snake-input" :class="[customClass, rootClass]" :style="rootStyle" @click="emit('click', $event)">
3
+ <slot name="prefix"><snake-icon v-if="prefixIcon" :name="prefixIcon" class="snake-input__icon" /></slot>
4
+ <input
5
+ class="snake-input__native"
6
+ :value="innerValue"
7
+ :type="type === 'password' ? 'text' : type"
8
+ :password="actualPassword"
9
+ :placeholder="placeholder"
10
+ :placeholder-style="`color:${placeholderColor};${placeholderStyle}`"
11
+ :maxlength="maxlength"
12
+ :disabled="disabled || readonly"
13
+ :focus="focus"
14
+ :cursor="cursor"
15
+ :selection-start="selectionStart"
16
+ :selection-end="selectionEnd"
17
+ :confirm-type="confirmType as any"
18
+ :confirm-hold="confirmHold"
19
+ :adjust-position="adjustPosition"
20
+ :hold-keyboard="holdKeyboard"
21
+ :cursor-spacing="cursorSpacing"
22
+ :style="inputStyle"
23
+ @input="onInput"
24
+ @focus="onFocus"
25
+ @blur="onBlur"
26
+ @confirm="confirm"
27
+ @keyboardheightchange="emit('keyboardheightchange', $event)"
28
+ @compositionstart="composing = true"
29
+ @compositionend="onCompositionEnd"
30
+ />
31
+ <snake-icon v-if="showClear" name="close-circle-fill" class="snake-input__action" @click="clear" />
32
+ <snake-icon
33
+ v-if="showPassword && (type === 'password' || password)"
34
+ :name="passwordVisible ? 'eye' : 'eye-off'"
35
+ class="snake-input__action"
36
+ @click="passwordVisible = !passwordVisible"
37
+ />
38
+ <slot name="suffix"><snake-icon v-if="suffixIcon" :name="suffixIcon" class="snake-input__icon" /></slot>
39
+ </view>
40
+ </template>
41
+
42
+ <script setup lang="ts">
43
+ /**
44
+ * @component Input
45
+ * @description 基于 uni-app input,支持清空、密码显示、格式化、前后插槽和 Form 校验联动。
46
+ * @see /components/input
47
+ */
48
+
49
+ import { computed, inject, ref, watch } from 'vue';
50
+ import { addUnit } from '../../libs/function/unit';
51
+ import { formItemKey } from '../snake-form-item/types';
52
+ import Icon from '../snake-icon/snake-icon.vue';
53
+ import type { InputEmits, InputProps } from './types';
54
+
55
+ defineOptions({ name: 'SnakeInput', options: { virtualHost: true, styleIsolation: 'shared' } });
56
+ const props = withDefaults(defineProps<InputProps>(), {
57
+ modelValue: '',
58
+ type: 'text',
59
+ password: false,
60
+ placeholder: '请输入内容',
61
+ placeholderStyle: '',
62
+ maxlength: 140,
63
+ clearable: false,
64
+ showPassword: false,
65
+ prefixIcon: '',
66
+ suffixIcon: '',
67
+ border: 'none',
68
+ shape: 'square',
69
+ color: 'var(--snake-color-text,#303133)',
70
+ placeholderColor: 'var(--snake-color-text-light,#c0c4cc)',
71
+ disabled: false,
72
+ readonly: false,
73
+ disabledColor: 'var(--snake-color-disabled-bg,#f5f7fa)',
74
+ fontSize: 28,
75
+ inputAlign: 'left',
76
+ formatTrigger: 'input',
77
+ trim: false,
78
+ focus: false,
79
+ cursor: -1,
80
+ selectionStart: -1,
81
+ selectionEnd: -1,
82
+ confirmType: 'done',
83
+ confirmHold: false,
84
+ adjustPosition: true,
85
+ holdKeyboard: false,
86
+ cursorSpacing: 0,
87
+ customClass: '',
88
+ customStyle: ''
89
+ });
90
+ const emit = defineEmits<InputEmits>();
91
+ const formItem = inject(formItemKey, null);
92
+ const focused = ref(false);
93
+ const composing = ref(false);
94
+ const passwordVisible = ref(false);
95
+ const innerValue = ref(String(props.modelValue ?? ''));
96
+ watch(
97
+ () => props.modelValue,
98
+ value => {
99
+ const next = String(value ?? '');
100
+ if (next !== innerValue.value) innerValue.value = next;
101
+ }
102
+ );
103
+ const size = computed(() => props.size || formItem?.size.value || 'default');
104
+ const actualPassword = computed(() => (props.type === 'password' || props.password) && !passwordVisible.value);
105
+ const showClear = computed(
106
+ () => props.clearable && !props.disabled && !props.readonly && focused.value && innerValue.value.length > 0
107
+ );
108
+ const rootClass = computed(() => [
109
+ `snake-input--${props.border}`,
110
+ `snake-input--${props.shape}`,
111
+ `snake-input--${size.value}`,
112
+ { 'is-focused': focused.value, 'is-error': Boolean(formItem?.errorVisible.value), 'is-disabled': props.disabled }
113
+ ]);
114
+ const rootStyle = computed(() => [
115
+ { backgroundColor: props.disabled ? props.disabledColor : undefined },
116
+ props.customStyle
117
+ ]);
118
+ const inputStyle = computed(() => ({
119
+ color: props.color,
120
+ fontSize: addUnit(props.fontSize, 'rpx'),
121
+ textAlign: props.inputAlign
122
+ }));
123
+ function format(value: string, trigger: 'input' | 'blur') {
124
+ let next = props.trim && trigger === 'blur' ? value.trim() : value;
125
+ if (props.formatter && props.formatTrigger === trigger) next = props.formatter(next);
126
+ return next;
127
+ }
128
+ function commit(value: string, trigger: 'input' | 'blur') {
129
+ const next = format(value, trigger);
130
+ innerValue.value = next;
131
+ emit('update:modelValue', next);
132
+ emit('input', next);
133
+ return next;
134
+ }
135
+ function onInput(event: any) {
136
+ const value = String(event.detail?.value ?? '');
137
+ if (composing.value) {
138
+ innerValue.value = value;
139
+ return;
140
+ }
141
+ commit(value, 'input');
142
+ void formItem?.notify('change');
143
+ }
144
+ function onCompositionEnd(event: any) {
145
+ composing.value = false;
146
+ commit(String(event.detail?.value ?? innerValue.value), 'input');
147
+ void formItem?.notify('change');
148
+ }
149
+ function onFocus(event: unknown) {
150
+ focused.value = true;
151
+ emit('focus', event);
152
+ }
153
+ function onBlur(event: any) {
154
+ focused.value = false;
155
+ const next = commit(String(event.detail?.value ?? innerValue.value), 'blur');
156
+ emit('change', next);
157
+ emit('blur', event);
158
+ void formItem?.notify('blur');
159
+ }
160
+ function clear(event: any) {
161
+ event?.stopPropagation?.();
162
+ innerValue.value = '';
163
+ emit('update:modelValue', '');
164
+ emit('input', '');
165
+ emit('change', '');
166
+ emit('clear');
167
+ void formItem?.notify('change');
168
+ }
169
+ function confirm(event: any) {
170
+ emit('confirm', String(event.detail?.value ?? innerValue.value), event);
171
+ }
172
+ </script>
173
+
174
+ <style scoped>
175
+ .snake-input {
176
+ display: flex;
177
+ box-sizing: border-box;
178
+ width: 100%;
179
+ align-items: center;
180
+ gap: 12rpx;
181
+ transition:
182
+ border-color 0.2s,
183
+ background-color 0.2s;
184
+ }
185
+ .snake-input--surround {
186
+ min-height: 80rpx;
187
+ padding: 0 22rpx;
188
+ border: 1px solid var(--snake-color-divider, #dcdfe6);
189
+ }
190
+ .snake-input--bottom {
191
+ min-height: 76rpx;
192
+ border-bottom: 1px solid var(--snake-color-divider, #dcdfe6);
193
+ }
194
+ .snake-input--circle {
195
+ border-radius: 999px;
196
+ }
197
+ .snake-input--square {
198
+ border-radius: var(--snake-radius-md, 12rpx);
199
+ }
200
+ .snake-input--small {
201
+ min-height: 64rpx;
202
+ }
203
+ .snake-input--large {
204
+ min-height: 92rpx;
205
+ }
206
+ .snake-input.is-focused {
207
+ border-color: var(--snake-color-primary, #06d290);
208
+ }
209
+ .snake-input.is-error {
210
+ border-color: var(--snake-color-error, #fa3534);
211
+ }
212
+ .snake-input.is-disabled {
213
+ opacity: 0.72;
214
+ }
215
+ .snake-input__native {
216
+ flex: 1;
217
+ min-width: 0;
218
+ height: 100%;
219
+ }
220
+ .snake-input__icon,
221
+ .snake-input__action {
222
+ flex: none;
223
+ color: var(--snake-color-text-muted, #909399);
224
+ }
225
+ </style>
@@ -0,0 +1,99 @@
1
+ import type { UnitValue } from '../../libs/function/unit';
2
+ import type { StyleValue } from '../../types/global';
3
+ import type { FormSize } from '../snake-form/types';
4
+ /** InputType 类型定义。 */
5
+ export type InputType = 'text' | 'number' | 'idcard' | 'digit' | 'password' | 'nickname';
6
+ /** InputShape 类型定义。 */
7
+ export type InputShape = 'square' | 'circle';
8
+ /** Input 组件的公开属性。 */
9
+ export interface InputProps {
10
+ /** 双向绑定的当前值。 */
11
+ modelValue?: string | number;
12
+ /** 组件类型或展示模式。 */
13
+ type?: InputType;
14
+ /** password 配置。 */
15
+ password?: boolean;
16
+ /** 输入为空时的占位文本。 */
17
+ placeholder?: string;
18
+ /** 占位文本样式。 */
19
+ placeholderStyle?: string;
20
+ /** 允许输入的最大字符数。 */
21
+ maxlength?: number;
22
+ /** 是否显示清空操作。 */
23
+ clearable?: boolean;
24
+ /** show password 配置。 */
25
+ showPassword?: boolean;
26
+ /** prefix icon 配置。 */
27
+ prefixIcon?: string;
28
+ /** suffix icon 配置。 */
29
+ suffixIcon?: string;
30
+ /** 边框展示模式。 */
31
+ border?: 'none' | 'surround' | 'bottom';
32
+ /** 组件形状。 */
33
+ shape?: InputShape;
34
+ /** 组件尺寸。 */
35
+ size?: FormSize;
36
+ /** 内容颜色。 */
37
+ color?: string;
38
+ /** 占位文本颜色。 */
39
+ placeholderColor?: string;
40
+ /** 是否禁用交互。 */
41
+ disabled?: boolean;
42
+ /** 是否为只读状态。 */
43
+ readonly?: boolean;
44
+ /** disabled color 配置。 */
45
+ disabledColor?: string;
46
+ /** 文字尺寸,数值按 rpx 处理。 */
47
+ fontSize?: UnitValue;
48
+ /** input align 配置。 */
49
+ inputAlign?: 'left' | 'center' | 'right';
50
+ /** formatter 配置。 */
51
+ formatter?: (value: string) => string;
52
+ /** format trigger 配置。 */
53
+ formatTrigger?: 'input' | 'blur';
54
+ /** trim 配置。 */
55
+ trim?: boolean;
56
+ /** 是否自动获取焦点。 */
57
+ focus?: boolean;
58
+ /** 输入框光标位置。 */
59
+ cursor?: number;
60
+ /** 文本选择区域的起始位置。 */
61
+ selectionStart?: number;
62
+ /** 文本选择区域的结束位置。 */
63
+ selectionEnd?: number;
64
+ /** 键盘右下角确认按钮类型。 */
65
+ confirmType?: string;
66
+ /** 确认输入后是否保持键盘弹出。 */
67
+ confirmHold?: boolean;
68
+ /** 键盘弹起时是否自动调整页面位置。 */
69
+ adjustPosition?: boolean;
70
+ /** 点击页面时是否保持键盘弹出。 */
71
+ holdKeyboard?: boolean;
72
+ /** 光标与键盘的距离,单位 px。 */
73
+ cursorSpacing?: number;
74
+ /** 根节点自定义类名。 */
75
+ customClass?: string;
76
+ /** 根节点自定义样式。 */
77
+ customStyle?: StyleValue;
78
+ }
79
+ /** Input 组件的事件契约。 */
80
+ export type InputEmits = {
81
+ /** update:modelValue 事件携带的参数。 */
82
+ 'update:modelValue': [value: string];
83
+ /** input 事件携带的参数。 */
84
+ input: [value: string];
85
+ /** change 事件携带的参数。 */
86
+ change: [value: string];
87
+ /** focus 事件携带的参数。 */
88
+ focus: [event: unknown];
89
+ /** blur 事件携带的参数。 */
90
+ blur: [event: unknown];
91
+ /** confirm 事件携带的参数。 */
92
+ confirm: [value: string, event: unknown];
93
+ /** clear 事件携带的参数。 */
94
+ clear: [];
95
+ /** click 事件携带的参数。 */
96
+ click: [event: unknown];
97
+ /** keyboardheightchange 事件携带的参数。 */
98
+ keyboardheightchange: [event: unknown];
99
+ };