@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,79 @@
1
+ import type { CSSProperties } from 'vue';
2
+ import type { UnitValue } from '../../libs/function/unit';
3
+ import type { StyleValue } from '../../types/global';
4
+
5
+ /** Tabs 对象数据项。 */
6
+ export interface TabItem extends Record<string, unknown> {
7
+ /** 默认标签字段。 */
8
+ name?: string | number;
9
+ /** 默认徽标字段。 */
10
+ count?: string | number;
11
+ /** 是否隐藏该标签。 */
12
+ hidden?: boolean;
13
+ }
14
+
15
+ /** Tabs 组件的公开属性。 */
16
+ export interface TabsProps {
17
+ /** 根节点自定义样式。 */
18
+ customStyle?: StyleValue;
19
+ /** 根节点自定义类名。 */
20
+ customClass?: string;
21
+ /** 是否允许横向拖动。 */
22
+ isScroll?: boolean;
23
+ /** 标签对象数组。 */
24
+ list?: TabItem[];
25
+ /** 当前激活索引。 */
26
+ current?: number | string;
27
+ /** 导航栏高度。 */
28
+ height?: UnitValue;
29
+ /** 标签字号。 */
30
+ fontSize?: UnitValue;
31
+ /** 动画时长,单位秒。 */
32
+ duration?: number | string;
33
+ /** 激活文字及滑块颜色。 */
34
+ activeColor?: string;
35
+ /** 未激活文字颜色。 */
36
+ inactiveColor?: string;
37
+ /** 滑块宽度。 */
38
+ barWidth?: UnitValue;
39
+ /** 滑块高度。 */
40
+ barHeight?: UnitValue;
41
+ /** 滚动模式标签左右内边距。 */
42
+ gutter?: UnitValue;
43
+ /** 导航栏背景色。 */
44
+ bgColor?: string;
45
+ /** 标签内容字段名。 */
46
+ name?: string;
47
+ /** 徽标内容字段名。 */
48
+ count?: string;
49
+ /** 徽标 top、right 偏移。 */
50
+ offset?: [number, number];
51
+ /** 是否显示圆点徽标。 */
52
+ isDot?: boolean;
53
+ /** 激活项是否加粗。 */
54
+ bold?: boolean;
55
+ /** 激活标签附加样式。 */
56
+ activeItemStyle?: CSSProperties;
57
+ /** 是否显示底部滑块。 */
58
+ showBar?: boolean;
59
+ /** 底部滑块附加样式。 */
60
+ barStyle?: CSSProperties;
61
+ /** 单个标签宽度。 */
62
+ itemWidth?: UnitValue;
63
+ }
64
+
65
+ /** Tabs 组件事件。 */
66
+ export type TabsEmits = {
67
+ /** 点击非当前标签时返回新索引。 */
68
+ change: [index: number];
69
+ };
70
+
71
+ /** Tabs 暴露的方法。 */
72
+ export interface TabsExpose {
73
+ /** 重新测量全部标签。 */
74
+ init: () => Promise<void>;
75
+ /** 执行标签点击逻辑。 */
76
+ clickTab: (index: number) => void;
77
+ /** 将当前标签居中并移动滑块。 */
78
+ scrollByIndex: () => void;
79
+ }
@@ -0,0 +1,292 @@
1
+ <template>
2
+ <view
3
+ v-if="show"
4
+ class="snake-text"
5
+ :class="[
6
+ bold ? 'snake-text--bold' : '',
7
+ block ? 'snake-text--block' : 'snake-text--inline',
8
+ lines ? 'snake-text--ellipsis snake-text--block' : '',
9
+ `snake-text--align-${align}`,
10
+ customClass
11
+ ]"
12
+ :style="[textStyle, customStyle]"
13
+ @click="onClick"
14
+ >
15
+ <!-- 前置图标 -->
16
+ <view v-if="prefixIcon" class="snake-text__icon snake-text__prefix-icon">
17
+ <snake-icon :name="prefixIcon" :custom-style="iconStyle" />
18
+ </view>
19
+ <!-- 价格模式 -->
20
+ <text
21
+ v-if="mode === 'price'"
22
+ class="snake-text__price"
23
+ :class="[type && `snake-text__value--${type}`]"
24
+ :style="textValueStyle"
25
+ >
26
+ <slot>¥{{ displayValue }}</slot>
27
+ </text>
28
+ <!-- link 模式 -->
29
+ <snake-link
30
+ v-else-if="mode === 'link'"
31
+ :text="String(displayValue)"
32
+ :href="href"
33
+ under-line
34
+ :style="textValueStyle"
35
+ />
36
+ <!-- 开放能力模式 -->
37
+ <template v-else-if="openType">
38
+ <button
39
+ class="snake-text__button snake-text__value"
40
+ :class="[type && `snake-text__value--${type}`]"
41
+ :style="textValueStyle"
42
+ :open-type="openType"
43
+ :lang="lang"
44
+ :session-from="sessionFrom"
45
+ :send-message-title="sendMessageTitle"
46
+ :send-message-path="sendMessagePath"
47
+ :send-message-img="sendMessageImg"
48
+ :show-message-card="showMessageCard"
49
+ :app-parameter="appParameter"
50
+ @getuserinfo="onGetUserInfo"
51
+ @contact="onContact"
52
+ @getphonenumber="onGetPhoneNumber"
53
+ @error="onError"
54
+ @launchapp="onLaunchApp"
55
+ @opensetting="onOpenSetting"
56
+ >
57
+ <slot>{{ displayValue }}</slot>
58
+ </button>
59
+ </template>
60
+ <!-- 默认模式 -->
61
+ <text v-else class="snake-text__value" :class="[type && `snake-text__value--${type}`]" :style="textValueStyle">
62
+ <slot>{{ displayValue }}</slot>
63
+ </text>
64
+ <!-- 后缀图标 -->
65
+ <view v-if="suffixIcon" class="snake-text__icon snake-text__suffix-icon">
66
+ <snake-icon :name="suffixIcon" :custom-style="iconStyle" />
67
+ </view>
68
+ </view>
69
+ </template>
70
+
71
+ <script setup lang="ts">
72
+ /**
73
+ * @component Text
74
+ * @description 文本,集成文本类常用功能:价格、手机号脱敏、姓名脱敏、日期格式化、超链接与拨打电话。
75
+ * @see /components/text
76
+ */
77
+
78
+ import { computed } from 'vue';
79
+ import { addUnit } from '../../libs/function/unit';
80
+ import { deepMerge } from '../../libs/function/deepMerge';
81
+ import { formatName, formatPrice } from '../../libs/function/format';
82
+ import { toStyle } from '../../libs/function/style';
83
+ import { timeFormat } from '../../libs/function/timeFormat';
84
+ import { test as testSuite } from '../../libs/function/test';
85
+ import Icon from '../snake-icon/snake-icon.vue';
86
+ import Link from '../snake-link/snake-link.vue';
87
+ import { textProps, type TextEmits } from './types';
88
+
89
+ defineOptions({ name: 'SnakeText', options: { virtualHost: true, styleIsolation: 'shared' } });
90
+ const props = defineProps(textProps);
91
+ const emit = defineEmits<TextEmits>();
92
+
93
+ // 是否 nvue 环境
94
+ const isNvue = computed(() => {
95
+ let nvue = false;
96
+ // #ifdef APP-NVUE
97
+ nvue = true;
98
+ // #endif
99
+ return nvue;
100
+ });
101
+
102
+ // 处理显示的值
103
+ const displayValue = computed(() => {
104
+ const { format, text, href, mode } = props;
105
+ let value: unknown = text;
106
+ if (typeof format === 'function') {
107
+ value = format(value);
108
+ }
109
+ switch (mode) {
110
+ case 'price':
111
+ if (!/^\d+(\.\d+)?$/.test(String(value))) return value;
112
+ value = formatPrice(value as string | number, 2);
113
+ break;
114
+ case 'phone':
115
+ if (format === 'encrypt') {
116
+ value = String(value).replace(/(\d{3})\d{4}(\d{4})/, '$1****$2');
117
+ }
118
+ break;
119
+ case 'name':
120
+ if (!testSuite.string(value)) return value;
121
+ if (format === 'encrypt') {
122
+ return formatName(String(value));
123
+ }
124
+ break;
125
+ case 'date':
126
+ if (testSuite.string(format) && !testSuite.empty(format)) {
127
+ return timeFormat(value as string | number, format as string);
128
+ }
129
+ return timeFormat(value as string | number, 'yyyy-mm-dd');
130
+ case 'link':
131
+ if (!testSuite.url(href)) return value;
132
+ break;
133
+ }
134
+ return value;
135
+ });
136
+
137
+ /** 根节点样式。 */
138
+ const textStyle = computed(() => {
139
+ const style: Record<string, unknown> = {
140
+ margin: typeof props.margin === 'number' ? `${props.margin}px` : props.margin,
141
+ justifyContent: props.align === 'left' ? 'flex-start' : props.align === 'center' ? 'center' : 'flex-end'
142
+ };
143
+ return toStyle(style);
144
+ });
145
+
146
+ /** 文本值样式。 */
147
+ const textValueStyle = computed(() => {
148
+ const style: Record<string, unknown> = {
149
+ textDecoration: props.decoration,
150
+ fontWeight: props.bold ? 'bold' : 'normal',
151
+ wordWrap: props.wordWrap,
152
+ fontSize: addUnit(props.size)
153
+ };
154
+ if (props.lines) {
155
+ if (props.lines === 1) {
156
+ style.display = 'block';
157
+ style.overflow = 'hidden';
158
+ style.textOverflow = 'ellipsis';
159
+ style.whiteSpace = 'nowrap';
160
+ } else {
161
+ style.display = '-webkit-box';
162
+ style['-webkit-box-orient'] = 'vertical';
163
+ style.WebkitLineClamp = Number(props.lines);
164
+ style.overflow = 'hidden';
165
+ }
166
+ }
167
+ if (!props.type) style.color = props.color;
168
+ if (isNvue.value && props.lines) style.lines = props.lines;
169
+ if (props.lineHeight) style.lineHeight = addUnit(props.lineHeight);
170
+
171
+ // 合并 textStyle,优先对象,其次字符串
172
+ if (testSuite.object(props.textStyle)) {
173
+ return toStyle(deepMerge(style, props.textStyle as Record<string, unknown>));
174
+ }
175
+ if (testSuite.string(props.textStyle)) {
176
+ return toStyle(style, props.textStyle as string);
177
+ }
178
+ return toStyle(style);
179
+ });
180
+
181
+ /** 点击事件。 */
182
+ function onClick() {
183
+ // 手机号模式且开启 call 时拨打电话
184
+ if (props.call && props.mode === 'phone') {
185
+ uni.makePhoneCall({
186
+ phoneNumber: String(props.text)
187
+ });
188
+ }
189
+ emit('click');
190
+ }
191
+ function onGetUserInfo(event: unknown) {
192
+ emit('getuserinfo', (event as { detail?: unknown })?.detail);
193
+ }
194
+ function onContact(event: unknown) {
195
+ emit('contact', (event as { detail?: unknown })?.detail);
196
+ }
197
+ function onGetPhoneNumber(event: unknown) {
198
+ emit('getphonenumber', (event as { detail?: unknown })?.detail);
199
+ }
200
+ function onError(event: unknown) {
201
+ emit('error', (event as { detail?: unknown })?.detail);
202
+ }
203
+ function onLaunchApp(event: unknown) {
204
+ emit('launchapp', (event as { detail?: unknown })?.detail);
205
+ }
206
+ function onOpenSetting(event: unknown) {
207
+ emit('opensetting', (event as { detail?: unknown })?.detail);
208
+ }
209
+ </script>
210
+
211
+ <style scoped>
212
+ .snake-text {
213
+ display: flex;
214
+ flex: 1;
215
+ flex-wrap: nowrap;
216
+ align-items: center;
217
+ word-break: break-all;
218
+ }
219
+ .snake-text--bold {
220
+ font-weight: bold;
221
+ }
222
+ .snake-text--inline {
223
+ display: inline-flex;
224
+ }
225
+ .snake-text--inline .snake-text__value {
226
+ display: inline-flex;
227
+ }
228
+ .snake-text--inline .snake-text__icon {
229
+ display: inline-flex;
230
+ }
231
+ .snake-text--block {
232
+ display: flex;
233
+ width: 100%;
234
+ }
235
+ .snake-text--block .snake-text__value {
236
+ display: flex;
237
+ }
238
+ .snake-text--block .snake-text__button {
239
+ display: block;
240
+ width: 100%;
241
+ }
242
+ .snake-text__price {
243
+ font-size: 14px;
244
+ color: var(--snake-color-text-secondary, #606266);
245
+ }
246
+ .snake-text__value {
247
+ display: flex;
248
+ flex-wrap: wrap;
249
+ align-items: center;
250
+ overflow: hidden;
251
+ font-size: 14px;
252
+ color: var(--snake-color-text-secondary, #606266);
253
+ text-overflow: ellipsis;
254
+ }
255
+ .snake-text__value--primary {
256
+ color: var(--snake-color-primary, #06d290);
257
+ }
258
+ .snake-text__value--warning {
259
+ color: var(--snake-color-warning, #ff9900);
260
+ }
261
+ .snake-text__value--success {
262
+ color: var(--snake-color-success, #19be6b);
263
+ }
264
+ .snake-text__value--info {
265
+ color: var(--snake-color-info, #909399);
266
+ }
267
+ .snake-text__value--error {
268
+ color: var(--snake-color-error, #fa3534);
269
+ }
270
+ .snake-text__value--main {
271
+ color: var(--snake-color-text, #303133);
272
+ }
273
+ .snake-text__value--content {
274
+ color: var(--snake-color-text-secondary, #606266);
275
+ }
276
+ .snake-text__value--tips {
277
+ color: var(--snake-color-text-muted, #909399);
278
+ }
279
+ .snake-text__value--light {
280
+ color: var(--snake-color-text-light, #c0c4cc);
281
+ }
282
+ .snake-text__button {
283
+ padding: 0;
284
+ margin: 0;
285
+ background: none;
286
+ border: none;
287
+ line-height: inherit;
288
+ }
289
+ .snake-text__button::after {
290
+ border: none;
291
+ }
292
+ </style>
@@ -0,0 +1,100 @@
1
+ import type { ExtractPropTypes, PropType } from 'vue';
2
+ import type { StyleValue } from '../../types/global';
3
+
4
+ /** TextMode 类型定义。 */
5
+ export type TextMode = 'text' | 'price' | 'phone' | 'name' | 'date' | 'link';
6
+ /** TextDecoration 类型定义。 */
7
+ export type TextDecoration = 'none' | 'underline' | 'line-through';
8
+ /** TextAlign 类型定义。 */
9
+ export type TextAlign = 'left' | 'center' | 'right';
10
+ /** TextWordWrap 类型定义。 */
11
+ export type TextWordWrap = 'break-word' | 'normal' | 'anywhere';
12
+
13
+ /** textProps 运行时属性及默认值。 */
14
+ export const textProps = {
15
+ /** 根节点自定义样式。 */
16
+ customStyle: { type: [String, Object, Array] as PropType<StyleValue>, default: '' },
17
+ /** 根节点自定义类名。 */
18
+ customClass: { type: String, default: '' },
19
+ /** 主题颜色。 */
20
+ type: { type: String, default: '' },
21
+ /** 是否显示文本。 */
22
+ show: { type: Boolean, default: true },
23
+ /** 显示的值。 */
24
+ text: { type: [String, Number] as PropType<string | number>, default: '' },
25
+ /** 前置图标。 */
26
+ prefixIcon: { type: String, default: '' },
27
+ /** 后置图标。 */
28
+ suffixIcon: { type: String, default: '' },
29
+ /** 文本处理模式。 */
30
+ mode: { type: String as PropType<TextMode>, default: 'text' },
31
+ /** 链接地址,mode 为 link 时使用。 */
32
+ href: { type: String, default: '' },
33
+ /** 格式化规则,字符串或函数。 */
34
+ format: { type: [String, Function] as PropType<string | ((value: unknown) => unknown)>, default: '' },
35
+ /** mode 为 phone 时,点击文本是否拨打电话。 */
36
+ call: { type: Boolean, default: false },
37
+ /** 小程序的打开方式。 */
38
+ openType: { type: String, default: '' },
39
+ /** 是否粗体。 */
40
+ bold: { type: Boolean, default: false },
41
+ /** 是否块状显示。 */
42
+ block: { type: Boolean, default: false },
43
+ /** 显示行数,超出显示省略号。 */
44
+ lines: { type: [String, Number] as PropType<string | number>, default: '' },
45
+ /** 文本颜色。 */
46
+ color: { type: String, default: 'var(--snake-color-text, #303133)' },
47
+ /** 字体大小。 */
48
+ size: { type: [String, Number] as PropType<string | number>, default: 28 },
49
+ /** 图标样式。 */
50
+ iconStyle: { type: [Object, Array, String] as PropType<StyleValue>, default: () => ({ fontSize: '15px' }) },
51
+ /** 文字样式。 */
52
+ textStyle: { type: [Object, Array, String] as PropType<StyleValue>, default: () => ({}) },
53
+ /** 文字装饰。 */
54
+ decoration: { type: String as PropType<TextDecoration>, default: 'none' },
55
+ /** 外边距。 */
56
+ margin: { type: [Object, String, Number] as PropType<Record<string, unknown> | string | number>, default: 0 },
57
+ /** 行高。 */
58
+ lineHeight: { type: [String, Number] as PropType<string | number>, default: '' },
59
+ /** 对齐方式。 */
60
+ align: { type: String as PropType<TextAlign>, default: 'left' },
61
+ /** 换行方式。 */
62
+ wordWrap: { type: String as PropType<TextWordWrap>, default: 'normal' },
63
+ /** 语言。 */
64
+ lang: { type: String, default: '' },
65
+ /** 会话来源。 */
66
+ sessionFrom: { type: String, default: '' },
67
+ /** 会话消息卡片标题。 */
68
+ sendMessageTitle: { type: String, default: '' },
69
+ /** 会话消息卡片跳转路径。 */
70
+ sendMessagePath: { type: String, default: '' },
71
+ /** 会话消息卡片图片地址。 */
72
+ sendMessageImg: { type: String, default: '' },
73
+ /** 是否显示会话消息卡片。 */
74
+ showMessageCard: { type: Boolean, default: false },
75
+ /** 打开 App 时传递的参数。 */
76
+ appParameter: { type: String, default: '' },
77
+ /** 原生表单行为类型。 */
78
+ formType: { type: String, default: '' }
79
+ } as const;
80
+
81
+ /** Text 组件的公开属性。 */
82
+ export type TextProps = ExtractPropTypes<typeof textProps>;
83
+
84
+ /** Text 组件的事件契约。 */
85
+ export type TextEmits = {
86
+ /** click 事件携带的参数。 */
87
+ click: [];
88
+ /** getuserinfo 事件携带的参数。 */
89
+ getuserinfo: [event: unknown];
90
+ /** contact 事件携带的参数。 */
91
+ contact: [event: unknown];
92
+ /** getphonenumber 事件携带的参数。 */
93
+ getphonenumber: [event: unknown];
94
+ /** error 事件携带的参数。 */
95
+ error: [event: unknown];
96
+ /** launchapp 事件携带的参数。 */
97
+ launchapp: [event: unknown];
98
+ /** opensetting 事件携带的参数。 */
99
+ opensetting: [event: unknown];
100
+ };
@@ -0,0 +1,171 @@
1
+ <template>
2
+ <view class="snake-textarea" :class="[customClass, rootClass]" :style="rootStyle">
3
+ <textarea
4
+ class="snake-textarea__native"
5
+ :value="innerValue"
6
+ :placeholder="placeholder"
7
+ :placeholder-style="`color:${placeholderColor};${placeholderStyle}`"
8
+ :maxlength="maxlength"
9
+ :auto-height="autoHeight"
10
+ :fixed="fixed"
11
+ :disabled="disabled || readonly"
12
+ :focus="focus"
13
+ :cursor="cursor"
14
+ :selection-start="selectionStart"
15
+ :selection-end="selectionEnd"
16
+ :confirm-type="confirmType as any"
17
+ :confirm-hold="confirmHold"
18
+ :adjust-position="adjustPosition"
19
+ :hold-keyboard="holdKeyboard"
20
+ :cursor-spacing="cursorSpacing"
21
+ :show-confirm-bar="showConfirmBar"
22
+ :style="{ color, fontSize: addUnit(fontSize, 'rpx') }"
23
+ @input="onInput"
24
+ @focus="
25
+ focused = true;
26
+ emit('focus', $event);
27
+ "
28
+ @blur="onBlur"
29
+ @confirm="emit('confirm', String($event.detail?.value ?? innerValue), $event)"
30
+ @linechange="emit('linechange', $event)"
31
+ @keyboardheightchange="emit('keyboardheightchange', $event)"
32
+ @compositionstart="composing = true"
33
+ @compositionend="onCompositionEnd"
34
+ />
35
+ <text v-if="count && maxlength > 0" class="snake-textarea__count">{{ innerValue.length }}/{{ maxlength }}</text>
36
+ </view>
37
+ </template>
38
+
39
+ <script setup lang="ts">
40
+ /**
41
+ * @component Textarea
42
+ * @description 用于多行文本输入,支持固定或自适应高度、字数统计和 Form 校验联动。
43
+ * @see /components/textarea
44
+ */
45
+
46
+ import { computed, inject, ref, watch } from 'vue';
47
+ import { addUnit } from '../../libs/function/unit';
48
+ import { formItemKey } from '../snake-form-item/types';
49
+ import type { TextareaEmits, TextareaProps } from './types';
50
+
51
+ defineOptions({ name: 'SnakeTextarea', options: { virtualHost: true, styleIsolation: 'shared' } });
52
+ const props = withDefaults(defineProps<TextareaProps>(), {
53
+ modelValue: '',
54
+ placeholder: '请输入内容',
55
+ placeholderStyle: '',
56
+ maxlength: 140,
57
+ height: 120,
58
+ autoHeight: false,
59
+ fixed: false,
60
+ count: false,
61
+ disabled: false,
62
+ readonly: false,
63
+ border: 'surround',
64
+ color: 'var(--snake-color-text,#303133)',
65
+ placeholderColor: 'var(--snake-color-text-light,#c0c4cc)',
66
+ fontSize: 28,
67
+ focus: false,
68
+ cursor: -1,
69
+ selectionStart: -1,
70
+ selectionEnd: -1,
71
+ confirmType: 'return',
72
+ confirmHold: false,
73
+ adjustPosition: true,
74
+ holdKeyboard: false,
75
+ cursorSpacing: 0,
76
+ showConfirmBar: true,
77
+ customClass: '',
78
+ customStyle: ''
79
+ });
80
+ const emit = defineEmits<TextareaEmits>();
81
+ const formItem = inject(formItemKey, null);
82
+ const innerValue = ref(String(props.modelValue ?? ''));
83
+ const focused = ref(false);
84
+ const composing = ref(false);
85
+ watch(
86
+ () => props.modelValue,
87
+ value => {
88
+ const next = String(value ?? '');
89
+ if (next !== innerValue.value) innerValue.value = next;
90
+ }
91
+ );
92
+ const size = computed(() => props.size || formItem?.size.value || 'default');
93
+ const rootClass = computed(() => [
94
+ `snake-textarea--${props.border}`,
95
+ `snake-textarea--${size.value}`,
96
+ { 'is-focused': focused.value, 'is-error': Boolean(formItem?.errorVisible.value), 'is-disabled': props.disabled }
97
+ ]);
98
+ const rootStyle = computed(() => [
99
+ { height: props.autoHeight ? 'auto' : addUnit(props.height, 'rpx') },
100
+ props.customStyle
101
+ ]);
102
+ function update(value: string) {
103
+ innerValue.value = value;
104
+ emit('update:modelValue', value);
105
+ emit('input', value);
106
+ }
107
+ function onInput(event: any) {
108
+ const value = String(event.detail?.value ?? '');
109
+ if (composing.value) {
110
+ innerValue.value = value;
111
+ return;
112
+ }
113
+ update(value);
114
+ void formItem?.notify('change');
115
+ }
116
+ function onCompositionEnd(event: any) {
117
+ composing.value = false;
118
+ update(String(event.detail?.value ?? innerValue.value));
119
+ void formItem?.notify('change');
120
+ }
121
+ function onBlur(event: any) {
122
+ focused.value = false;
123
+ const value = String(event.detail?.value ?? innerValue.value);
124
+ update(value);
125
+ emit('change', value);
126
+ emit('blur', event);
127
+ void formItem?.notify('blur');
128
+ }
129
+ </script>
130
+
131
+ <style scoped>
132
+ .snake-textarea {
133
+ position: relative;
134
+ box-sizing: border-box;
135
+ width: 100%;
136
+ min-height: 160rpx;
137
+ padding: 20rpx 22rpx 42rpx;
138
+ border-radius: var(--snake-radius-md, 12rpx);
139
+ transition: border-color 0.2s;
140
+ }
141
+ .snake-textarea--surround {
142
+ border: 1px solid var(--snake-color-divider, #dcdfe6);
143
+ }
144
+ .snake-textarea--bottom {
145
+ border-bottom: 1px solid var(--snake-color-divider, #dcdfe6);
146
+ border-radius: 0;
147
+ }
148
+ .snake-textarea.is-focused {
149
+ border-color: var(--snake-color-primary, #06d290);
150
+ }
151
+ .snake-textarea.is-error {
152
+ border-color: var(--snake-color-error, #fa3534);
153
+ }
154
+ .snake-textarea.is-disabled {
155
+ background: var(--snake-color-disabled-bg, #f5f7fa);
156
+ opacity: 0.72;
157
+ }
158
+ .snake-textarea__native {
159
+ width: 100%;
160
+ height: 100%;
161
+ min-height: 120rpx;
162
+ line-height: 1.55;
163
+ }
164
+ .snake-textarea__count {
165
+ position: absolute;
166
+ right: 18rpx;
167
+ bottom: 12rpx;
168
+ color: var(--snake-color-text-muted, #909399);
169
+ font-size: 22rpx;
170
+ }
171
+ </style>