uview-pro 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 (149) hide show
  1. package/changelog.md +6 -0
  2. package/components/u-action-sheet/u-action-sheet.vue +205 -0
  3. package/components/u-alert-tips/u-alert-tips.vue +241 -0
  4. package/components/u-avatar/u-avatar.vue +220 -0
  5. package/components/u-avatar-cropper/u-avatar-cropper.vue +329 -0
  6. package/components/u-avatar-cropper/weCropper.d.ts +54 -0
  7. package/components/u-avatar-cropper/weCropper.js +1267 -0
  8. package/components/u-avatar-cropper/weCropper.ts +1254 -0
  9. package/components/u-back-top/u-back-top.vue +156 -0
  10. package/components/u-badge/u-badge.vue +189 -0
  11. package/components/u-button/u-button.vue +562 -0
  12. package/components/u-calendar/u-calendar.vue +725 -0
  13. package/components/u-car-keyboard/u-car-keyboard.vue +236 -0
  14. package/components/u-card/u-card.vue +240 -0
  15. package/components/u-cell-group/u-cell-group.vue +56 -0
  16. package/components/u-cell-item/u-cell-item.vue +245 -0
  17. package/components/u-checkbox/u-checkbox.vue +310 -0
  18. package/components/u-checkbox-group/u-checkbox-group.vue +134 -0
  19. package/components/u-circle-progress/u-circle-progress.vue +210 -0
  20. package/components/u-col/u-col.vue +135 -0
  21. package/components/u-collapse/u-collapse.vue +82 -0
  22. package/components/u-collapse-item/u-collapse-item.vue +190 -0
  23. package/components/u-column-notice/u-column-notice.vue +264 -0
  24. package/components/u-count-down/u-count-down.vue +333 -0
  25. package/components/u-count-to/u-count-to.vue +297 -0
  26. package/components/u-divider/u-divider.vue +141 -0
  27. package/components/u-dropdown/u-dropdown.vue +311 -0
  28. package/components/u-dropdown-item/u-dropdown-item.vue +135 -0
  29. package/components/u-empty/u-empty.vue +111 -0
  30. package/components/u-field/u-field.vue +469 -0
  31. package/components/u-form/u-form.vue +162 -0
  32. package/components/u-form-item/u-form-item.vue +476 -0
  33. package/components/u-full-screen/u-full-screen.vue +80 -0
  34. package/components/u-gap/u-gap.vue +48 -0
  35. package/components/u-grid/u-grid.vue +101 -0
  36. package/components/u-grid-item/u-grid-item.vue +136 -0
  37. package/components/u-icon/u-icon.vue +389 -0
  38. package/components/u-image/types.ts +48 -0
  39. package/components/u-image/u-image.vue +218 -0
  40. package/components/u-index-anchor/u-index-anchor.vue +101 -0
  41. package/components/u-index-list/u-index-list.vue +376 -0
  42. package/components/u-input/u-input.vue +462 -0
  43. package/components/u-keyboard/u-keyboard.vue +188 -0
  44. package/components/u-lazy-load/u-lazy-load.vue +288 -0
  45. package/components/u-line/u-line.vue +71 -0
  46. package/components/u-line-progress/u-line-progress.vue +128 -0
  47. package/components/u-link/u-link.vue +87 -0
  48. package/components/u-loading/u-loading.vue +111 -0
  49. package/components/u-loadmore/u-loadmore.vue +205 -0
  50. package/components/u-mask/u-mask.vue +137 -0
  51. package/components/u-message-input/u-message-input.vue +315 -0
  52. package/components/u-modal/u-modal.vue +284 -0
  53. package/components/u-navbar/u-navbar.vue +314 -0
  54. package/components/u-no-network/image.ts +2 -0
  55. package/components/u-no-network/u-no-network.vue +311 -0
  56. package/components/u-notice-bar/u-notice-bar.vue +274 -0
  57. package/components/u-number-box/u-number-box.vue +344 -0
  58. package/components/u-number-keyboard/u-number-keyboard.vue +170 -0
  59. package/components/u-parse/libs/CssHandler.js +100 -0
  60. package/components/u-parse/libs/MpHtmlParser.js +580 -0
  61. package/components/u-parse/libs/config.js +80 -0
  62. package/components/u-parse/libs/handler.wxs +22 -0
  63. package/components/u-parse/libs/trees.vue +505 -0
  64. package/components/u-parse/u-parse.vue +645 -0
  65. package/components/u-picker/u-picker.vue +808 -0
  66. package/components/u-popup/u-popup.vue +404 -0
  67. package/components/u-radio/u-radio.vue +272 -0
  68. package/components/u-radio-group/u-radio-group.vue +116 -0
  69. package/components/u-rate/u-rate.vue +349 -0
  70. package/components/u-read-more/u-read-more.vue +199 -0
  71. package/components/u-row/u-row.vue +95 -0
  72. package/components/u-row-notice/u-row-notice.vue +273 -0
  73. package/components/u-search/u-search.vue +298 -0
  74. package/components/u-section/u-section.vue +175 -0
  75. package/components/u-select/u-select.vue +387 -0
  76. package/components/u-skeleton/u-skeleton.vue +230 -0
  77. package/components/u-slider/u-slider.vue +293 -0
  78. package/components/u-steps/u-steps.vue +200 -0
  79. package/components/u-sticky/u-sticky.vue +189 -0
  80. package/components/u-subsection/u-subsection.vue +388 -0
  81. package/components/u-swipe-action/u-swipe-action.vue +289 -0
  82. package/components/u-swiper/u-swiper.vue +305 -0
  83. package/components/u-switch/u-switch.vue +146 -0
  84. package/components/u-tabbar/u-tabbar.vue +347 -0
  85. package/components/u-table/u-table.vue +104 -0
  86. package/components/u-tabs/u-tabs.vue +322 -0
  87. package/components/u-tabs-swiper/u-tabs-swiper.vue +426 -0
  88. package/components/u-tag/u-tag.vue +270 -0
  89. package/components/u-td/u-td.vue +76 -0
  90. package/components/u-th/u-th.vue +70 -0
  91. package/components/u-time-line/u-time-line.vue +39 -0
  92. package/components/u-time-line-item/u-time-line-item.vue +88 -0
  93. package/components/u-toast/types.ts +4 -0
  94. package/components/u-toast/u-toast.vue +238 -0
  95. package/components/u-top-tips/u-top-tips.vue +118 -0
  96. package/components/u-tr/u-tr.vue +24 -0
  97. package/components/u-upload/u-upload.vue +600 -0
  98. package/components/u-verification-code/u-verification-code.vue +194 -0
  99. package/components/u-waterfall/u-waterfall.vue +186 -0
  100. package/iconfont.css +910 -0
  101. package/index.scss +23 -0
  102. package/index.ts +166 -0
  103. package/libs/config/config.ts +26 -0
  104. package/libs/config/zIndex.ts +37 -0
  105. package/libs/css/color.scss +155 -0
  106. package/libs/css/common.scss +176 -0
  107. package/libs/css/style.components.scss +7 -0
  108. package/libs/css/style.h5.scss +8 -0
  109. package/libs/css/style.mp.scss +72 -0
  110. package/libs/css/style.nvue.scss +3 -0
  111. package/libs/css/style.vue.scss +175 -0
  112. package/libs/function/$parent.ts +22 -0
  113. package/libs/function/addUnit.ts +13 -0
  114. package/libs/function/color.ts +37 -0
  115. package/libs/function/colorGradient.ts +123 -0
  116. package/libs/function/debounce.ts +28 -0
  117. package/libs/function/deepClone.ts +39 -0
  118. package/libs/function/deepMerge.ts +34 -0
  119. package/libs/function/getParent.ts +59 -0
  120. package/libs/function/getRect.ts +26 -0
  121. package/libs/function/guid.ts +42 -0
  122. package/libs/function/md5.ts +397 -0
  123. package/libs/function/parent.ts +21 -0
  124. package/libs/function/queryParams.ts +60 -0
  125. package/libs/function/random.ts +16 -0
  126. package/libs/function/randomArray.ts +11 -0
  127. package/libs/function/route.ts +118 -0
  128. package/libs/function/sys.ts +15 -0
  129. package/libs/function/test.ts +229 -0
  130. package/libs/function/throttle.ts +31 -0
  131. package/libs/function/timeFormat.ts +54 -0
  132. package/libs/function/timeFrom.ts +48 -0
  133. package/libs/function/toast.ts +14 -0
  134. package/libs/function/trim.ts +21 -0
  135. package/libs/function/type2icon.ts +36 -0
  136. package/libs/hooks/useEmitter.ts +77 -0
  137. package/libs/hooks/useParent.ts +29 -0
  138. package/libs/request/index.ts +237 -0
  139. package/libs/store/index.ts +88 -0
  140. package/libs/util/area.ts +1 -0
  141. package/libs/util/async-validator.js +1356 -0
  142. package/libs/util/city.ts +1 -0
  143. package/libs/util/emitter.ts +112 -0
  144. package/libs/util/mitt.ts +118 -0
  145. package/libs/util/parent.ts +20 -0
  146. package/libs/util/province.ts +1 -0
  147. package/package.json +98 -0
  148. package/readme.md +165 -0
  149. package/theme.scss +38 -0
@@ -0,0 +1,322 @@
1
+ <template>
2
+ <view class="u-tabs" :style="{ background: bgColor }">
3
+ <!-- $u.getRect()对组件根节点无效,因为写了.in(this),故这里获取内层接点尺寸 -->
4
+ <view>
5
+ <scroll-view scroll-x class="u-scroll-view" :scroll-left="scrollLeft" scroll-with-animation>
6
+ <view class="u-scroll-box" :id="id" :class="{ 'u-tabs-scroll-flex': !isScroll }">
7
+ <view class="u-tab-item u-line-1" :id="'u-tab-item-' + index" v-for="(item, index) in list" :key="index" @tap="clickTab(index)" :style="tabItemStyle(index)">
8
+ <u-badge :count="item[count] || item['count'] || 0" :offset="offset" size="mini"></u-badge>
9
+ {{ item[name] || item['name'] }}
10
+ </view>
11
+ <view v-if="showBar" class="u-tab-bar" :style="tabBarStyle"></view>
12
+ </view>
13
+ </scroll-view>
14
+ </view>
15
+ </view>
16
+ </template>
17
+
18
+ <script setup lang="ts">
19
+ import { ref, computed, watch, onMounted, nextTick, getCurrentInstance } from 'vue';
20
+ import { $u } from '../..';
21
+
22
+ defineOptions({ name: 'u-tabs' });
23
+
24
+ /**
25
+ * tabs 标签
26
+ * @description 该组件,是一个tabs标签组件,在标签多的时候,可以配置为左右滑动,标签少的时候,可以禁止滑动。 该组件的一个特点是配置为滚动模式时,激活的tab会自动移动到组件的中间位置。
27
+ * @tutorial https://www.uviewui.com/components/tabs.html
28
+ * @property {Boolean} is-scroll tabs是否可以左右拖动(默认true)
29
+ * @property {Array} list 标签数组,元素为对象,如[{name: '推荐'}]
30
+ * @property {String|Number} current 指定哪个tab为激活状态(默认0)
31
+ * @property {String|Number} height 导航栏的高度,单位rpx(默认80)
32
+ * @property {String|Number} font-size tab文字大小,单位rpx(默认30)
33
+ * @property {String|Number} duration 滑块移动一次所需的时间,单位秒(默认0.5)
34
+ * @property {String} active-color 滑块和激活tab文字的颜色(默认#2979ff)
35
+ * @property {String} inactive-color tabs文字颜色(默认#303133)
36
+ * @property {String|Number} bar-width 滑块宽度,单位rpx(默认40)
37
+ * @property {Object} active-item-style 活动tabs item的样式,对象形式
38
+ * @property {Object} bar-style 底部滑块的样式,对象形式
39
+ * @property {Boolean} show-bar 是否显示底部的滑块(默认true)
40
+ * @property {String|Number} bar-height 滑块高度,单位rpx(默认6)
41
+ * @property {String|Number} item-width 标签的宽度(默认auto)
42
+ * @property {String|Number} gutter 单个tab标签的左右内边距之和,单位rpx(默认40)
43
+ * @property {String} bg-color tabs导航栏的背景颜色(默认#ffffff)
44
+ * @property {String} name 组件内部读取的list参数中的属性名(tab名称),见官网说明(默认name)
45
+ * @property {String} count 组件内部读取的list参数中的属性名(badge徽标数),同name属性的使用,见官网说明(默认count)
46
+ * @property {Array} offset 设置badge徽标数的位置偏移,格式为 [x, y],也即设置的为top和right的值,单位rpx(默认[5, 20])
47
+ * @property {Boolean} bold 激活选项的字体是否加粗(默认true)
48
+ * @event {Function} change 点击标签时触发
49
+ * @example <u-tabs ref="tabs" :list="list" :is-scroll="false"></u-tabs>
50
+ */
51
+
52
+ // props 定义,保留参数注释
53
+ const props = defineProps({
54
+ /** tabs是否可以左右拖动 */
55
+ isScroll: { type: Boolean, default: true },
56
+ /** 标签数组 */
57
+ list: { type: Array as () => Array<Record<string, any>>, default: () => [] },
58
+ /** 当前活动tab的索引 */
59
+ current: { type: [Number, String], default: 0 },
60
+ /** 导航栏的高度和行高 */
61
+ height: { type: [String, Number], default: 80 },
62
+ /** 字体大小 */
63
+ fontSize: { type: [String, Number], default: 30 },
64
+ /** 过渡动画时长, 单位s */
65
+ duration: { type: [String, Number], default: 0.5 },
66
+ /** 选中项的主题颜色 */
67
+ activeColor: { type: String, default: '#2979ff' },
68
+ /** 未选中项的颜色 */
69
+ inactiveColor: { type: String, default: '#303133' },
70
+ /** 菜单底部移动的bar的宽度,单位rpx */
71
+ barWidth: { type: [String, Number], default: 40 },
72
+ /** 移动bar的高度 */
73
+ barHeight: { type: [String, Number], default: 6 },
74
+ /** 单个tab的左右内边距之和,单位rpx */
75
+ gutter: { type: [String, Number], default: 30 },
76
+ /** 导航栏的背景颜色 */
77
+ bgColor: { type: String, default: '#ffffff' },
78
+ /** 读取传入的数组对象的属性(tab名称) */
79
+ name: { type: String, default: 'name' },
80
+ /** 读取传入的数组对象的属性(徽标数) */
81
+ count: { type: String, default: 'count' },
82
+ /** 徽标数位置偏移 */
83
+ offset: { type: Array, default: () => [5, 20] },
84
+ /** 活动tab字体是否加粗 */
85
+ bold: { type: Boolean, default: true },
86
+ /** 当前活动tab item的样式 */
87
+ activeItemStyle: { type: Object, default: () => ({}) },
88
+ /** 是否显示底部的滑块 */
89
+ showBar: { type: Boolean, default: true },
90
+ /** 底部滑块的自定义样式 */
91
+ barStyle: { type: Object, default: () => ({}) },
92
+ /** 标签的宽度 */
93
+ itemWidth: { type: [Number, String], default: 'auto' }
94
+ });
95
+
96
+ // emits 定义
97
+ const emit = defineEmits(['change']);
98
+ const instance = getCurrentInstance();
99
+ // 滚动scroll-view的左边滚动距离
100
+ const scrollLeft = ref(0);
101
+ // 存放对tab菜单查询后的节点信息
102
+ const tabQueryInfo = ref<any[]>([]);
103
+ // 屏幕宽度,单位为px
104
+ const componentWidth = ref(0);
105
+ // 移动bar需要通过translateX()移动的距离
106
+ const scrollBarLeft = ref(0);
107
+ // 父元素(tabs组件)到屏幕左边的距离
108
+ const parentLeft = ref(0);
109
+ // id值
110
+ const id = ref($u.guid());
111
+ // 当前活动tab索引
112
+ const currentIndex = ref(props.current);
113
+ // 滑块第一次移动时(页面刚生成时),无需动画,否则给人怪异的感觉
114
+ const barFirstTimeMove = ref(true);
115
+
116
+ // 监听list变化,重置索引并重新布局
117
+ // 监听tab的变化,重新计算tab菜单的布局信息,因为实际使用中菜单可能是通过
118
+ // 后台获取的(如新闻app顶部的菜单),获取返回需要一定时间,所以list变化时,重新获取布局信息
119
+ watch(
120
+ () => props.list,
121
+ (n, o) => {
122
+ // list变动时,重制内部索引,否则可能导致超出数组边界的情况
123
+ if (n.length !== o.length) currentIndex.value = 0;
124
+ // 用$nextTick等待视图更新完毕后再计算tab的局部信息,否则可能因为tab还没生成就获取,就会有问题
125
+ nextTick(() => {
126
+ init();
127
+ });
128
+ }
129
+ );
130
+
131
+ // 监听current变化,自动滚动
132
+ watch(
133
+ () => props.current,
134
+ nVal => {
135
+ // 视图更新后再执行移动操作
136
+ nextTick(() => {
137
+ currentIndex.value = nVal;
138
+ scrollByIndex();
139
+ });
140
+ },
141
+ { immediate: true }
142
+ );
143
+
144
+ // 移动bar的样式
145
+ const tabBarStyle = computed(() => {
146
+ const style: Record<string, any> = {
147
+ width: props.barWidth + 'rpx',
148
+ transform: `translate(${scrollBarLeft.value}px, -100%)`,
149
+ // 滑块在页面渲染后第一次滑动时,无需动画效果
150
+ 'transition-duration': `${barFirstTimeMove.value ? 0 : props.duration}s`,
151
+ 'background-color': props.activeColor,
152
+ height: props.barHeight + 'rpx',
153
+ opacity: barFirstTimeMove.value ? 0 : 1,
154
+ // 设置一个很大的值,它会自动取能用的最大值,不用高度的一半,是因为高度可能是单数,会有小数出现
155
+ 'border-radius': `${Number(props.barHeight) / 2}px`
156
+ };
157
+ Object.assign(style, props.barStyle);
158
+ return style;
159
+ });
160
+
161
+ // tab的样式
162
+ function tabItemStyle(index: number) {
163
+ let style: Record<string, any> = {
164
+ height: props.height + 'rpx',
165
+ 'line-height': props.height + 'rpx',
166
+ 'font-size': props.fontSize + 'rpx',
167
+ 'transition-duration': `${props.duration}s`,
168
+ padding: props.isScroll ? `0 ${props.gutter}rpx` : '',
169
+ flex: props.isScroll ? 'auto' : '1',
170
+ width: $u.addUnit(props.itemWidth)
171
+ };
172
+ // 字体加粗
173
+ if (index == Number(currentIndex.value) && props.bold) style.fontWeight = 'bold';
174
+ if (index == Number(currentIndex.value)) {
175
+ style.color = props.activeColor;
176
+ // 给选中的tab item添加外部自定义的样式
177
+ style = Object.assign(style, props.activeItemStyle);
178
+ } else {
179
+ style.color = props.inactiveColor;
180
+ }
181
+ return style;
182
+ }
183
+
184
+ /**
185
+ * 初始化tab布局信息
186
+ */
187
+ async function init() {
188
+ // 获取tabs组件的尺寸信息
189
+ const tabRect = await $u.getRect('#' + id.value, instance);
190
+ // tabs组件距离屏幕左边的宽度
191
+ parentLeft.value = tabRect.left;
192
+ // tabs组件的宽度
193
+ componentWidth.value = tabRect.width;
194
+ getTabRect();
195
+ }
196
+
197
+ /**
198
+ * 点击某一个tab菜单
199
+ */
200
+ function clickTab(index: number) {
201
+ // 点击当前活动tab,不触发事件
202
+ if (index == currentIndex.value) return;
203
+ // 发送事件给父组件
204
+ emit('change', index);
205
+ }
206
+
207
+ /**
208
+ * 查询tab的布局信息
209
+ */
210
+ function getTabRect() {
211
+ // 创建节点查询
212
+ const query = uni.createSelectorQuery().in(instance?.proxy);
213
+ // 历遍所有tab,这里是执行了查询,最终使用exec()会一次性返回查询的数组结果
214
+ for (let i = 0; i < props.list.length; i++) {
215
+ // 只要size和rect两个参数
216
+ query.select(`#u-tab-item-${i}`).fields({ size: true, rect: true }, () => {});
217
+ }
218
+ // 执行查询,一次性获取多个结果
219
+ query.exec((res: any[]) => {
220
+ tabQueryInfo.value = res;
221
+ // 初始化滚动条和移动bar的位置
222
+ scrollByIndex();
223
+ });
224
+ }
225
+
226
+ /**
227
+ * 滚动scroll-view,让活动的tab处于屏幕的中间位置
228
+ */
229
+ function scrollByIndex() {
230
+ // 当前活动tab的布局信息,有tab菜单的width和left(为元素左边界到父元素左边界的距离)等信息
231
+ const tabInfo = tabQueryInfo.value[Number(currentIndex.value)];
232
+ if (!tabInfo) return;
233
+ // 活动tab的宽度
234
+ const tabWidth = tabInfo.width;
235
+ // 活动item的左边到tabs组件左边的距离,用item的left减去tabs的left
236
+ const offsetLeft = tabInfo.left - parentLeft.value;
237
+ // 将活动的tabs-item移动到屏幕正中间,实际上是对scroll-view的移动
238
+ const scrollL = offsetLeft - (componentWidth.value - tabWidth) / 2;
239
+ scrollLeft.value = scrollL < 0 ? 0 : scrollL;
240
+ // 当前活动item的中点点到左边的距离减去滑块宽度的一半,即可得到滑块所需的移动距离
241
+ const left = tabInfo.left + tabInfo.width / 2 - parentLeft.value;
242
+ // 计算当前活跃item到组件左边的距离
243
+ scrollBarLeft.value = left - uni.upx2px(Number(props.barWidth)) / 2;
244
+ // 第一次移动滑块的时候,barFirstTimeMove为true,放到延时中将其设置false
245
+ // 延时是因为scrollBarLeft作用于computed计算时,需要一个过程需,否则导致出错
246
+ if (barFirstTimeMove.value) {
247
+ setTimeout(() => {
248
+ barFirstTimeMove.value = false;
249
+ }, 100);
250
+ }
251
+ }
252
+
253
+ onMounted(() => {
254
+ init();
255
+ });
256
+
257
+ defineExpose({ init, clickTab, scrollByIndex });
258
+ </script>
259
+
260
+ <style lang="scss" scoped>
261
+ @import '../../libs/css/style.components.scss';
262
+
263
+ view,
264
+ scroll-view {
265
+ box-sizing: border-box;
266
+ }
267
+
268
+ /* #ifndef APP-NVUE */
269
+ ::-webkit-scrollbar,
270
+ ::-webkit-scrollbar,
271
+ ::-webkit-scrollbar {
272
+ display: none;
273
+ width: 0 !important;
274
+ height: 0 !important;
275
+ -webkit-appearance: none;
276
+ background: transparent;
277
+ }
278
+ /* #endif */
279
+
280
+ .u-scroll-box {
281
+ position: relative;
282
+ /* #ifdef MP-TOUTIAO */
283
+ white-space: nowrap;
284
+ /* #endif */
285
+ }
286
+
287
+ /* #ifdef H5 */
288
+ // 通过样式穿透,隐藏H5下,scroll-view下的滚动条
289
+ scroll-view ::v-deep ::-webkit-scrollbar {
290
+ display: none;
291
+ width: 0 !important;
292
+ height: 0 !important;
293
+ -webkit-appearance: none;
294
+ background: transparent;
295
+ }
296
+ /* #endif */
297
+
298
+ .u-scroll-view {
299
+ width: 100%;
300
+ white-space: nowrap;
301
+ position: relative;
302
+ }
303
+
304
+ .u-tab-item {
305
+ position: relative;
306
+ /* #ifndef APP-NVUE */
307
+ display: inline-block;
308
+ /* #endif */
309
+ text-align: center;
310
+ transition-property: background-color, color;
311
+ }
312
+
313
+ .u-tab-bar {
314
+ position: absolute;
315
+ bottom: 0;
316
+ }
317
+
318
+ .u-tabs-scroll-flex {
319
+ @include vue-flex;
320
+ justify-content: space-between;
321
+ }
322
+ </style>