- 电子药箱: 药品库存管理 + 手动录入 + 今日用药打卡 - 药品百科: 搜索 + 分类筛选 + 20种药品静态数据 - 惠教中心: 4条药品使用指南课程 - 我的: 家庭成员信息管理 - 自定义TabBar + navigation-bar组件 - SVG药品分类插图
65 lines
1.5 KiB
TypeScript
65 lines
1.5 KiB
TypeScript
// components/collapse/collapse.ts
|
|
export { }
|
|
Component({
|
|
properties: {
|
|
title: {
|
|
type: String,
|
|
value: ''
|
|
},
|
|
titleStyle: {
|
|
type: String,
|
|
value: ''
|
|
},
|
|
defaultOpen: {
|
|
type: Boolean,
|
|
value: false
|
|
},
|
|
disableOpen: {
|
|
type: Boolean,
|
|
value: false
|
|
},
|
|
offsetHeight: {
|
|
type: Number,
|
|
value: 0
|
|
}
|
|
},
|
|
|
|
data: {
|
|
open: false,
|
|
contentHeight: 0
|
|
},
|
|
|
|
lifetimes: {
|
|
ready(this: WechatMiniprogram.Component.TrivialInstance) {
|
|
this.setData({ open: this.data.defaultOpen })
|
|
this.calcHeight()
|
|
}
|
|
},
|
|
|
|
methods: {
|
|
toggle(this: WechatMiniprogram.Component.TrivialInstance) {
|
|
if (this.data.disableOpen) return;
|
|
|
|
const open = !this.data.open;
|
|
this.setData({ open }, () => {
|
|
if (open) {
|
|
// 等展开后再算高度
|
|
this.calcHeight();
|
|
}
|
|
});
|
|
},
|
|
|
|
calcHeight(this: WechatMiniprogram.Component.TrivialInstance) {
|
|
const query = this.createSelectorQuery()
|
|
query.select('#content').boundingClientRect()
|
|
query.exec(res => {
|
|
if (res && res[0]) {
|
|
this.setData({
|
|
contentHeight: res[0].height
|
|
})
|
|
}
|
|
})
|
|
}
|
|
}
|
|
})
|