fimoi-tab-bar 1.1.0 → 1.1.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/fimoiTabBar/index.vue +56 -19
- package/package.json +1 -1
package/fimoiTabBar/index.vue
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<div class="tabbar" :style="barStyle">
|
|
3
|
-
<
|
|
4
|
-
:class="{ active: currentIndex === index }"
|
|
3
|
+
<div v-for="(item, index) in processedTabs" :key="index" class="tabbar-item"
|
|
4
|
+
:class="{ active: currentIndex === index }" @click="handleSelect(index)">
|
|
5
5
|
<template v-if="item.checked || item.unchecked">
|
|
6
6
|
<img v-if="currentIndex === index && item.checked" class="icon-image" :src="item.checked" />
|
|
7
7
|
<img v-else-if="item.unchecked" class="icon-image" :src="item.unchecked" />
|
|
8
8
|
</template>
|
|
9
9
|
<template v-else>
|
|
10
|
-
<span class="icon-text" :style="
|
|
10
|
+
<span class="icon-text" :style="item.iconStyle">{{ item.icon }}</span>
|
|
11
11
|
</template>
|
|
12
|
-
<span class="label" :style="labelStyle
|
|
13
|
-
</
|
|
12
|
+
<span class="label" :style="item.labelStyle">{{ item.name }}</span>
|
|
13
|
+
</div>
|
|
14
14
|
</div>
|
|
15
15
|
</template>
|
|
16
16
|
<script>
|
|
@@ -39,6 +39,9 @@ export default {
|
|
|
39
39
|
return {
|
|
40
40
|
internalIndex: 0,
|
|
41
41
|
};
|
|
42
|
+
},
|
|
43
|
+
mounted() {
|
|
44
|
+
|
|
42
45
|
},
|
|
43
46
|
computed: {
|
|
44
47
|
currentIndex() {
|
|
@@ -54,24 +57,25 @@ export default {
|
|
|
54
57
|
const config = this.styleConfig || {};
|
|
55
58
|
const toRpx = (val) => (typeof val === "number" ? `${val}rpx` : val);
|
|
56
59
|
|
|
57
|
-
|
|
60
|
+
const styles = {
|
|
58
61
|
position: config.position || "fixed",
|
|
59
62
|
left: 0,
|
|
60
63
|
right: 0,
|
|
61
64
|
bottom: 0,
|
|
62
65
|
height: toRpx(config.height) || "128rpx",
|
|
63
|
-
background: config.background || "
|
|
64
|
-
borderTop: toRpx(config.borderTop) || "1rpx solid #eaeaea",
|
|
65
|
-
boxShadow: config.boxShadow || "0 -12rpx 32rpx rgba(0, 0, 0, 0.06)",
|
|
66
|
+
background: config.background || "transparent", // 匹配图片中的深色背景
|
|
66
67
|
paddingBottom: "env(safe-area-inset-bottom)", // 增加刘海屏适配
|
|
67
68
|
};
|
|
69
|
+
|
|
70
|
+
return Object.keys(styles)
|
|
71
|
+
.map((key) => `${key.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`)}: ${styles[key]}`)
|
|
72
|
+
.join("; ");
|
|
68
73
|
},
|
|
69
74
|
itemStyle() {
|
|
70
75
|
const config = this.styleConfig || {};
|
|
71
76
|
const toRpx = (val) => (typeof val === "number" ? `${val}rpx` : val);
|
|
72
77
|
|
|
73
78
|
return {
|
|
74
|
-
color: config.inactiveColor || "#7a7a7a",
|
|
75
79
|
fontSize: toRpx(config.fontSize) || "24rpx",
|
|
76
80
|
};
|
|
77
81
|
},
|
|
@@ -83,6 +87,39 @@ export default {
|
|
|
83
87
|
fontSize: toRpx(config.iconSize) || "40rpx",
|
|
84
88
|
};
|
|
85
89
|
},
|
|
90
|
+
processedTabs() {
|
|
91
|
+
const config = this.styleConfig || {};
|
|
92
|
+
const toRpx = (val) => (typeof val === "number" ? `${val}rpx` : val);
|
|
93
|
+
|
|
94
|
+
return this.tabs.map((item, index) => {
|
|
95
|
+
const isActive = this.currentIndex === index;
|
|
96
|
+
const activeColor = config.activeColor || "#9d2dff"; // 用户要求的选中颜色
|
|
97
|
+
const inactiveColor = config.inactiveColor || "#ffffff80"; // 用户要求的未选中颜色
|
|
98
|
+
const fontSize = toRpx(config.fontSize) || "24rpx";
|
|
99
|
+
const iconSize = toRpx(config.iconSize) || "40rpx";
|
|
100
|
+
|
|
101
|
+
const iconStyles = {
|
|
102
|
+
color: isActive ? activeColor : inactiveColor,
|
|
103
|
+
fontSize: iconSize,
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const labelStyles = {
|
|
107
|
+
color: isActive ? activeColor : inactiveColor,
|
|
108
|
+
fontSize: fontSize,
|
|
109
|
+
fontWeight: isActive ? config.activeWeight || "normal" : config.inactiveWeight || "normal",
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
return {
|
|
113
|
+
...item,
|
|
114
|
+
iconStyle: Object.keys(iconStyles)
|
|
115
|
+
.map((key) => `${key.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`)}: ${iconStyles[key]}`)
|
|
116
|
+
.join("; "),
|
|
117
|
+
labelStyle: Object.keys(labelStyles)
|
|
118
|
+
.map((key) => `${key.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`)}: ${labelStyles[key]}`)
|
|
119
|
+
.join("; "),
|
|
120
|
+
};
|
|
121
|
+
});
|
|
122
|
+
},
|
|
86
123
|
},
|
|
87
124
|
methods: {
|
|
88
125
|
handleSelect(index) {
|
|
@@ -99,7 +136,7 @@ export default {
|
|
|
99
136
|
console.error("switchTab failed:", err);
|
|
100
137
|
// 如果 switchTab 失败,尝试 navigateTo
|
|
101
138
|
uni.navigateTo({ url: item.link });
|
|
102
|
-
}
|
|
139
|
+
},
|
|
103
140
|
});
|
|
104
141
|
} else {
|
|
105
142
|
uni.navigateTo({
|
|
@@ -108,18 +145,12 @@ export default {
|
|
|
108
145
|
console.error("navigateTo failed:", err);
|
|
109
146
|
// 如果 navigateTo 失败,尝试 switchTab
|
|
110
147
|
uni.switchTab({ url: item.link });
|
|
111
|
-
}
|
|
148
|
+
},
|
|
112
149
|
});
|
|
113
150
|
}
|
|
114
151
|
}
|
|
115
152
|
this.$emit("change", item);
|
|
116
153
|
},
|
|
117
|
-
labelStyle(isActive) {
|
|
118
|
-
return {
|
|
119
|
-
color: isActive ? this.styleConfig.activeColor || "#409eff" : this.styleConfig.inactiveColor || "#7a7a7a",
|
|
120
|
-
fontWeight: isActive ? this.styleConfig.activeWeight || 600 : this.styleConfig.inactiveWeight || 400,
|
|
121
|
-
};
|
|
122
|
-
},
|
|
123
154
|
},
|
|
124
155
|
};
|
|
125
156
|
</script>
|
|
@@ -139,8 +170,14 @@ export default {
|
|
|
139
170
|
justify-content: center;
|
|
140
171
|
gap: 8rpx;
|
|
141
172
|
border: none;
|
|
142
|
-
background: transparent;
|
|
173
|
+
background: transparent !important;
|
|
143
174
|
cursor: pointer;
|
|
175
|
+
-webkit-tap-highlight-color: transparent;
|
|
176
|
+
/* 移除移动端点击高亮 */
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
.tabbar-item.active {
|
|
180
|
+
background: transparent !important;
|
|
144
181
|
}
|
|
145
182
|
|
|
146
183
|
.icon-text {
|