u-tabbar-item.js
3.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
"use strict";
const uni_modules_uviewPlus_components_uTabbarItem_props = require("./props.js");
const uni_modules_uviewPlus_libs_mixin_mpMixin = require("../../libs/mixin/mpMixin.js");
const uni_modules_uviewPlus_libs_mixin_mixin = require("../../libs/mixin/mixin.js");
const uni_modules_uviewPlus_libs_function_index = require("../../libs/function/index.js");
const common_vendor = require("../../../../common/vendor.js");
const _sfc_main = {
name: "u-tabbar-item",
mixins: [uni_modules_uviewPlus_libs_mixin_mpMixin.mpMixin, uni_modules_uviewPlus_libs_mixin_mixin.mixin, uni_modules_uviewPlus_components_uTabbarItem_props.props],
data() {
return {
isActive: false,
// 是否处于激活状态
parentData: {
value: null,
activeColor: "",
inactiveColor: ""
}
};
},
// 微信小程序中 options 选项
options: {
virtualHost: true
//将自定义节点设置成虚拟的,更加接近Vue组件的表现。我们不希望自定义组件的这个节点本身可以设置样式、响应 flex 布局等
},
created() {
this.init();
},
emits: ["click", "change"],
methods: {
addStyle: uni_modules_uviewPlus_libs_function_index.addStyle,
init() {
this.updateParentData();
if (!this.parent) {
uni_modules_uviewPlus_libs_function_index.error("u-tabbar-item必须搭配u-tabbar组件使用");
}
const index = this.parent.children.indexOf(this);
this.isActive = (this.name || index) === this.parentData.value;
},
updateParentData() {
this.getParentData("u-tabbar");
},
// 此方法将会被父组件u-tabbar调用
updateFromParent() {
this.init();
},
clickHandler() {
this.$nextTick(() => {
const index = this.parent.children.indexOf(this);
const name = this.name || index;
if (name !== this.parent.value) {
this.parent.$emit("change", name);
}
this.$emit("click", name);
});
}
}
};
if (!Array) {
const _easycom_u_icon2 = common_vendor.resolveComponent("u-icon");
const _easycom_u_badge2 = common_vendor.resolveComponent("u-badge");
(_easycom_u_icon2 + _easycom_u_badge2)();
}
const _easycom_u_icon = () => "../u-icon/u-icon.js";
const _easycom_u_badge = () => "../u-badge/u-badge.js";
if (!Math) {
(_easycom_u_icon + _easycom_u_badge)();
}
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
return common_vendor.e({
a: _ctx.icon
}, _ctx.icon ? {
b: common_vendor.p({
name: _ctx.icon,
color: $data.isActive ? $data.parentData.activeColor : $data.parentData.inactiveColor,
size: 20
})
} : common_vendor.e({
c: $data.isActive
}, $data.isActive ? {} : {}), {
d: common_vendor.p({
absolute: true,
offset: [0, _ctx.dot ? "34rpx" : _ctx.badge > 9 ? "14rpx" : "20rpx"],
customStyle: _ctx.badgeStyle,
isDot: _ctx.dot,
value: _ctx.badge || (_ctx.dot ? 1 : null),
show: _ctx.dot || _ctx.badge > 0
}),
e: common_vendor.t(_ctx.text),
f: $data.isActive ? $data.parentData.activeColor : $data.parentData.inactiveColor,
g: common_vendor.s($options.addStyle(_ctx.customStyle)),
h: common_vendor.o((...args) => $options.clickHandler && $options.clickHandler(...args))
});
}
const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-e01cdc2c"]]);
wx.createComponent(Component);