2024-01-16 22:53:42 +08:00

157 lines
4.6 KiB
JavaScript

var e = require("../../../../common/vendor.js"),
t = {
name: "uniCollapseItem",
props: {
title: { type: String, default: "" },
name: { type: [Number, String], default: "" },
disabled: { type: Boolean, default: !1 },
showAnimation: { type: Boolean, default: !0 },
open: { type: Boolean, default: !1 },
thumb: { type: String, default: "" },
titleBorder: { type: String, default: "auto" },
border: { type: Boolean, default: !0 },
showArrow: { type: Boolean, default: !0 },
},
data: function () {
return {
isOpen: !1,
isheight: null,
height: 0,
elId: "Uni_".concat(Math.ceil(1e6 * Math.random()).toString(36)),
nameSync: 0,
};
},
watch: {
open: function (e) {
(this.isOpen = e), this.onClick(e, "init");
},
},
updated: function (e) {
var t = this;
this.$nextTick(function () {
t.init(!0);
});
},
created: function () {
(this.collapse = this.getCollapse()),
(this.oldHeight = 0),
this.onClick(this.open, "init");
},
unmounted: function () {
(this.__isUnmounted = !0), this.uninstall();
},
mounted: function () {
this.collapse &&
("" !== this.name
? (this.nameSync = this.name)
: (this.nameSync = this.collapse.childrens.length + ""),
-1 === this.collapse.names.indexOf(this.nameSync)
? this.collapse.names.push(this.nameSync)
: console.warn("name 值 ".concat(this.nameSync, " 重复")),
-1 === this.collapse.childrens.indexOf(this) &&
this.collapse.childrens.push(this),
this.init());
},
methods: {
init: function (e) {
this.getCollapseHeight(e);
},
uninstall: function () {
var e = this;
this.collapse &&
(this.collapse.childrens.forEach(function (t, i) {
t === e && e.collapse.childrens.splice(i, 1);
}),
this.collapse.names.forEach(function (t, i) {
t === e.nameSync && e.collapse.names.splice(i, 1);
}));
},
onClick: function (e, t) {
this.disabled ||
((this.isOpen = e),
this.isOpen && this.collapse && this.collapse.setAccordion(this),
"init" !== t && this.collapse.onChange(e, this));
},
getCollapseHeight: function (t) {
var i = this,
n =
arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : 0;
e.index
.createSelectorQuery()
.in(this)
.select("#".concat(this.elId))
.fields({ size: !0 }, function (e) {
if (!(n >= 10)) {
if (!e) return n++, void i.getCollapseHeight(!1, n);
(i.height = e.height),
(i.isheight = !0),
t || i.onClick(i.isOpen, "init");
}
})
.exec();
},
getNvueHwight: function (e) {
var t = this;
dom.getComponentRect(this.$refs["collapse--hook"], function (i) {
if (i && i.result && i.size) {
if (((t.height = i.size.height), (t.isheight = !0), e)) return;
t.onClick(t.open, "init");
}
});
},
getCollapse: function () {
for (
var e =
arguments.length > 0 && void 0 !== arguments[0]
? arguments[0]
: "uniCollapse",
t = this.$parent,
i = t.$options.name;
i !== e;
) {
if (!(t = t.$parent)) return !1;
i = t.$options.name;
}
return t;
},
},
};
Array || e.resolveComponent("uni-icons")(), Math;
var i = e._export_sfc(t, [
[
"render",
function (t, i, n, o, s, l) {
return e.e(
{ a: n.thumb },
n.thumb ? { b: n.thumb } : {},
{ c: e.t(n.title), d: n.disabled ? 1 : "", e: n.showArrow },
n.showArrow
? {
f: e.p({
color: n.disabled ? "#ddd" : "#bbb",
size: "14",
type: "bottom",
}),
g: s.isOpen ? 1 : "",
h: !0 === n.showAnimation ? 1 : "",
}
: {},
{
i: e.o(function (e) {
return l.onClick(!s.isOpen);
}),
j: s.isOpen && "auto" === n.titleBorder ? 1 : "",
k: "none" !== n.titleBorder ? 1 : "",
l: s.elId,
m: s.isheight ? 1 : "",
n: n.border && s.isOpen ? 1 : "",
o: n.showAnimation ? 1 : "",
p: (s.isOpen ? s.height : 0) + "px",
}
);
},
],
]);
wx.createComponent(i);