|
@@ -1,11 +1,11 @@
|
|
|
<template>
|
|
<template>
|
|
|
<div
|
|
<div
|
|
|
class="nut-tabbar-item"
|
|
class="nut-tabbar-item"
|
|
|
- :class="{ 'nut-tabbar-item__icon--unactive': state.active != state.index }"
|
|
|
|
|
|
|
+ :class="{ 'nut-tabbar-item__icon--unactive': !active }"
|
|
|
:style="{
|
|
:style="{
|
|
|
- color: state.active == state.index ? state.activeColor : state.unactiveColor
|
|
|
|
|
|
|
+ color: active ? state.activeColor : state.unactiveColor
|
|
|
}"
|
|
}"
|
|
|
- @click="change(state.index)"
|
|
|
|
|
|
|
+ @click="change()"
|
|
|
>
|
|
>
|
|
|
<view class="nut-tabbar-item_icon-box">
|
|
<view class="nut-tabbar-item_icon-box">
|
|
|
<template v-if="!dot">
|
|
<template v-if="!dot">
|
|
@@ -33,7 +33,7 @@
|
|
|
v-if="!icon && activeImg"
|
|
v-if="!icon && activeImg"
|
|
|
class="nut-tabbar-item_icon-box_icon"
|
|
class="nut-tabbar-item_icon-box_icon"
|
|
|
:style="{
|
|
:style="{
|
|
|
- backgroundImage: `url(${state.active == state.index ? activeImg : img})`,
|
|
|
|
|
|
|
+ backgroundImage: `url(${active ? activeImg : img})`,
|
|
|
width: state.size,
|
|
width: state.size,
|
|
|
height: state.size
|
|
height: state.size
|
|
|
}"
|
|
}"
|
|
@@ -59,6 +59,9 @@ export default create({
|
|
|
type: String,
|
|
type: String,
|
|
|
default: ''
|
|
default: ''
|
|
|
},
|
|
},
|
|
|
|
|
+ name: {
|
|
|
|
|
+ type: String
|
|
|
|
|
+ },
|
|
|
icon: {
|
|
icon: {
|
|
|
// 标签页显示的icon
|
|
// 标签页显示的icon
|
|
|
type: String,
|
|
type: String,
|
|
@@ -108,14 +111,23 @@ export default create({
|
|
|
const router = useRouter();
|
|
const router = useRouter();
|
|
|
const relation = (child: ComponentInternalInstance): void => {
|
|
const relation = (child: ComponentInternalInstance): void => {
|
|
|
if (child.proxy) {
|
|
if (child.proxy) {
|
|
|
- let index = parent.children.length;
|
|
|
|
|
- state.index = index;
|
|
|
|
|
parent.children.push(child.proxy);
|
|
parent.children.push(child.proxy);
|
|
|
|
|
+ const index = computed(() => parent.children.indexOf(child.proxy));
|
|
|
|
|
+ state.index = props.name ?? index.value;
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
relation(getCurrentInstance() as ComponentInternalInstance);
|
|
relation(getCurrentInstance() as ComponentInternalInstance);
|
|
|
- function change(index: Number) {
|
|
|
|
|
- parent.changeIndex(index);
|
|
|
|
|
|
|
+ const active = computed(() => state.index === state.active);
|
|
|
|
|
+
|
|
|
|
|
+ function change() {
|
|
|
|
|
+ let key = props.name ?? state.index;
|
|
|
|
|
+ let index = null;
|
|
|
|
|
+ if (props.name) {
|
|
|
|
|
+ index = parent.children.findIndex((item: any) => {
|
|
|
|
|
+ return item.name == key;
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ parent.changeIndex(index ?? key, state.index);
|
|
|
}
|
|
}
|
|
|
const choosed = computed(() => {
|
|
const choosed = computed(() => {
|
|
|
if (parent) {
|
|
if (parent) {
|
|
@@ -125,13 +137,19 @@ export default create({
|
|
|
});
|
|
});
|
|
|
watch(choosed, (value, oldValue) => {
|
|
watch(choosed, (value, oldValue) => {
|
|
|
state.active = value;
|
|
state.active = value;
|
|
|
|
|
+ let index = value;
|
|
|
|
|
+ if (props.name) {
|
|
|
|
|
+ index = parent.children.findIndex((item: any) => {
|
|
|
|
|
+ return item.name == value;
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
setTimeout(() => {
|
|
setTimeout(() => {
|
|
|
- if (parent.children[value].href) {
|
|
|
|
|
- window.location.href = parent.children[value].href;
|
|
|
|
|
|
|
+ if (parent.children[index].href) {
|
|
|
|
|
+ window.location.href = parent.children[index].href;
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
- if (parent.children[value].to) {
|
|
|
|
|
- let to = parent.children[value].to;
|
|
|
|
|
|
|
+ if (parent.children[index].to) {
|
|
|
|
|
+ let to = parent.children[index].to;
|
|
|
if (to && router) {
|
|
if (to && router) {
|
|
|
router.push(to);
|
|
router.push(to);
|
|
|
} else {
|
|
} else {
|
|
@@ -142,6 +160,7 @@ export default create({
|
|
|
});
|
|
});
|
|
|
return {
|
|
return {
|
|
|
state,
|
|
state,
|
|
|
|
|
+ active,
|
|
|
change
|
|
change
|
|
|
};
|
|
};
|
|
|
}
|
|
}
|