v-uni-app-ui 1.0.0 → 1.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.
- package/components/config.js +123 -0
- package/components/layout/v-card/v-card.vue +108 -0
- package/components/layout/v-grid/v-grid.vue +162 -0
- package/components/layout/v-icon-grid/v-icon-grid.vue +195 -0
- package/components/layout/v-infinite-scroll/v-infinite-scroll.vue +172 -0
- package/components/layout/v-list/v-list.vue +43 -0
- package/components/layout/v-row/v-row.vue +142 -0
- package/components/layout/v-waterfall/v-waterfall.vue +79 -0
- package/components/model/compound/v-checkbox-group/v-checkbox-group.vue +96 -0
- package/components/model/compound/v-console/v-console.js +20 -0
- package/components/model/compound/v-console/v-console.vue +299 -0
- package/components/model/compound/v-date-time/v-date-time.vue +261 -0
- package/components/model/compound/v-dialog/v-dialog.vue +178 -0
- package/components/model/compound/v-drum-select-picker/v-drum-select-picker.vue +83 -0
- package/components/model/compound/v-form/v-form.vue +226 -0
- package/components/model/compound/v-form-item/v-form-item.vue +255 -0
- package/components/model/compound/v-image/v-image.vue +357 -0
- package/components/model/compound/v-input-desensitize/v-input-desensitize.vue +101 -0
- package/components/model/compound/v-page/v-page.vue +11 -0
- package/components/model/compound/v-pages/v-pages.vue +141 -0
- package/components/model/compound/v-picker-list/v-picker-list.vue +109 -0
- package/components/model/compound/v-popup/v-popup.vue +151 -0
- package/components/model/compound/v-radio-group/v-radio-group.vue +86 -0
- package/components/model/compound/v-select-picker/v-select-picker.vue +202 -0
- package/components/model/compound/v-series-picker-list/v-series-picker-list.vue +221 -0
- package/components/model/compound/v-series-select-picker/v-series-select-picker.vue +203 -0
- package/components/model/compound/v-switch/v-switch.vue +136 -0
- package/components/model/compound/v-tabs-page/v-tabs-page.vue +138 -0
- package/components/model/native/v-badge/v-badge.vue +143 -0
- package/components/model/native/v-button/v-button.vue +273 -0
- package/components/model/native/v-carousel/v-carousel.vue +138 -0
- package/components/model/native/v-checkbox/v-checkbox.vue +215 -0
- package/components/model/native/v-collapse/v-collapse.vue +190 -0
- package/components/model/native/v-header-navigation-bar/v-header-navigation-bar.vue +92 -0
- package/components/model/native/v-input/v-input.vue +352 -0
- package/components/model/native/v-input-code/v-input-code.vue +146 -0
- package/components/model/native/v-loading/v-loading.vue +206 -0
- package/components/model/native/v-menu/v-menu.vue +222 -0
- package/components/model/native/v-menu-slide/v-menu-slide.vue +364 -0
- package/components/model/native/v-min-loading/v-min-loading.vue +80 -0
- package/components/model/native/v-null/v-null.vue +97 -0
- package/components/model/native/v-overlay/v-overlay.vue +96 -0
- package/components/model/native/v-pull-up-refresh/v-pull-up-refresh.vue +157 -0
- package/components/model/native/v-radio/v-radio.vue +138 -0
- package/components/model/native/v-scroll-list/v-scroll-list.vue +169 -0
- package/components/model/native/v-steps/v-steps.vue +253 -0
- package/components/model/native/v-table/v-table.vue +203 -0
- package/components/model/native/v-tabs/v-tabs.vue +235 -0
- package/components/model/native/v-tag/v-tag.vue +206 -0
- package/components/model/native/v-text/v-text.vue +187 -0
- package/components/model/native/v-text-button/v-text-button.vue +139 -0
- package/components/model/native/v-textarea/v-textarea.vue +178 -0
- package/components/model/native/v-title/v-title.vue +91 -0
- package/components/model/native/v-toast/info.png +0 -0
- package/components/model/native/v-toast/success.png +0 -0
- package/components/model/native/v-toast/v-toast.vue +198 -0
- package/components/model/native/v-toast/warn.png +0 -0
- package/components/model/native/v-upload-file-button/v-upload-file-button.vue +296 -0
- package/components/model/native/v-video/v-video.vue +175 -0
- package/components/model/native/v-window/v-window.vue +158 -0
- package/package.json +18 -94
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view class="v-steps" :class="[direction]">
|
|
3
|
+
<view v-for="(step, index) in steps" :key="index" class="step-item" :class="[getStepStatus(index), { 'last-item': index === steps.length - 1 }]">
|
|
4
|
+
<view class="step-icon-container">
|
|
5
|
+
<view class="step-icon">
|
|
6
|
+
<text v-if="index < active" class="icon-check">✓</text>
|
|
7
|
+
<text v-else-if="index === active" class="step-number">{{ index + 1 }}</text>
|
|
8
|
+
<text v-else class="step-number">{{ index + 1 }}</text>
|
|
9
|
+
</view>
|
|
10
|
+
<view v-if="index !== steps.length - 1" class="step-line"></view>
|
|
11
|
+
</view>
|
|
12
|
+
<view class="step-content">
|
|
13
|
+
<text class="step-title">{{ step.title }}</text>
|
|
14
|
+
<text v-if="step.desc" class="step-desc">{{ step.desc }}</text>
|
|
15
|
+
</view>
|
|
16
|
+
</view>
|
|
17
|
+
</view>
|
|
18
|
+
</template>
|
|
19
|
+
|
|
20
|
+
<script lang="ts" setup>
|
|
21
|
+
import { computed, inject } from 'vue';
|
|
22
|
+
|
|
23
|
+
interface Step {
|
|
24
|
+
title: string;
|
|
25
|
+
desc?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const props = defineProps({
|
|
29
|
+
steps: {
|
|
30
|
+
type: Array as () => Step[],
|
|
31
|
+
required: true
|
|
32
|
+
},
|
|
33
|
+
active: {
|
|
34
|
+
type: Number,
|
|
35
|
+
default: 0,
|
|
36
|
+
validator: (value: number) => value >= 0
|
|
37
|
+
},
|
|
38
|
+
direction: {
|
|
39
|
+
type: String,
|
|
40
|
+
default: 'horizontal',
|
|
41
|
+
validator: (value: string) => ['horizontal', 'vertical'].includes(value)
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
const config = inject<any>('config');
|
|
45
|
+
const getStepStatus = (index: number) => {
|
|
46
|
+
if (index < props.active) return 'finished';
|
|
47
|
+
if (index === props.active) return 'active';
|
|
48
|
+
return 'waiting';
|
|
49
|
+
};
|
|
50
|
+
</script>
|
|
51
|
+
|
|
52
|
+
<style lang="scss" scoped>
|
|
53
|
+
$primary-color: #287afa;
|
|
54
|
+
$success-color: #31d283;
|
|
55
|
+
$warning-color: #ff9628;
|
|
56
|
+
$info-color: #969696;
|
|
57
|
+
$text-primary: #333333;
|
|
58
|
+
$text-regular: #666666;
|
|
59
|
+
$text-placeholder: #c0c4cc;
|
|
60
|
+
$border-color: #969696;
|
|
61
|
+
$bg-color: #f5f7fa;
|
|
62
|
+
|
|
63
|
+
.v-steps {
|
|
64
|
+
display: flex;
|
|
65
|
+
width: 100%;
|
|
66
|
+
box-sizing: border-box;
|
|
67
|
+
|
|
68
|
+
&.horizontal {
|
|
69
|
+
flex-direction: row;
|
|
70
|
+
justify-content: space-between;
|
|
71
|
+
padding: 16rpx 0;
|
|
72
|
+
|
|
73
|
+
.step-item {
|
|
74
|
+
flex: 1;
|
|
75
|
+
display: flex;
|
|
76
|
+
flex-direction: column;
|
|
77
|
+
align-items: center;
|
|
78
|
+
position: relative;
|
|
79
|
+
|
|
80
|
+
.step-icon-container {
|
|
81
|
+
display: flex;
|
|
82
|
+
align-items: center;
|
|
83
|
+
justify-content: center;
|
|
84
|
+
position: relative;
|
|
85
|
+
width: 100%;
|
|
86
|
+
|
|
87
|
+
.step-line {
|
|
88
|
+
position: absolute;
|
|
89
|
+
left: 72.5%;
|
|
90
|
+
top: 50%;
|
|
91
|
+
transform: translateY(-50%);
|
|
92
|
+
width: calc(100% - 80rpx);
|
|
93
|
+
height: 4rpx;
|
|
94
|
+
background-color: v-bind('config.VSteps.lineBackgroundColor');
|
|
95
|
+
z-index: 1;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
.step-content {
|
|
100
|
+
text-align: center;
|
|
101
|
+
margin-top: 16rpx;
|
|
102
|
+
padding: 0 20rpx;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
&.last-item .step-line {
|
|
106
|
+
display: none;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
&.vertical {
|
|
112
|
+
flex-direction: column;
|
|
113
|
+
padding: 16rpx 0;
|
|
114
|
+
|
|
115
|
+
.step-item {
|
|
116
|
+
display: flex;
|
|
117
|
+
position: relative;
|
|
118
|
+
padding-bottom: 40rpx;
|
|
119
|
+
|
|
120
|
+
&:last-child {
|
|
121
|
+
padding-bottom: 0;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
.step-icon-container {
|
|
125
|
+
display: flex;
|
|
126
|
+
flex-direction: column;
|
|
127
|
+
align-items: center;
|
|
128
|
+
margin-right: 24rpx;
|
|
129
|
+
|
|
130
|
+
.step-line {
|
|
131
|
+
flex: 1;
|
|
132
|
+
width: 4rpx;
|
|
133
|
+
background-color: v-bind('config.VSteps.lineBackgroundColor');
|
|
134
|
+
margin-top: 16rpx;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
.step-content {
|
|
139
|
+
flex: 1;
|
|
140
|
+
padding-bottom: 40rpx;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
&.last-item .step-line {
|
|
144
|
+
display: none;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
.step-icon {
|
|
150
|
+
width: 60rpx;
|
|
151
|
+
height: 60rpx;
|
|
152
|
+
border-radius: 50%;
|
|
153
|
+
display: flex;
|
|
154
|
+
align-items: center;
|
|
155
|
+
justify-content: center;
|
|
156
|
+
position: relative;
|
|
157
|
+
z-index: 2;
|
|
158
|
+
font-size: 32rpx;
|
|
159
|
+
font-weight: bold;
|
|
160
|
+
background-color: white;
|
|
161
|
+
border: 4rpx solid v-bind('config.border.color');
|
|
162
|
+
color: v-bind('config.fontColor.subTitle');
|
|
163
|
+
transition: all 0.3s ease;
|
|
164
|
+
|
|
165
|
+
.step-number {
|
|
166
|
+
line-height: 1;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
.icon-check {
|
|
170
|
+
font-size: 36rpx;
|
|
171
|
+
font-weight: bold;
|
|
172
|
+
line-height: 1;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
.step-title {
|
|
177
|
+
font-size: 32rpx;
|
|
178
|
+
font-weight: bold;
|
|
179
|
+
color: v-bind('config.fontColor.default');
|
|
180
|
+
display: block;
|
|
181
|
+
line-height: 1.4;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
.step-desc {
|
|
185
|
+
font-size: 26rpx;
|
|
186
|
+
color: v-bind('config.fontColor.subTitle');
|
|
187
|
+
display: block;
|
|
188
|
+
margin-top: 8rpx;
|
|
189
|
+
line-height: 1.4;
|
|
190
|
+
}
|
|
191
|
+
.finished {
|
|
192
|
+
.step-icon {
|
|
193
|
+
border-color: v-bind('config.border.color');
|
|
194
|
+
background-color: v-bind('config.backgroundColor.succeed');
|
|
195
|
+
color: white;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
.step-line {
|
|
199
|
+
background-color: v-bind('config.backgroundColor.succeed') !important;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
.step-title {
|
|
203
|
+
color: v-bind('config.fontColor.default');
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
.active {
|
|
207
|
+
.step-icon {
|
|
208
|
+
border-color: v-bind('config.border.default');
|
|
209
|
+
background-color: v-bind('config.backgroundColor.default');
|
|
210
|
+
color: white;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
.step-title {
|
|
214
|
+
color: v-bind('config.fontColor.default');
|
|
215
|
+
font-weight: bold;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
.waiting {
|
|
220
|
+
.step-icon {
|
|
221
|
+
border-color: v-bind('config.border.color');
|
|
222
|
+
background-color: white;
|
|
223
|
+
color: v-bind('config.fontColor.text');
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
.step-title {
|
|
227
|
+
color: v-bind('config.fontColor.text');
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
.step-desc {
|
|
231
|
+
color: v-bind('config.fontColor.text');
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
@media (max-width: 768px) {
|
|
237
|
+
.v-steps.horizontal {
|
|
238
|
+
.step-item {
|
|
239
|
+
.step-content {
|
|
240
|
+
padding: 0 10rpx;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
.step-title {
|
|
244
|
+
font-size: 28rpx;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
.step-desc {
|
|
248
|
+
font-size: 24rpx;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
</style>
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view class="v-table-container">
|
|
3
|
+
<view class="v-table">
|
|
4
|
+
<view class="v-table-header" @click="handleHeaderClick">
|
|
5
|
+
<view class="v-table-header-cell" v-for="(column, index) in columns" :key="index" :style="{ width: column.width , flex: '1 1 0%'}">
|
|
6
|
+
{{ column.label }}
|
|
7
|
+
<view v-if="column.prop && sortable" class="sort-icon">
|
|
8
|
+
<text class="arrow-up" :class="{ active: column.prop === sortConfig.prop && sortConfig.order === 'asc' }">↑</text>
|
|
9
|
+
<text class="arrow-down" :class="{ active: column.prop === sortConfig.prop && sortConfig.order === 'desc' }">↓</text>
|
|
10
|
+
</view>
|
|
11
|
+
</view>
|
|
12
|
+
</view>
|
|
13
|
+
<view class="v-table-body">
|
|
14
|
+
<view v-if="!data.length" class="empty-data">
|
|
15
|
+
<slot name="empty">暂无数据</slot>
|
|
16
|
+
</view>
|
|
17
|
+
<view class="v-table-row" v-for="(row, rowIndex) in sortedData" :key="rowIndex">
|
|
18
|
+
<view class="v-table-cell" v-for="(column, colIndex) in columns" :key="colIndex" :style="{ width: column.width , flex: '1 1 0%'}">
|
|
19
|
+
<slot :name="`cell-${column.prop}`" :row="row" :column="column" :index="rowIndex">
|
|
20
|
+
{{ row[column.prop] }}
|
|
21
|
+
</slot>
|
|
22
|
+
</view>
|
|
23
|
+
</view>
|
|
24
|
+
</view>
|
|
25
|
+
</view>
|
|
26
|
+
</view>
|
|
27
|
+
</template>
|
|
28
|
+
|
|
29
|
+
<script lang="ts" setup>
|
|
30
|
+
import { computed, ref ,inject} from 'vue';
|
|
31
|
+
|
|
32
|
+
interface TableColumn {
|
|
33
|
+
prop: string;
|
|
34
|
+
label: string;
|
|
35
|
+
width?: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
interface SortConfig {
|
|
39
|
+
prop: string | null;
|
|
40
|
+
order: 'asc' | 'desc' | null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* v-table
|
|
45
|
+
* columns 表格列配置
|
|
46
|
+
* prop 表格列绑定的数据属性名
|
|
47
|
+
* label 表格列标题
|
|
48
|
+
* width 表格列宽度
|
|
49
|
+
* data 表格数据数组
|
|
50
|
+
* sortable 是否支持排序 默认值:false 可选值true支持排序、false不支持排序
|
|
51
|
+
*/
|
|
52
|
+
const props = defineProps({
|
|
53
|
+
columns: {
|
|
54
|
+
type: Array,
|
|
55
|
+
default: () => [],
|
|
56
|
+
required: true
|
|
57
|
+
},
|
|
58
|
+
data: {
|
|
59
|
+
type: Array,
|
|
60
|
+
default: () => []
|
|
61
|
+
},
|
|
62
|
+
sortable: {
|
|
63
|
+
type: Boolean,
|
|
64
|
+
default: false
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
const config = inject<any>('config');
|
|
69
|
+
const sortConfig = ref<SortConfig>({
|
|
70
|
+
prop: null,
|
|
71
|
+
order: null
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
const sortedData = computed(() => {
|
|
75
|
+
if (!props.sortable || !props.data.length || !sortConfig.value.prop) {
|
|
76
|
+
return props.data;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return [...props.data].sort((a, b) => {
|
|
80
|
+
const aValue = a[sortConfig.value.prop];
|
|
81
|
+
const bValue = b[sortConfig.value.prop];
|
|
82
|
+
|
|
83
|
+
if (sortConfig.value.order === 'asc') {
|
|
84
|
+
return aValue > bValue ? 1 : -1;
|
|
85
|
+
} else {
|
|
86
|
+
return aValue < bValue ? 1 : -1;
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
const handleHeaderClick = (event: any) => {
|
|
92
|
+
const target = event.target;
|
|
93
|
+
const columnName = target.closest('.v-table-header-cell');
|
|
94
|
+
if (!columnName) return;
|
|
95
|
+
|
|
96
|
+
const columnProp = props.columns.find((col, index) => {
|
|
97
|
+
const cell = target.closest('.v-table-header-cell');
|
|
98
|
+
return cell && cell.getAttribute('data-index') === index.toString();
|
|
99
|
+
}).prop;
|
|
100
|
+
|
|
101
|
+
if (!columnProp) return;
|
|
102
|
+
|
|
103
|
+
if (sortConfig.value.prop === columnProp) {
|
|
104
|
+
sortConfig.value.order = sortConfig.value.order === 'asc' ? 'desc' : 'asc';
|
|
105
|
+
} else {
|
|
106
|
+
sortConfig.value.prop = columnProp;
|
|
107
|
+
sortConfig.value.order = 'asc';
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
</script>
|
|
111
|
+
|
|
112
|
+
<style lang="scss" scoped>
|
|
113
|
+
.v-table-container {
|
|
114
|
+
width: 100%;
|
|
115
|
+
border-radius: 8rpx;
|
|
116
|
+
overflow: hidden;
|
|
117
|
+
box-shadow: 0 2rpx 12rpx 0 rgba(0, 0, 0, 0.1);
|
|
118
|
+
border: 1rpx solid v-bind("config.border.color");
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
.v-table {
|
|
122
|
+
width: 100%;
|
|
123
|
+
box-sizing: border-box;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
.v-table-header {
|
|
127
|
+
display: flex;
|
|
128
|
+
background-color: v-bind("config.VTable.backgroundColor");
|
|
129
|
+
border-bottom: 1rpx solid v-bind("config.border.color");
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
.v-table-header-cell {
|
|
133
|
+
padding: 12rpx 16rpx;
|
|
134
|
+
font-weight: bold;
|
|
135
|
+
color: v-bind("config.fontColor.mianTitle");
|
|
136
|
+
text-align: left;
|
|
137
|
+
box-sizing: border-box;
|
|
138
|
+
border-right: 1rpx solid v-bind("config.border.color");
|
|
139
|
+
cursor: pointer;
|
|
140
|
+
position: relative;
|
|
141
|
+
user-select: none;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
.v-table-header-cell:hover {
|
|
145
|
+
background-color: v-bind("config.VTable.backgroundColor");
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
.sort-icon {
|
|
149
|
+
display: inline-block;
|
|
150
|
+
margin-left: 5rpx;
|
|
151
|
+
vertical-align: middle;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
.arrow-up,
|
|
155
|
+
.arrow-down {
|
|
156
|
+
display: block;
|
|
157
|
+
font-size: v-bind("config.fontSize.smallText");
|
|
158
|
+
color: v-bind("config.fontColor.text");
|
|
159
|
+
margin: 0 2rpx;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
.arrow-up.active,
|
|
163
|
+
.arrow-down.active {
|
|
164
|
+
color: v-bind("config.fontColor.default");
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
.v-table-body {
|
|
168
|
+
display: flex;
|
|
169
|
+
flex-direction: column;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
.v-table-row {
|
|
173
|
+
display: flex;
|
|
174
|
+
border-bottom: 1rpx solid v-bind("config.border.color");
|
|
175
|
+
transition: background-color 0.3s;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
.v-table-row:hover {
|
|
179
|
+
background-color: v-bind("config.VTable.backgroundColor");
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
.v-table-row:last-child {
|
|
183
|
+
border-bottom: none;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
.v-table-row:nth-child(even) {
|
|
187
|
+
background-color: #v-bind("config.VTable.backgroundColor");
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
.v-table-cell {
|
|
191
|
+
padding: 12px 16px;
|
|
192
|
+
color: v-bind("config.fontColor.text");
|
|
193
|
+
text-align: left;
|
|
194
|
+
box-sizing: border-box;
|
|
195
|
+
border-right: 1rpx solid v-bind("config.border.color");
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
.empty-data {
|
|
199
|
+
padding: 20rpx;
|
|
200
|
+
text-align: center;
|
|
201
|
+
color: v-bind("config.fontColor.text");
|
|
202
|
+
}
|
|
203
|
+
</style>
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view class="v-tabs">
|
|
3
|
+
<scroll-view scroll-x class="tabs-scroll" :scroll-left="scrollLeft" :show-scrollbar="false" :scroll-with-animation="true">
|
|
4
|
+
<view class="tabs-container">
|
|
5
|
+
<view
|
|
6
|
+
v-for="(item, index) in tabs"
|
|
7
|
+
:key="item.key || index"
|
|
8
|
+
class="tab-item"
|
|
9
|
+
:class="[{ active: index === activeIndex }, hoverClass]"
|
|
10
|
+
:style="{
|
|
11
|
+
minWidth: `${minTabWidth}rpx`,
|
|
12
|
+
padding: `0 ${itemPadding}rpx`
|
|
13
|
+
}"
|
|
14
|
+
@click="handleTabClick(index)"
|
|
15
|
+
:id="`tab_${index}`"
|
|
16
|
+
>
|
|
17
|
+
<text class="tab-text">{{ item.title }}</text>
|
|
18
|
+
</view>
|
|
19
|
+
<view v-show="isLine" class="tab-line" :style="lineStyle"></view>
|
|
20
|
+
</view>
|
|
21
|
+
</scroll-view>
|
|
22
|
+
</view>
|
|
23
|
+
</template>
|
|
24
|
+
|
|
25
|
+
<script lang="ts" setup>
|
|
26
|
+
import { ref, computed, watch, onMounted, nextTick } from 'vue';
|
|
27
|
+
|
|
28
|
+
interface TabList {
|
|
29
|
+
title: string;
|
|
30
|
+
key: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* v-tabs 标签页 无内容
|
|
35
|
+
* value 双向绑定值 默认值:0
|
|
36
|
+
* tabs 标签标题
|
|
37
|
+
* activeColor 高亮颜色 默认值:#287afa
|
|
38
|
+
* inactiveColor 标题颜色 默认值:#666
|
|
39
|
+
* isLine 是否显示下划线 默认值:true
|
|
40
|
+
* lineWidth 下划线宽度 默认值:最大标题宽度
|
|
41
|
+
* lineHeight 下划线厚度 默认值:8
|
|
42
|
+
* lineOffset 下划线距离标题距离 默认值:4
|
|
43
|
+
* minTabWidth 最小标题宽度 默认值:120
|
|
44
|
+
* itemPadding 标题内边距 默认值:32
|
|
45
|
+
* hoverClass 悬浮名称 默认值:tabs-hover
|
|
46
|
+
* 相关事件:change
|
|
47
|
+
*/
|
|
48
|
+
const props = defineProps({
|
|
49
|
+
value: {
|
|
50
|
+
type: Number,
|
|
51
|
+
default: 0
|
|
52
|
+
},
|
|
53
|
+
tabs: {
|
|
54
|
+
type: Array as () => TabList[],
|
|
55
|
+
required: true
|
|
56
|
+
},
|
|
57
|
+
activeColor: {
|
|
58
|
+
type: String,
|
|
59
|
+
default: '#287afa'
|
|
60
|
+
},
|
|
61
|
+
inactiveColor: {
|
|
62
|
+
type: String,
|
|
63
|
+
default: '#666'
|
|
64
|
+
},
|
|
65
|
+
isLine: {
|
|
66
|
+
type: Boolean,
|
|
67
|
+
default: true
|
|
68
|
+
},
|
|
69
|
+
lineHeight: {
|
|
70
|
+
type: String,
|
|
71
|
+
default: '8'
|
|
72
|
+
},
|
|
73
|
+
lineWidth: {
|
|
74
|
+
type: Number,
|
|
75
|
+
default: 20
|
|
76
|
+
},
|
|
77
|
+
lineOffset: {
|
|
78
|
+
type: Number,
|
|
79
|
+
default: 0
|
|
80
|
+
},
|
|
81
|
+
minTabWidth: {
|
|
82
|
+
type: Number,
|
|
83
|
+
default: 120
|
|
84
|
+
},
|
|
85
|
+
itemPadding: {
|
|
86
|
+
type: Number,
|
|
87
|
+
default: 32
|
|
88
|
+
},
|
|
89
|
+
hoverClass: {
|
|
90
|
+
type: String,
|
|
91
|
+
default: 'tabs-hover'
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
const emit = defineEmits(['update:value', 'change']);
|
|
96
|
+
|
|
97
|
+
const activeIndex = ref(props.value);
|
|
98
|
+
const tabRects = ref<{ left: number; width: number }[]>([]);
|
|
99
|
+
const scrollLeft = ref(0);
|
|
100
|
+
const isLandscape = ref(false);
|
|
101
|
+
|
|
102
|
+
const lineStyle = computed(() => {
|
|
103
|
+
if (!tabRects.value[activeIndex.value]) return {};
|
|
104
|
+
const current = tabRects.value[activeIndex.value];
|
|
105
|
+
return {
|
|
106
|
+
width: `${props.lineWidth === 0 ? current.width : props.lineWidth}px`,
|
|
107
|
+
transform: `translateX(${current.left}px)`,
|
|
108
|
+
backgroundColor: props.activeColor,
|
|
109
|
+
height: uni.upx2px(parseFloat(props.lineHeight)) + 'px',
|
|
110
|
+
bottom: `2rpx`
|
|
111
|
+
};
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
let updateTimer = null;
|
|
115
|
+
const updateTabRects = () => {
|
|
116
|
+
clearTimeout(updateTimer);
|
|
117
|
+
updateTimer = setTimeout(() => {
|
|
118
|
+
nextTick(() => {
|
|
119
|
+
uni.createSelectorQuery()
|
|
120
|
+
.selectAll('.tab-item')
|
|
121
|
+
.boundingClientRect((rects: any) => {
|
|
122
|
+
tabRects.value = rects.map((rect: any) => ({
|
|
123
|
+
left: rect.left - (rects[0]?.left || 0),
|
|
124
|
+
width: rect.width
|
|
125
|
+
}));
|
|
126
|
+
})
|
|
127
|
+
.exec();
|
|
128
|
+
});
|
|
129
|
+
}, 100);
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
const handleTabClick = (index: number) => {
|
|
133
|
+
if (activeIndex.value === index) return;
|
|
134
|
+
activeIndex.value = index;
|
|
135
|
+
scrollToTab(index);
|
|
136
|
+
emit('change', index);
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
const scrollToTab = (index: number) => {
|
|
140
|
+
const current = tabRects.value[index];
|
|
141
|
+
if (!current) return;
|
|
142
|
+
|
|
143
|
+
const systemInfo = uni.getSystemInfoSync();
|
|
144
|
+
const tabWidth = current.width;
|
|
145
|
+
const tabLeft = current.left;
|
|
146
|
+
|
|
147
|
+
const viewCenter = systemInfo.windowWidth / 2;
|
|
148
|
+
const tabCenter = tabLeft + tabWidth / 2;
|
|
149
|
+
const targetScroll = Math.max(0, tabCenter - viewCenter);
|
|
150
|
+
|
|
151
|
+
requestAnimationFrame(() => {
|
|
152
|
+
scrollLeft.value = targetScroll;
|
|
153
|
+
});
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
const checkOrientation = () => {
|
|
157
|
+
const { windowWidth, windowHeight } = uni.getSystemInfoSync();
|
|
158
|
+
isLandscape.value = windowWidth > windowHeight;
|
|
159
|
+
updateTabRects();
|
|
160
|
+
scrollToTab(activeIndex.value);
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
watch(activeIndex, (val) => {
|
|
164
|
+
emit('update:value', val);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
onMounted(() => {
|
|
168
|
+
checkOrientation();
|
|
169
|
+
uni.onWindowResize(checkOrientation);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
watch(() => props.tabs, updateTabRects);
|
|
173
|
+
</script>
|
|
174
|
+
|
|
175
|
+
<style lang="scss" scoped>
|
|
176
|
+
.v-tabs {
|
|
177
|
+
width: 100%;
|
|
178
|
+
background-color: #fff;
|
|
179
|
+
position: relative;
|
|
180
|
+
padding: 0 env(safe-area-inset-left);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
.tabs-scroll {
|
|
184
|
+
width: 100%;
|
|
185
|
+
white-space: nowrap;
|
|
186
|
+
padding: 0 env(safe-area-inset-right);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
.tabs-container {
|
|
190
|
+
position: relative;
|
|
191
|
+
display: inline-flex;
|
|
192
|
+
height: 80rpx;
|
|
193
|
+
align-items: center;
|
|
194
|
+
padding: 0 20rpx;
|
|
195
|
+
will-change: transform;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
.tab-item {
|
|
199
|
+
position: relative;
|
|
200
|
+
height: 100%;
|
|
201
|
+
display: inline-flex;
|
|
202
|
+
align-items: center;
|
|
203
|
+
transition: color 0.3s;
|
|
204
|
+
flex-shrink: 0;
|
|
205
|
+
|
|
206
|
+
&.active {
|
|
207
|
+
.tab-text {
|
|
208
|
+
color: v-bind('props.activeColor');
|
|
209
|
+
font-weight: 500;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
.tab-text {
|
|
214
|
+
margin: auto;
|
|
215
|
+
font-size: clamp(24rpx, 4vw, 32rpx);
|
|
216
|
+
color: v-bind('props.inactiveColor');
|
|
217
|
+
transition: color 0.3s;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
.tab-line {
|
|
222
|
+
position: absolute;
|
|
223
|
+
bottom: 0;
|
|
224
|
+
border-radius: v-bind('props.lineHeight');
|
|
225
|
+
transition: all 0.3s cubic-bezier(0.35, 0, 0.25, 1);
|
|
226
|
+
transform-origin: 0 50%;
|
|
227
|
+
-webkit-backface-visibility: hidden;
|
|
228
|
+
backface-visibility: hidden;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
.tabs-hover {
|
|
232
|
+
opacity: 0.6;
|
|
233
|
+
transition: opacity 0.2s;
|
|
234
|
+
}
|
|
235
|
+
</style>
|