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,426 @@
1
+ <template>
2
+ <view class="u-tabs" :style="{ zIndex: zIndex, background: bgColor }">
3
+ <scroll-view scroll-x class="u-scroll-view" :scroll-left="scrollLeft" scroll-with-animation :style="{ zIndex: Number(zIndex) + 1 }">
4
+ <view class="u-tabs-scroll-box" :class="{ 'u-tabs-scroll-flex': !isScroll }">
5
+ <view class="u-tabs-item" :style="tabItemStyle(index)" v-for="(item, index) in getTabs" :key="index" :class="[preId + index]" @tap="emitTabChange(index)">
6
+ <u-badge :count="item[count] || item['count'] || 0" :offset="offset" size="mini"></u-badge>
7
+ {{ item[name] || item['name'] }}
8
+ </view>
9
+ <view v-if="showBar" class="u-scroll-bar" :style="tabBarStyle"></view>
10
+ </view>
11
+ </scroll-view>
12
+ </view>
13
+ </template>
14
+
15
+ <script setup lang="ts">
16
+ import { ref, computed, watch, nextTick, onMounted, getCurrentInstance } from 'vue';
17
+ import colorGradient from '../../libs/function/colorGradient';
18
+
19
+ defineOptions({ name: 'u-tabs-swiper' });
20
+
21
+ /**
22
+ * tabsSwiper 全屏选项卡
23
+ * @description 该组件内部实现主要依托于uniapp的scroll-view和swiper组件,主要特色是切换过程中,tabsSwiper文字的颜色可以渐变,底部滑块可以 跟随式滑动,活动tab滚动居中等。应用场景可以用于需要左右切换页面,比如商城的订单中心(待收货-待付款-待评价-已退货)等应用场景。
24
+ * @tutorial https://www.uviewui.com/components/tabsSwiper.html
25
+ * @property {Boolean} is-scroll tabs是否可以左右拖动(默认true)
26
+ * @property {Array} list 标签数组,元素为对象,如[{name: '推荐'}]
27
+ * @property {String|Number} current 指定哪个tab为激活状态(默认0)
28
+ * @property {String|Number} height 导航栏的高度,单位rpx(默认80)
29
+ * @property {String|Number} font-size tab文字大小,单位rpx(默认30)
30
+ * @property {String|Number} swiper-width tabs组件外部swiper的宽度,默认为屏幕宽度,单位rpx(默认750)
31
+ * @property {String} active-color 滑块和激活tab文字的颜色(默认#2979ff)
32
+ * @property {String} inactive-color tabs文字颜色(默认#303133)
33
+ * @property {String|Number} bar-width 滑块宽度,单位rpx(默认40)
34
+ * @property {String|Number} bar-height 滑块高度,单位rpx(默认6)
35
+ * @property {Object} bar-style 底部滑块的样式,对象形式
36
+ * @property {Object} active-item-style 活动tabs item的样式,对象形式
37
+ * @property {Boolean} show-bar 是否显示底部的滑块(默认true)
38
+ * @property {String|Number} gutter 单个tab标签的左右内边距之和,单位rpx(默认40)
39
+ * @property {String} bg-color tabs导航栏的背景颜色(默认#ffffff)
40
+ * @property {String} name 组件内部读取的list参数中的属性名,见官网说明(默认name)
41
+ * @property {String} count 组件内部读取的list参数中的属性名(badge徽标数),同name属性的使用,见官网说明(默认count)
42
+ * @property {Array} offset 设置badge徽标数的位置偏移,格式为 [x, y],也即设置的为top和right的值,单位rpx(默认[5, 20])
43
+ * @property {Boolean} bold 激活选项的字体是否加粗(默认true)
44
+ * @event {Function} change 点击标签时触发
45
+ * @example <u-tabs-swiper ref="tabs" :list="list" :is-scroll="false"></u-tabs-swiper>
46
+ */
47
+
48
+ // props 定义,保留参数注释
49
+ const props = defineProps({
50
+ /** tabs是否可以左右拖动 */
51
+ isScroll: { type: Boolean, default: true },
52
+ /** 标签数组 */
53
+ list: { type: Array as () => Array<Record<string, any>>, default: () => [] },
54
+ /** 当前活动tab的索引 */
55
+ current: { type: [Number, String], default: 0 },
56
+ /** 导航栏的高度和行高,单位rpx */
57
+ height: { type: [Number, String], default: 80 },
58
+ /** 字体大小,单位rpx */
59
+ fontSize: { type: [Number, String], default: 30 },
60
+ // 过渡动画时长, 单位s
61
+ // duration: {
62
+ // type: [Number, String],
63
+ // default: 0.5
64
+ // },
65
+ /** 外部swiper的宽度, 单位rpx */
66
+ swiperWidth: { type: [String, Number], default: 750 },
67
+ /** 选中项的主题颜色 */
68
+ activeColor: { type: String, default: '#2979ff' },
69
+ /** 未选中项的颜色 */
70
+ inactiveColor: { type: String, default: '#303133' },
71
+ /** 菜单底部移动的bar的宽度,单位rpx */
72
+ barWidth: { type: [Number, String], default: 40 },
73
+ /** 移动bar的高度 */
74
+ barHeight: { type: [Number, String], default: 6 },
75
+ /** 单个tab的左或右内边距(各占一半),单位rpx */
76
+ gutter: { type: [Number, String], default: 40 },
77
+ /** 如果是绝对定位,添加z-index值 */
78
+ zIndex: { type: [Number, String], default: 1 },
79
+ /** 导航栏的背景颜色 */
80
+ bgColor: { type: String, default: '#ffffff' },
81
+ /** 滚动至中心目标类型 */
82
+ autoCenterMode: { type: String, default: 'window' },
83
+ /** 读取传入的数组对象的属性(tab名称) */
84
+ name: { type: String, default: 'name' },
85
+ /** 读取传入的数组对象的属性(徽标数) */
86
+ count: { type: String, default: 'count' },
87
+ /** 徽标数位置偏移 */
88
+ offset: { type: Array, default: () => [5, 20] },
89
+ /** 活动tab字体是否加粗 */
90
+ bold: { type: Boolean, default: true },
91
+ /** 当前活动tab item的样式 */
92
+ activeItemStyle: { type: Object, default: () => ({}) },
93
+ /** 是否显示底部的滑块 */
94
+ showBar: { type: Boolean, default: true },
95
+ /** 底部滑块的自定义样式 */
96
+ barStyle: { type: Object, default: () => ({}) }
97
+ });
98
+
99
+ const color = colorGradient;
100
+ const { windowWidth } = uni.getSystemInfoSync();
101
+ const preId = 'UEl_';
102
+
103
+ // emits 定义
104
+ const emit = defineEmits(['change']);
105
+ const instance = getCurrentInstance();
106
+ // 滚动scroll-view的左边滚动距离
107
+ const scrollLeft = ref(0);
108
+ // 存放对tab菜单查询后的节点信息
109
+ const tabQueryInfo = ref<any[]>([]);
110
+ // 屏幕宽度,单位为px
111
+ const componentsWidth = ref(0);
112
+ // 滑块需要通过translateX()移动的距离
113
+ const line3Dx = ref(0);
114
+ const line3AddDx = ref(0);
115
+ const animationFinishCurrent = ref(Number(props.current));
116
+ // 两个颜色之间的渐变等分
117
+ const colorStep = ref(100);
118
+ const colorGradientArr = ref<string[]>([]);
119
+ const tabsInfo = ref<any[]>([]);
120
+ const sW = ref(uni.upx2px(Number(props.swiperWidth)));
121
+
122
+ // 计算当前活跃tab索引
123
+ const getCurrent = computed(() => {
124
+ const current = Number(props.current);
125
+ // 判断是否超出边界
126
+ if (current > getTabs.value.length - 1) return getTabs.value.length - 1;
127
+ if (current < 0) return 0;
128
+ return current;
129
+ });
130
+
131
+ // 获取tabs数组
132
+ const getTabs = computed(() => props.list);
133
+
134
+ // 滑块需要移动的距离
135
+ const scrollBarLeft = computed(() => Number(line3Dx.value) + Number(line3AddDx.value));
136
+
137
+ // 滑块宽度转为px单位
138
+ const barWidthPx = computed(() => uni.upx2px(Number(props.barWidth)));
139
+
140
+ // tab的样式
141
+ function tabItemStyle(index: number) {
142
+ let style: Record<string, any> = {
143
+ height: props.height + 'rpx',
144
+ lineHeight: props.height + 'rpx',
145
+ padding: `0 ${Number(props.gutter) / 2}rpx`,
146
+ color: tabsInfo.value.length > 0 ? (tabsInfo.value[index] ? tabsInfo.value[index].color : props.activeColor) : props.inactiveColor,
147
+ fontSize: props.fontSize + 'rpx',
148
+ zIndex: Number(props.zIndex) + 2,
149
+ fontWeight: index == getCurrent.value && props.bold ? 'bold' : 'normal'
150
+ };
151
+ if (index == getCurrent.value) {
152
+ // 给选中的tab item添加外部自定义的样式
153
+ style = Object.assign(style, props.activeItemStyle);
154
+ }
155
+ return style;
156
+ }
157
+
158
+ // 底部滑块的样式
159
+ const tabBarStyle = computed(() => {
160
+ let style: Record<string, any> = {
161
+ width: barWidthPx.value + 'px',
162
+ height: props.barHeight + 'rpx',
163
+ borderRadius: '100px',
164
+ backgroundColor: props.activeColor,
165
+ left: scrollBarLeft.value + 'px'
166
+ };
167
+ return Object.assign(style, props.barStyle);
168
+ });
169
+
170
+ // 颜色渐变过程数组
171
+ function updateColorGradientArr() {
172
+ colorGradientArr.value = color.colorGradient(props.inactiveColor, props.activeColor, colorStep.value);
173
+ }
174
+
175
+ // tabsInfo 计算
176
+ async function getTabsInfo() {
177
+ return new Promise<void>(resolve => {
178
+ const view = uni.createSelectorQuery().in(instance?.proxy);
179
+ for (let i = 0; i < props.list.length; i++) {
180
+ view.select('.' + preId + i).boundingClientRect();
181
+ }
182
+ view.exec((res: any[]) => {
183
+ const arr: any[] = [];
184
+ for (let i = 0; i < res.length; i++) {
185
+ // 给每个tab添加其文字颜色属性
186
+ res[i].color = props.inactiveColor;
187
+ // 当前tab直接赋予activeColor
188
+ if (i == getCurrent.value) res[i].color = props.activeColor;
189
+ arr.push(res[i]);
190
+ }
191
+ tabsInfo.value = arr;
192
+ resolve();
193
+ });
194
+ });
195
+ }
196
+
197
+ // 当swiper滑动结束,计算滑块最终要停留的位置
198
+ function countLine3Dx() {
199
+ const tab = tabsInfo.value[animationFinishCurrent.value];
200
+ // 让滑块中心点和当前tab中心重合
201
+ if (tab) line3Dx.value = tab.left + tab.width / 2 - barWidthPx.value / 2 - tabsInfo.value[0].left;
202
+ }
203
+
204
+ // swiper宽度由rpx转为px单位
205
+ function countPx() {
206
+ // swiper宽度由rpx转为px单位,因为dx等,都是px单位
207
+ sW.value = uni.upx2px(Number(props.swiperWidth));
208
+ }
209
+
210
+ // 触发change事件
211
+ function emitTabChange(index: number) {
212
+ emit('change', index);
213
+ }
214
+
215
+ // 滚动居中
216
+ function setScrollViewToCenter() {
217
+ const tab = tabsInfo.value[animationFinishCurrent.value];
218
+ if (tab) {
219
+ const tabCenter = tab.left + tab.width / 2;
220
+ let fatherWidth;
221
+ if (props.autoCenterMode === 'window') fatherWidth = windowWidth;
222
+ else fatherWidth = componentsWidth.value;
223
+ scrollLeft.value = tabCenter - fatherWidth / 2;
224
+ }
225
+ }
226
+
227
+ // 查询tab组件宽度
228
+ function getQuery(cb?: (data: any) => void) {
229
+ try {
230
+ const view = uni.createSelectorQuery().in(instance?.proxy).select('.u-tabs');
231
+ view.fields({ size: true }, (data: any) => {
232
+ if (data) {
233
+ componentsWidth.value = data.width;
234
+ if (cb) cb(data);
235
+ } else {
236
+ getQuery(cb);
237
+ }
238
+ }).exec();
239
+ } catch (e) {
240
+ componentsWidth.value = windowWidth;
241
+ }
242
+ }
243
+
244
+ // 颜色渐变tab滑动
245
+ function setDx(dx: number) {
246
+ let nextTabIndex = dx > 0 ? animationFinishCurrent.value + 1 : animationFinishCurrent.value - 1;
247
+ // 判断索引是否超出边界
248
+ nextTabIndex = nextTabIndex <= 0 ? 0 : nextTabIndex;
249
+ nextTabIndex = nextTabIndex >= props.list.length ? props.list.length - 1 : nextTabIndex;
250
+ const tab = tabsInfo.value[nextTabIndex];
251
+ // 当前tab中心点x轴坐标
252
+ const nowTab = tabsInfo.value[animationFinishCurrent.value];
253
+ const nowTabX = nowTab.left + nowTab.width / 2;
254
+ // 下一个tab
255
+ const nextTabX = tab.left + tab.width / 2;
256
+ // 两个tab之间的距离,因为下一个tab可能在当前tab的左边或者右边,取绝对值即可
257
+ const distanceX = Math.abs(nextTabX - nowTabX);
258
+ line3AddDx.value = (dx / sW.value) * distanceX;
259
+ setTabColor(animationFinishCurrent.value, nextTabIndex, dx);
260
+ }
261
+
262
+ // 设置tab的颜色
263
+ function setTabColor(nowTabIndex: number, nextTabIndex: number, dx: number) {
264
+ let colorIndex = Math.abs(Math.ceil((dx / sW.value) * 100));
265
+ const colorLength = colorGradientArr.value.length;
266
+ // 处理超出索引边界的情况
267
+ colorIndex = colorIndex >= colorLength ? colorLength - 1 : colorIndex <= 0 ? 0 : colorIndex;
268
+ // 设置下一个tab的颜色
269
+ tabsInfo.value[nextTabIndex].color = colorGradientArr.value[colorIndex];
270
+ // 设置当前tab的颜色
271
+ tabsInfo.value[nowTabIndex].color = colorGradientArr.value[colorLength - 1 - colorIndex];
272
+ }
273
+
274
+ // swiper结束滑动
275
+ function setFinishCurrent(current: number) {
276
+ // 如果滑动的索引不一致,修改tab颜色变化,因为可能会有直接点击tab的情况
277
+ tabsInfo.value = tabsInfo.value.map((val, index) => {
278
+ val.color = current == index ? props.activeColor : props.inactiveColor;
279
+ return val;
280
+ });
281
+ line3AddDx.value = 0;
282
+ animationFinishCurrent.value = current;
283
+ countLine3Dx();
284
+ }
285
+
286
+ // 监听current变化
287
+ watch(
288
+ () => props.current,
289
+ n => {
290
+ setFinishCurrent(Number(n));
291
+ }
292
+ );
293
+
294
+ // 监听list变化
295
+ watch(
296
+ () => props.list,
297
+ () => {
298
+ nextTick(() => {
299
+ init();
300
+ });
301
+ }
302
+ );
303
+
304
+ // 初始化
305
+ async function init() {
306
+ countPx();
307
+ await getTabsInfo();
308
+ countLine3Dx();
309
+ getQuery(() => {
310
+ setScrollViewToCenter();
311
+ });
312
+ updateColorGradientArr();
313
+ }
314
+
315
+ onMounted(() => {
316
+ init();
317
+ });
318
+
319
+ defineExpose({ init, emit, setDx, setFinishCurrent, setTabColor, setScrollViewToCenter });
320
+ </script>
321
+
322
+ <style scoped lang="scss">
323
+ @import '../../libs/css/style.components.scss';
324
+
325
+ view,
326
+ scroll-view {
327
+ box-sizing: border-box;
328
+ }
329
+
330
+ .u-tabs {
331
+ width: 100%;
332
+ transition-property: background-color, color;
333
+ }
334
+
335
+ /* #ifndef APP-NVUE */
336
+ ::-webkit-scrollbar,
337
+ ::-webkit-scrollbar,
338
+ ::-webkit-scrollbar {
339
+ display: none;
340
+ width: 0 !important;
341
+ height: 0 !important;
342
+ -webkit-appearance: none;
343
+ background: transparent;
344
+ }
345
+ /* #endif */
346
+
347
+ /* #ifdef H5 */
348
+ // 通过样式穿透,隐藏H5下,scroll-view下的滚动条
349
+ scroll-view ::v-deep ::-webkit-scrollbar {
350
+ display: none;
351
+ width: 0 !important;
352
+ height: 0 !important;
353
+ -webkit-appearance: none;
354
+ background: transparent;
355
+ }
356
+
357
+ /* #endif */
358
+
359
+ .u-scroll-view {
360
+ width: 100%;
361
+ white-space: nowrap;
362
+ position: relative;
363
+ }
364
+
365
+ .u-tabs-scroll-box {
366
+ position: relative;
367
+ }
368
+
369
+ .u-tabs-scroll-flex {
370
+ @include vue-flex;
371
+ justify-content: space-between;
372
+ }
373
+
374
+ .u-tabs-scroll-flex .u-tabs-item {
375
+ flex: 1;
376
+ }
377
+
378
+ .u-tabs-item {
379
+ position: relative;
380
+ display: inline-block;
381
+ text-align: center;
382
+ transition-property: background-color, color, font-weight;
383
+ }
384
+
385
+ .content {
386
+ overflow: hidden;
387
+ white-space: nowrap;
388
+ text-overflow: ellipsis;
389
+ }
390
+
391
+ .boxStyle {
392
+ pointer-events: none;
393
+ position: absolute;
394
+ transition-property: all;
395
+ }
396
+
397
+ .boxStyle2 {
398
+ pointer-events: none;
399
+ position: absolute;
400
+ bottom: 0;
401
+ transition-property: all;
402
+ transform: translateY(-100%);
403
+ }
404
+
405
+ .itemBackgroundBox {
406
+ pointer-events: none;
407
+ position: absolute;
408
+ top: 0;
409
+ transition-property: left, background-color;
410
+ @include vue-flex;
411
+ flex-direction: row;
412
+ justify-content: center;
413
+ align-items: center;
414
+ }
415
+
416
+ .itemBackground {
417
+ height: 100%;
418
+ width: 100%;
419
+ transition-property: all;
420
+ }
421
+
422
+ .u-scroll-bar {
423
+ position: absolute;
424
+ bottom: 4rpx;
425
+ }
426
+ </style>
@@ -0,0 +1,270 @@
1
+ <template>
2
+ <view
3
+ v-if="show"
4
+ :class="[disabled ? 'u-disabled' : '', 'u-size-' + size, 'u-shape-' + shape, 'u-mode-' + mode + '-' + type]"
5
+ class="u-tag"
6
+ :style="[customStyle]"
7
+ @tap="clickTag"
8
+ >
9
+ {{ text }}
10
+ <view class="u-icon-wrap" @tap.stop>
11
+ <u-icon @click="close" size="22" v-if="closeable" :color="closeIconColor" name="close" class="u-close-icon" :style="[iconStyle]"></u-icon>
12
+ </view>
13
+ </view>
14
+ </template>
15
+
16
+ <script setup lang="ts">
17
+ import { computed } from 'vue';
18
+
19
+ defineOptions({
20
+ name: 'u-tag'
21
+ });
22
+
23
+ /**
24
+ * tag 提示
25
+ * @description 该组件一般用于标记和选择
26
+ * @tutorial https://www.uviewui.com/components/tag.html
27
+ * @property {String} type 主题类型(默认primary)
28
+ * @property {String} size 标签大小(默认default)
29
+ * @property {String} shape 标签形状(默认square)
30
+ * @property {String} text 标签的文字内容
31
+ * @property {String} bg-color 自定义标签的背景颜色
32
+ * @property {String} border-color 标签的边框颜色
33
+ * @property {String} close-color 关闭按钮的颜色
34
+ * @property {String|Number} index 点击标签时,会通过click事件返回该值
35
+ * @property {String} mode 模式选择,见官网说明(默认light)
36
+ * @property {Boolean} closeable 是否可关闭,设置为true,文字右边会出现一个关闭图标(默认false)
37
+ * @property {Boolean} show 标签显示与否(默认true)
38
+ * @event {Function} click 点击标签触发
39
+ * @event {Function} close closeable为true时,点击标签关闭按钮触发
40
+ * @example <u-tag text="雪月夜" type="success" />
41
+ */
42
+
43
+ const emit = defineEmits<{
44
+ (e: 'click', index: string | number): void;
45
+ (e: 'close', index: string | number): void;
46
+ }>();
47
+
48
+ const props = defineProps({
49
+ /** 标签类型 info、primary、success、warning、error */
50
+ type: { type: String, default: 'primary' },
51
+ /** 是否禁用这个标签,禁用的话,会屏蔽点击事件 */
52
+ disabled: { type: [Boolean, String], default: false },
53
+ /** 标签的大小,分为default(默认),mini(较小) */
54
+ size: { type: String, default: 'default' },
55
+ /** tag的形状,circle(两边半圆形), square(方形,带圆角),circleLeft(左边是半圆),circleRight(右边是半圆) */
56
+ shape: { type: String, default: 'square' },
57
+ /** 标签文字 */
58
+ text: { type: [String, Number], default: '' },
59
+ /** 背景颜色,默认为空字符串,即不处理 */
60
+ bgColor: { type: String, default: '' },
61
+ /** 标签字体颜色,默认为空字符串,即不处理 */
62
+ color: { type: String, default: '' },
63
+ /** 镂空形式标签的边框颜色 */
64
+ borderColor: { type: String, default: '' },
65
+ /** 关闭按钮图标的颜色 */
66
+ closeColor: { type: String, default: '' },
67
+ /** 点击时返回的索引值,用于区分例遍的数组哪个元素被点击了 */
68
+ index: { type: [Number, String], default: '' },
69
+ /** 模式选择,dark|light|plain */
70
+ mode: { type: String, default: 'light' },
71
+ /** 是否可关闭 */
72
+ closeable: { type: Boolean, default: false },
73
+ /** 是否显示 */
74
+ show: { type: Boolean, default: true }
75
+ });
76
+
77
+ /**
78
+ * 计算 tag 的自定义样式
79
+ */
80
+ const customStyle = computed(() => {
81
+ let style: Record<string, any> = {};
82
+ // 文字颜色(如果有此值,会覆盖type值的颜色)
83
+ if (props.color) style.color = props.color;
84
+ // tag的背景颜色(如果有此值,会覆盖type值的颜色)
85
+ if (props.bgColor) style.backgroundColor = props.bgColor;
86
+ // 如果是镂空型tag,没有传递边框颜色(borderColor)的话,使用文字的颜色(color属性)
87
+ if (props.mode === 'plain' && props.color && !props.borderColor) style.borderColor = props.color;
88
+ else style.borderColor = props.borderColor;
89
+ return style;
90
+ });
91
+
92
+ /**
93
+ * 计算关闭图标的样式
94
+ */
95
+ const iconStyle = computed(() => {
96
+ if (!props.closeable) return undefined;
97
+ let style: Record<string, any> = {};
98
+ if (props.size === 'mini') style.fontSize = '20rpx';
99
+ else style.fontSize = '22rpx';
100
+ if (props.mode === 'plain' || props.mode === 'light') style.color = props.type;
101
+ else if (props.mode === 'dark') style.color = '#ffffff';
102
+ if (props.closeColor) style.color = props.closeColor;
103
+ return style;
104
+ });
105
+
106
+ /**
107
+ * 关闭图标的颜色
108
+ */
109
+ const closeIconColor = computed(() => {
110
+ // 如果定义了关闭图标的颜色,就用此值,否则用字体颜色的值
111
+ // 如果上面的二者都没有,如果是dark深色模式,图标就为白色
112
+ // 最后如果上面的三者都不合适,就返回type值给图标获取颜色
113
+ if (props.closeColor) return props.closeColor;
114
+ else if (props.color) return props.color;
115
+ else if (props.mode === 'dark') return '#ffffff';
116
+ else return props.type;
117
+ });
118
+
119
+ /**
120
+ * 标签被点击
121
+ */
122
+ function clickTag() {
123
+ // 如果是disabled状态,不发送点击事件
124
+ if (props.disabled) return;
125
+ emit('click', props.index);
126
+ }
127
+
128
+ /**
129
+ * 点击标签关闭按钮
130
+ */
131
+ function close() {
132
+ emit('close', props.index);
133
+ }
134
+ </script>
135
+
136
+ <style lang="scss" scoped>
137
+ @import '../../libs/css/style.components.scss';
138
+
139
+ .u-tag {
140
+ box-sizing: border-box;
141
+ align-items: center;
142
+ border-radius: 6rpx;
143
+ /* #ifndef APP-NVUE */
144
+ display: inline-block;
145
+ /* #endif */
146
+ line-height: 1;
147
+ }
148
+
149
+ .u-size-default {
150
+ font-size: 22rpx;
151
+ padding: 12rpx 22rpx;
152
+ }
153
+
154
+ .u-size-mini {
155
+ font-size: 20rpx;
156
+ padding: 6rpx 12rpx;
157
+ }
158
+
159
+ .u-mode-light-primary {
160
+ background-color: $u-type-primary-light;
161
+ color: $u-type-primary;
162
+ border: 1px solid $u-type-primary-disabled;
163
+ }
164
+
165
+ .u-mode-light-success {
166
+ background-color: $u-type-success-light;
167
+ color: $u-type-success;
168
+ border: 1px solid $u-type-success-disabled;
169
+ }
170
+
171
+ .u-mode-light-error {
172
+ background-color: $u-type-error-light;
173
+ color: $u-type-error;
174
+ border: 1px solid $u-type-error-disabled;
175
+ }
176
+
177
+ .u-mode-light-warning {
178
+ background-color: $u-type-warning-light;
179
+ color: $u-type-warning;
180
+ border: 1px solid $u-type-warning-disabled;
181
+ }
182
+
183
+ .u-mode-light-info {
184
+ background-color: $u-type-info-light;
185
+ color: $u-type-info;
186
+ border: 1px solid $u-type-info-disabled;
187
+ }
188
+
189
+ .u-mode-dark-primary {
190
+ background-color: $u-type-primary;
191
+ color: #ffffff;
192
+ }
193
+
194
+ .u-mode-dark-success {
195
+ background-color: $u-type-success;
196
+ color: #ffffff;
197
+ }
198
+
199
+ .u-mode-dark-error {
200
+ background-color: $u-type-error;
201
+ color: #ffffff;
202
+ }
203
+
204
+ .u-mode-dark-warning {
205
+ background-color: $u-type-warning;
206
+ color: #ffffff;
207
+ }
208
+
209
+ .u-mode-dark-info {
210
+ background-color: $u-type-info;
211
+ color: #ffffff;
212
+ }
213
+
214
+ .u-mode-plain-primary {
215
+ background-color: #ffffff;
216
+ color: $u-type-primary;
217
+ border: 1px solid $u-type-primary;
218
+ }
219
+
220
+ .u-mode-plain-success {
221
+ background-color: #ffffff;
222
+ color: $u-type-success;
223
+ border: 1px solid $u-type-success;
224
+ }
225
+
226
+ .u-mode-plain-error {
227
+ background-color: #ffffff;
228
+ color: $u-type-error;
229
+ border: 1px solid $u-type-error;
230
+ }
231
+
232
+ .u-mode-plain-warning {
233
+ background-color: #ffffff;
234
+ color: $u-type-warning;
235
+ border: 1px solid $u-type-warning;
236
+ }
237
+
238
+ .u-mode-plain-info {
239
+ background-color: #ffffff;
240
+ color: $u-type-info;
241
+ border: 1px solid $u-type-info;
242
+ }
243
+
244
+ .u-disabled {
245
+ opacity: 0.55;
246
+ }
247
+
248
+ .u-shape-circle {
249
+ border-radius: 100rpx;
250
+ }
251
+
252
+ .u-shape-circleRight {
253
+ border-radius: 0 100rpx 100rpx 0;
254
+ }
255
+
256
+ .u-shape-circleLeft {
257
+ border-radius: 100rpx 0 0 100rpx;
258
+ }
259
+
260
+ .u-close-icon {
261
+ margin-left: 14rpx;
262
+ font-size: 22rpx;
263
+ color: $u-type-success;
264
+ }
265
+
266
+ .u-icon-wrap {
267
+ display: inline-flex;
268
+ transform: scale(0.86);
269
+ }
270
+ </style>